1 /* 2 * Localization test program for CUPS. 3 * 4 * Copyright 2007-2015 by Apple Inc. 5 * Copyright 1997-2006 by Easy Software Products. 6 * 7 * These coded instructions, statements, and computer programs are the 8 * property of Apple Inc. and are protected by Federal copyright 9 * law. Distribution and use rights are outlined in the file "LICENSE.txt" 10 * which should have been included with this file. If this file is 11 * missing or damaged, see the license at "http://www.cups.org/". 12 * 13 * This file is subject to the Apple OS-Developed Software exception. 14 */ 15 16 /* 17 * Include necessary headers... 18 */ 19 20 #include "cups-private.h" 21 #include "ppd-private.h" 22 23 24 /* 25 * 'main()' - Load the specified language and show the strings for yes and no. 26 */ 27 28 int /* O - Exit status */ 29 main(int argc, /* I - Number of command-line arguments */ 30 char *argv[]) /* I - Command-line arguments */ 31 { 32 int i; /* Looping var */ 33 int errors = 0; /* Number of errors */ 34 cups_lang_t *language; /* Message catalog */ 35 cups_lang_t *language2; /* Message catalog */ 36 struct lconv *loc; /* Locale data */ 37 char buffer[1024]; /* String buffer */ 38 double number; /* Number */ 39 static const char * const tests[] = /* Test strings */ 40 { 41 "1", 42 "-1", 43 "3", 44 "5.125" 45 }; 46 47 48 if (argc == 1) 49 { 50 language = cupsLangDefault(); 51 language2 = cupsLangDefault(); 52 } 53 else 54 { 55 language = cupsLangGet(argv[1]); 56 language2 = cupsLangGet(argv[1]); 57 58 setenv("LANG", argv[1], 1); 59 setenv("SOFTWARE", "CUPS/" CUPS_SVERSION, 1); 60 } 61 62 _cupsSetLocale(argv); 63 64 if (language != language2) 65 { 66 errors ++; 67 68 puts("**** ERROR: Language cache did not work! ****"); 69 puts("First result from cupsLangGet:"); 70 } 71 72 printf("Language = \"%s\"\n", language->language); 73 printf("Encoding = \"%s\"\n", _cupsEncodingName(language->encoding)); 74 printf("No = \"%s\"\n", _cupsLangString(language, "No")); 75 printf("Yes = \"%s\"\n", _cupsLangString(language, "Yes")); 76 77 if (language != language2) 78 { 79 puts("Second result from cupsLangGet:"); 80 81 printf("Language = \"%s\"\n", language2->language); 82 printf("Encoding = \"%s\"\n", _cupsEncodingName(language2->encoding)); 83 printf("No = \"%s\"\n", _cupsLangString(language2, "No")); 84 printf("Yes = \"%s\"\n", _cupsLangString(language2, "Yes")); 85 } 86 87 loc = localeconv(); 88 89 for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i ++) 90 { 91 number = _cupsStrScand(tests[i], NULL, loc); 92 93 printf("_cupsStrScand(\"%s\") number=%f\n", tests[i], number); 94 95 _cupsStrFormatd(buffer, buffer + sizeof(buffer), number, loc); 96 97 printf("_cupsStrFormatd(%f) buffer=\"%s\"\n", number, buffer); 98 99 if (strcmp(buffer, tests[i])) 100 { 101 errors ++; 102 puts("**** ERROR: Bad formatted number! ****"); 103 } 104 } 105 106 if (argc == 3) 107 { 108 ppd_file_t *ppd; /* PPD file */ 109 ppd_option_t *option; /* PageSize option */ 110 ppd_choice_t *choice; /* PageSize/Letter choice */ 111 112 if ((ppd = ppdOpenFile(argv[2])) == NULL) 113 { 114 printf("Unable to open PPD file \"%s\".\n", argv[2]); 115 errors ++; 116 } 117 else 118 { 119 ppdLocalize(ppd); 120 121 if ((option = ppdFindOption(ppd, "PageSize")) == NULL) 122 { 123 puts("No PageSize option."); 124 errors ++; 125 } 126 else 127 { 128 printf("PageSize: %s\n", option->text); 129 130 if ((choice = ppdFindChoice(option, "Letter")) == NULL) 131 { 132 puts("No Letter PageSize choice."); 133 errors ++; 134 } 135 else 136 { 137 printf("Letter: %s\n", choice->text); 138 } 139 } 140 141 ppdClose(ppd); 142 } 143 } 144 145 return (errors > 0); 146 } 147