/* -*-c-*-
*
- * $Id: xgetline.c,v 1.2 1998/11/18 21:25:30 mdw Exp $
+ * $Id: xgetline.c,v 1.6 1998/12/03 00:56:29 mdw Exp $
*
* Fetch a line of text from the user
*
/*----- Revision history --------------------------------------------------*
*
* $Log: xgetline.c,v $
+ * Revision 1.6 1998/12/03 00:56:29 mdw
+ * Set focus on the entry field, rather than leaving things to luck.
+ *
+ * Revision 1.5 1998/12/03 00:39:44 mdw
+ * Force focus when starting up.
+ *
+ * Revision 1.4 1998/11/30 22:36:47 mdw
+ * Tidy up tabbing in help texts very slightly.
+ *
+ * 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.
*
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "mdwfocus.h"
#include "mdwopt.h"
+#include "quis.h"
/*----- Main code ---------------------------------------------------------*/
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
* parser would barf about.
*/
+ ego(argv[0]);
gtk_init(&argc, &argv);
/* --- Parse options from command line --- */
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' },
/* --- 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\t 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;
}
if (f & f_duff) {
- fprintf(stderr, "xgetline: bad arguments\n");
+ usage(stderr);
exit(EXIT_FAILURE);
}
/* --- Go go go --- */
+ gtk_widget_realize(win);
+ mdwfocus(win);
+ gtk_widget_grab_focus(entry);
gtk_widget_show(win);
gtk_main();