X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/642e1d683b654aa7115e2ed815940c1fd7da0206..f3b35b6bbd646fb0e676ef3d64c91b38ff9f9162:/xscsize.c diff --git a/xscsize.c b/xscsize.c index ace018e..93cac68 100644 --- a/xscsize.c +++ b/xscsize.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xscsize.c,v 1.1 1998/11/16 23:00:49 mdw Exp $ + * $Id: xscsize.c,v 1.2 1998/11/21 22:30:22 mdw Exp $ * * Return X display size to shell script * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: xscsize.c,v $ + * Revision 1.2 1998/11/21 22:30:22 mdw + * Support GNU-style long options throughout, and introduce proper help + * text to all programs. Update manual pages to match. + * * Revision 1.1 1998/11/16 23:00:49 mdw * Initial versions. * @@ -40,11 +44,23 @@ #include #include -#include #include +#include "mdwopt.h" +#include "quis.h" + /*----- Main code ---------------------------------------------------------*/ +static void version(FILE *fp) +{ + fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); +} + +static void usage(FILE *fp) +{ + fprintf(fp, "Usage: %s [-bcx] [-d display]\n", QUIS); +} + int main(int argc, char *argv[]) { const char *display = 0; @@ -60,11 +76,56 @@ int main(int argc, char *argv[]) /* --- Parse command line options --- */ + ego(argv[0]); + for (;;) { - int i = getopt(argc, argv, "d:bcx"); + static struct option opt[] = { + { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, + { "display", required_argument, 0, 'd' }, + { "bourne-shell", 0, 0, 'b' }, + { "c-shell", 0, 0, 'c' }, + { "export", 0, 0, 'x' }, + { 0, 0, 0, 0 } + }; + + int i = getopt_long(argc, argv, "huv d:bcx", opt, 0); if (i < 0) break; switch (i) { + case 'h': + version(stdout); + fputs("\n", stdout); + usage(stdout); + fputs( +"\n" +"Reads the size of the X root window and outputs it in a form suitable\n" +"for use as a shell assignment statement, defining variables XWIDTH and\n" +"XHEIGHT.\n" +"\n" +"Options:\n" +"\n" +"-h, --help Display this help text\n" +"-u, --usage Display a short usage summary\n" +"-v, --version Display the program's version number\n" +"\n" +"-d, --display=DISPLAY Choose X display to connect to\n" +"-b, --bourne-shell Output text suitable for a Bourne shell\n" +"-c, --c-shell Output text suitable for a C shell\n" +"-x, --export Export the variables into the environment\n", + stdout); + exit(0); + break; + case 'u': + usage(stdout); + exit(0); + break; + case 'v': + version(stdout); + exit(0); + break; + case 'd': display = optarg; break; @@ -78,7 +139,7 @@ int main(int argc, char *argv[]) f |= f_export; break; default: - fprintf(stderr, "Usage: xscsize [-bcx] [-d DISPLAY]\n"); + usage(stderr); exit(EXIT_FAILURE); break; }