[eggheads-patches] PATCH: baselang.patch

Fabian Knittel fknittel at gmx.de
Mon Oct 11 22:44:01 CST 1999


[ baselang.patch ]

This patch fixes a quirk in the language system's behaviour.

As the different language variants of a specific section are
not always in sync and may miss a few elements, this patch
makes eggdrop always first load the english version, which
contains all elements, and then tries to load more preferred
languages on top.

Fabian
-------------- next part --------------
diff -urN eggdrop1.3~/doc/UPDATES1.3 eggdrop1.3/doc/UPDATES1.3
--- eggdrop1.3~/doc/UPDATES1.3	Mon Oct 11 02:31:32 1999
+++ eggdrop1.3/doc/UPDATES1.3	Mon Oct 11 23:28:46 1999
@@ -4,6 +4,8 @@
 
 1.3.29
 Foundby   Fixedby   What....
+	  Fabian    the language table is now always first loaded with english
+		    rather than the more preferred languages
 	  drummer   Adds ismodeline macros.
 ranjha	  Fabian    .help * is now converted to .help all
 Ben	  Fabian    cmd_su doesn't require a passwd for the target user if
diff -urN eggdrop1.3~/src/eggdrop.h eggdrop1.3/src/eggdrop.h
--- eggdrop1.3~/src/eggdrop.h	Mon Oct 11 02:31:32 1999
+++ eggdrop1.3/src/eggdrop.h	Mon Oct 11 21:51:02 1999
@@ -45,7 +45,11 @@
 #define NICKLEN		NICKMAX + 1
 #define NOTENAMELEN     ((HANDLEN * 2) + 1)
 
+/* language stuff */
 #define LANGDIR	"./language"	/* language file directory */
+#define BASELANG "english"	/* language which always gets loaded before
+				   all other languages. You don't want to
+				   change this. */
 
 /* have to use a weird way to make the compiler error out cos not all
  * compilers support #error or error */
diff -urN eggdrop1.3~/src/language.c eggdrop1.3/src/language.c
--- eggdrop1.3~/src/language.c	Mon Oct 11 02:31:32 1999
+++ eggdrop1.3/src/language.c	Mon Oct 11 22:29:57 1999
@@ -73,9 +73,10 @@
 static void read_lang(char *);
 void add_lang_section(char *);
 int del_lang_section(char *);
-static char *get_langfile(char *, lang_sec *);
+static char *get_specific_langfile(char *, lang_sec *);
+static char *get_langfile(lang_sec *);
 static int split_lang(char *, char **, char **);
-int cmd_loadlanguage(struct userrec *u, int idx, char *par);
+int cmd_loadlanguage(struct userrec *, int, char *);
 
 
 /* add a new preferred language to the list of languages. Newly added
@@ -179,7 +180,7 @@
   context;
   while (ls) {
     if (ls->section) {
-      langfile = get_langfile(ls->section, ls);
+      langfile = get_langfile(ls);
       /* found a language with a more preferred language? */
       if (langfile) {
         read_lang(langfile);
@@ -206,7 +207,8 @@
   context;
   FLANG = fopen(langfile, "r");
   if (FLANG == NULL) {
-    putlog(LOG_MISC, "*", "LANG: unexpected: reading from file %s failed.");
+    putlog(LOG_MISC, "*", "LANG: unexpected: reading from file %s failed.",
+	   langfile);
     return;
   }
 
@@ -275,6 +277,7 @@
 {
   char *langfile = NULL;
   lang_sec *ls = langsection, *ols = NULL;
+  int ok = 0;
  
   context;
   while (ls) {
@@ -292,17 +295,26 @@
   ls->lang = NULL;
   ls->next = NULL;
 
-  /* connect to existing list of sections */
+  /* Connect to existing list of sections */
   if (ols)
     ols->next = ls;
   else
     langsection = ls;
   putlog(LOG_MISC, "*", "LANG: Added section %s.", section);
   
-  langfile = get_langfile(section, ls);
+  /* Always load base language */
+  langfile = get_specific_langfile(BASELANG, ls);
+  if (langfile) {
+    read_lang(langfile);
+    nfree(langfile);
+    ok = 1;
+  }
+  /* Now overwrite base language with a more preferred one */
+  langfile = get_langfile(ls);
   if (!langfile) {
-    putlog(LOG_MISC, "*", "LANG: No lang files found for section %s.",
-	   section);
+    if (!ok)
+      putlog(LOG_MISC, "*", "LANG: No lang files found for section %s.",
+	     section);
     return;
   }
   read_lang(langfile);
@@ -332,13 +344,33 @@
   return 0;
 }
 
+static char *get_specific_langfile(char *language, lang_sec *sec)
+{
+  char *ldir = getenv("EGG_LANGDIR");
+  char *langfile;
+  FILE *sfile = NULL;
+
+  if (!ldir)
+    ldir = LANGDIR;
+  langfile = nmalloc(strlen(ldir) + strlen(sec->section) + strlen(language)+8);
+  sprintf(langfile, "%s/%s.%s.lang", ldir, sec->section, language);
+  sfile = fopen(langfile, "r");
+  if (sfile) {
+    fclose(sfile);
+    /* save language used for this section */
+    sec->lang = nrealloc(sec->lang, strlen(language) + 1);
+    strcpy(sec->lang, language);
+    return langfile;
+  }
+  nfree(langfile);
+  return NULL;
+}
+
 /* Searches for available language files and returns the file with the
  * most preferred language.
  */
-static char *get_langfile(char *section, lang_sec *sec)
+static char *get_langfile(lang_sec *sec)
 {
-  FILE *sfile = NULL;
-  char *ldir = getenv("EGG_LANGDIR");
   char *langfile;
   lang_pri *lp = langpriority;
 
@@ -348,22 +380,9 @@
     if (sec->lang && !strcmp(sec->lang, lp->lang)) {
       return NULL;
     }
-    if (ldir) {
-      langfile = nmalloc(strlen(ldir)+strlen(section)+strlen(lp->lang)+8);
-      sprintf(langfile, "%s/%s.%s.lang", ldir, section, lp->lang);
-    } else {
-      langfile = nmalloc(strlen(LANGDIR)+strlen(section)+strlen(lp->lang)+8);
-      sprintf(langfile, "%s/%s.%s.lang", LANGDIR, section, lp->lang);
-    }
-    sfile = fopen(langfile, "r");
-    if (sfile) {
-      fclose(sfile);
-      /* save language used for this section */
-      sec->lang = nrealloc(sec->lang, strlen(lp->lang) + 1);
-      strcpy(sec->lang, lp->lang);
+    langfile = get_specific_langfile(lp->lang, sec);
+    if (langfile)
       return langfile;
-    }
-    nfree(langfile);
     lp = lp->next;
   }
   /* we did not find any files, clear the language field */


More information about the Patches mailing list