[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#136312: marked as done (boot-floppies: Support list of languages to use like glibc LANGUAGE varialbe)



Your message dated Mon, 04 Dec 2006 21:04:55 +0000
with message-id <1165266295.27634.4.camel@kaa.jungle.aubergine.my-net-space.net>
and subject line Un-reopening
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: boot-floppies
Version: N/A - current CVS
Severity: wishlist

I'm working on fixes for base-config, and in the process I thought it
is smart to change dbootstrap to be able to us the lang->msgcat
content the same way as the LANGUAGE environment is handled by libc,
ie as a colon separated list of langauges to try.  It is very relevant
for Norwegian, where Bokmål and Nynorsk is very similar, and very
similar to Danish and Swedish, and it would be better to use any of
these instead of English.

The following patch changes how the msgcat string is used.  It is
relative to the current anonymous CVS version.

 - Avoid code duplication in main.c, and standardize how the messages
   catalog file is loaded.  Allow the language code string to be a colon
   separated list.
 - Modify boxChooseLanguageVariant() accept a list of language codes
 - Change release_notes.c to use the same code path with and without
   the language chooser.  Make it accept a list of language codes.
 - In util.c, allow a language list when choosing download host.
 - in norwegian.src, demonstrate how this new list should be used for
   Norwegian bokmål and nynorsk.

Index: main.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/main.c,v
retrieving revision 1.142
diff -u -3 -p -u -r1.142 main.c
--- main.c	2002/02/27 19:42:50	1.142
+++ main.c	2002/03/01 13:25:59
@@ -710,6 +710,65 @@ static void check_proc (void) {
     	exit(1);
     }
 }
