tst_nl_langinfo.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <langinfo.h>
  5. #include <nl_types.h>
  6. #if !defined(__UCLIBC__) && 0
  7. #define DO_EXTRA
  8. #endif
  9. int main(int argc, char **argv)
  10. {
  11. char *l;
  12. const unsigned char *x;
  13. /* const unsigned char *y; */
  14. const unsigned char *p;
  15. if (argc > 2) {
  16. printf("invalid args\n");
  17. return EXIT_FAILURE;
  18. }
  19. if (argc == 1) {
  20. l = "";
  21. } else {
  22. l = *++argv;
  23. }
  24. if (!(x = setlocale(LC_ALL,l))) {
  25. printf("couldn't set locale %s\n", l);
  26. return EXIT_FAILURE;
  27. }
  28. /* printf("\nsetlocale returned:\n "); */
  29. /* do { */
  30. /* printf("\\x%02x", *x); */
  31. /* } while (*x++); */
  32. /* printf("\n"); */
  33. #ifndef __BCC__
  34. #define STR(X) #X
  35. #else
  36. #define STR(X) __STR(X)
  37. #endif
  38. #define __PASTE2(A,B) A.B
  39. #define DO_NL_I(X) \
  40. printf( STR(X) " = %d\n", (int) nl_langinfo(X) );
  41. #define DO_NL_S(X) \
  42. printf( STR(X) " = \"%s\"\n", nl_langinfo(X) );
  43. #define DO_NL_C(X) \
  44. printf( STR(X) " = \"\\x%02x\"\n", *((unsigned char *) nl_langinfo(X)) );
  45. printf("ctype\n");
  46. DO_NL_S(CODESET);
  47. #ifdef DO_EXTRA
  48. DO_NL_I(_NL_CTYPE_INDIGITS_MB_LEN);
  49. DO_NL_S(_NL_CTYPE_INDIGITS0_MB);
  50. DO_NL_S(_NL_CTYPE_INDIGITS1_MB);
  51. DO_NL_S(_NL_CTYPE_INDIGITS2_MB);
  52. DO_NL_S(_NL_CTYPE_INDIGITS3_MB);
  53. DO_NL_S(_NL_CTYPE_INDIGITS4_MB);
  54. DO_NL_S(_NL_CTYPE_INDIGITS5_MB);
  55. DO_NL_S(_NL_CTYPE_INDIGITS6_MB);
  56. DO_NL_S(_NL_CTYPE_INDIGITS7_MB);
  57. DO_NL_S(_NL_CTYPE_INDIGITS8_MB);
  58. DO_NL_S(_NL_CTYPE_INDIGITS9_MB);
  59. #endif
  60. DO_NL_S(_NL_CTYPE_OUTDIGIT0_MB);
  61. DO_NL_S(_NL_CTYPE_OUTDIGIT1_MB);
  62. DO_NL_S(_NL_CTYPE_OUTDIGIT2_MB);
  63. DO_NL_S(_NL_CTYPE_OUTDIGIT3_MB);
  64. DO_NL_S(_NL_CTYPE_OUTDIGIT4_MB);
  65. DO_NL_S(_NL_CTYPE_OUTDIGIT5_MB);
  66. DO_NL_S(_NL_CTYPE_OUTDIGIT6_MB);
  67. DO_NL_S(_NL_CTYPE_OUTDIGIT7_MB);
  68. DO_NL_S(_NL_CTYPE_OUTDIGIT8_MB);
  69. DO_NL_S(_NL_CTYPE_OUTDIGIT9_MB);
  70. printf("numeric\n");
  71. DO_NL_S(RADIXCHAR); /* DECIMAL_POINT */
  72. DO_NL_S(THOUSEP); /* THOUSANDS_SEP */
  73. /* DO_NL_S(GROUPING); */
  74. printf("GROUPING = \"");
  75. for (p = (unsigned char *) nl_langinfo(GROUPING) ; *p ; p++) {
  76. printf("\\x%02x", *p);
  77. }
  78. printf("\"\n\n");
  79. printf("monetary\n");
  80. DO_NL_S(INT_CURR_SYMBOL);
  81. DO_NL_S(CURRENCY_SYMBOL);
  82. DO_NL_S(MON_DECIMAL_POINT);
  83. DO_NL_S(MON_THOUSANDS_SEP);
  84. /* DO_NL_S(MON_GROUPING); */
  85. printf("MON_GROUPING = \"");
  86. for (p = (unsigned char *) nl_langinfo(MON_GROUPING) ; *p ; p++) {
  87. printf("\\x%02x", *p);
  88. }
  89. printf("\"\n\n");
  90. DO_NL_S(POSITIVE_SIGN);
  91. DO_NL_S(NEGATIVE_SIGN);
  92. DO_NL_C(INT_FRAC_DIGITS);
  93. DO_NL_C(FRAC_DIGITS);
  94. DO_NL_C(P_CS_PRECEDES);
  95. DO_NL_C(P_SEP_BY_SPACE);
  96. DO_NL_C(N_CS_PRECEDES);
  97. DO_NL_C(N_SEP_BY_SPACE);
  98. DO_NL_C(P_SIGN_POSN);
  99. DO_NL_C(N_SIGN_POSN);
  100. DO_NL_C(INT_P_CS_PRECEDES);
  101. DO_NL_C(INT_P_SEP_BY_SPACE);
  102. DO_NL_C(INT_N_CS_PRECEDES);
  103. DO_NL_C(INT_N_SEP_BY_SPACE);
  104. DO_NL_C(INT_P_SIGN_POSN);
  105. DO_NL_C(INT_N_SIGN_POSN);
  106. DO_NL_S(CRNCYSTR); /* CURRENCY_SYMBOL */
  107. printf("time\n");
  108. DO_NL_S(ABDAY_1);
  109. DO_NL_S(ABDAY_2);
  110. DO_NL_S(ABDAY_3);
  111. DO_NL_S(ABDAY_4);
  112. DO_NL_S(ABDAY_5);
  113. DO_NL_S(ABDAY_6);
  114. DO_NL_S(ABDAY_7);
  115. DO_NL_S(DAY_1);
  116. DO_NL_S(DAY_2);
  117. DO_NL_S(DAY_3);
  118. DO_NL_S(DAY_4);
  119. DO_NL_S(DAY_5);
  120. DO_NL_S(DAY_6);
  121. DO_NL_S(DAY_7);
  122. DO_NL_S(ABMON_1);
  123. DO_NL_S(ABMON_2);
  124. DO_NL_S(ABMON_3);
  125. DO_NL_S(ABMON_4);
  126. DO_NL_S(ABMON_5);
  127. DO_NL_S(ABMON_6);
  128. DO_NL_S(ABMON_7);
  129. DO_NL_S(ABMON_8);
  130. DO_NL_S(ABMON_9);
  131. DO_NL_S(ABMON_10);
  132. DO_NL_S(ABMON_11);
  133. DO_NL_S(ABMON_12);
  134. DO_NL_S(MON_1);
  135. DO_NL_S(MON_2);
  136. DO_NL_S(MON_3);
  137. DO_NL_S(MON_4);
  138. DO_NL_S(MON_5);
  139. DO_NL_S(MON_6);
  140. DO_NL_S(MON_7);
  141. DO_NL_S(MON_8);
  142. DO_NL_S(MON_9);
  143. DO_NL_S(MON_10);
  144. DO_NL_S(MON_11);
  145. DO_NL_S(MON_12);
  146. DO_NL_S(AM_STR);
  147. DO_NL_S(PM_STR);
  148. DO_NL_S(D_T_FMT);
  149. DO_NL_S(D_FMT);
  150. DO_NL_S(T_FMT);
  151. DO_NL_S(T_FMT_AMPM);
  152. /* DO_NL_S(ERA); */
  153. {
  154. const char *p = nl_langinfo(ERA);
  155. if (!p || !*p) {
  156. printf("ERA = (none)\n");
  157. } else {
  158. int i;
  159. printf("ERA:\n");
  160. for (i=0 ; i < 100 ; i++) {
  161. printf(" %3d: \"%s\"\n", i, p);
  162. while (*p) ++p;
  163. ++p;
  164. if (!*p) break;
  165. }
  166. }
  167. }
  168. DO_NL_S(ERA_YEAR); /* non SuSv3 */
  169. DO_NL_S(ERA_D_FMT);
  170. /* DO_NL_S(ALT_DIGITS); */
  171. {
  172. const char *p = nl_langinfo(ALT_DIGITS);
  173. if (!p || !*p) {
  174. printf("ALT_DIGITS = (none)\n");
  175. } else {
  176. int i;
  177. printf("ALT_DIGITS:\n");
  178. for (i=0 ; i < 100 ; i++) {
  179. printf(" %3d: \"%s\"\n", i, p);
  180. while (*p) ++p;
  181. ++p;
  182. }
  183. }
  184. }
  185. DO_NL_S(ERA_D_T_FMT);
  186. DO_NL_S(ERA_T_FMT);
  187. #ifdef DO_EXTRA
  188. DO_NL_C(_NL_TIME_WEEK_NDAYS);
  189. DO_NL_I(_NL_TIME_WEEK_1STDAY); /* grr... this won't work with 16bit ptrs */
  190. DO_NL_C(_NL_TIME_WEEK_1STWEEK);
  191. DO_NL_C(_NL_TIME_FIRST_WEEKDAY);
  192. DO_NL_C(_NL_TIME_FIRST_WORKDAY);
  193. DO_NL_C(_NL_TIME_CAL_DIRECTION);
  194. DO_NL_S(_NL_TIME_TIMEZONE);
  195. DO_NL_S(_DATE_FMT);
  196. #endif
  197. printf("messages\n");
  198. DO_NL_S(YESEXPR);
  199. DO_NL_S(NOEXPR);
  200. DO_NL_S(YESSTR);
  201. DO_NL_S(NOSTR);
  202. #ifdef DO_EXTRA
  203. printf("paper\n");
  204. DO_NL_I(_NL_PAPER_HEIGHT);
  205. DO_NL_I(_NL_PAPER_WIDTH);
  206. printf("name\n");
  207. DO_NL_S(_NL_NAME_NAME_FMT);
  208. DO_NL_S(_NL_NAME_NAME_GEN);
  209. DO_NL_S(_NL_NAME_NAME_MR);
  210. DO_NL_S(_NL_NAME_NAME_MRS);
  211. DO_NL_S(_NL_NAME_NAME_MISS);
  212. DO_NL_S(_NL_NAME_NAME_MS);
  213. printf("address\n");
  214. DO_NL_S(_NL_ADDRESS_POSTAL_FMT);
  215. DO_NL_S(_NL_ADDRESS_COUNTRY_NAME);
  216. DO_NL_S(_NL_ADDRESS_COUNTRY_POST);
  217. DO_NL_S(_NL_ADDRESS_COUNTRY_AB2);
  218. DO_NL_S(_NL_ADDRESS_COUNTRY_AB3);
  219. DO_NL_S(_NL_ADDRESS_COUNTRY_CAR);
  220. DO_NL_I(_NL_ADDRESS_COUNTRY_NUM);
  221. DO_NL_S(_NL_ADDRESS_COUNTRY_ISBN);
  222. DO_NL_S(_NL_ADDRESS_LANG_NAME);
  223. DO_NL_S(_NL_ADDRESS_LANG_AB);
  224. DO_NL_S(_NL_ADDRESS_LANG_TERM);
  225. DO_NL_S(_NL_ADDRESS_LANG_LIB);
  226. printf("telephone\n");
  227. DO_NL_S(_NL_TELEPHONE_TEL_INT_FMT);
  228. DO_NL_S(_NL_TELEPHONE_TEL_DOM_FMT);
  229. DO_NL_S(_NL_TELEPHONE_INT_SELECT);
  230. DO_NL_S(_NL_TELEPHONE_INT_PREFIX);
  231. printf("measurement\n");
  232. DO_NL_C(_NL_MEASUREMENT_MEASUREMENT); /* 1 is metric, 2 is US */
  233. printf("identification\n");
  234. DO_NL_S(_NL_IDENTIFICATION_TITLE);
  235. DO_NL_S(_NL_IDENTIFICATION_SOURCE);
  236. DO_NL_S(_NL_IDENTIFICATION_ADDRESS);
  237. DO_NL_S(_NL_IDENTIFICATION_CONTACT);
  238. DO_NL_S(_NL_IDENTIFICATION_EMAIL);
  239. DO_NL_S(_NL_IDENTIFICATION_TEL);
  240. DO_NL_S(_NL_IDENTIFICATION_FAX);
  241. DO_NL_S(_NL_IDENTIFICATION_LANGUAGE);
  242. DO_NL_S(_NL_IDENTIFICATION_TERRITORY);
  243. DO_NL_S(_NL_IDENTIFICATION_AUDIENCE);
  244. DO_NL_S(_NL_IDENTIFICATION_APPLICATION);
  245. DO_NL_S(_NL_IDENTIFICATION_ABBREVIATION);
  246. DO_NL_S(_NL_IDENTIFICATION_REVISION);
  247. DO_NL_S(_NL_IDENTIFICATION_DATE);
  248. DO_NL_S(_NL_IDENTIFICATION_CATEGORY);
  249. #endif
  250. return EXIT_SUCCESS;
  251. }