From 156dd8aa898f68df90aca210ff73cf4278438a6d Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 5 Sep 2006 19:43:11 +0000 Subject: [PATCH] The command-line applications did not convert command-line strings to UTF-8 as needed (STR #1958) berkeley/lpc.c: berkeley/lpq.c: berkeley/lpr.c: berkeley/lprm.c: systemv/accept.c: systemv/cancel.c: systemv/cupsaddsmb.c: systemv/cupstestdsc.c: systemv/cupstestppd.c: systemv/lp.c: systemv/lpadmin.c: systemv/lpinfo.c: systemv/lpmove.c: systemv/lpoptions.c: systemv/lppasswd.c: systemv/lpstat.c: - main(): Add argv to _cupsSetLocale() call. cups/i18n.h: - Add argv argument to _cupsSetLocale(). cups/langprintf.c: - _cupsSetLocale(): Add argv argument and code to convert argv[1] to argv[argc-1] to UTF-8 as needed. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@5925 7a7537e8-13f0-0310-91df-b6672ffda945 --- berkeley/lpc.c | 2 +- berkeley/lpq.c | 2 +- berkeley/lpr.c | 2 +- berkeley/lprm.c | 2 +- cups/i18n.h | 2 +- cups/langprintf.c | 49 ++++++++++++++++++++++++++++++++++++++----- systemv/accept.c | 2 +- systemv/cancel.c | 2 +- systemv/cupsaddsmb.c | 2 +- systemv/cupstestdsc.c | 2 +- systemv/cupstestppd.c | 2 +- systemv/lp.c | 2 +- systemv/lpadmin.c | 2 +- systemv/lpinfo.c | 2 +- systemv/lpmove.c | 2 +- systemv/lpoptions.c | 2 +- systemv/lppasswd.c | 2 +- systemv/lpstat.c | 2 +- 18 files changed, 61 insertions(+), 22 deletions(-) diff --git a/berkeley/lpc.c b/berkeley/lpc.c index 5ef12d269..02a726f2e 100644 --- a/berkeley/lpc.c +++ b/berkeley/lpc.c @@ -65,7 +65,7 @@ main(int argc, /* I - Number of command-line arguments */ *params; /* Pointer to parameters */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Connect to the scheduler... diff --git a/berkeley/lpq.c b/berkeley/lpq.c index c975ca88f..67db3119e 100644 --- a/berkeley/lpq.c +++ b/berkeley/lpq.c @@ -78,7 +78,7 @@ main(int argc, /* I - Number of command-line arguments */ cups_dest_t *dests; /* Destinations */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Check for command-line options... diff --git a/berkeley/lpr.c b/berkeley/lpr.c index 0bcbd28d3..631cee65b 100644 --- a/berkeley/lpr.c +++ b/berkeley/lpr.c @@ -93,7 +93,7 @@ main(int argc, /* I - Number of command-line arguments */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ - _cupsSetLocale(); + _cupsSetLocale(argv); deletefile = 0; printer = NULL; diff --git a/berkeley/lprm.c b/berkeley/lprm.c index 21217332e..587853245 100644 --- a/berkeley/lprm.c +++ b/berkeley/lprm.c @@ -61,7 +61,7 @@ main(int argc, /* I - Number of command-line arguments */ http_encryption_t encryption; /* Encryption? */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Setup to cancel individual print jobs... diff --git a/cups/i18n.h b/cups/i18n.h index 233db986e..d4775376d 100644 --- a/cups/i18n.h +++ b/cups/i18n.h @@ -105,7 +105,7 @@ extern const char *_cupsLangString(cups_lang_t *lang, const char *message); extern void _cupsMessageFree(cups_array_t *a); extern cups_array_t *_cupsMessageLoad(const char *filename); extern const char *_cupsMessageLookup(cups_array_t *a, const char *m); -extern void _cupsSetLocale(void); +extern void _cupsSetLocale(char *argv[]); # ifdef __cplusplus } diff --git a/cups/langprintf.c b/cups/langprintf.c index 21b6c278c..6753f1936 100644 --- a/cups/langprintf.c +++ b/cups/langprintf.c @@ -28,7 +28,7 @@ * * _cupsLangPrintf() - Print a formatted message string to a file. * _cupsLangPuts() - Print a static message string to a file. - * _cupsSetLocale() - Set the current locale. + * _cupsSetLocale() - Set the current locale and transcode the command-line. */ /* @@ -140,15 +140,18 @@ _cupsLangPuts(FILE *fp, /* I - File to write to */ /* - * '_cupsSetLocale()' - Set the current locale. + * '_cupsSetLocale()' - Set the current locale and transcode the command-line. */ void -_cupsSetLocale(void) +_cupsSetLocale(char *argv[]) /* IO - Command-line arguments */ { + int i; /* Looping var */ + char buffer[8192]; /* Command-line argument buffer */ + _cups_globals_t *cg; /* Global data */ #ifdef LC_TIME - const char *lc_time; /* Current LC_TIME value */ - char new_lc_time[255], /* New LC_TIME value */ + const char *lc_time; /* Current LC_TIME value */ + char new_lc_time[255], /* New LC_TIME value */ *charset; /* Pointer to character set */ #endif /* LC_TIME */ @@ -181,6 +184,42 @@ _cupsSetLocale(void) setlocale(LC_TIME, new_lc_time); #endif /* LC_TIME */ + + /* + * Initialize the default language info... + */ + + cg = _cupsGlobals(); + + if (!cg->lang_default) + cg->lang_default = cupsLangDefault(); + + /* + * Transcode the command-line arguments from the locale charset to + * UTF-8... + */ + + if (cg->lang_default->encoding != CUPS_US_ASCII && + cg->lang_default->encoding != CUPS_UTF8) + { + for (i = 1; argv[i]; i ++) + { + /* + * Try converting from the locale charset to UTF-8... + */ + + if (cupsCharsetToUTF8((cups_utf8_t *)buffer, argv[i], sizeof(buffer), + cg->lang_default->encoding) < 0) + continue; + + /* + * Save the new string if it differs from the original... + */ + + if (strcmp(buffer, argv[i])) + argv[i] = strdup(buffer); + } + } } diff --git a/systemv/accept.c b/systemv/accept.c index 41dfed434..9cee0e753 100644 --- a/systemv/accept.c +++ b/systemv/accept.c @@ -58,7 +58,7 @@ main(int argc, /* I - Number of command-line arguments */ int cancel; /* Cancel jobs? */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * See what operation we're supposed to do... diff --git a/systemv/cancel.c b/systemv/cancel.c index 8e0dea494..509b8f69a 100644 --- a/systemv/cancel.c +++ b/systemv/cancel.c @@ -60,7 +60,7 @@ main(int argc, /* I - Number of command-line arguments */ ipp_op_t op; /* Operation */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Setup to cancel individual print jobs... diff --git a/systemv/cupsaddsmb.c b/systemv/cupsaddsmb.c index 64054eeaf..7bb2d5db2 100644 --- a/systemv/cupsaddsmb.c +++ b/systemv/cupsaddsmb.c @@ -78,7 +78,7 @@ main(int argc, /* I - Number of command-line arguments */ cups_dest_t *dests; /* Printers */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Parse command-line arguments... diff --git a/systemv/cupstestdsc.c b/systemv/cupstestdsc.c index 910561c6d..db5ea18cd 100644 --- a/systemv/cupstestdsc.c +++ b/systemv/cupstestdsc.c @@ -65,7 +65,7 @@ main(int argc, /* I - Number of command-line args */ int num_files; /* Number of files tested */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Collect command-line arguments... diff --git a/systemv/cupstestppd.c b/systemv/cupstestppd.c index 9b799243b..25c23b04a 100644 --- a/systemv/cupstestppd.c +++ b/systemv/cupstestppd.c @@ -113,7 +113,7 @@ main(int argc, /* I - Number of command-line arguments */ "JCL", "PAGE", "PROLOG" }; - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Display PPD files for each file listed on the command-line... diff --git a/systemv/lp.c b/systemv/lp.c index db3fbb494..92061e420 100644 --- a/systemv/lp.c +++ b/systemv/lp.c @@ -117,7 +117,7 @@ main(int argc, /* I - Number of command-line arguments */ return (0); #endif /* __sun */ - _cupsSetLocale(); + _cupsSetLocale(argv); silent = 0; printer = NULL; diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index a03a8977e..abece172d 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -92,7 +92,7 @@ main(int argc, /* I - Number of command-line arguments */ cups_option_t *options; /* Options */ - _cupsSetLocale(); + _cupsSetLocale(argv); http = NULL; printer = NULL; diff --git a/systemv/lpinfo.c b/systemv/lpinfo.c index 484ea29fb..deab62ed9 100644 --- a/systemv/lpinfo.c +++ b/systemv/lpinfo.c @@ -62,7 +62,7 @@ main(int argc, /* I - Number of command-line arguments */ int long_status; /* Long listing? */ - _cupsSetLocale(); + _cupsSetLocale(argv); http = NULL; long_status = 0; diff --git a/systemv/lpmove.c b/systemv/lpmove.c index 1cd5cfad5..5c71f05b6 100644 --- a/systemv/lpmove.c +++ b/systemv/lpmove.c @@ -66,7 +66,7 @@ main(int argc, /* I - Number of command-line arguments */ *dest; /* New destination */ - _cupsSetLocale(); + _cupsSetLocale(argv); dest = NULL; dests = NULL; diff --git a/systemv/lpoptions.c b/systemv/lpoptions.c index 778066397..1e0d5744c 100644 --- a/systemv/lpoptions.c +++ b/systemv/lpoptions.c @@ -69,7 +69,7 @@ main(int argc, /* I - Number of command-line arguments */ *option; /* Current option */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Loop through the command-line arguments... diff --git a/systemv/lppasswd.c b/systemv/lppasswd.c index 68bf570eb..b960ca5c0 100644 --- a/systemv/lppasswd.c +++ b/systemv/lppasswd.c @@ -102,7 +102,7 @@ main(int argc, /* I - Number of command-line arguments */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET*/ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Check to see if stdin, stdout, and stderr are still open... diff --git a/systemv/lpstat.c b/systemv/lpstat.c index af0a14c3c..139f8adb2 100644 --- a/systemv/lpstat.c +++ b/systemv/lpstat.c @@ -85,7 +85,7 @@ main(int argc, /* I - Number of command-line arguments */ char op; /* Last operation on command-line */ - _cupsSetLocale(); + _cupsSetLocale(argv); /* * Parse command-line options... -- 2.39.5