+/*
+ * Try to load all the languages specified by the colon separated
+ * priority list of langauge codes.  Fall back to messages.en,
+ * messages.trm and the TRMBACKUP catalog if none of the languages in
+ * the list works.
+ *
+ * Return true (1) if successfull and false (0) if unable to load any
+ * of the languages.
+ */
+int load_msgcat(char *list) {
+  char *msgcat = (char *)malloc (PATH_MAX);
+  char *languagelist = strdup(list);
+  char *language = NULL;
+  for ( language = strtok(languagelist, ":");
+	language && *language;
+	language = strtok(NULL, ":") )
+  {
+    snprintf (msgcat, PATH_MAX, "/etc/messages.%s", language);
+    msgcat[PATH_MAX - 1] = '\0';
+    DEBUGMSG ("i18n mode, trying to load message catalog %s", msgcat);
+    if ( LOAD_TRMFILE (msgcat) == 0) /* Succeded ? */
+    {
+      free(languagelist);
+      free (msgcat);
+      return 0;
+    }
+  }	
+  free(languagelist);
+  languagelist = NULL;
+
+  free (msgcat);
+  msgcat = NULL;
+
+  /* Try to load english, and the backup catalogs as well*/
+  if ( LOAD_TRMFILE("/etc/messages.en") != 0 ||
+       LOAD_TRMFILE("/etc/messages.trm") != 0 ||
+       LOAD_TRMFILE(TRMBACKUP) != 0 )
+  {
+    char message[255];
+
+    snprintf (message, sizeof (message),
+	      "An error occured while loading localized application messages from '%s'. English messages will be used instead.",
+	      lang->msgcat);
+    message[254] = '\0'; /* Just in case */
+	      
+    problemBoxEn (message, "Problem");
+    return 0;
+  }
+  return 1;
+}
+
+void reboot_missing_messages(void) {
+  problemBoxEn ("An error occurred while loading application messages",
+		"Problem");
+  reboot(RB_AUTOBOOT);
+  /* when not root and debugging */
+  boxFinished();
+  exit(1); 
+}
 
 int main (void) {
     char *term;
@@ -795,31 +854,11 @@ int main (void) {
 	  do {
 	    lang = boxChooseLanguageVariant (langs);
 	  } while (lang == NULL);
-	  snprintf (msgcat, PATH_MAX, "/etc/messages.%s", lang->msgcat);
-	  msgcat[PATH_MAX - 1] = '\0';
-	  DEBUGMSG ("loading message catalog %s", msgcat);
-	  
-	  if (LOAD_TRMFILE (msgcat) == 0)         /* Failed to load localized strings? */
-	  {
-	    if (LOAD_TRMFILE (TRMBACKUP) == 0)  /* Failed to load English strings as well? */
-            {
-	      problemBoxEn ("An error occured while loading application messages.", "Problem");
-	      
-	      reboot (RB_AUTOBOOT);
-	      
-	      /* when not root and debugging */
-	      boxFinished();
-	      exit(1); 
-	    }
-	    else
-	    {
-	      char message[255];
 
-	      snprintf (message, sizeof (message), "An error occured while loading localized application messages from '%s'. English messages will be used instead.", msgcat);
-	      message[254] = '\0'; /* Just in case */
-	      
-	      problemBoxEn (message, "Problem");
-	    }
+	  /* Get colon separated priority list of language codes
+	     (message catalogs) to use. */
+	  if ( load_msgcat(lang->msgcat) == 0 ) {    /* Failed to load localized strings? */
+	    reboot_missing_messages();
 	  }
 	} else {
 	  /* Try to force the language to English */
@@ -831,21 +870,10 @@ int main (void) {
 	  }
 	  lang = langs->list->items[0].p;
 
-	  snprintf (msgcat, PATH_MAX, "/etc/messages.%s", lang->msgcat);
-	  msgcat[PATH_MAX - 1] = '\0';
-	  DEBUGMSG ("i18n mode, loading message catalog %s", msgcat);
-
 	  /* The English messages might be /etc/messages.en, or
 	     /etc/messages.trm in a single locale system */
-	  if (LOAD_TRMFILE (msgcat) == 0
-	      && LOAD_TRMFILE ("/etc/messages.trm") == 0)
-	  {
-	    problemBoxEn ("An error occurred while loading application messages", "Problem");
-	    reboot(RB_AUTOBOOT);
-	    /* when not root and debugging */
-	    boxFinished();
-	    exit(1); 
-	  }
+	  if ( load_msgcat(lang->msgcat) == 0)
+	    reboot_missing_messages();
 	}
 
         free (msgcat);
@@ -853,17 +881,8 @@ int main (void) {
 #else
     /* We can use problemBox only AFTER boxInit */
     /* So it's important that no (NO!!!) function before this call (LOAD_TRMFILE) uses gettext function */
-    if (LOAD_TRMFILE(TRMFILE) == 0 && LOAD_TRMFILE(TRMBACKUP) == 0) {
-	char message[255];
-	snprintf(message, sizeof(message), 
-		 "An error occured while loading application messages from '%s'.", TRMFILE);
-    message[254] = '\0'; /* Just in case */
-	problemBoxEn (message, "Problem");
-	reboot(RB_AUTOBOOT);
-	/* when not root and debugging */
-	boxFinished();
-	exit(1); 
-    }
+    if ( load_msgcat("") == 0 )   /* Only loading default. */
+      reboot_missing_messages();
 #endif
 
 #if #cpu (m68k)
Index: boxes.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/boxes.c,v
retrieving revision 1.63
diff -u -3 -p -u -r1.63 boxes.c
--- boxes.c	2002/03/01 12:30:27	1.63
+++ boxes.c	2002/03/01 13:25:59
@@ -1171,10 +1171,23 @@ boxChooseLanguageVariant (const struct l
 	    struct language_item *li = list[i].list->items[0].p;
 	    if (list[i].list->items[0].d != 1)
 		continue;
-	    sprintf(prtbuf, "/etc/messages.%s", li->msgcat);
-	    if (access(prtbuf, R_OK))
-		continue;
-
+	    /* If any of the languages listed in the colon separated
+	       list of language codes is available, accept it */
+	    {
+		int accessable = 0;
+		char *languagelist = strdup(li->msgcat);
+		char *language = NULL;
+		for ( language = strtok(languagelist, ":");
+		      language && *language; language = strtok(NULL, ":") )
+		{
+		    sprintf(prtbuf, "/etc/messages.%s", language);
+		    if (0 == access(prtbuf, R_OK))
+			++accessable;
+		}
+		free(languagelist);
+		if (! accessable)
+		    continue;
+	    }
             wpadit (tempo, list[i].hint, width);
             newtListboxAddEntry (lang_list, tempo, list + i);
         }
Index: release_notes.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/release_notes.c,v
retrieving revision 1.9
diff -u -3 -p -u -r1.9 release_notes.c
--- release_notes.c	2002/03/01 12:30:27	1.9
+++ release_notes.c	2002/03/01 13:25:59
@@ -8,56 +8,83 @@
 #include "lang.h"
 
 #ifdef _TESTING_
-#  define RELEASE_FILE	"../../scripts/rootdisk/messages/C/release_notes"
+#  define RELEASE_FILE	"../../scripts/rootdisk/messages/%s%s/release_notes"
 #else
-#  define RELEASE_FILE	"/release_notes"
+#  define RELEASE_FILE	"/release_notes%s%s"
 #endif
 
 int
-release_notes (const char *suffix)
+release_notes (const char *msgcat)
 {
     struct stat s;
     int fd;
-#ifdef USE_LANGUAGE_CHOOSER
     char *fname = (char *)malloc (PATH_MAX);
 
-    if (suffix != NULL)
-        snprintf (fname, PATH_MAX, "%s.%s", RELEASE_FILE, suffix);
-    else
-        strcpy (fname, RELEASE_FILE);
-
-    if ((NAME_ISREG (fname, &s) && (fd=open (fname, O_RDONLY)) >= 0)
-	|| (NAME_ISREG(RELEASE_FILE, &s) && (fd=open (RELEASE_FILE, O_RDONLY)) >= 0))
+    char *languagelist;
+    char *suffix;
+    int found_file = 0;
+
+    if (msgcat == NULL) {
+#ifdef _TESTING_
+        msgcat = "C";
 #else
-    if (NAME_ISREG(RELEASE_FILE, &s) && (fd=open(RELEASE_FILE, O_RDONLY)) >= 0)
-#endif
+    msgcat = "";
+#endif /* _TESTING_ */
+    }
+    languagelist = strdup(msgcat);
+
+    for ( suffix = strtok(languagelist, ":"); suffix;
+	  suffix = strtok(NULL, ":") )
     {
-        char *buf = (char *)malloc (s.st_size+1);
-        size_t num;
+#ifdef _TESTING_
+        const char *separator = "";
+#else
+	const char *separator = ".";
+#endif /* _TESTING_ */
 
-		num = read (fd, buf, s.st_size);
-		close(fd);
-		buf[s.st_size] = '\0';
-
-		wideMessageBox (buf, _("Release Notes"));
-
-        free (buf);
-    } else {
-#ifdef USE_LANGUAGE_CHOOSER
-        ERRMSG("cannot find release notes file %s", 
-               fname);
-        free (fname);
-        return -1;
+        if (!suffix && ! *suffix)
+	{
+	  separator = "";
+#ifdef _TESTING_
+	  suffix = "C";
 #else
-        ERRMSG("cannot find release notes file %s", 
-               RELEASE_FILE);
+	  suffix = "";
+#endif /* _TESTING_ */
+	}
+
+	snprintf (fname, PATH_MAX, RELEASE_FILE, separator, suffix);
+
+	// wideMessageBox(fname, _("Release Notes"));
+
+	if ((NAME_ISREG (fname, &s) && (fd=open (fname, O_RDONLY)) >= 0)
+	    || (NAME_ISREG(RELEASE_FILE, &s)
+		&& (fd=open (RELEASE_FILE, O_RDONLY)) >= 0))
+	{
+	    char *buf = (char *)malloc (s.st_size+1);
+	    size_t num;
+
+	    num = read (fd, buf, s.st_size);
+	    close(fd);
+	    buf[s.st_size] = '\0';
+
+	    wideMessageBox (buf, _("Release Notes"));
+
+	    free (buf);
+	    ++found_file;
+	    break;
+	}
+    }
+
+    if ( ! found_file) {
+        free(languagelist);
+        free (fname);
+
+	ERRMSG("cannot find release notes file %s", fname);
         return -1;
-#endif
     }
 
-#ifdef USE_LANGUAGE_CHOOSER
+    free(languagelist);
     free (fname);
-#endif
 
     return (0);
 }
Index: util.c
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/util.c,v
retrieving revision 1.74
diff -u -3 -p -u -r1.74 util.c
--- util.c	2002/03/01 12:30:27	1.74
+++ util.c	2002/03/01 13:25:59
@@ -1195,7 +1201,17 @@ void find_opt_server (char * hostname)
    {
       int i = 0;
       while(mirror_country_map[i] != NULL) {
-         if(strcmp(lang->msgcat,mirror_country_map[i]) == 0) {
+	 char *languagelist = strdup(lang->msgcat);
+	 char *language = NULL;
+	 int match = 0;
+	 for ( language = strtok(languagelist, ":");
+	       language && *language;
+	       language = strtok(NULL, ":") ) {
+	    if(strcmp(language,mirror_country_map[i]) == 0)
+	       match = 1;
+	 }
+	 free(languagelist);
+	 if (match) {
             sprintf(hostname, "ftp.%s.debian.org", mirror_country_map[i+1]);
 	    return;
          }
Index: langs/norwegian.src
===================================================================
RCS file: /cvs/debian-boot/boot-floppies/utilities/dbootstrap/langs/norwegian.src,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 norwegian.src
--- langs/norwegian.src	2001/10/17 03:30:12	1.1
+++ langs/norwegian.src	2002/03/01 13:25:59
@@ -3,10 +3,10 @@
     <hint>no - Du har valgt norsk.  Trykk Enter for å fortsette</hint>
     <list>
         <name>Velg språkvariant</name>
-        <item arch="i386" locale="no_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nb">
+        <item arch="i386" locale="no_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nb_NO:nb:no_NO:no:nn_NO:nn:dk:sv">
             <name>Bokmål</name>
         </item>
-        <item arch="i386" locale="nn_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nn">
+        <item arch="i386" locale="nn_NO.ISO-8859-1" acm="iso01" font="LatArCyrHeb-16" keymap="i386/qwerty/no-latin1" msgcat="nn_NO:nn:nb_NO:nb:no_NO:no:dk:sv">
             <name>Nynorsk</name>
         </item>
     </list>


--- End Message ---
--- Begin Message ---
Grrr, typoed the bug number.

Sorry about that :-(

Adam

--- End Message ---

Reply to: