From a674f249fc94458e9532819b33b990874c278ad9 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 15 Apr 2024 16:00:42 -0400 Subject: [PATCH] Update _ppdCacheCreateWithPPD to accept languages to localize. --- backend/ipp.c | 6 +- cups/ppd-cache.c | 155 +++++++++++++++++++++++++++++++---------- cups/ppd-mark.c | 6 +- cups/ppd-private.h | 4 +- scheduler/conf.h | 2 + scheduler/cupsfilter.c | 6 +- scheduler/printers.c | 8 +-- tools/ippeveps.c | 2 +- 8 files changed, 127 insertions(+), 62 deletions(-) diff --git a/backend/ipp.c b/backend/ipp.c index 749ad085d8..17966f7f31 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -9,10 +9,6 @@ * information. */ -/* - * Include necessary headers. - */ - #include "backend-private.h" #include #include @@ -1323,7 +1319,7 @@ main(int argc, /* I - Number of command-line args */ ppd_attr_t *mandatory; /* cupsMandatory value */ ppd = ppdOpenFile(getenv("PPD")); - pc = _ppdCacheCreateWithPPD(ppd); + pc = _ppdCacheCreateWithPPD(NULL, ppd); ppdMarkDefaults(ppd); cupsMarkOptions(ppd, num_options, options); diff --git a/cups/ppd-cache.c b/cups/ppd-cache.c index 679f3695ec..0cd49851ff 100644 --- a/cups/ppd-cache.c +++ b/cups/ppd-cache.c @@ -8,14 +8,11 @@ * information. */ -/* - * Include necessary headers... - */ - #include "cups-private.h" #include "ppd-private.h" #include "debug-internal.h" #include +#include /* @@ -37,7 +34,6 @@ static const char *ppd_get_string(cups_lang_t *base, cups_lang_t *printer, const static const char *ppd_inputslot_for_keyword(_ppd_cache_t *pc, const char *keyword); static void ppd_put_strings(cups_file_t *fp, cups_lang_t *langs, const char *ppd_option, const char *ppd_choice, const char *pwg_msgid); static void pwg_add_finishing(cups_array_t *finishings, ipp_finishings_t template, const char *name, const char *value); -static void pwg_add_message(cups_array_t *a, const char *msg, const char *str); static int pwg_compare_finishings(_pwg_finishings_t *a, _pwg_finishings_t *b, void *data); static int pwg_compare_sizes(cups_size_t *a, cups_size_t *b, void *data); static cups_size_t *pwg_copy_size(cups_size_t *size, void *data); @@ -1023,7 +1019,9 @@ _ppdCacheCreateWithFile( */ _ppd_cache_t * /* O - PPD cache and mapping data */ -_ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ +_ppdCacheCreateWithPPD( + cups_lang_t *langs, /* I - Languages to load */ + ppd_file_t *ppd) /* I - PPD file */ { int i, j, k; /* Looping vars */ _ppd_cache_t *pc; /* PWG mapping data */ @@ -1068,6 +1066,8 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ const char *filter; /* Current filter */ _pwg_finishings_t *finishings; /* Current finishings value */ char msg_id[256]; /* Message identifier */ + cups_lang_t *lang; /* Current language */ + _cups_message_t msg; /* Message */ DEBUG_printf("_ppdCacheCreateWithPPD(ppd=%p)", (void *)ppd); @@ -1089,8 +1089,6 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ goto create_error; } - pc->strings = _cupsMessageNew(NULL); - /* * Copy and convert size data... */ @@ -1353,7 +1351,32 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ */ snprintf(msg_id, sizeof(msg_id), "media-source.%s", pwg_name); - pwg_add_message(pc->strings, msg_id, choice->text); + msg.msg = msg_id; + + for (lang = langs; lang; lang = lang->next) + { + // See if the string is already localized... + if (cupsArrayFind(lang->strings, &msg)) + continue; // Yes + + // Otherwise add the text... + if (!strcmp(lang->language, "en")) + { + // English + msg.str = choice->text; + } + else + { + // Other languauge... + snprintf(ppd_name, sizeof(ppd_name), "%s.InputSlot", lang->language); + if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL) + msg.str = ppd_attr->text; + else + continue; + } + + cupsArrayAdd(lang->strings, &msg); + } } } @@ -1464,12 +1487,38 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ } } + /* * Add localized text for PWG keyword to message catalog... */ snprintf(msg_id, sizeof(msg_id), "media-type.%s", map->pwg); - pwg_add_message(pc->strings, msg_id, choice->text); + msg.msg = msg_id; + + for (lang = langs; lang; lang = lang->next) + { + // See if the string is already localized... + if (cupsArrayFind(lang->strings, &msg)) + continue; // Yes + + // Otherwise add the text... + if (!strcmp(lang->language, "en")) + { + // English + msg.str = choice->text; + } + else + { + // Other languauge... + snprintf(ppd_name, sizeof(ppd_name), "%s.MediaType", lang->language); + if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL) + msg.str = ppd_attr->text; + else + continue; + } + + cupsArrayAdd(lang->strings, &msg); + } } } @@ -1497,12 +1546,38 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ map->pwg = strdup(pwg_keyword); map->ppd = strdup(choice->choice); + /* * Add localized text for PWG keyword to message catalog... */ - snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_keyword); - pwg_add_message(pc->strings, msg_id, choice->text); + snprintf(msg_id, sizeof(msg_id), "output-bin.%s", pwg_name); + msg.msg = msg_id; + + for (lang = langs; lang; lang = lang->next) + { + // See if the string is already localized... + if (cupsArrayFind(lang->strings, &msg)) + continue; // Yes + + // Otherwise add the text... + if (!strcmp(lang->language, "en")) + { + // English + msg.str = choice->text; + } + else + { + // Other languauge... + snprintf(ppd_name, sizeof(ppd_name), "%s.OutputBin", lang->language); + if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL) + msg.str = ppd_attr->text; + else + continue; + } + + cupsArrayAdd(lang->strings, &msg); + } } } @@ -1520,12 +1595,14 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ do { +#if 0 /* * Add localized text for PWG keyword to message catalog... */ snprintf(msg_id, sizeof(msg_id), "preset-name.%s", ppd_attr->spec); pwg_add_message(pc->strings, msg_id, ppd_attr->text); +#endif // 0 /* * Get the options for this preset... @@ -1978,7 +2055,32 @@ _ppdCacheCreateWithPPD(ppd_file_t *ppd) /* I - PPD file */ */ snprintf(msg_id, sizeof(msg_id), "finishing-template.%s", choice->choice); - pwg_add_message(pc->strings, msg_id, choice->text); + msg.msg = msg_id; + + for (lang = langs; lang; lang = lang->next) + { + // See if the string is already localized... + if (cupsArrayFind(lang->strings, &msg)) + continue; // Yes + + // Otherwise add the text... + if (!strcmp(lang->language, "en")) + { + // English + msg.str = choice->text; + } + else + { + // Other languauge... + snprintf(ppd_name, sizeof(ppd_name), "%s.cupsFinishingTemplate", lang->language); + if ((ppd_attr = ppdFindAttr(ppd, ppd_name, choice->choice)) != NULL) + msg.str = ppd_attr->text; + else + continue; + } + + cupsArrayAdd(lang->strings, &msg); + } } } @@ -2132,8 +2234,6 @@ _ppdCacheDestroy(_ppd_cache_t *pc) /* I - PPD cache and mapping data */ cupsArrayDelete(pc->support_files); - cupsArrayDelete(pc->strings); - free(pc); } @@ -5483,13 +5583,13 @@ ppd_get_string(cups_lang_t *base, // I - Base (CUPS) localization return (""); cupsCopyString(buffer, msgptr, bufsize); - buffer[0] = toupper(buffer[0] & 255); + buffer[0] = (char)toupper(buffer[0] & 255); for (bufptr = buffer + 1; *bufptr; bufptr ++) { if (*bufptr == '-') { *bufptr = ' '; - bufptr[1] = toupper(bufptr[1] & 255); + bufptr[1] = (char)toupper(bufptr[1] & 255); } } @@ -5548,27 +5648,6 @@ pwg_add_finishing( } -/* - * 'pwg_add_message()' - Add a message to the PPD cached strings. - */ - -static void -pwg_add_message(cups_array_t *a, /* I - Message catalog */ - const char *msg, /* I - Message identifier */ - const char *str) /* I - Localized string */ -{ - _cups_message_t *m; /* New message */ - - - if ((m = calloc(1, sizeof(_cups_message_t))) != NULL) - { - m->msg = strdup(msg); - m->str = strdup(str); - cupsArrayAdd(a, m); - } -} - - /* * 'pwg_compare_finishings()' - Compare two finishings values. */ diff --git a/cups/ppd-mark.c b/cups/ppd-mark.c index ef3e253405..1b1f5f211d 100644 --- a/cups/ppd-mark.c +++ b/cups/ppd-mark.c @@ -11,10 +11,6 @@ * PostScript is a trademark of Adobe Systems, Inc. */ -/* - * Include necessary headers... - */ - #include "cups-private.h" #include "ppd-private.h" #include "debug-internal.h" @@ -97,7 +93,7 @@ cupsMarkOptions( * Load PPD cache and mapping data as needed... */ - ppd->cache = _ppdCacheCreateWithPPD(ppd); + ppd->cache = _ppdCacheCreateWithPPD(NULL, ppd); } cache = ppd->cache; diff --git a/cups/ppd-private.h b/cups/ppd-private.h index f264406cce..fbeac2d559 100644 --- a/cups/ppd-private.h +++ b/cups/ppd-private.h @@ -136,8 +136,6 @@ struct _ppd_cache_s /**** PPD cache and PWG conversion data ****/ char *password; /* cupsJobPassword value */ cups_array_t *mandatory; /* cupsMandatory value */ char *charge_info_uri; /* cupsChargeInfoURI value */ - cups_lang_t *langs; /* Localization languages/strings */ - cups_array_t *strings; /* TODO: REMOVE ME */ cups_array_t *support_files; /* Support files - ICC profiles, etc. */ }; @@ -151,7 +149,7 @@ extern int _cupsRasterExecPS(cups_page_header2_t *h, int *preferred_bits, const extern int _cupsRasterInterpretPPD(cups_page_header2_t *h, ppd_file_t *ppd, int num_options, cups_option_t *options, cups_interpret_cb_t func) _CUPS_PRIVATE; extern _ppd_cache_t *_ppdCacheCreateWithFile(const char *filename, ipp_t **attrs) _CUPS_PRIVATE; -extern _ppd_cache_t *_ppdCacheCreateWithPPD(ppd_file_t *ppd) _CUPS_PRIVATE; +extern _ppd_cache_t *_ppdCacheCreateWithPPD(cups_lang_t *langs, ppd_file_t *ppd) _CUPS_PRIVATE; extern void _ppdCacheDestroy(_ppd_cache_t *pc) _CUPS_PRIVATE; extern const char *_ppdCacheGetBin(_ppd_cache_t *pc, const char *output_bin) _CUPS_PRIVATE; extern int _ppdCacheGetFinishingOptions(_ppd_cache_t *pc, ipp_t *job, ipp_finishings_t value, int num_options, cups_option_t **options) _CUPS_PRIVATE; diff --git a/scheduler/conf.h b/scheduler/conf.h index c80b45fcb1..19b5c1621b 100644 --- a/scheduler/conf.h +++ b/scheduler/conf.h @@ -110,6 +110,8 @@ VAR char *ConfigurationFile VALUE(NULL), /* Directory for request files */ *DocumentRoot VALUE(NULL); /* Root directory for documents */ +VAR cups_lang_t *Languages VALUE(NULL); + /* Languages that cupsd is providing */ VAR cups_array_t *ServerAlias VALUE(NULL); /* Alias names for server */ VAR int ServerNameIsIP VALUE(0); diff --git a/scheduler/cupsfilter.c b/scheduler/cupsfilter.c index a1511cd6b9..ebe6a37773 100644 --- a/scheduler/cupsfilter.c +++ b/scheduler/cupsfilter.c @@ -8,10 +8,6 @@ * Licensed under Apache License v2.0. See the file "LICENSE" for more information. */ -/* - * Include necessary headers... - */ - #include #include #include @@ -714,7 +710,7 @@ add_printer_filters( return (NULL); } - pc = _ppdCacheCreateWithPPD(ppd); + pc = _ppdCacheCreateWithPPD(NULL, ppd); if (!pc) return (NULL); diff --git a/scheduler/printers.c b/scheduler/printers.c index 0872534071..e4384abc63 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -9,10 +9,6 @@ * information. */ -/* - * Include necessary headers... - */ - #include "cupsd.h" #include #ifdef HAVE_APPLICATIONSERVICES_H @@ -4028,7 +4024,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ * Add make/model and other various attributes... */ - p->pc = _ppdCacheCreateWithPPD(ppd); + p->pc = _ppdCacheCreateWithPPD(Languages, ppd); if (!p->pc) cupsdLogMessage(CUPSD_LOG_WARN, "Unable to create cache of \"%s\": %s", ppd_name, cupsGetErrorString()); @@ -4154,6 +4150,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ ippAddString(p->ppd_attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-make-and-model", NULL, p->make_model); +#if 0 // TODO: Save global strings if (p->pc && p->pc->strings) _cupsMessageSave(strings_name, _CUPS_MESSAGE_STRINGS, p->pc->strings); @@ -4161,6 +4158,7 @@ load_ppd(cupsd_printer_t *p) /* I - Printer */ cupsdSetString(&p->strings, strings_name); else cupsdClearString(&p->strings); +#endif // 0 num_urf = 0; urf[num_urf ++] = "V1.4"; diff --git a/tools/ippeveps.c b/tools/ippeveps.c index 7a74098058..e4082f1f32 100644 --- a/tools/ippeveps.c +++ b/tools/ippeveps.c @@ -421,7 +421,7 @@ get_options(cups_option_t **options) /* O - Options */ * Load PPD file and the corresponding IPP <-> PPD cache data... */ - if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL && (ppd_cache = _ppdCacheCreateWithPPD(ppd)) != NULL) + if ((ppd = ppdOpenFile(getenv("PPD"))) != NULL && (ppd_cache = _ppdCacheCreateWithPPD(NULL, ppd)) != NULL) { /* TODO: Fix me - values are names, not numbers... Also need to support finishings-col */ if ((value = getenv("IPP_FINISHINGS")) == NULL) -- 2.47.2