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

Re: Small cleanup for utilities/dbootstrap/release_notes.c



[Petter Reinholdtsen]
> It works.  Here is a new patch to be able to test displaying release
> notes in other languages.
> 
> 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/11 23:07:41
> @@ -3,14 +3,19 @@
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <fcntl.h>
> +#ifdef USE_LANGUAGE_CHOOSER
> +#include <locale.h>
> +#endif /* USE_LANGUAGE_CHOOSER */

wops.  This should be '#if defined(_TESTING_) && defined(USE_LANGUAGE_CHOOSER)'

Any hopes of getting the two cleanup patches applied?  I waiting for
them to be included before I submit a new patch to handle language
lists (like gettext's LANGUAGE) in the lang->msgcat variable.

For those who forgot, I made two patches for release_notes.c:

 - fix the test code to be able to test displaying non-english
   translations

 - reorganize code to remove #ifdefs and make he code shorter.  This
   will make it a lot easier to add a loop in the USE_LANGAUGE_CHOOSER
   part without changing other parts of the code.  This moves the
   display code into a separate function, and rewrites how the
   fallback to english is done.

Here is a patch containing both fixes:

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/13 09:17:39
@@ -3,61 +3,69 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#if defined(_TESTING_) && defined(USE_LANGUAGE_CHOOSER)
+#include <locale.h>
+#endif /* _TESTING_ and USE_LANGUAGE_CHOOSER */
 
 #include "dbootstrap.h"
 #include "lang.h"
 
 #ifdef _TESTING_
 #  define RELEASE_FILE	"../../scripts/rootdisk/messages/C/release_notes"
+#  define RELEASE_FILE_FMT "../../scripts/rootdisk/messages/%s/release_notes"
 #else
 #  define RELEASE_FILE	"/release_notes"
+#  define RELEASE_FILE_FMT "/release_notes.%s"
 #endif
 
-int
-release_notes (const char *suffix)
+static int
+display_notes(const char *filename)
 {
     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))
-#else
-    if (NAME_ISREG(RELEASE_FILE, &s) && (fd=open(RELEASE_FILE, O_RDONLY)) >= 0)
-#endif
+    if (NAME_ISREG (filename, &s) && (fd=open (filename, 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';
+	num = read (fd, buf, s.st_size);
+	close(fd);
+	buf[s.st_size] = '\0';
 
-		wideMessageBox (buf, _("Release Notes"));
+	wideMessageBox (buf, _("Release Notes"));
 
         free (buf);
+	return 0;
     } else {
-#ifdef USE_LANGUAGE_CHOOSER
-        ERRMSG("cannot find release notes file %s", 
-               fname);
-        free (fname);
-        return -1;
-#else
-        ERRMSG("cannot find release notes file %s", 
-               RELEASE_FILE);
-        return -1;
-#endif
+        ERRMSG("cannot find release notes file %s", filename);
+	return -1;
     }
+}
 
+int
+release_notes (const char *suffix)
+{
 #ifdef USE_LANGUAGE_CHOOSER
-    free (fname);
-#endif
+    if (suffix != NULL)
+    {
+        /* If malloc() fails, it will display RELEASE_FILE */
+        char *fname = (char *)malloc (PATH_MAX);
+	if (fname)
+	{
+	    snprintf (fname, PATH_MAX, RELEASE_FILE_FMT, suffix);
+	    if (display_notes(fname) == 0)
+	    {
+	        free (fname);
+		return 0;
+	    }
+	    free(fname);
+	}
+    }
+#endif /* USE_LANGUAGE_CHOOSER */
+
+    if (display_notes(RELEASE_FILE) != 0)
+        return -1;
+
 
     return (0);
 }
@@ -67,6 +75,9 @@ release_notes (const char *suffix)
 int main(int argc, char *argv[]){
     char *msgcat = NULL;
 
+#ifdef USE_LANGUAGE_CHOOSER
+    setlocale(LC_ALL, "");
+#endif /* USE_LANGUAGE_CHOOSER */
     LOAD_TRMFILE("test.trm");
     get_kver();
     boxInit();




Reply to: