/* -*-c-*-
*
- * $Id: xgetline.c,v 1.7 1998/12/11 09:53:02 mdw Exp $
+ * $Id: xgetline.c,v 1.13 2004/04/08 01:36:29 mdw Exp $
*
* Fetch a line of text from the user
*
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-/*----- Revision history --------------------------------------------------*
- *
- * $Log: xgetline.c,v $
- * Revision 1.7 1998/12/11 09:53:02 mdw
- * Updates for mLib/mgLib. Support history files for recalling past
- * entries, using a drop-down list.
- *
- * 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.
- *
- * Revision 1.1 1998/11/16 23:00:49 mdw
- * Initial versions.
- *
- */
-
/*----- Header files ------------------------------------------------------*/
#include <stdio.h>
const char *list = 0;
int histmax = 20;
- GList *hist;
+ GList *hist = 0;
- enum {
- f_invis = 1,
- f_duff = 2,
- f_history = 4,
- f_nochoice = 8
- };
+#define f_invis 1u
+#define f_duff 2u
+#define f_history 4u
+#define f_nochoice 8u
/* --- User interface bits --- */
/* --- Long options structure --- */
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' },
- { "password", 0, 0, 'i' },
- { "invisible", 0, 0, 'i' },
- { "history", required_argument, 0, 'H' },
- { "list", required_argument, 0, 'l' },
- { "histmax", required_argument, 0, 'm' },
- { "no-choice", 0, 0, 'n' },
- { 0, 0, 0, 0 }
+ { "help", 0, 0, 'h' },
+ { "usage", 0, 0, 'u' },
+ { "version", 0, 0, 'v' },
+ { "title", OPTF_ARGREQ, 0, 't' },
+ { "prompt", OPTF_ARGREQ, 0, 'p' },
+ { "default", OPTF_ARGREQ, 0, 'd' },
+ { "password", 0, 0, 'i' },
+ { "invisible", 0, 0, 'i' },
+ { "history", OPTF_ARGREQ, 0, 'H' },
+ { "list", OPTF_ARGREQ, 0, 'l' },
+ { "histmax", OPTF_ARGREQ, 0, 'm' },
+ { "no-choice", 0, 0, 'n' },
+ { 0, 0, 0, 0 }
};
int i;
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"
-"\n"
-"-l, --list=FILE Read FILE into a drop-down list\n"
-"-n, --no-choice No free text input: must choose item from list\n"
-"-H, --history=FILE As for `--list', but update with new string\n"
-"-m, --histmax=MAX Maximum number of items written back to file\n",
+ 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\
+\n\
+-l, --list=FILE Read FILE into a drop-down list\n\
+-n, --no-choice No free text input: must choose item from list\n\
+-H, --history=FILE As for `--list', but update with new string\n\
+-m, --histmax=MAX Maximum number of items written back to file\n",
stdout);
exit(0);
break;
* Inability to open the file is not a disaster.
*/
- hist = 0;
if (fp) {
- dstr d;
+ dstr d = DSTR_INIT;
- dstr_create(&d);
while (dstr_putline(&d, fp) != EOF) {
hist = g_list_append(hist, xstrdup(d.buf));
- dstr_destroy(&d);
+ DRESET(&d);
}
+ dstr_destroy(&d);
fclose(fp);
}
}
gtk_combo_set_case_sensitive(GTK_COMBO(combo), 1);
gtk_combo_set_use_arrows_always(GTK_COMBO(combo), 1);
+ gtk_combo_disable_activate(GTK_COMBO(combo));
if (strcmp(dfl, "@") == 0)
gtk_entry_set_text(GTK_ENTRY(entry), hist ? (char *)hist->data : "");
else
/* --- If history is enabled, output a new history file --- *
*
- * If the first entry was accepted verbatim, don't bother.
+ * If the first entry was accepted verbatim, or if the entry is a blank
+ * line, don't bother.
*/
- if (f & f_history && !(hist && strcmp(p, hist->data) == 0)) {
+ if (f & f_history && *p && !(hist && strcmp(p, hist->data) == 0)) {
int fd;
FILE *fp;
int i;
fputc('\n', fp);
for (i = 1, g = hist; (histmax < 1 || i < histmax) && g; g = g->next) {
- if (strcmp(g->data, p) != 0) {
+ if (*(char *)g->data && strcmp(g->data, p) != 0) {
fputs(g->data, fp);
fputc('\n', fp);
i++;