gen-unicode-ctype.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /* Generate a Unicode conforming LC_CTYPE category from a UnicodeData file.
  2. Copyright (C) 2000-2001 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Bruno Haible <haible@clisp.cons.org>, 2000.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. /* Usage example:
  17. $ gen-unicode /usr/local/share/Unidata/UnicodeData.txt 3.1
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <stdbool.h>
  22. #include <string.h>
  23. #include <time.h>
  24. /* This structure represents one line in the UnicodeData.txt file. */
  25. struct unicode_attribute
  26. {
  27. const char *name; /* Character name */
  28. const char *category; /* General category */
  29. const char *combining; /* Canonical combining classes */
  30. const char *bidi; /* Bidirectional category */
  31. const char *decomposition; /* Character decomposition mapping */
  32. const char *decdigit; /* Decimal digit value */
  33. const char *digit; /* Digit value */
  34. const char *numeric; /* Numeric value */
  35. int mirrored; /* mirrored */
  36. const char *oldname; /* Old Unicode 1.0 name */
  37. const char *comment; /* Comment */
  38. unsigned int upper; /* Uppercase mapping */
  39. unsigned int lower; /* Lowercase mapping */
  40. unsigned int title; /* Titlecase mapping */
  41. };
  42. /* Missing fields are represented with "" for strings, and NONE for
  43. characters. */
  44. #define NONE (~(unsigned int)0)
  45. /* The entire contents of the UnicodeData.txt file. */
  46. struct unicode_attribute unicode_attributes [0x110000];
  47. /* Stores in unicode_attributes[i] the values from the given fields. */
  48. static void
  49. fill_attribute (unsigned int i,
  50. const char *field1, const char *field2,
  51. const char *field3, const char *field4,
  52. const char *field5, const char *field6,
  53. const char *field7, const char *field8,
  54. const char *field9, const char *field10,
  55. const char *field11, const char *field12,
  56. const char *field13, const char *field14)
  57. {
  58. struct unicode_attribute * uni;
  59. if (i >= 0x110000)
  60. {
  61. fprintf (stderr, "index too large\n");
  62. exit (1);
  63. }
  64. if (strcmp (field2, "Cs") == 0)
  65. /* Surrogates are UTF-16 artefacts, not real characters. Ignore them. */
  66. return;
  67. uni = &unicode_attributes[i];
  68. /* Copy the strings. */
  69. uni->name = strdup (field1);
  70. uni->category = (field2[0] == '\0' ? "" : strdup (field2));
  71. uni->combining = (field3[0] == '\0' ? "" : strdup (field3));
  72. uni->bidi = (field4[0] == '\0' ? "" : strdup (field4));
  73. uni->decomposition = (field5[0] == '\0' ? "" : strdup (field5));
  74. uni->decdigit = (field6[0] == '\0' ? "" : strdup (field6));
  75. uni->digit = (field7[0] == '\0' ? "" : strdup (field7));
  76. uni->numeric = (field8[0] == '\0' ? "" : strdup (field8));
  77. uni->mirrored = (field9[0] == 'Y');
  78. uni->oldname = (field10[0] == '\0' ? "" : strdup (field10));
  79. uni->comment = (field11[0] == '\0' ? "" : strdup (field11));
  80. uni->upper = (field12[0] =='\0' ? NONE : strtoul (field12, NULL, 16));
  81. uni->lower = (field13[0] =='\0' ? NONE : strtoul (field13, NULL, 16));
  82. uni->title = (field14[0] =='\0' ? NONE : strtoul (field14, NULL, 16));
  83. }
  84. /* Maximum length of a field in the UnicodeData.txt file. */
  85. #define FIELDLEN 120
  86. /* Reads the next field from STREAM. The buffer BUFFER has size FIELDLEN.
  87. Reads up to (but excluding) DELIM.
  88. Returns 1 when a field was successfully read, otherwise 0. */
  89. static int
  90. getfield (FILE *stream, char *buffer, int delim)
  91. {
  92. int count = 0;
  93. int c;
  94. for (; (c = getc (stream)), (c != EOF && c != delim); )
  95. {
  96. /* The original unicode.org UnicodeData.txt file happens to have
  97. CR/LF line terminators. Silently convert to LF. */
  98. if (c == '\r')
  99. continue;
  100. /* Put c into the buffer. */
  101. if (++count >= FIELDLEN - 1)
  102. {
  103. fprintf (stderr, "field too long\n");
  104. exit (1);
  105. }
  106. *buffer++ = c;
  107. }
  108. if (c == EOF)
  109. return 0;
  110. *buffer = '\0';
  111. return 1;
  112. }
  113. /* Stores in unicode_attributes[] the entire contents of the UnicodeData.txt
  114. file. */
  115. static void
  116. fill_attributes (const char *unicodedata_filename)
  117. {
  118. unsigned int i, j;
  119. FILE *stream;
  120. char field0[FIELDLEN];
  121. char field1[FIELDLEN];
  122. char field2[FIELDLEN];
  123. char field3[FIELDLEN];
  124. char field4[FIELDLEN];
  125. char field5[FIELDLEN];
  126. char field6[FIELDLEN];
  127. char field7[FIELDLEN];
  128. char field8[FIELDLEN];
  129. char field9[FIELDLEN];
  130. char field10[FIELDLEN];
  131. char field11[FIELDLEN];
  132. char field12[FIELDLEN];
  133. char field13[FIELDLEN];
  134. char field14[FIELDLEN];
  135. int lineno = 0;
  136. for (i = 0; i < 0x110000; i++)
  137. unicode_attributes[i].name = NULL;
  138. stream = fopen (unicodedata_filename, "r");
  139. if (stream == NULL)
  140. {
  141. fprintf (stderr, "error during fopen of '%s'\n", unicodedata_filename);
  142. exit (1);
  143. }
  144. for (;;)
  145. {
  146. int n;
  147. lineno++;
  148. n = getfield (stream, field0, ';');
  149. n += getfield (stream, field1, ';');
  150. n += getfield (stream, field2, ';');
  151. n += getfield (stream, field3, ';');
  152. n += getfield (stream, field4, ';');
  153. n += getfield (stream, field5, ';');
  154. n += getfield (stream, field6, ';');
  155. n += getfield (stream, field7, ';');
  156. n += getfield (stream, field8, ';');
  157. n += getfield (stream, field9, ';');
  158. n += getfield (stream, field10, ';');
  159. n += getfield (stream, field11, ';');
  160. n += getfield (stream, field12, ';');
  161. n += getfield (stream, field13, ';');
  162. n += getfield (stream, field14, '\n');
  163. if (n == 0)
  164. break;
  165. if (n != 15)
  166. {
  167. fprintf (stderr, "short line in'%s':%d\n",
  168. unicodedata_filename, lineno);
  169. exit (1);
  170. }
  171. i = strtoul (field0, NULL, 16);
  172. if (field1[0] == '<'
  173. && strlen (field1) >= 9
  174. && !strcmp (field1 + strlen(field1) - 8, ", First>"))
  175. {
  176. /* Deal with a range. */
  177. lineno++;
  178. n = getfield (stream, field0, ';');
  179. n += getfield (stream, field1, ';');
  180. n += getfield (stream, field2, ';');
  181. n += getfield (stream, field3, ';');
  182. n += getfield (stream, field4, ';');
  183. n += getfield (stream, field5, ';');
  184. n += getfield (stream, field6, ';');
  185. n += getfield (stream, field7, ';');
  186. n += getfield (stream, field8, ';');
  187. n += getfield (stream, field9, ';');
  188. n += getfield (stream, field10, ';');
  189. n += getfield (stream, field11, ';');
  190. n += getfield (stream, field12, ';');
  191. n += getfield (stream, field13, ';');
  192. n += getfield (stream, field14, '\n');
  193. if (n != 15)
  194. {
  195. fprintf (stderr, "missing end range in '%s':%d\n",
  196. unicodedata_filename, lineno);
  197. exit (1);
  198. }
  199. if (!(field1[0] == '<'
  200. && strlen (field1) >= 8
  201. && !strcmp (field1 + strlen (field1) - 7, ", Last>")))
  202. {
  203. fprintf (stderr, "missing end range in '%s':%d\n",
  204. unicodedata_filename, lineno);
  205. exit (1);
  206. }
  207. field1[strlen (field1) - 7] = '\0';
  208. j = strtoul (field0, NULL, 16);
  209. for (; i <= j; i++)
  210. fill_attribute (i, field1+1, field2, field3, field4, field5,
  211. field6, field7, field8, field9, field10,
  212. field11, field12, field13, field14);
  213. }
  214. else
  215. {
  216. /* Single character line */
  217. fill_attribute (i, field1, field2, field3, field4, field5,
  218. field6, field7, field8, field9, field10,
  219. field11, field12, field13, field14);
  220. }
  221. }
  222. if (ferror (stream) || fclose (stream))
  223. {
  224. fprintf (stderr, "error reading from '%s'\n", unicodedata_filename);
  225. exit (1);
  226. }
  227. }
  228. /* Character mappings. */
  229. static unsigned int
  230. to_upper (unsigned int ch)
  231. {
  232. if (unicode_attributes[ch].name != NULL
  233. && unicode_attributes[ch].upper != NONE)
  234. return unicode_attributes[ch].upper;
  235. else
  236. return ch;
  237. }
  238. static unsigned int
  239. to_lower (unsigned int ch)
  240. {
  241. if (unicode_attributes[ch].name != NULL
  242. && unicode_attributes[ch].lower != NONE)
  243. return unicode_attributes[ch].lower;
  244. else
  245. return ch;
  246. }
  247. static unsigned int
  248. to_title (unsigned int ch)
  249. {
  250. if (unicode_attributes[ch].name != NULL
  251. && unicode_attributes[ch].title != NONE)
  252. return unicode_attributes[ch].title;
  253. else
  254. return ch;
  255. }
  256. /* Character class properties. */
  257. static bool
  258. is_upper (unsigned int ch)
  259. {
  260. return (to_lower (ch) != ch);
  261. }
  262. static bool
  263. is_lower (unsigned int ch)
  264. {
  265. return (to_upper (ch) != ch)
  266. /* <U00DF> is lowercase, but without simple to_upper mapping. */
  267. || (ch == 0x00DF);
  268. }
  269. static bool
  270. is_alpha (unsigned int ch)
  271. {
  272. return (unicode_attributes[ch].name != NULL
  273. && ((unicode_attributes[ch].category[0] == 'L'
  274. /* Theppitak Karoonboonyanan <thep@links.nectec.or.th> says
  275. <U0E2F>, <U0E46> should belong to is_punct. */
  276. && (ch != 0x0E2F) && (ch != 0x0E46))
  277. /* Theppitak Karoonboonyanan <thep@links.nectec.or.th> says
  278. <U0E31>, <U0E34>..<U0E3A>, <U0E47>..<U0E4E> are is_alpha. */
  279. || (ch == 0x0E31)
  280. || (ch >= 0x0E34 && ch <= 0x0E3A)
  281. || (ch >= 0x0E47 && ch <= 0x0E4E)
  282. /* Avoid warning for <U0345>. */
  283. || (ch == 0x0345)
  284. /* Avoid warnings for <U2160>..<U217F>. */
  285. || (unicode_attributes[ch].category[0] == 'N'
  286. && unicode_attributes[ch].category[1] == 'l')
  287. /* Avoid warnings for <U24B6>..<U24E9>. */
  288. || (unicode_attributes[ch].category[0] == 'S'
  289. && unicode_attributes[ch].category[1] == 'o'
  290. && strstr (unicode_attributes[ch].name, " LETTER ")
  291. != NULL)
  292. /* Consider all the non-ASCII digits as alphabetic.
  293. ISO C 99 forbids us to have them in category "digit",
  294. but we want iswalnum to return true on them. */
  295. || (unicode_attributes[ch].category[0] == 'N'
  296. && unicode_attributes[ch].category[1] == 'd'
  297. && !(ch >= 0x0030 && ch <= 0x0039))));
  298. }
  299. static bool
  300. is_digit (unsigned int ch)
  301. {
  302. #if 0
  303. return (unicode_attributes[ch].name != NULL
  304. && unicode_attributes[ch].category[0] == 'N'
  305. && unicode_attributes[ch].category[1] == 'd');
  306. /* Note: U+0BE7..U+0BEF and U+1369..U+1371 are digit systems without
  307. a zero. Must add <0> in front of them by hand. */
  308. #else
  309. /* SUSV2 gives us some freedom for the "digit" category, but ISO C 99
  310. takes it away:
  311. 7.25.2.1.5:
  312. The iswdigit function tests for any wide character that corresponds
  313. to a decimal-digit character (as defined in 5.2.1).
  314. 5.2.1:
  315. the 10 decimal digits 0 1 2 3 4 5 6 7 8 9
  316. */
  317. return (ch >= 0x0030 && ch <= 0x0039);
  318. #endif
  319. }
  320. static bool
  321. is_outdigit (unsigned int ch)
  322. {
  323. return (ch >= 0x0030 && ch <= 0x0039);
  324. }
  325. static bool
  326. is_blank (unsigned int ch)
  327. {
  328. return (ch == 0x0009 /* '\t' */
  329. /* Category Zs without mention of "<noBreak>" */
  330. || (unicode_attributes[ch].name != NULL
  331. && unicode_attributes[ch].category[0] == 'Z'
  332. && unicode_attributes[ch].category[1] == 's'
  333. && !strstr (unicode_attributes[ch].decomposition, "<noBreak>")));
  334. }
  335. static bool
  336. is_space (unsigned int ch)
  337. {
  338. /* Don't make U+00A0 a space. Non-breaking space means that all programs
  339. should treat it like a punctuation character, not like a space. */
  340. return (ch == 0x0020 /* ' ' */
  341. || ch == 0x000C /* '\f' */
  342. || ch == 0x000A /* '\n' */
  343. || ch == 0x000D /* '\r' */
  344. || ch == 0x0009 /* '\t' */
  345. || ch == 0x000B /* '\v' */
  346. /* Categories Zl, Zp, and Zs without mention of "<noBreak>" */
  347. || (unicode_attributes[ch].name != NULL
  348. && unicode_attributes[ch].category[0] == 'Z'
  349. && (unicode_attributes[ch].category[1] == 'l'
  350. || unicode_attributes[ch].category[1] == 'p'
  351. || (unicode_attributes[ch].category[1] == 's'
  352. && !strstr (unicode_attributes[ch].decomposition,
  353. "<noBreak>")))));
  354. }
  355. static bool
  356. is_cntrl (unsigned int ch)
  357. {
  358. return (unicode_attributes[ch].name != NULL
  359. && (!strcmp (unicode_attributes[ch].name, "<control>")
  360. /* Categories Zl and Zp */
  361. || (unicode_attributes[ch].category[0] == 'Z'
  362. && (unicode_attributes[ch].category[1] == 'l'
  363. || unicode_attributes[ch].category[1] == 'p'))));
  364. }
  365. static bool
  366. is_xdigit (unsigned int ch)
  367. {
  368. #if 0
  369. return is_digit (ch)
  370. || (ch >= 0x0041 && ch <= 0x0046)
  371. || (ch >= 0x0061 && ch <= 0x0066);
  372. #else
  373. /* SUSV2 gives us some freedom for the "xdigit" category, but ISO C 99
  374. takes it away:
  375. 7.25.2.1.12:
  376. The iswxdigit function tests for any wide character that corresponds
  377. to a hexadecimal-digit character (as defined in 6.4.4.1).
  378. 6.4.4.1:
  379. hexadecimal-digit: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F
  380. */
  381. return (ch >= 0x0030 && ch <= 0x0039)
  382. || (ch >= 0x0041 && ch <= 0x0046)
  383. || (ch >= 0x0061 && ch <= 0x0066);
  384. #endif
  385. }
  386. static bool
  387. is_graph (unsigned int ch)
  388. {
  389. return (unicode_attributes[ch].name != NULL
  390. && strcmp (unicode_attributes[ch].name, "<control>")
  391. && !is_space (ch));
  392. }
  393. static bool
  394. is_print (unsigned int ch)
  395. {
  396. return (unicode_attributes[ch].name != NULL
  397. && strcmp (unicode_attributes[ch].name, "<control>")
  398. /* Categories Zl and Zp */
  399. && !(unicode_attributes[ch].name != NULL
  400. && unicode_attributes[ch].category[0] == 'Z'
  401. && (unicode_attributes[ch].category[1] == 'l'
  402. || unicode_attributes[ch].category[1] == 'p')));
  403. }
  404. static bool
  405. is_punct (unsigned int ch)
  406. {
  407. #if 0
  408. return (unicode_attributes[ch].name != NULL
  409. && unicode_attributes[ch].category[0] == 'P');
  410. #else
  411. /* The traditional POSIX definition of punctuation is every graphic,
  412. non-alphanumeric character. */
  413. return (is_graph (ch) && !is_alpha (ch) && !is_digit (ch));
  414. #endif
  415. }
  416. static bool
  417. is_combining (unsigned int ch)
  418. {
  419. /* Up to Unicode 3.0.1 we took the Combining property from the PropList.txt
  420. file. In 3.0.1 it was identical to the union of the general categories
  421. "Mn", "Mc", "Me". In Unicode 3.1 this property has been dropped from the
  422. PropList.txt file, so we take the latter definition. */
  423. return (unicode_attributes[ch].name != NULL
  424. && unicode_attributes[ch].category[0] == 'M'
  425. && (unicode_attributes[ch].category[1] == 'n'
  426. || unicode_attributes[ch].category[1] == 'c'
  427. || unicode_attributes[ch].category[1] == 'e'));
  428. }
  429. static bool
  430. is_combining_level3 (unsigned int ch)
  431. {
  432. return is_combining (ch)
  433. && !(unicode_attributes[ch].combining[0] != '\0'
  434. && unicode_attributes[ch].combining[0] != '0'
  435. && strtoul (unicode_attributes[ch].combining, NULL, 10) >= 200);
  436. }
  437. /* Return the UCS symbol string for a Unicode character. */
  438. static const char *
  439. ucs_symbol (unsigned int i)
  440. {
  441. static char buf[11+1];
  442. sprintf (buf, (i < 0x10000 ? "<U%04X>" : "<U%08X>"), i);
  443. return buf;
  444. }
  445. /* Return the UCS symbol range string for a Unicode characters interval. */
  446. static const char *
  447. ucs_symbol_range (unsigned int low, unsigned int high)
  448. {
  449. static char buf[24+1];
  450. strcpy (buf, ucs_symbol (low));
  451. strcat (buf, "..");
  452. strcat (buf, ucs_symbol (high));
  453. return buf;
  454. }
  455. /* Output a character class (= property) table. */
  456. static void
  457. output_charclass (FILE *stream, const char *classname,
  458. bool (*func) (unsigned int))
  459. {
  460. char table[0x110000];
  461. unsigned int i;
  462. bool need_semicolon;
  463. const int max_column = 75;
  464. int column;
  465. for (i = 0; i < 0x110000; i++)
  466. table[i] = (int) func (i);
  467. fprintf (stream, "%s ", classname);
  468. need_semicolon = false;
  469. column = 1000;
  470. for (i = 0; i < 0x110000; )
  471. {
  472. if (!table[i])
  473. i++;
  474. else
  475. {
  476. unsigned int low, high;
  477. char buf[25];
  478. low = i;
  479. do
  480. i++;
  481. while (i < 0x110000 && table[i]);
  482. high = i - 1;
  483. if (low == high)
  484. strcpy (buf, ucs_symbol (low));
  485. else
  486. strcpy (buf, ucs_symbol_range (low, high));
  487. if (need_semicolon)
  488. {
  489. fprintf (stream, ";");
  490. column++;
  491. }
  492. if (column + strlen (buf) > max_column)
  493. {
  494. fprintf (stream, "/\n ");
  495. column = 3;
  496. }
  497. fprintf (stream, "%s", buf);
  498. column += strlen (buf);
  499. need_semicolon = true;
  500. }
  501. }
  502. fprintf (stream, "\n");
  503. }
  504. /* Output a character mapping table. */
  505. static void
  506. output_charmap (FILE *stream, const char *mapname,
  507. unsigned int (*func) (unsigned int))
  508. {
  509. char table[0x110000];
  510. unsigned int i;
  511. bool need_semicolon;
  512. const int max_column = 75;
  513. int column;
  514. for (i = 0; i < 0x110000; i++)
  515. table[i] = (func (i) != i);
  516. fprintf (stream, "%s ", mapname);
  517. need_semicolon = false;
  518. column = 1000;
  519. for (i = 0; i < 0x110000; i++)
  520. if (table[i])
  521. {
  522. char buf[25+1];
  523. strcpy (buf, "(");
  524. strcat (buf, ucs_symbol (i));
  525. strcat (buf, ",");
  526. strcat (buf, ucs_symbol (func (i)));
  527. strcat (buf, ")");
  528. if (need_semicolon)
  529. {
  530. fprintf (stream, ";");
  531. column++;
  532. }
  533. if (column + strlen (buf) > max_column)
  534. {
  535. fprintf (stream, "/\n ");
  536. column = 3;
  537. }
  538. fprintf (stream, "%s", buf);
  539. column += strlen (buf);
  540. need_semicolon = true;
  541. }
  542. fprintf (stream, "\n");
  543. }
  544. /* Output the width table. */
  545. static void
  546. output_widthmap (FILE *stream)
  547. {
  548. }
  549. /* Output the tables to the given file. */
  550. static void
  551. output_tables (const char *filename, const char *version)
  552. {
  553. FILE *stream;
  554. unsigned int ch;
  555. stream = fopen (filename, "w");
  556. if (stream == NULL)
  557. {
  558. fprintf (stderr, "cannot open '%s' for writing\n", filename);
  559. exit (1);
  560. }
  561. fprintf (stream, "escape_char /\n");
  562. fprintf (stream, "comment_char %%\n");
  563. fprintf (stream, "\n");
  564. fprintf (stream, "%% Generated automatically by gen-unicode-ctype for Unicode %s.\n",
  565. version);
  566. fprintf (stream, "\n");
  567. fprintf (stream, "LC_IDENTIFICATION\n");
  568. fprintf (stream, "title \"Unicode %s FDCC-set\"\n", version);
  569. fprintf (stream, "source \"UnicodeData.txt, PropList.txt\"\n");
  570. fprintf (stream, "address \"\"\n");
  571. fprintf (stream, "contact \"\"\n");
  572. fprintf (stream, "email \"bug-glibc-locales@gnu.org\"\n");
  573. fprintf (stream, "tel \"\"\n");
  574. fprintf (stream, "fax \"\"\n");
  575. fprintf (stream, "language \"\"\n");
  576. fprintf (stream, "territory \"Earth\"\n");
  577. fprintf (stream, "revision \"%s\"\n", version);
  578. {
  579. time_t now;
  580. char date[11];
  581. now = time (NULL);
  582. strftime (date, sizeof (date), "%Y-%m-%d", gmtime (&now));
  583. fprintf (stream, "date \"%s\"\n", date);
  584. }
  585. fprintf (stream, "category \"unicode:2001\";LC_CTYPE\n");
  586. fprintf (stream, "END LC_IDENTIFICATION\n");
  587. fprintf (stream, "\n");
  588. /* Verifications. */
  589. for (ch = 0; ch < 0x110000; ch++)
  590. {
  591. /* toupper restriction: "Only characters specified for the keywords
  592. lower and upper shall be specified. */
  593. if (to_upper (ch) != ch && !(is_lower (ch) || is_upper (ch)))
  594. fprintf (stderr,
  595. "%s is not upper|lower but toupper(0x%04X) = 0x%04X\n",
  596. ucs_symbol (ch), ch, to_upper (ch));
  597. /* tolower restriction: "Only characters specified for the keywords
  598. lower and upper shall be specified. */
  599. if (to_lower (ch) != ch && !(is_lower (ch) || is_upper (ch)))
  600. fprintf (stderr,
  601. "%s is not upper|lower but tolower(0x%04X) = 0x%04X\n",
  602. ucs_symbol (ch), ch, to_lower (ch));
  603. /* alpha restriction: "Characters classified as either upper or lower
  604. shall automatically belong to this class. */
  605. if ((is_lower (ch) || is_upper (ch)) && !is_alpha (ch))
  606. fprintf (stderr, "%s is upper|lower but not alpha\n", ucs_symbol (ch));
  607. /* alpha restriction: "No character specified for the keywords cntrl,
  608. digit, punct or space shall be specified." */
  609. if (is_alpha (ch) && is_cntrl (ch))
  610. fprintf (stderr, "%s is alpha and cntrl\n", ucs_symbol (ch));
  611. if (is_alpha (ch) && is_digit (ch))
  612. fprintf (stderr, "%s is alpha and digit\n", ucs_symbol (ch));
  613. if (is_alpha (ch) && is_punct (ch))
  614. fprintf (stderr, "%s is alpha and punct\n", ucs_symbol (ch));
  615. if (is_alpha (ch) && is_space (ch))
  616. fprintf (stderr, "%s is alpha and space\n", ucs_symbol (ch));
  617. /* space restriction: "No character specified for the keywords upper,
  618. lower, alpha, digit, graph or xdigit shall be specified."
  619. upper, lower, alpha already checked above. */
  620. if (is_space (ch) && is_digit (ch))
  621. fprintf (stderr, "%s is space and digit\n", ucs_symbol (ch));
  622. if (is_space (ch) && is_graph (ch))
  623. fprintf (stderr, "%s is space and graph\n", ucs_symbol (ch));
  624. if (is_space (ch) && is_xdigit (ch))
  625. fprintf (stderr, "%s is space and xdigit\n", ucs_symbol (ch));
  626. /* cntrl restriction: "No character specified for the keywords upper,
  627. lower, alpha, digit, punct, graph, print or xdigit shall be
  628. specified." upper, lower, alpha already checked above. */
  629. if (is_cntrl (ch) && is_digit (ch))
  630. fprintf (stderr, "%s is cntrl and digit\n", ucs_symbol (ch));
  631. if (is_cntrl (ch) && is_punct (ch))
  632. fprintf (stderr, "%s is cntrl and punct\n", ucs_symbol (ch));
  633. if (is_cntrl (ch) && is_graph (ch))
  634. fprintf (stderr, "%s is cntrl and graph\n", ucs_symbol (ch));
  635. if (is_cntrl (ch) && is_print (ch))
  636. fprintf (stderr, "%s is cntrl and print\n", ucs_symbol (ch));
  637. if (is_cntrl (ch) && is_xdigit (ch))
  638. fprintf (stderr, "%s is cntrl and xdigit\n", ucs_symbol (ch));
  639. /* punct restriction: "No character specified for the keywords upper,
  640. lower, alpha, digit, cntrl, xdigit or as the <space> character shall
  641. be specified." upper, lower, alpha, cntrl already checked above. */
  642. if (is_punct (ch) && is_digit (ch))
  643. fprintf (stderr, "%s is punct and digit\n", ucs_symbol (ch));
  644. if (is_punct (ch) && is_xdigit (ch))
  645. fprintf (stderr, "%s is punct and xdigit\n", ucs_symbol (ch));
  646. if (is_punct (ch) && (ch == 0x0020))
  647. fprintf (stderr, "%s is punct\n", ucs_symbol (ch));
  648. /* graph restriction: "No character specified for the keyword cntrl
  649. shall be specified." Already checked above. */
  650. /* print restriction: "No character specified for the keyword cntrl
  651. shall be specified." Already checked above. */
  652. /* graph - print relation: differ only in the <space> character.
  653. How is this possible if there are more than one space character?!
  654. I think susv2/xbd/locale.html should speak of "space characters",
  655. not "space character". */
  656. if (is_print (ch) && !(is_graph (ch) || /* ch == 0x0020 */ is_space (ch)))
  657. fprintf (stderr,
  658. "%s is print but not graph|<space>\n", ucs_symbol (ch));
  659. if (!is_print (ch) && (is_graph (ch) || ch == 0x0020))
  660. fprintf (stderr,
  661. "%s is graph|<space> but not print\n", ucs_symbol (ch));
  662. }
  663. fprintf (stream, "LC_CTYPE\n");
  664. output_charclass (stream, "upper", is_upper);
  665. output_charclass (stream, "lower", is_lower);
  666. output_charclass (stream, "alpha", is_alpha);
  667. output_charclass (stream, "digit", is_digit);
  668. output_charclass (stream, "outdigit", is_outdigit);
  669. output_charclass (stream, "blank", is_blank);
  670. output_charclass (stream, "space", is_space);
  671. output_charclass (stream, "cntrl", is_cntrl);
  672. output_charclass (stream, "punct", is_punct);
  673. output_charclass (stream, "xdigit", is_xdigit);
  674. output_charclass (stream, "graph", is_graph);
  675. output_charclass (stream, "print", is_print);
  676. output_charclass (stream, "class \"combining\";", is_combining);
  677. output_charclass (stream, "class \"combining_level3\";", is_combining_level3);
  678. output_charmap (stream, "toupper", to_upper);
  679. output_charmap (stream, "tolower", to_lower);
  680. output_charmap (stream, "map \"totitle\";", to_title);
  681. output_widthmap (stream);
  682. fprintf (stream, "END LC_CTYPE\n");
  683. if (ferror (stream) || fclose (stream))
  684. {
  685. fprintf (stderr, "error writing to '%s'\n", filename);
  686. exit (1);
  687. }
  688. }
  689. int
  690. main (int argc, char * argv[])
  691. {
  692. if (argc != 3)
  693. {
  694. fprintf (stderr, "Usage: %s UnicodeData.txt version\n", argv[0]);
  695. exit (1);
  696. }
  697. fill_attributes (argv[1]);
  698. output_tables ("unicode", argv[2]);
  699. return 0;
  700. }