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

Small cleanup for utilities/dbootstrap/release_notes.c



Could someone please apply the following cleanup?  It reduces the
duplicate code, reduces the number of #ifdefs, and makes it a lot
easier to change the code to handle langauge lists in the lang->msgcat
variable.

BTW: The test code is unable to test other languages.  Should this be
fixed?

This is relative to the current CVS.

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/10 23:23:56
@@ -13,51 +13,54 @@
 #  define RELEASE_FILE	"/release_notes"
 #endif
 
-int
-release_notes (const char *suffix)
+static int
+display_notes(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, "%s.%s", RELEASE_FILE, 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);
 }



Reply to: