New file: mdwfocus.c
[xtoys] / xgetline.c
index 1da9ed1..ed621ae 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: xgetline.c,v 1.1 1998/11/16 23:00:49 mdw Exp $
+ * $Id: xgetline.c,v 1.4 1998/11/30 22:36:47 mdw Exp $
  *
  * Fetch a line of text from the user
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: xgetline.c,v $
+ * 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.
+ *
  * Revision 1.1  1998/11/16 23:00:49  mdw
  * Initial versions.
  *
@@ -44,6 +54,7 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "mdwopt.h"
+#include "quis.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -104,6 +115,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
@@ -145,6 +184,7 @@ int main(int argc, char *argv[])
    * parser would barf about.
    */   
 
+  ego(argv[0]);
   gtk_init(&argc, &argv);
 
   /* --- Parse options from command line --- */
@@ -155,6 +195,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' },
@@ -166,13 +208,44 @@ int main(int argc, char *argv[])
 
     /* --- Fetch an option --- */
 
-    i = getopt_long(argc, argv, "ht: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;
@@ -192,7 +265,7 @@ int main(int argc, char *argv[])
   }
 
   if (f & f_duff) {
-    fprintf(stderr, "xgetline: bad arguments\n");
+    usage(stderr);
     exit(EXIT_FAILURE);
   }