Support customization of menu messages.
authorH. Peter Anvin <hpa@zytor.com>
Wed, 28 Feb 2007 06:38:10 +0000 (22:38 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 28 Feb 2007 06:38:10 +0000 (22:38 -0800)
NEWS
README.menu
com32/modules/menu.h
com32/modules/menumain.c
com32/modules/readconfig.c

diff --git a/NEWS b/NEWS
index 31847f1..3b17d5b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Changes in 3.40:
        * It is now supported to load a different configuration file
          with the CONFIG keyword.
        * Fix API call 0x0019 (Read Disk.)
+       * MENU AUTOBOOT, MENU TABMSG, MENU PASSPROMPT allows
+         internationalization of menu messages.
 
 Changes in 3.36:
        * MEMDISK: Disable EDD by default on floppy disks.  EDD can be
index fe4f909..efa7989 100644 (file)
@@ -121,6 +121,22 @@ MENU INCLUDE filename
        command, so any labels defined in it are unavailable.
 
 
+MENU AUTOBOOT message
+
+       Replaces the message "Automatic boot in # seconds".  The
+       symbol # is replaced with the number of seconds remaining.
+
+
+MENU TABMSG message
+
+       Replaces the message "Press [Tab] to edit options".
+
+
+MENU PASSPROMPT message
+
+       Replaces the message "Password required".
+
+
 MENU COLOR element ansi foreground background shadow
 
        Sets the color of element "element" to the specified color
index acdbb34..0a5808d 100644 (file)
@@ -81,6 +81,9 @@ extern char *menu_title;
 extern char *ontimeout;
 extern char *onerror;
 extern char *menu_master_passwd;
+extern char *menu_tab_msg;
+extern char *menu_autoboot_msg;
+extern char *menu_passprompt_msg;
 
 extern char *menu_background;
 
index 14e0af2..7c96a70 100644 (file)
@@ -279,7 +279,6 @@ static int mygetkey(clock_t timeout)
 static int
 ask_passwd(const char *menu_entry)
 {
-  static const char title[] = "Password required";
   char user_passwd[WIDTH], *p;
   int done;
   int key;
@@ -298,8 +297,8 @@ ask_passwd(const char *menu_entry)
     putchar('q');
 
   printf("j\017\033[%d;%dH\1#12 %s \033[%d;%dH\1#13",
-        PASSWD_ROW, (WIDTH-((int)sizeof(title)+1))/2,
-        title, PASSWD_ROW+1, PASSWD_MARGIN+3);
+        PASSWD_ROW, (WIDTH-(strlen(menu_passprompt_msg)+2))/2,
+        menu_passprompt_msg, PASSWD_ROW+1, PASSWD_MARGIN+3);
 
   /* Actually allow user to type a password, then compare to the SHA1 */
   done = 0;
@@ -392,8 +391,7 @@ draw_menu(int sel, int top, int edit_line)
   fputs("j\017", stdout);
 
   if ( edit_line && allowedit && !menu_master_passwd )
-    printf("\1#08\033[%d;1H%s", TABMSG_ROW,
-          pad_line("Press [Tab] to edit options", 1, WIDTH));
+    printf("\1#08\033[%d;1H%s", TABMSG_ROW, pad_line(menu_tab_msg, 1, WIDTH));
 
   printf("\1#00\033[%d;1H", END_ROW);
 }
@@ -629,10 +627,27 @@ run_menu(void)
       key_timeout = 0;
 
     if ( key_timeout ) {
+      char buf[256];
       int tol = timeout_left/CLK_TCK;
-      int nc = snprintf(NULL, 0, " Automatic boot in %d seconds ", tol);
-      printf("\033[%d;%dH\1#14 Automatic boot in \1#15%d\1#14 seconds ",
-            TIMEOUT_ROW, 1+((WIDTH-nc)>>1), tol);
+      int nc = 0, nnc;
+      const char *tp = menu_autoboot_msg;
+      char tc;
+      char *tq = buf;
+
+      while ((tq-buf) < (sizeof buf-16) && (tc = *tp)) {
+       if (tc == '#') {
+         nnc = sprintf(tq, "\1#15%d\1#14", tol);
+         tq += nnc;
+         nc += nnc-8;          /* 8 formatting characters */
+       } else {
+         *tq++ = tc;
+         nc++;
+       }
+       tp++;
+      }
+      *tq = '\0';
+
+      printf("\033[%d;%dH\1#14 %s ", TIMEOUT_ROW, 1+((WIDTH-nc)>>1), buf);
       to_clear = 1;
     } else {
       to_clear = 0;
index 0f9b7c6..5489c72 100644 (file)
@@ -32,12 +32,16 @@ int timeout      = 0;
 int shiftkey     = 0;          /* Only display menu if shift key pressed */
 long long totaltimeout = 0;
 
-char *menu_title  = "";
+char *menu_title  = NULL;
 char *ontimeout   = NULL;
 char *onerror     = NULL;
 
 char *menu_master_passwd = NULL;
 
+char *menu_tab_msg;
+char *menu_autoboot_msg;
+char *menu_passprompt_msg;
+
 char *menu_background = NULL;
 
 struct menu_entry menu_entries[MAX_ENTRIES];
@@ -456,6 +460,15 @@ static void parse_config_file(FILE *f)
        if (menu_background)
          free(menu_background);
        menu_background = dup_word(&p);
+      } else if ( (ep = looking_at(p, "autoboot")) ) {
+       free(menu_autoboot_msg);
+       menu_autoboot_msg = strdup(skipspace(ep));
+      } else if ( (ep = looking_at(p, "tabmsg")) ) {
+       free(menu_tab_msg);
+       menu_tab_msg = strdup(skipspace(ep));
+      } else if ( (ep = looking_at(p, "passprompt")) ) {
+       free(menu_passprompt_msg);
+       menu_passprompt_msg = strdup(skipspace(ep));
       } else if ((ep = looking_at(p, "color")) ||
                 (ep = looking_at(p, "colour"))) {
        int i;
@@ -576,8 +589,19 @@ void parse_configs(char **argv)
 {
   const char *filename;
 
+  /* Initialize defaults */
+
+  menu_title = strdup("");
+  menu_tab_msg = strdup("Press [Tab] to edit options");
+  menu_autoboot_msg = strdup("Automatic boot in # sections");
+  menu_passprompt_msg = strdup("Password required");
+
+  /* Other initialization */
+
   get_ipappend();
 
+  /* Actually process the files */
+
   if ( !*argv ) {
     parse_one_config("~");
   } else {