tst_nl_langinfo.c 6.4 KB

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