[AC] Poldek a spece w utf8

Witold Filipczyk witekfl w poczta.onet.pl
Śro, 30 Maj 2007, 16:51:21 CEST


W załączniku poprawiona łatka. Teraz to można już puścić?
-------------- następna część ---------
--- poldek-0.20.1-cvs20070108.22/pkgdir/pndir/description.c.stare	2007-05-29 22:39:55.000000000 +0200
+++ poldek-0.20.1-cvs20070108.22/pkgdir/pndir/description.c	2007-05-30 15:11:58.000000000 +0200
@@ -166,6 +166,7 @@
         for (i = n_array_size(langs) - 1; i >= 0; i--) {
             struct tndb *db;
             const char *lang;
+            char lang_utf8[24];
             char dkey[512];
             int  dklen;
 
@@ -176,6 +177,19 @@
             if ((db = pndir_db_dscr_h_get(db_dscr_h, lang)) == NULL)
                 continue;
 
+            snprintf(lang_utf8, sizeof(lang_utf8), "%s.UTF-8", lang);
+
+            dklen = n_snprintf(dkey, sizeof(dkey), "%s%s", key, lang_utf8);
+            vlen = tndb_get(db, dkey, dklen, val, sizeof(val));
+            DBGF("ld %s: %s (%d)\n", pkg_snprintf_s(pkg), lang_utf8, vlen);
+            if (vlen > 0) {
+                tn_buf_it it;
+                n_buf_clean(nbuf);
+                n_buf_init(nbuf, val, vlen);
+                n_buf_it_init(&it, nbuf);
+                pkguinf_restore_i18n(pkgu, &it, lang_utf8);
+            }
+    
             dklen = n_snprintf(dkey, sizeof(dkey), "%s%s", key, lang);
             vlen = tndb_get(db, dkey, dklen, val, sizeof(val));
             DBGF("ld %s: %s (%d)\n", pkg_snprintf_s(pkg), lang, vlen);
--- poldek-0.20.1-cvs20070108.22/pkgu.c.stare	2007-05-29 21:40:39.000000000 +0200
+++ poldek-0.20.1-cvs20070108.22/pkgu.c	2007-05-30 16:37:16.000000000 +0200
@@ -15,6 +15,8 @@
 */
 
 #include <ctype.h>
+#include <iconv.h>
+#include <langinfo.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -576,7 +576,27 @@
         return 0;
     description = n_buf_it_getz(it, &dlen);
 
-    inf = pkguinf_i18n_new(pkgu->_na, summary, description);
+    if (strstr(lang, "UTF-8")) {
+        iconv_t cd;
+        size_t u_slen = slen, u_dlen = dlen;
+        char *new_s, *new_d;
+        char *summary_utf8 = n_malloc(u_slen + 1);
+        char *description_utf8 = n_malloc(u_dlen + 1);
+
+        new_s = summary_utf8;
+        new_d = description_utf8;
+        cd = iconv_open(nl_langinfo(CODESET), "UTF-8");
+        iconv(cd, &summary, &slen, &new_s, &u_slen);
+        iconv(cd, &description, &dlen, &new_d, &u_dlen);
+        iconv_close(cd);
+        *new_s = '\0';
+        *new_d = '\0';
+        inf = pkguinf_i18n_new(pkgu->_na, summary_utf8, description_utf8);
+        n_free(summary_utf8);
+        n_free(description_utf8);
+    } else {
+        inf = pkguinf_i18n_new(pkgu->_na, summary, description);
+    }
     n_hash_insert(pkgu->_ht, lang, inf);
     
     pkgu->summary = inf->summary;


Więcej informacji o liście dyskusyjnej pld-devel-pl