Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date/time display error for non-UTF-8 locales with lpstat #1751

Closed
michaelrsweet opened this issue Jun 6, 2006 · 5 comments
Closed

Date/time display error for non-UTF-8 locales with lpstat #1751

michaelrsweet opened this issue Jun 6, 2006 · 5 comments
Milestone

Comments

@michaelrsweet
Copy link
Collaborator

Version: 1.2.1
CUPS.org User: inger.altlinux

  1. cups lpstat utility uses _cupsLangPrintf() function to output results
  2. _cupsLangPrintf accepts utf8 strings only
  3. utility also uses strftime() function to perform current system time
  4. strftime() function with "%c" format will create string with my local, _ not utf8_ characters (koi8-r encoding)

As a result _cupsLangPrintf will fail and I see nothing on the screen.

How to reproduce it:
$ locale
LANG=ru_RU.KOI8-R
LC_CTYPE="ru_RU.KOI8-R"
LC_NUMERIC="ru_RU.KOI8-R"
LC_TIME="ru_RU.KOI8-R"
LC_COLLATE="ru_RU.KOI8-R"
LC_MONETARY="ru_RU.KOI8-R"
LC_MESSAGES="ru_RU.KOI8-R"
LC_PAPER="ru_RU.KOI8-R"
LC_NAME="ru_RU.KOI8-R"
LC_ADDRESS="ru_RU.KOI8-R"
LC_TELEPHONE="ru_RU.KOI8-R"
LC_MEASUREMENT="ru_RU.KOI8-R"
LC_IDENTIFICATION="ru_RU.KOI8-R"
LC_ALL=
$ lpstat -a
$

However:

$ LC_ALL=C lpstat -a
loc accepting requests since Mon Jun 5 15:35:26 2006
samsung accepting requests since Mon Jun 5 15:44:58 2006
$ LC_ALL=ru_RU.utf8 lpstat -a|iconv -futf8
loc accepting requests since �нд 05 ��н 2006 15:35:26
samsung accepting requests since �нд 05 ��н 2006 15:44:58
$

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Changing priority to match severity and summary to match actual problem...

Looks like we are going to have to hack lpstat to force a UTF-8 locale for LC_TIME.

Does the following produce the correct results on your system?

LC_TIME=ru_RU.UTF-8 lpstat -a

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: inger.altlinux

Yes, all works well (without any additional iconv in command line)

$ LC_TIME=ru_RU.utf8 lpstat -a
loc accepting requests since �нд 05 ��н 2006 15:35:26
samsung accepting requests since �нд 05 ��н 2006 15:44:58

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

OK, I believe I have a fix for this now; please test the attached patch or current SVN trunk...

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: inger.altlinux

works well on my system, thank you.

@michaelrsweet
Copy link
Collaborator Author

"str1751.patch":

Index: lpstat.c

--- lpstat.c (revision 5633)
+++ lpstat.c (working copy)
@@ -71,26 +71,59 @@
*/

int
-main(int argc, /* I - Number of command-line arguments */

  • char _argv[])     /_ I - Command-line arguments _/
    
    +main(int argc, /_ I - Number of command-line arguments */
  • char _argv[])         /_ I - Command-line arguments */
    
    {
  • int i, /* Looping var */
  •   status;     /\* Exit status */
    
  • http_t http; / Connection to server */
  • int num_dests; /* Number of user destinations */
  • cups_dest_t dests; / User destinations */
  • int long_status; /* Long status report? */
  • int ranking; /* Show job ranking? */
  • const char which; / Which jobs to show? */
  • char op; /* Last operation on command-line */
  • int i, /* Looping var */
  •   status;         /\* Exit status */
    
  • http_t http; / Connection to server */
  • int num_dests; /* Number of user destinations */
  • cups_dest_t dests; / User destinations */
  • int long_status; /* Long status report? */
  • int ranking; /* Show job ranking? */
  • const char which; / Which jobs to show? */
  • char op; /* Last operation on command-line */

/*

  • 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

  • {
  • const char lc_time; / Current LC_TIME value */
  • char new_lc_time[255], /* New LC_TIME value */
  •   _charset;       /_ Pointer to character set */
    
  • 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 */
  • /*
  • * Parse command-line options...
  • */

http = NULL;
num_dests = 0;
dests = NULL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant