[Phil Blundell] > Would you mind sending a patch that contains only the changes > necessary for multiple language code handling, without any > reorganisation of the rest of the code? I think that would make it > easier for people to review.
Yes, and no. Would it be easier to send a patch reorganize the code first, and then a patch to add support of the language list? Adding the required loop to release_notes.c would make the new code almost unreadable. Adding the required loop to main.c seem to be fairly readable. I'll make a new patch after you let me know if release_notes.c can be cleaned up before I change the behavior. > > + if ( LOAD_TRMFILE("/etc/messages.en") != 0 || > + LOAD_TRMFILE("/etc/messages.trm") != 0 || > + LOAD_TRMFILE(TRMBACKUP) != 0 ) > > That doesn't look quite right to me. What is wrong? The fact that TRMBACKUP can be the same as one of the others? I thought it didn't matter. For some definitions, it will be different, and handling the special case would make the code more complicated. The following change to release_notes.c would make it a easier to rewrite it to use a loop. --- release_notes.c.~1.9.~ Wed Mar 6 22:37:54 2002 +++ release_notes.c Wed Mar 6 23:14:08 2002 @@ -13,53 +13,59 @@ # define RELEASE_FILE "/release_notes" #endif +static void +display_notes(int fd) +{ + 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); +} + int release_notes (const char *suffix) { struct stat s; int fd; -#ifdef USE_LANGUAGE_CHOOSER - char *fname = (char *)malloc (PATH_MAX); + char *fname = RELEASE_FILE; + int retval = 0; +#ifdef USE_LANGUAGE_CHOOSER + char *buf = NULL; if (suffix != NULL) - snprintf (fname, PATH_MAX, "%s.%s", RELEASE_FILE, suffix); - else - strcpy (fname, RELEASE_FILE); + { + /* How should OOM be handled? */ + buf = (char *)malloc (PATH_MAX); + + snprintf (buf, PATH_MAX, "%s.%s", RELEASE_FILE, suffix); + fname = buf; + } 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) + if (NAME_ISREG(fname, &s) && (fd=open(fname, O_RDONLY)) >= 0) #endif { - 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); + display_notes(fd); } 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 + retval = -1; } #ifdef USE_LANGUAGE_CHOOSER - free (fname); + if (buf) + free (buf); #endif - return (0); + return retval; } #ifdef _TESTING_ -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]