Break out locale match test.
authorjbj <devnull@localhost>
Fri, 20 Aug 1999 17:55:12 +0000 (17:55 +0000)
committerjbj <devnull@localhost>
Fri, 20 Aug 1999 17:55:12 +0000 (17:55 +0000)
CVS patchset: 3241
CVS date: 1999/08/20 17:55:12

lib/header.c
lib/header.h
po/rpm.pot

index 1ee8f07..7d6cd9c 100644 (file)
@@ -785,6 +785,45 @@ int headerGetRawEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c)
     return 1;
 }
 
+static int headerMatchLocale(const char *td, const char *l, const char *le)
+{
+    const char *fe;
+
+    /*
+     * The range [l,le) contains the next locale to match:
+     *    ll[_CC][.EEEEE][@dddd]
+     * where
+     *    ll   ISO language code (in lowercase).
+     *    CC   (optional) ISO coutnry code (in uppercase).
+     *    EEEEE        (optional) encoding (not really standardized).
+     *    dddd (optional) dialect.
+     */
+
+    /* First try a complete match. */
+    if (!strncmp(td, l, (le - l)))
+       return 1;
+
+    /* Next, try stripping optional dialect and matching.  */
+    for (fe = l; fe < le && *fe != '@'; fe++)
+       ;
+    if (fe < le && !strncmp(td, l, (fe - l)))
+       return 1;
+
+    /* Next, try stripping optional codeset and matching.  */
+    for (fe = l; fe < le && *fe != '.'; fe++)
+       ;
+    if (fe < le && !strncmp(td, l, (fe - l)))
+       return 1;
+
+    /* Finally, try stripping optional country code and matching. */
+    for (fe = l; fe < le && *fe != '_'; fe++)
+       ;
+    if (fe < le && !strncmp(td, l, (fe - l)))
+       return 1;
+
+    return 0;
+}
+
 static char *headerFindI18NString(Header h, struct indexEntry *entry)
 {
     const char *lang, *l, *le;
@@ -798,9 +837,9 @@ static char *headerFindI18NString(Header h, struct indexEntry *entry)
        return entry->data;
 
     for (l = lang; *l; l = le) {
-       const char *td, *fe;
+       const char *td;
        char *ed;
-       int count;
+       int langNum;
 
        while (*l && *l == ':')                 /* skip leading colons */
            l++;
@@ -809,47 +848,69 @@ static char *headerFindI18NString(Header h, struct indexEntry *entry)
        for (le = l; *le && *le != ':'; le++)   /* find end of this locale */
            ;
 
-       /*
-        * The range [l,le) now contains the next locale to match:
-        *    ll[_CC][.EEEEE][@dddd]
-        * where
-        *    ll        ISO language code (in lowercase).
-        *    CC        (optional) ISO coutnry code (in uppercase).
-        *    EEEEE     (optional) encoding (not really standardized).
-        *    dddd      (optional) dialect.
-        */
-
        /* For each entry in the header ... */
-       for (count = entry->info.count, td = table->data, ed = entry->data;
-            count-- > 0; td += strlen(td) + 1, ed += strlen(ed) + 1) {
-
-           /* First try a complete match. */
-           if (!strncmp(td, l, (le - l)))
-               return ed;
-
-           /* Next, try stripping optional dialect and matching.  */
-           for (fe = l; fe < le && *fe != '@'; fe++)
-               ;
-           if (fe < le && !strncmp(td, l, (fe - l)))
-               return ed;
-
-           /* Next, try stripping optional codeset and matching.  */
-           for (fe = l; fe < le && *fe != '.'; fe++)
-               ;
-           if (fe < le && !strncmp(td, l, (fe - l)))
-               return ed;
-
-           /* Finally, try stripping optional country code and matching. */
-           for (fe = l; fe < le && *fe != '_'; fe++)
-               ;
-           if (fe < le && !strncmp(td, l, (fe - l)))
-               return ed;
+       for (langNum = 0, td = table->data, ed = entry->data;
+            langNum < entry->info.count;
+            langNum++, td += strlen(td) + 1, ed += strlen(ed) + 1) {
+
+               if (headerMatchLocale(td, l, le))
+                   return ed;
+
        }
     }
 
     return entry->data;
 }
 
+void headerSetLangPath(Header h, const char * lang)
+{
+    const char *l, *le;
+    struct indexEntry * table;
+
+    if (lang == NULL ||
+      (table = findEntry(h, HEADER_I18NTABLE, RPM_STRING_ARRAY_TYPE)) == NULL) {
+       h->langNum = -1;
+       return;
+    }
+
+    for (l = lang; *l; l = le) {
+       const char *td;
+       int langNum;
+
+       while (*l && *l == ':')                 /* skip leading colons */
+           l++;
+       if (*l == '\0')
+           break;
+       for (le = l; *le && *le != ':'; le++)   /* find end of this locale */
+           ;
+
+       for (langNum = 0, td = table->data;
+            langNum < table->info.count;
+            langNum++, td += strlen(td) + 1) {
+
+               if (headerMatchLocale(td, l, le)) {
+                   h->langNum = langNum;
+                   return;
+               }
+
+       }
+    }
+
+    h->langNum = -1;
+}
+
+void headerResetLang(Header h)
+{
+    const char * str;
+
+    if ((str = getenv("LANGUAGE"))) {
+       headerSetLangPath(h, str);
+       return;
+    }
+   
+    headerSetLangPath(h, getenv("LANG"));
+}
+
 static int intGetEntry(Header h, int_32 tag, int_32 *type, void **p, int_32 *c,
                       int minMem)
 {
@@ -2121,58 +2182,6 @@ const struct headerSprintfExtension headerDefaultFormats[] = {
     { HEADER_EXT_LAST, NULL, { NULL } }
 };
 
-void headerSetLangPath(Header h, char * lang) {
-    char * buf, * chptr, * start, * next;
-    struct indexEntry * table;
-    int langNum;
-
-    table = findEntry(h, HEADER_I18NTABLE, RPM_STRING_ARRAY_TYPE);
-
-    if (!lang || !table) {
-       h->langNum = -1;
-       return;
-    }
-
-    buf = alloca(strlen(lang) + 1);
-    strcpy(buf, lang);
-
-    start = buf;
-    while (start) {
-       chptr = strchr(start, ':');
-       if (chptr) *chptr = '\0';
-       
-       next = table->data;
-       for (langNum = 0; langNum < table->info.count; langNum++) {
-           if (!strcmp(next, start)) break;
-           next += strlen(next) + 1;
-       }
-       
-       if (langNum < table->info.count) {
-           h->langNum = langNum;
-           break;
-       }
-       
-       if (chptr)
-           start = chptr + 1;
-       else
-           start = NULL;
-    }
-
-    if (!start)
-       h->langNum = -1;
-}
-
-void headerResetLang(Header h) {
-    char * str;
-
-    if ((str = getenv("LANGUAGE"))) {
-       headerSetLangPath(h, str);
-       return;
-    }
-   
-    headerSetLangPath(h, getenv("LANG"));
-}
-
 void headerCopyTags(Header headerFrom, Header headerTo, int *tagstocopy)
 {
     int *p;
index 8d00497..14c0f93 100644 (file)
@@ -159,7 +159,7 @@ void headerFreeIterator(/*@only@*/ HeaderIterator iter);
 void headerResetLang(Header h);
 /* sets the language path for the header; this doesn't need to be done if
    the LANGUAGE or LANG enivronment variable are correct */
-void headerSetLangPath(Header h, char * lang);
+void headerSetLangPath(Header h, const char * lang);
 
 Header headerCopy(Header h);
 void headerSort(Header h);
index b20cf53..e6127c8 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-08-19 15:21-0400\n"
+"POT-Creation-Date: 1999-08-20 13:48-0400\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -2016,8 +2016,8 @@ msgid ""
 msgstr ""
 
 #: ../lib/formats.c:65 ../lib/formats.c:83 ../lib/formats.c:104
-#: ../lib/formats.c:137 ../lib/header.c:2015 ../lib/header.c:2032
-#: ../lib/header.c:2052
+#: ../lib/formats.c:137 ../lib/header.c:2076 ../lib/header.c:2093
+#: ../lib/header.c:2113
 msgid "(not a number)"
 msgstr ""
 
@@ -2108,69 +2108,69 @@ msgstr ""
 msgid "Data type %d not supprted\n"
 msgstr ""
 
-#: ../lib/header.c:1015
+#: ../lib/header.c:1076
 #, c-format
 msgid "Bad count for headerAddEntry(): %d\n"
 msgstr ""
 
-#: ../lib/header.c:1415
+#: ../lib/header.c:1476
 #, c-format
 msgid "missing { after %"
 msgstr ""
 
-#: ../lib/header.c:1443
+#: ../lib/header.c:1504
 msgid "missing } after %{"
 msgstr ""
 
-#: ../lib/header.c:1455
+#: ../lib/header.c:1516
 msgid "empty tag format"
 msgstr ""
 
-#: ../lib/header.c:1465
+#: ../lib/header.c:1526
 msgid "empty tag name"
 msgstr ""
 
-#: ../lib/header.c:1480
+#: ../lib/header.c:1541
 msgid "unknown tag"
 msgstr ""
 
-#: ../lib/header.c:1506
+#: ../lib/header.c:1567
 msgid "] expected at end of array"
 msgstr ""
 
-#: ../lib/header.c:1522
+#: ../lib/header.c:1583
 msgid "unexpected ]"
 msgstr ""
 
-#: ../lib/header.c:1524
+#: ../lib/header.c:1585
 msgid "unexpected }"
 msgstr ""
 
-#: ../lib/header.c:1576
+#: ../lib/header.c:1637
 msgid "? expected in expression"
 msgstr ""
 
-#: ../lib/header.c:1583
+#: ../lib/header.c:1644
 msgid "{ expected after ? in expression"
 msgstr ""
 
-#: ../lib/header.c:1593 ../lib/header.c:1625
+#: ../lib/header.c:1654 ../lib/header.c:1686
 msgid "} expected in expression"
 msgstr ""
 
-#: ../lib/header.c:1600
+#: ../lib/header.c:1661
 msgid ": expected following ? subexpression"
 msgstr ""
 
-#: ../lib/header.c:1613
+#: ../lib/header.c:1674
 msgid "{ expected after : in expression"
 msgstr ""
 
-#: ../lib/header.c:1632
+#: ../lib/header.c:1693
 msgid "| expected at end of expression"
 msgstr ""
 
-#: ../lib/header.c:1799
+#: ../lib/header.c:1860
 msgid "(unknown type)"
 msgstr ""