X-Git-Url: https://git.distorted.org.uk/~mdw/xtoys/blobdiff_plain/642e1d683b654aa7115e2ed815940c1fd7da0206..f3b35b6bbd646fb0e676ef3d64c91b38ff9f9162:/xgetline.c diff --git a/xgetline.c b/xgetline.c index 2647772..e05bc22 100644 --- a/xgetline.c +++ b/xgetline.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: xgetline.c,v 1.2 1998/11/18 21:25:30 mdw Exp $ + * $Id: xgetline.c,v 1.3 1998/11/21 22:30:20 mdw Exp $ * * Fetch a line of text from the user * @@ -29,6 +29,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: xgetline.c,v $ + * Revision 1.3 1998/11/21 22:30:20 mdw + * Support GNU-style long options throughout, and introduce proper help + * text to all programs. Update manual pages to match. + * * Revision 1.2 1998/11/18 21:25:30 mdw * Remove bogus `-h' option from the options list. * @@ -47,6 +51,7 @@ #include #include "mdwopt.h" +#include "quis.h" /*----- Main code ---------------------------------------------------------*/ @@ -107,6 +112,34 @@ static gboolean check_escape(GtkWidget *w, GdkEventKey *ev, gpointer *p) return (0); } +/* --- @version@ --- * + * + * Arguments: @FILE *fp@ = output stream to print the message on + * + * Returns: --- + * + * Use: Spits out a version message. + */ + +static void version(FILE *fp) +{ + fprintf(fp, "%s (xtoys version " VERSION ")\n", QUIS); +} + +/* --- @usage@ --- * + * + * Arguments: @FILE *fp@ = output stream to print the message on + * + * Returns: --- + * + * Use: Spits out a usage message. + */ + +static void usage(FILE *fp) +{ + fprintf(fp, "Usage: %s [-i] [-t title] [-p prompt] [-d default]\n", QUIS); +} + /* --- @main@ --- * * * Arguments: @int argc@ = number of command line arguments @@ -148,6 +181,7 @@ int main(int argc, char *argv[]) * parser would barf about. */ + ego(argv[0]); gtk_init(&argc, &argv); /* --- Parse options from command line --- */ @@ -158,6 +192,8 @@ int main(int argc, char *argv[]) static struct option opt[] = { { "help", 0, 0, 'h' }, + { "usage", 0, 0, 'u' }, + { "version", 0, 0, 'v' }, { "title", required_argument, 0, 't' }, { "prompt", required_argument, 0, 'p' }, { "default", required_argument, 0, 'd' }, @@ -169,13 +205,44 @@ int main(int argc, char *argv[]) /* --- Fetch an option --- */ - i = getopt_long(argc, argv, "t:p:d:i", opt, 0); + i = getopt_long(argc, argv, "huv t:p:d:i", opt, 0); if (i < 0) break; /* --- Work out what to do with it --- */ switch (i) { + case 'h': + version(stdout); + fputs("\n", stdout); + usage(stdout); + fputs( +"\n" +"Pops up a small window requesting input from a user, and echoes the\n" +"response to stdout, where it can be collected by a shell script.\n" +"\n" +"Options available are:\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" +"-i, --invisible Don't show the user's string as it's typed\n" +"-t, --title=TITLE Set the window's title string\n" +"-p, --prompt=PROMPT Set the window's prompt string\n" +"-d, --default=DEFAULT Set the default string already in the window\n", + stdout); + exit(0); + break; + case 'u': + usage(stdout); + exit(0); + break; + case 'v': + version(stdout); + exit(0); + break; + case 't': title = optarg; break; @@ -195,7 +262,7 @@ int main(int argc, char *argv[]) } if (f & f_duff) { - fprintf(stderr, "xgetline: bad arguments\n"); + usage(stderr); exit(EXIT_FAILURE); }