Index: ppdc/ppdc-catalog.cxx =================================================================== --- ppdc/ppdc-catalog.cxx (revision 8049) +++ ppdc/ppdc-catalog.cxx (working copy) @@ -14,12 +14,6 @@ // // Contents: // -// ppdcCatalog::ppdcCatalog() - Create a shared message catalog. -// ppdcCatalog::~ppdcCatalog() - Destroy a shared message catalog. -// ppdcCatalog::add_message() - Add a new message. -// ppdcCatalog::find_message() - Find a message in a catalog... -// ppdcCatalog::load_messages() - Load messages from a .po file. -// ppdcCatalog::save_messages() - Save the messages to a .po file. // // @@ -113,14 +107,16 @@ // void -ppdcCatalog::add_message(const char *id)// I - Message ID to add +ppdcCatalog::add_message( + const char *id, // I - Message ID to add + const char *string) // I - Translation string { ppdcMessage *m; // Current message char text[1024]; // Text to translate // Range check input... - if (!id || !*id) + if (!id) return; // Verify that we don't already have the message ID... @@ -128,10 +124,22 @@ m; m = (ppdcMessage *)messages->next()) if (!strcmp(m->id->value, id)) + { + if (string) + { + m->string->release(); + m->string = new ppdcString(string); + } return; + } // Add the message... - snprintf(text, sizeof(text), "TRANSLATE %s", id); + if (!string) + { + snprintf(text, sizeof(text), "TRANSLATE %s", id); + string = text; + } + messages->add(new ppdcMessage(id, text)); } @@ -166,7 +174,6 @@ const char *f) // I - Message catalog file { cups_file_t *fp; // Message file - ppdcMessage *temp; // Current message char line[4096], // Line buffer *ptr, // Pointer into buffer id[4096], // Translation ID @@ -268,9 +275,7 @@ else if (ch == ';') { // Add string... - temp = new ppdcMessage(id, str); - - messages->add(temp); + add_message(id, str); } } } @@ -293,9 +298,16 @@ * "multiple lines" */ + int which, // In msgid? + haveid, // Did we get a msgid string? + havestr; // Did we get a msgstr string? + linenum = 0; id[0] = '\0'; str[0] = '\0'; + haveid = 0; + havestr = 0; + which = 0; while (cupsFileGets(fp, line, sizeof(line))) { @@ -372,19 +384,18 @@ // Create or add to a message... if (!strncmp(line, "msgid", 5)) { - if (id[0] && str[0]) - { - temp = new ppdcMessage(id, str); + if (haveid && havestr) + add_message(id, str); - messages->add(temp); - } - strlcpy(id, ptr, sizeof(id)); str[0] = '\0'; + haveid = 1; + havestr = 0; + which = 1; } else if (!strncmp(line, "msgstr", 6)) { - if (!id[0]) + if (!haveid) { _cupsLangPrintf(stderr, _("ERROR: Need a msgid line before any " @@ -395,10 +406,12 @@ } strlcpy(str, ptr, sizeof(str)); + havestr = 1; + which = 2; } - else if (line[0] == '\"' && str[0]) + else if (line[0] == '\"' && which == 2) strlcat(str, ptr, sizeof(str)); - else if (line[0] == '\"' && id[0]) + else if (line[0] == '\"' && which == 1) strlcat(id, ptr, sizeof(id)); else { @@ -409,12 +422,8 @@ } } - if (id[0] && str[0]) - { - temp = new ppdcMessage(id, str); - - messages->add(temp); - } + if (haveid && havestr) + add_message(id, str); } else goto unknown_load_format; Index: ppdc/ppdc.h =================================================================== --- ppdc/ppdc.h (revision 8049) +++ ppdc/ppdc.h (working copy) @@ -164,8 +164,7 @@ ppdcCatalog(const char *l, const char *f = 0); ~ppdcCatalog(); - void add_message(ppdcMessage *m) { messages->add(m); } - void add_message(const char *id); + void add_message(const char *id, const char *string = NULL); const char *find_message(const char *id); int load_messages(const char *f); int save_messages(const char *f);