Remove ENABLE_NLS definition. Either we HAVE_USELOCALE or we don't translate at...
[citadel.git] / webcit / setup.c
index 25690cee12f21c00b65167f6dbc61deef9739b2d..f4653dcac0563304ce5d32be7b594e13acce5627 100644 (file)
@@ -1,10 +1,7 @@
 /*
- * $Id$
- *
  * WebCit setup utility
  * 
  * (This is basically just an install wizard.  It's not required.)
- *
  */
 
 #include "sysdep.h"
@@ -21,6 +18,23 @@ char setup_directory[SIZ];
 int using_web_installer = 0;
 char suggested_url[SIZ];
 
+/* some copies... 
+int syslog(int loglevel, const char *format, ...){return 0;} */
+void wc_printf(const char *format,...){}
+
+void RegisterNS(const char *NSName, long len, 
+               int nMinArgs, 
+               int nMaxArgs, 
+               WCHandlerFunc HandlerFunc,
+               WCPreevalFunc PreEvalFunc,
+               int ContextRequired){}
+void RegisterHeaderHandler(const char *Name, long Len, Header_Evaluator F){}
+pthread_key_t MyConKey;
+
+#ifdef HAVE_USELOCALE 
+int localeoffset = 1;
+#endif
+
 /*
  * Delete an entry from /etc/inittab
  */
@@ -142,7 +156,7 @@ int yesno(char *question, int default_value)
 {
        int i = 0;
        int answer = 0;
-       char buf[SIZ];
+       char buf[SIZ] = "";
 
        switch (setup_type) {
 
@@ -152,14 +166,17 @@ int yesno(char *question, int default_value)
                                question,
                                ( default_value ? "Yes" : "No" )
                        );
-                       fgets(buf, sizeof buf, stdin);
-                       answer = tolower(buf[0]);
-                       if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
-                               answer = default_value;
-                       else if (answer == 'y')
-                               answer = 1;
-                       else if (answer == 'n')
-                               answer = 0;
+                       if (fgets(buf, sizeof buf, stdin))
+                       {
+                               answer = tolower(buf[0]);
+                               if ((buf[0]==0) || (buf[0]==13) || (buf[0]==10))
+                                       answer = default_value;
+                               else if (answer == 'y')
+                                       answer = 1;
+                               else if (answer == 'n')
+                                       answer = 0;
+                       }
+
                } while ((answer < 0) || (answer > 1));
                break;
 
@@ -186,7 +203,7 @@ int yesno(char *question, int default_value)
 
 void set_value(char *prompt, char str[])
 {
-       char buf[SIZ];
+       char buf[SIZ] = "";
        char dialog_result[PATH_MAX];
        char setupmsg[SIZ];
        FILE *fp;
@@ -199,12 +216,12 @@ void set_value(char *prompt, char str[])
                printf("\n%s\n", prompt);
                printf("This is currently set to:\n%s\n", str);
                printf("Enter new value or press return to leave unchanged:\n");
-               fgets(buf, sizeof buf, stdin);
-               buf[strlen(buf) - 1] = 0;
+               if (fgets(buf, sizeof buf, stdin)) {
+                       buf[strlen(buf) - 1] = 0;
+               }
                if (strlen(buf) != 0)
                        strcpy(str, buf);
                break;
-
        case UI_DIALOG:
                CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
                sprintf(buf, "exec %s --inputbox '%s' 19 72 '%s' 2>%s",
@@ -215,9 +232,10 @@ void set_value(char *prompt, char str[])
                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;
+                       if (fgets(str, sizeof buf, fp)){
+                               if (str[strlen(str)-1] == 10) {
+                                       str[strlen(str)-1] = 0;
+                               }
                        }
                        fclose(fp);
                        unlink(dialog_result);
@@ -228,6 +246,69 @@ void set_value(char *prompt, char str[])
 }
 
 
+extern const char *AvailLang[];
+int GetLocalePrefs(void)
+{
+       int nLocales;
+       StrBuf *Buf;
+       char buf[SIZ];
+       char dialog_result[PATH_MAX];
+       FILE *fp;
+       int i = 0;
+       int offs = 0;
+
+       nLocales = 0; 
+       while (!IsEmptyStr(AvailLang[nLocales]))
+               nLocales++;
+
+       Buf = NewStrBuf();
+
+       StrBufAppendBufPlain(Buf, HKEY("Select the locale webcit should use : \n"), 0);
+#ifdef HAVE_USELOCALE 
+       StrBufAppendBufPlain(Buf, HKEY(" 0 Let the user select it at the login prompt (default)\n"), 0);
+       offs ++;
+#endif
+       for (i = 0; i < nLocales; i++) {
+               StrBufAppendPrintf(Buf, " %ld: %s\n", i + offs, AvailLang[i]);
+
+       }
+
+       switch (setup_type) {
+       case UI_TEXT:
+               title("WebCit setup");
+               printf("\n%s\n", ChrPtr(Buf));
+               printf("This is currently set to:\n%ld\n", 0L);
+               printf("Enter new value or press return to leave unchanged:\n");
+               if (fgets(buf, sizeof buf, stdin))
+                       return atoi(buf);
+               break;
+
+       case UI_DIALOG:
+               CtdlMakeTempFileName(dialog_result, sizeof dialog_result);
+               sprintf(buf, "exec %s --inputbox '%s' 19 72 '%ld' 2>%s",
+                       getenv("CTDL_DIALOG"),
+                       ChrPtr(Buf),
+                       0L,
+                       dialog_result);
+               system(buf);
+               fp = fopen(dialog_result, "r");
+               if (fp != NULL) {
+                       char *str = &buf[0];
+                       if (fgets(str, sizeof buf, fp)){
+                               if (str[strlen(str)-1] == 10) {
+                                       str[strlen(str)-1] = 0;
+                               }
+                       }
+                       fclose(fp);
+                       unlink(dialog_result);
+                       return atoi(buf);
+               }
+               break;
+
+       }
+       return 0;
+}
+
 void important_message(char *title, char *msgtext)
 {
        char buf[SIZ];
@@ -238,7 +319,7 @@ void important_message(char *title, char *msgtext)
                printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
                printf("       %s \n\n%s\n\n", title, msgtext);
                printf("Press return to continue...");
-               fgets(buf, sizeof buf, stdin);
+               if (fgets(buf, sizeof buf, stdin));
                break;
 
        case UI_DIALOG:
@@ -325,6 +406,9 @@ void progress(char *text, long int curr, long int cmax)
  */
 void install_init_scripts(void)
 {
+#ifdef HAVE_USELOCALE
+       int localechoice;
+#endif
        char question[1024];
        char buf[256];
        char http_port[128];
@@ -342,7 +426,7 @@ void install_init_scripts(void)
        fp = fopen(initfile, "r");
        if (fp != NULL) {
                if (yesno("WebCit already appears to be configured to start at boot.\n"
-                  "Would you like to keep your boot configuration as is?\n", 1) == 1) {
+                         "Would you like to keep your boot configuration as is?\n", 1) == 1) {
                        return;
                }
                fclose(fp);
@@ -351,11 +435,15 @@ void install_init_scripts(void)
 
        /* Otherwise, prompt the user to create an entry. */
        snprintf(question, sizeof question,
-               "Would you like to automatically start WebCit at boot?"
-       );
+                "Would you like to automatically start WebCit at boot?"
+               );
        if (yesno(question, 1) == 0)
                return;
 
+
+#ifdef HAVE_USELOCALE
+       localechoice = GetLocalePrefs();
+#endif
        /* Defaults */
        sprintf(http_port, "2000");
 #ifdef HAVE_OPENSSL
@@ -404,20 +492,20 @@ void install_init_scripts(void)
 
        /* Now ask for the port numbers */
        snprintf(question, sizeof question,
-               "On which port do you want WebCit to listen for HTTP "
-               "requests?\n\nYou can use the standard port (80) if you are "
-               "not running another\nweb server (such as Apache), otherwise "
-               "select another port.");
+                "On which port do you want WebCit to listen for HTTP "
+                "requests?\n\nYou can use the standard port (80) if you are "
+                "not running another\nweb server (such as Apache), otherwise "
+                "select another port.");
        set_value(question, http_port);
        uname(&my_utsname);
        sprintf(suggested_url, "http://%s:%s/", my_utsname.nodename, http_port);
 
 #ifdef HAVE_OPENSSL
        snprintf(question, sizeof question,
-               "On which port do you want WebCit to listen for HTTPS "
-               "requests?\n\nYou can use the standard port (443) if you are "
-               "not running another\nweb server (such as Apache), otherwise "
-               "select another port.");
+                "On which port do you want WebCit to listen for HTTPS "
+                "requests?\n\nYou can use the standard port (443) if you are "
+                "not running another\nweb server (such as Apache), otherwise "
+                "select another port.");
        set_value(question, https_port);
 #endif
 
