From 16e10d1a3dc3717945e9381b5c723c5f8b9a266b Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 10 Sep 2004 03:49:18 +0000 Subject: [PATCH] * Added 'dialog' mode to setup --- webcit/ChangeLog | 4 ++- webcit/setup.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/webcit/ChangeLog b/webcit/ChangeLog index c1dcd939c..f9b6898cd 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,7 @@ $Log$ +Revision 523.2 2004/09/10 03:49:17 ajc +* Added 'dialog' mode to setup + Revision 523.1 2004/08/31 20:31:01 ajc * When saving VTODO (tasks), insert a UID if none is already present. Also increment the sequence, or insert one if none is already present. @@ -2040,4 +2043,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/setup.c b/webcit/setup.c index 4478728c6..70fab6827 100644 --- a/webcit/setup.c +++ b/webcit/setup.c @@ -31,6 +31,7 @@ #define UI_TEXT 0 /* Default setup type -- text only */ +#define UI_DIALOG 2 /* Use the 'dialog' program */ #define UI_SILENT 3 /* Silent running, for use in scripts */ #define UI_NEWT 4 /* Use the "newt" window library */ @@ -108,7 +109,7 @@ void shutdown_service(void) { strcpy(init_entry, ""); /* Determine the fully qualified path name of webserver */ - snprintf(looking_for, sizeof looking_for, "%s/webserver ", WEBCITDIR); + snprintf(looking_for, sizeof looking_for, "%s/webserver ", setup_directory); /* Pound through /etc/inittab line by line. Set have_entry to 1 if * an entry is found which we believe starts webserver. @@ -175,8 +176,8 @@ int yesno(char *question) newtComponent form = NULL; newtComponent yesbutton = NULL; newtComponent nobutton = NULL; - int i = 0; #endif + int i = 0; int answer = 0; char buf[SIZ]; @@ -194,6 +195,19 @@ int yesno(char *question) } while ((answer < 0) || (answer > 1)); break; + case UI_DIALOG: + sprintf(buf, "exec %s --yesno '%s' 10 72", + getenv("CTDL_DIALOG"), + question); + i = system(buf); + if (i == 0) { + answer = 1; + } + else { + answer = 0; + } + break; + #ifdef HAVE_NEWT case UI_NEWT: newtCenteredWindow(76, 10, "Question"); @@ -230,7 +244,9 @@ void set_value(char *prompt, char str[]) int i; #endif char buf[SIZ]; + char *dialog_result; char setupmsg[SIZ]; + FILE *fp; strcpy(setupmsg, ""); @@ -245,6 +261,27 @@ void set_value(char *prompt, char str[]) if (strlen(buf) != 0) strcpy(str, buf); break; + + case UI_DIALOG: + dialog_result = tmpnam(NULL); + sprintf(buf, "exec %s --backtitle '%s' --inputbox '%s' 19 72 '%s' 2>%s", + getenv("CTDL_DIALOG"), + "WebCit setup", + prompt, + str, + dialog_result); + system(buf); + fp = fopen(dialog_result, "r"); + if (fp != NULL) { + fgets(str, sizeof buf, fp); + if (str[strlen(str)-1] == 10) { + str[strlen(str)-1] = 0; + } + fclose(fp); + unlink(dialog_result); + } + break; + #ifdef HAVE_NEWT case UI_NEWT: @@ -284,6 +321,14 @@ void important_message(char *title, char *msgtext) fgets(buf, sizeof buf, stdin); break; + case UI_DIALOG: + sprintf(buf, "exec %s --backtitle '%s' --msgbox '%s' 19 72", + getenv("CTDL_DIALOG"), + title, + msgtext); + system(buf); + break; + #ifdef HAVE_NEWT case UI_NEWT: newtCenteredWindow(76, 10, title); @@ -322,6 +367,8 @@ void progress(char *text, long int curr, long int cmax) #endif static long dots_printed = 0L; long a = 0; + char buf[SIZ]; + static FILE *fp = NULL; switch (setup_type) { @@ -347,6 +394,33 @@ void progress(char *text, long int curr, long int cmax) } break; + case UI_DIALOG: + if (curr == 0) { + sprintf(buf, "exec %s --gauge '%s' 7 72 0", + getenv("CTDL_DIALOG"), + text); + fp = popen(buf, "w"); + if (fp != NULL) { + fprintf(fp, "0\n"); + fflush(fp); + } + } + else if (curr == cmax) { + if (fp != NULL) { + fprintf(fp, "100\n"); + pclose(fp); + fp = NULL; + } + } + else { + a = (curr * 100) / cmax; + if (fp != NULL) { + fprintf(fp, "%ld\n", a); + fflush(fp); + } + } + break; + #ifdef HAVE_NEWT case UI_NEWT: if (curr == 0) { @@ -392,7 +466,7 @@ void check_inittab_entry(void) char portname[128]; /* Determine the fully qualified path name of webserver */ - snprintf(looking_for, sizeof looking_for, "%s/webserver ", WEBCITDIR); + snprintf(looking_for, sizeof looking_for, "%s/webserver", setup_directory); /* If there's already an entry, then we have nothing left to do. */ if (strlen(init_entry) > 0) { @@ -494,6 +568,11 @@ void check_inittab_entry(void) int discover_ui(void) { + /* Use "dialog" if we have it */ + if (getenv("CTDL_DIALOG") != NULL) { + return UI_DIALOG; + } + #ifdef HAVE_NEWT newtInit(); newtCls(); -- 2.39.2