[GLUE] Rsync SAMBA_3_0 SVN r25598 in order to create the v3-0-test branch.
[gd/samba/.git] / source / intl / lang_tdb.c
index c2def85d6e95cd689afb9dff5ca26606229dd860..ddb3d4d65e3e4202d5cd9eae21e790a6ffceed29 100644 (file)
@@ -32,7 +32,7 @@ static BOOL load_msg(const char *msg_file)
        char **lines;
        int num_lines, i;
        char *msgid, *msgstr;
-       TDB_DATA data;
+       TDB_DATA key, data;
 
        lines = file_lines_load(msg_file, &num_lines,0);
 
@@ -63,8 +63,11 @@ static BOOL load_msg(const char *msg_file)
                        }
                        all_string_sub(msgid, "\\n", "\n", 0);
                        all_string_sub(msgstr, "\\n", "\n", 0);
-                       data = string_term_tdb_data(msgstr);
-                       tdb_store_bystring(tdb, msgid, data, 0);
+                       key.dptr = msgid;
+                       key.dsize = strlen(msgid)+1;
+                       data.dptr = msgstr;
+                       data.dsize = strlen(msgstr)+1;
+                       tdb_store(tdb, key, data, 0);
                        msgid = NULL;
                }
        }
@@ -175,7 +178,7 @@ BOOL lang_tdb_init(const char *lang)
 */
 const char *lang_msg(const char *msgid)
 {
-       TDB_DATA data;
+       TDB_DATA key, data;
        const char *p;
        char *q, *msgid_quoted;
        int count;
@@ -211,7 +214,10 @@ const char *lang_msg(const char *msgid)
 
        *q = 0;
 
-       data = tdb_fetch_bystring(tdb, msgid_quoted);
+       key.dptr = (char *)msgid_quoted;
+       key.dsize = strlen(msgid_quoted)+1;
+       
+       data = tdb_fetch(tdb, key);
 
        free(msgid_quoted);
 
@@ -231,6 +237,32 @@ void lang_msg_free(const char *msgstr)
        free((void *)msgstr);
 }
 
+
+/*
+  when the _() translation macro is used there is no obvious place to free
+  the resulting string and there is no easy way to give a static pointer.
+  All we can do is rotate between some static buffers and hope a single d_printf() 
+  doesn't have more calls to _() than the number of buffers 
+*/
+const char *lang_msg_rotate(const char *msgid)
+{
+#define NUM_LANG_BUFS 16
+       char *msgstr;
+       static pstring bufs[NUM_LANG_BUFS];
+       static int next;
+
+       msgstr = (char *)lang_msg(msgid);
+       if (!msgstr) return msgid;
+
+       pstrcpy(bufs[next], msgstr);
+       msgstr = bufs[next];
+
+       next = (next+1) % NUM_LANG_BUFS;
+       
+       return msgstr;
+}
+
+
 /* 
    return the current language - needed for language file mappings 
 */