@@ -428,7 +516,7 @@ void install_init_scripts(void)
        }
        else {
                snprintf(question, sizeof question,
-                       "Is the Citadel service running on the same host as WebCit?");
+                        "Is the Citadel service running on the same host as WebCit?");
                if (yesno(question, ((!strcasecmp(hostname, "uds")) ? 1 : 0))) {
                        strcpy(hostname, "uds");
                        if (atoi(portname) != 0) strcpy(portname, "/usr/local/citadel");
@@ -438,9 +526,9 @@ void install_init_scripts(void)
                        if (!strcasecmp(hostname, "uds")) strcpy(hostname, "127.0.0.1");
                        if (atoi(portname) == 0) strcpy(portname, "504");
                        set_value("Enter the host name or IP address of your "
-                               "Citadel server.", hostname);
+                                 "Citadel server.", hostname);
                        set_value("Enter the port number on which Citadel is "
-                               "running (usually 504)", portname);
+                                 "running (usually 504)", portname);
                }
        }
 
@@ -448,7 +536,10 @@ void install_init_scripts(void)
        fp = fopen(initfile, "w");
 
        fprintf(fp,     "#!/bin/sh\n"
-                       "\n"
+               "\n"
+               "# uncomment this to create coredumps as described in\n"
+               "# http://www.citadel.org/doku.php/faq:mastering_your_os:gdb#how.do.i.make.my.system.produce.core-files\n"
+               "# ulimit -c unlimited\n"
                        "WEBCIT_DIR=%s\n", setup_directory);
        fprintf(fp,     "HTTP_PORT=%s\n", http_port);
 #ifdef HAVE_OPENSSL
@@ -456,6 +547,19 @@ void install_init_scripts(void)
 #endif
        fprintf(fp,     "CTDL_HOSTNAME=%s\n", hostname);
        fprintf(fp,     "CTDL_PORTNAME=%s\n", portname);
+
+#ifdef HAVE_USELOCALE 
+       if (localechoice == 0) {
+               fprintf(fp, "export WEBCIT_LANG=%s\n", AvailLang[localechoice - localeoffset]);
+       }
+#else
+       fprintf(fp,     "# your system doesn't support locales\n");
+#endif
+
+
+
+
+
        fprintf(fp,     "\n"
                        "\n"
                        "case \"$1\" in\n"
@@ -547,6 +651,7 @@ int main(int argc, char *argv[])
        int a;
        char aaa[256];
        int info_only = 0;
+
        strcpy(suggested_url, "http://<your_host_name>:<port>/");
 
        /* set an invalid setup type */