summaryrefslogtreecommitdiff
path: root/cups/language.c
diff options
context:
space:
mode:
authorMichael R Sweet <michaelrsweet@gmail.com>2017-12-19 14:53:00 -0500
committerMichael R Sweet <michaelrsweet@gmail.com>2017-12-19 14:53:00 -0500
commit2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e (patch)
tree3d9da027144be82db3acea277a4c7dcd58d0f40f /cups/language.c
parent3d90ace3170087acd66d189fcf2362242815f88d (diff)
downloadcups-2fa1ba3cc0e02799b739ef0e06efc940a8c5a33e.tar.gz
Generate strings files for localizing PPD options (Issue #5194)
cups/language-private.h: - New _cupsMessageAdd and _cupsMessageSave private APIs. cups/language.c: - Implement new _cupsMessageAdd and _cupsMessageSave private APIs. cups/ppd-cache.c: - Generate strings array when loading cache from PPD. - Remove strings_uri (just pulling strings from PPD now). cups/ppd-private.h: - Remove strings_uri and add strings array to cache. scheduler/client.c: - Add support for /strings/NAME.strings - Cleanup implementation of GET/HEAD/POST to files. scheduler/ipp.c: - Return local strings file URI. - Clean up copy_printer_attrs implementation. scheduler/printers.c: - Save strings array to cache file, drop support for strings_uri. scheduler/printers.h: - Add strings filename to cupsd_printer_t structure.
Diffstat (limited to 'cups/language.c')
-rw-r--r--cups/language.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/cups/language.c b/cups/language.c
index 1f2a125be..78d7d1573 100644
--- a/cups/language.c
+++ b/cups/language.c
@@ -147,6 +147,7 @@ static cups_lang_t *cups_cache_lookup(const char *name, cups_encoding_t encoding
static int cups_message_compare(_cups_message_t *m1, _cups_message_t *m2);
static void cups_message_free(_cups_message_t *m);
static void cups_message_load(cups_lang_t *lang);
+static void cups_message_puts(cups_file_t *fp, const char *s);
static int cups_read_strings(cups_file_t *fp, int flags, cups_array_t *a);
static void cups_unquote(char *d, const char *s);
@@ -1225,6 +1226,57 @@ _cupsMessageNew(void *context) /* I - User data */
}
+/*
+ * '_cupsMessageSave()' - Save a message catalog array.
+ */
+
+int /* O - 0 on success, -1 on failure */
+_cupsMessageSave(const char *filename,/* I - Output filename */
+ int flags, /* I - Format flags */
+ cups_array_t *a) /* I - Message array */
+{
+ cups_file_t *fp; /* Output file */
+ _cups_message_t *m; /* Current message */
+
+
+ /*
+ * Output message catalog file...
+ */
+
+ if ((fp = cupsFileOpen(filename, "w")) == NULL)
+ return (-1);
+
+ /*
+ * Write each message...
+ */
+
+ if (flags & _CUPS_MESSAGE_STRINGS)
+ {
+ for (m = (_cups_message_t *)cupsArrayFirst(a); m; m = (_cups_message_t *)cupsArrayNext(a))
+ {
+ cupsFilePuts(fp, "\"");
+ cups_message_puts(fp, m->msg);
+ cupsFilePuts(fp, "\" = \"");
+ cups_message_puts(fp, m->str);
+ cupsFilePuts(fp, "\";\n");
+ }
+ }
+ else
+ {
+ for (m = (_cups_message_t *)cupsArrayFirst(a); m; m = (_cups_message_t *)cupsArrayNext(a))
+ {
+ cupsFilePuts(fp, "msgid \"");
+ cups_message_puts(fp, m->msg);
+ cupsFilePuts(fp, "\"\nmsgstr \"");
+ cups_message_puts(fp, m->str);
+ cupsFilePuts(fp, "\"\n");
+ }
+ }
+
+ return (cupsFileClose(fp));
+}
+
+
#ifdef __APPLE__
/*
* 'appleLangDefault()' - Get the default locale string.
@@ -1670,6 +1722,44 @@ cups_message_load(cups_lang_t *lang) /* I - Language */
/*
+ * 'cups_message_puts()' - Write a message string with quoting.
+ */
+
+static void
+cups_message_puts(cups_file_t *fp, /* I - File to write to */
+ const char *s) /* I - String to write */
+{
+ const char *start, /* Start of substring */
+ *ptr; /* Pointer into string */
+
+
+ for (start = s, ptr = s; *ptr; ptr ++)
+ {
+ if (strchr("\\\"\n\t", *ptr))
+ {
+ if (ptr > start)
+ {
+ cupsFileWrite(fp, start, (size_t)(ptr - start));
+ start = ptr + 1;
+ }
+
+ if (*ptr == '\\')
+ cupsFileWrite(fp, "\\\\", 2);
+ else if (*ptr == '\"')
+ cupsFileWrite(fp, "\\\"", 2);
+ else if (*ptr == '\n')
+ cupsFileWrite(fp, "\\n", 2);
+ else /* if (*ptr == '\t') */
+ cupsFileWrite(fp, "\\t", 2);
+ }
+ }
+
+ if (ptr > start)
+ cupsFileWrite(fp, start, (size_t)(ptr - start));
+}
+
+
+/*
* 'cups_read_strings()' - Read a pair of strings from a .strings file.
*/