]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/langprintf.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / langprintf.c
index f4fa589caffe334de2808b53717ffd475ab51c24..da835dc284954b764602bb9b892e100089861290 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: langprintf.c 177 2006-06-21 00:20:03Z jlovell $"
+ * "$Id: langprintf.c 5926 2006-09-05 20:45:47Z mike $"
  *
  *   Localized printf/puts functions for the Common UNIX Printing
  *   System (CUPS).
@@ -28,6 +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 and transcode the command-line.
  */
 
 /*
@@ -139,5 +140,89 @@ _cupsLangPuts(FILE        *fp,             /* I - File to write to */
 
 
 /*
- * End of "$Id: langprintf.c 177 2006-06-21 00:20:03Z jlovell $".
+ * '_cupsSetLocale()' - Set the current locale and transcode the command-line.
+ */
+
+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 */
+               *charset;               /* Pointer to character set */
+#endif /* LC_TIME */
+
+
+ /*
+  * Set the locale so that times, etc. are displayed properly.
+  *
+  * Unfortunately, while we need the localized time value, we *don't*
+  * want to use the localized charset for the time value, so we need
+  * to set LC_TIME to the locale name with .UTF-8 on the end (if
+  * the locale includes a character set specifier...)
+  */
+
+  setlocale(LC_ALL, "");
+
+#ifdef LC_TIME
+  if ((lc_time = setlocale(LC_TIME, NULL)) == NULL)
+    lc_time = setlocale(LC_ALL, NULL);
+
+  if (lc_time)
+  {
+    strlcpy(new_lc_time, lc_time, sizeof(new_lc_time));
+    if ((charset = strchr(new_lc_time, '.')) == NULL)
+      charset = new_lc_time + strlen(new_lc_time);
+
+    strlcpy(charset, ".UTF-8", sizeof(new_lc_time) - (charset - new_lc_time));
+  }
+  else
+    strcpy(new_lc_time, "C");
+
+  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);
+    }
+  }
+}
+
+
+/*
+ * End of "$Id: langprintf.c 5926 2006-09-05 20:45:47Z mike $".
  */