1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
|
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* http://www.opensource.org/licenses/cpl1.0.txt *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
/*
* generate <lc.h> implementation tables from lc.tab
* this must make it through vanilla cc with no -last
*
* # comment
* :charset:
* code name ms-codepage
* :language:
* code name alt1|alt2... charset|... attr1|attr2|...
* ...
* :territory:
* code name lang1|lang2...
* :abbreviation:
*/
#include <stdio.h>
#include <ctype.h>
#ifdef __STDC__
#include <stdlib.h>
#include <string.h>
#endif
typedef struct Link_s
{
struct Link_s* next;
char* code;
int index;
} Link_t;
typedef struct Table_s
{
Link_t* root;
int count;
} Table_t;
typedef struct Abbreviation_s
{
Link_t link;
char* value;
} Abbreviation_t;
typedef struct Attribute_s
{
Link_t link;
} Attribute_t;
typedef struct Attribute_list_s
{
struct Attribute_list_s*next;
Attribute_t* attribute;
} Attribute_list_t;
typedef struct Charset_s
{
Link_t link;
char* alternates;
char* ms;
} Charset_t;
typedef struct Language_s
{
Link_t link;
char* name;
char* alternates;
Charset_t* charset;
Attribute_list_t* attributes;
} Language_t;
typedef struct Language_list_s
{
struct Language_list_s* next;
Language_t* language;
} Language_list_t;
typedef struct Territory_s
{
Link_t link;
char* name;
Language_list_t* languages;
int primary;
int index;
} Territory_t;
typedef struct Map_s
{
Link_t link;
Language_t* language;
Territory_t* territory;
Charset_t* charset;
Attribute_t* attribute;
} Map_t;
static struct State_s
{
Table_t attribute;
Table_t charset;
Table_t language;
Table_t territory;
Table_t map;
} state;
#define INIT 0
#define CHARSET 1
#define LANGUAGE 2
#define TERRITORY 3
#define MAP 4
#define elementsof(x) (sizeof(x)/sizeof(x[0]))
#define newof(p,t,n,x) ((t*)malloc(sizeof(t)*(n)+(x)))
static Link_t*
#if defined(__STDC__) || defined(__cplusplus)
enter(register Table_t* tab, register Link_t* v)
#else
enter(tab, v)
register Table_t* tab;
register Link_t* v;
#endif
{
register Link_t* x;
register Link_t* p;
for (p = 0, x = tab->root; x; p = x, x = x->next)
if (!strcmp(x->code, v->code))
return x;
if (p)
p->next = v;
else
tab->root = v;
v->next = 0;
v->index = tab->count++;
return v;
}
static Link_t*
#if defined(__STDC__) || defined(__cplusplus)
lookup(register Table_t* tab, register char* s)
#else
lookup(tab, s)
register Table_t* tab;
register char* s;
#endif
{
register Link_t* x;
for (x = tab->root; x; x = x->next)
if (!strcmp(x->code, s))
return x;
return 0;
}
static char*
#if defined(__STDC__) || defined(__cplusplus)
copy(char** p, register char* f)
#else
copy(p, f)
char** p;
register char* f;
#endif
{
register char* t;
char* b;
if (!f)
return 0;
b = t = *p;
while (*t++ = *f++);
*p = t;
return b;
}
static void
#if defined(__STDC__) || defined(__cplusplus)
macro(FILE* f, char* p1, char* p2, char* p3)
#else
macro(f, p1, p2, p3)
FILE* f;
char* p1;
char* p2;
char* p3;
#endif
{
register int c;
register char* s;
register char* b;
register char* e;
int i;
int m;
int n;
char* part[4];
char buf[128];
part[0] = p1;
part[1] = p2;
part[2] = p3;
part[3] = 0;
n = 0;
fprintf(f, "\n");
do
{
i = m = 0;
b = buf;
e = &buf[sizeof(buf)-1];
while (b < e)
{
if (!(s = part[i++]))
break;
if (i > 1)
*b++ = '_';
while ((c = *s++) && b < e)
{
if (c == '|')
{
part[i-1] = s;
m = 1;
break;
}
else if (islower(c))
c = toupper(c);
else if (!isalnum(c))
c = '_';
*b++ = c;
}
}
*b = 0;
fprintf(f, "#ifdef %s\n%s,\n#else\n", buf, buf);
n++;
} while (m);
fprintf(f, "0,\n");
while (n-- > 0)
fprintf(f, "#endif\n");
}
#if defined(__STDC__) || defined(__cplusplus)
int
main(int argc, char** argv)
#else
int
main(argc, argv)
int argc;
char** argv;
#endif
{
register char* s;
register char** vp;
register char** ve;
Attribute_t* ap;
Attribute_list_t* al;
Attribute_list_t* az;
Charset_t* cp;
Territory_t* tp;
Language_t* lp;
Language_list_t* ll;
Language_list_t* lz;
Map_t* mp;
char* b;
char* f;
char* command;
char* hdr;
char* lib;
FILE* hf;
FILE* lf;
int c;
int i;
int line;
int type;
int language_attribute_max;
int territory_language_max;
char* arg[5];
char buf[1024];
command = *argv++;
line = 0;
if (!(hdr = *argv++) || !(lib = *argv++) || *argv)
{
fprintf(stderr, "%s: { hdr lib tab } arguments expected\n", command);
return 1;
}
if (!(hf = fopen(hdr, "w")))
{
fprintf(stderr, "%s: %s: cannot write\n", command, hdr);
return 1;
}
if (!(lf = fopen(lib, "w")))
{
fprintf(stderr, "%s: %s: cannot write\n", command, lib);
return 1;
}
type = 0;
language_attribute_max = 0;
territory_language_max = 0;
state.language.count = 2;
state.territory.count = 2;
ve = &arg[elementsof(arg)];
fprintf(hf, "/* : : generated by %s : : */\n", command);
fprintf(hf, "#pragma prototyped\n");
fprintf(hf, "\n");
fprintf(hf, "#ifndef _LC_H\n");
fprintf(hf, "#define _LC_H\t\t\t1\n");
fprintf(hf, "\n");
fprintf(hf, "#include <ast.h>\n");
fprintf(hf, "\n");
fprintf(hf, "#define LC_abbreviated\t\t0x00001\n");
fprintf(hf, "#define LC_checked\t\t0x00002\n");
fprintf(hf, "#define LC_debug\t\t0x00004\n");
fprintf(hf, "#define LC_default\t\t0x00008\n");
fprintf(hf, "#define LC_defined\t\t0x00010\n");
fprintf(hf, "#define LC_local\t\t0x00020\n");
fprintf(hf, "#define LC_primary\t\t0x00040\n");
fprintf(hf, "#define LC_qualified\t\t0x00080\n");
fprintf(hf, "#define LC_undefined\t\t0x00100\n");
fprintf(hf, "#define LC_utf8\t\t\t0x00200\n");
fprintf(hf, "#define LC_verbose\t\t0x00400\n");
fprintf(hf, "#define LC_setlocale\t\t\t0x10000\n");
fprintf(hf, "#define LC_setenv\t\t\t0x20000\n");
fprintf(hf, "#define LC_user\t\t\t0x40000\n");
fprintf(lf, "/* : : generated by %s : : */\n", command);
fprintf(lf, "\n");
fprintf(lf, "#include \"lclib.h\"\n");
fprintf(lf, "#include \"lclang.h\"\n");
fprintf(lf, "\n");
while (s = fgets(buf, sizeof(buf), stdin))
{
line++;
while (isspace(*s))
s++;
if (!*s || *s == '#')
continue;
b = s;
vp = arg;
for (;;)
{
for (*vp++ = s; *s && !isspace(*s); s++);
if (!*s)
break;
for (*s++ = 0; isspace(*s); s++);
if (!strcmp(*(vp - 1), "-"))
*(vp - 1) = 0;
if (!*s || vp >= ve)
break;
}
while (vp < ve)
*vp++ = 0;
if (*arg[0] == ':')
{
if (!strcmp(arg[0], ":map:"))
{
if (type != TERRITORY)
{
fprintf(stderr, "%s: %d: %s: must be specified after :territory:\n", command, line, arg[0]);
return 1;
}
type = MAP;
continue;
}
else if (!strcmp(arg[0], ":charset:"))
{
if (type != INIT)
{
fprintf(stderr, "%s: %d: %s must be specified first\n", command, line, arg[0]);
return 1;
}
type = CHARSET;
continue;
}
else if (!strcmp(arg[0], ":territory:"))
{
if (type != LANGUAGE)
{
fprintf(stderr, "%s: %d: %s: must be specified after :language:\n", command, line, arg[0]);
return 1;
}
type = TERRITORY;
continue;
}
else if (!strcmp(arg[0], ":language:"))
{
if (type != CHARSET)
{
fprintf(stderr, "%s: %d: %s must be specified after :charset:\n", command, line, arg[0]);
return 1;
}
type = LANGUAGE;
continue;
}
else
{
fprintf(stderr, "%s: %d: %s invalid\n", command, line, arg[0]);
return 1;
}
}
if (!arg[1])
{
fprintf(stderr, "%s: %d: at least two arguments expected\n", command, line);
return 1;
}
switch (type)
{
case CHARSET:
if (!(cp = newof(0, Charset_t, 1, s - b + 1)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
b = (char*)(cp + 1);
cp->link.code = copy(&b, arg[0]);
cp->alternates = copy(&b, arg[1]);
cp->ms = copy(&b, arg[2]);
if (cp != (Charset_t*)enter(&state.charset, (Link_t*)cp))
{
fprintf(stderr, "%s: %d: %s: duplicate charset\n", command, line, cp->link.code);
return 1;
}
break;
case TERRITORY:
if (!(tp = newof(0, Territory_t, 1, s - b + 1)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
b = (char*)(tp + 1);
tp->link.code = copy(&b, arg[0]);
tp->name = copy(&b, arg[1]);
tp->languages = 0;
if (s = copy(&b, arg[2]))
{
i = 0;
while (*(b = s))
{
for (; *s && *s != ':' && *s != '|'; s++);
if (c = *s)
*s++ = 0;
if (!(lp = (Language_t*)lookup(&state.language, b)))
{
fprintf(stderr, "%s: %d: %s: unknown language\n", command, line, b);
return 1;
}
if (!(ll = newof(0, Language_list_t, 1, 0)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
if (!tp->languages)
tp->languages = ll;
else
lz->next = ll;
lz = ll;
ll->language = lp;
ll->next = 0;
i++;
if (c == ':')
{
for (b = s; *s && *s != '|'; s++);
if (*s)
*s++ = 0;
if (!strcmp(b, "primary"))
tp->primary = 1;
}
}
if (territory_language_max < i)
territory_language_max = i;
}
if (tp != (Territory_t*)enter(&state.territory, (Link_t*)tp))
{
fprintf(stderr, "%s: %d: %s: duplicate territory\n", command, line, tp->link.code);
return 1;
}
break;
case LANGUAGE:
if (!(lp = newof(0, Language_t, 1, s - b + 1)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
b = (char*)(lp + 1);
lp->link.code = copy(&b, arg[0]);
lp->name = copy(&b, arg[1]);
lp->alternates = copy(&b, arg[2]);
if (!arg[3])
lp->charset = 0;
else if (!(lp->charset = (Charset_t*)lookup(&state.charset, arg[3])))
{
fprintf(stderr, "%s: %d: %s: unknown charset\n", command, line, arg[3]);
return 1;
}
lp->attributes = 0;
if (s = copy(&b, arg[4]))
{
i = 0;
fprintf(lf, "\nconst Lc_attribute_t attribute_%s[] =\n{\n", lp->link.code);
while (*(b = s))
{
for (f = 0; *s && *s != '|'; s++)
if (*s == ':')
{
*s++ = 0;
f = s;
}
if (*s)
*s++ = 0;
fprintf(lf, "{\"%s\",", b);
if (f)
fprintf(lf, "LC_%s,", f);
else
fprintf(lf, "0,");
if (!(ap = newof(0, Attribute_t, 1, 0)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
ap->link.code = b;
ap->link.index = i++;
if (!(al = newof(0, Attribute_list_t, 1, 0)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
if (!lp->attributes)
lp->attributes = al;
else
az->next = al;
az = al;
al->attribute = ap;
al->next = 0;
macro(lf, "SUBLANG", lp->name, b);
fprintf(lf, "\n},\n");
}
if (language_attribute_max < i)
language_attribute_max = i;
fprintf(lf, "};\n");
}
if (lp != (Language_t*)enter(&state.language, (Link_t*)lp))
{
fprintf(stderr, "%s: %d: %s: duplicate language\n", command, line, lp->link.code);
return 1;
}
break;
case MAP:
if (!(mp = newof(0, Map_t, 1, s - b + 1)))
{
fprintf(stderr, "%s: %d: out of space\n", command, line);
return 1;
}
b = (char*)(mp + 1);
mp->link.code = copy(&b, arg[0]);
if (!arg[2])
{
fprintf(stderr, "%s: %d: territory code expected\n", command, line);
return 1;
}
if (!(mp->language = (Language_t*)lookup(&state.language, arg[1])))
{
fprintf(stderr, "%s: %d: %s: unknown language\n", command, line, arg[1]);
return 1;
}
if (!(mp->territory = (Territory_t*)lookup(&state.territory, arg[2])))
{
fprintf(stderr, "%s: %d: %s: unknown territory\n", command, line, arg[2]);
return 1;
}
if (!arg[3])
mp->charset = 0;
else if (!(mp->charset = (Charset_t*)lookup(&state.charset, arg[3])))
{
fprintf(stderr, "%s: %d: %s: unknown charset\n", command, line, arg[3]);
return 1;
}
mp->attribute = 0;
if (arg[4])
{
for (al = mp->language->attributes; al; al = al->next)
if (!strcmp(al->attribute->link.code, arg[4]))
{
mp->attribute = al->attribute;
break;
}
if (!mp->attribute)
{
fprintf(stderr, "%s: %d: %s: unknown attribute\n", command, line, arg[4]);
return 1;
}
}
if (mp != (Map_t*)enter(&state.map, (Link_t*)mp))
{
fprintf(stderr, "%s: %d: %s: duplicate map\n", command, line, mp->link.code);
return 1;
}
break;
}
}
fprintf(hf, "#define LC_language_attribute_max\t\t%d\n", language_attribute_max);
fprintf(hf, "#define LC_territory_language_max\t\t%d\n", territory_language_max);
fprintf(hf, "\nstruct Lc_s;\n");
fprintf(hf, "\ntypedef struct Lc_info_s\n{\n");
fprintf(hf, "\tconst struct Lc_s*\tlc;\n");
fprintf(hf, "\tunsigned long\t\tnumber;\n");
fprintf(hf, "\tvoid*\t\t\tdata;\n");
fprintf(hf, "} Lc_info_t;\n");
fprintf(hf, "\ntypedef struct Lc_attribute_s\n{\n");
fprintf(hf, "\tconst char*\t\tname;\n");
fprintf(hf, "\tunsigned long\t\tflags;\n");
fprintf(hf, "\tunsigned long\t\tindex;\n");
fprintf(hf, "} Lc_attribute_t;\n");
fprintf(hf, "\ntypedef struct Lc_charset_s\n{\n");
fprintf(hf, "\tconst char*\t\tcode;\n");
fprintf(hf, "\tconst char*\t\talternates;\n");
fprintf(hf, "\tconst char*\t\tms;\n");
fprintf(hf, "\tunsigned long\t\tindex;\n");
fprintf(hf, "} Lc_charset_t;\n");
fprintf(hf, "\ntypedef struct Lc_language_s\n{\n");
fprintf(hf, "\tconst char*\t\tcode;\n");
fprintf(hf, "\tconst char*\t\tname;\n");
fprintf(hf, "\tconst char*\t\talternates;\n");
fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n");
fprintf(hf, "\tunsigned long\t\tflags;\n");
fprintf(hf, "\tunsigned long\t\tindex;\n");
fprintf(hf, "\tconst Lc_attribute_t*\tattributes[LC_language_attribute_max];\n");
fprintf(hf, "} Lc_language_t;\n");
fprintf(hf, "\ntypedef struct Lc_territory_s\n{\n");
fprintf(hf, "\tconst char*\t\tcode;\n");
fprintf(hf, "\tconst char*\t\tname;\n");
fprintf(hf, "\tunsigned long\t\tflags;\n");
fprintf(hf, "\tunsigned long\t\tindex;\n");
fprintf(hf, "\tconst Lc_language_t*\tlanguages[LC_territory_language_max];\n");
fprintf(hf, "#ifdef _LC_TERRITORY_PRIVATE_\n");
fprintf(hf, "\t_LC_TERRITORY_PRIVATE_\n");
fprintf(hf, "#endif\n");
fprintf(hf, "} Lc_territory_t;\n");
fprintf(hf, "\ntypedef struct Lc_map_s\n{\n");
fprintf(hf, "\tconst char*\t\tcode;\n");
fprintf(hf, "\tconst Lc_language_t*\tlanguage;\n");
fprintf(hf, "\tconst Lc_territory_t*\tterritory;\n");
fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n");
fprintf(hf, "\tconst Lc_attribute_t*\tattribute;\n");
fprintf(hf, "} Lc_map_t;\n");
fprintf(hf, "\ntypedef struct Lc_attribute_list_s\n{\n");
fprintf(hf, "\tstruct Lc_attribute_list_s*\tnext;\n");
fprintf(hf, "\tconst Lc_attribute_t*\t\tattribute;\n");
fprintf(hf, "} Lc_attribute_list_t;\n");
fprintf(hf, "\ntypedef struct Lc_s\n{\n");
fprintf(hf, "\tconst char*\t\tname;\n");
fprintf(hf, "\tconst char*\t\tcode;\n");
fprintf(hf, "\tconst Lc_language_t*\tlanguage;\n");
fprintf(hf, "\tconst Lc_territory_t*\tterritory;\n");
fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n");
fprintf(hf, "\tconst Lc_attribute_list_t*\tattributes;\n");
fprintf(hf, "\tunsigned long\t\tflags;\n");
fprintf(hf, "\tunsigned long\t\tindex;\n");
fprintf(hf, "#ifdef _LC_PRIVATE_\n");
fprintf(hf, "\t_LC_PRIVATE_\n");
fprintf(hf, "#endif\n");
fprintf(hf, "} Lc_t;\n");
fprintf(hf, "\nstruct Lc_category_s;\n");
fprintf(hf, "\ntypedef int (*Lc_category_set_f)(struct Lc_category_s*);\n");
fprintf(hf, "\ntypedef struct Lc_category_s\n{\n");
fprintf(hf, "\tconst char*\t\tname;\n");
fprintf(hf, "\tint\t\t\texternal;\n");
fprintf(hf, "\tint\t\t\tinternal;\n");
fprintf(hf, "\tLc_category_set_f\tsetf;\n");
fprintf(hf, "\tLc_t*\t\t\tprev;\n");
fprintf(hf, "\tunsigned int\t\tflags;\n");
fprintf(hf, "} Lc_category_t;\n");
fprintf(hf, "\n");
fprintf(hf, "#if _BLD_ast && defined(__EXPORT__)\n");
fprintf(hf, "#define extern\t\t__EXPORT__\n");
fprintf(hf, "#endif\n");
fprintf(hf, "\n");
fprintf(hf, "extern size_t\t\tlccanon(Lc_t*, unsigned long flags, char*, size_t);\n");
fprintf(hf, "extern Lc_category_t*\tlccategories(void);\n");
fprintf(hf, "extern int\t\tlcindex(int, int);\n");
fprintf(hf, "extern Lc_info_t*\tlcinfo(int);\n");
fprintf(hf, "extern Lc_t*\t\tlcmake(const char*);\n");
fprintf(hf, "extern Lc_t*\t\tlcscan(Lc_t*);\n");
fprintf(hf, "\n");
fprintf(hf, "#undef\textern\n");
fprintf(lf, "\nconst Lc_charset_t lc_charsets[] =\n{\n");
for (cp = (Charset_t*)state.charset.root; cp; cp = (Charset_t*)cp->link.next)
{
fprintf(lf, "{\"%s\",", cp->link.code);
if (cp->alternates)
fprintf(lf, "\"%s\",", cp->alternates);
else
fprintf(lf, "0,");
if (cp->ms)
fprintf(lf, "\"%s\",", cp->ms);
else
fprintf(lf, "0");
fprintf(lf, "},\n");
}
fprintf(lf, "\t0\n};\n");
fprintf(lf, "\nconst Lc_language_t lc_languages[] =\n{\n");
fprintf(lf, "{\"C\",\"C\",\"POSIX\",&lc_charsets[0],LC_default,0,");
for (i = 0; i < language_attribute_max; i++)
fprintf(lf, "0,");
fprintf(lf, "},\n");
fprintf(lf, "{\"debug\",\"debug\",0,&lc_charsets[0],LC_debug,0,");
for (i = 0; i < language_attribute_max; i++)
fprintf(lf, "0,");
fprintf(lf, "},\n");
for (lp = (Language_t*)state.language.root; lp; lp = (Language_t*)lp->link.next)
{
fprintf(lf, "{\"%s\",\"%s\",", lp->link.code, lp->name);
if (lp->alternates)
fprintf(lf, "\"%s\",", lp->alternates);
else
fprintf(lf, "0,");
fprintf(lf, "&lc_charsets[%d],0,", lp->charset ? lp->charset->link.index : 0);
macro(lf, "LANG", lp->name, (char*)0);
for (i = 0, al = lp->attributes; al; al = al->next, i++)
fprintf(lf, "&attribute_%s[%d],", lp->link.code, al->attribute->link.index);
for (; i < language_attribute_max; i++)
fprintf(lf, "0,");
fprintf(lf, "\n},\n");
}
fprintf(lf, "\t0\n};\n");
fprintf(lf, "\nconst Lc_territory_t lc_territories[] =\n{\n");
fprintf(lf, "{\"C\",\"C\",LC_default,0,&lc_languages[0],");
for (i = 1; i < 2 * territory_language_max; i++)
fprintf(lf, "0,");
fprintf(lf, "},\n");
fprintf(lf, "{\"debug\",\"debug\",LC_debug,0,&lc_languages[1],");
for (i = 1; i < 2 * territory_language_max; i++)
fprintf(lf, "0,");
fprintf(lf, "},\n");
for (tp = (Territory_t*)state.territory.root; tp; tp = (Territory_t*)tp->link.next)
{
fprintf(lf, "{\"%s\",\"%s\",", tp->link.code, tp->name);
if (tp->primary)
fprintf(lf, "LC_primary,");
else
fprintf(lf, "0,");
macro(lf, "CTRY", tp->name, (char*)0);
for (i = 0, ll = tp->languages; ll; ll = ll->next, i++)
fprintf(lf, "&lc_languages[%d],", ll->language->link.index);
for (; i < territory_language_max; i++)
fprintf(lf, "0,");
for (i = 0, ll = tp->languages; ll; ll = ll->next, i++)
macro(lf, "SUBLANG", ll->language->name, tp->name);
for (; i < territory_language_max; i++)
fprintf(lf, "0,");
fprintf(lf, "\n},\n");
}
fprintf(lf, "\t0\n};\n");
fprintf(lf, "\nconst Lc_map_t lc_maps[] =\n{\n");
for (mp = (Map_t*)state.map.root; mp; mp = (Map_t*)mp->link.next)
{
fprintf(lf, "{\"%s\",", mp->link.code);
fprintf(lf, "&lc_languages[%d],", mp->language->link.index);
fprintf(lf, "&lc_territories[%d],", mp->territory->link.index);
fprintf(lf, "&lc_charsets[%d],", mp->charset ? mp->charset->link.index : 0);
if (mp->attribute)
fprintf(lf, "&attribute_%s[%d]", mp->language->link.code, mp->attribute->link.index);
else
fprintf(lf, "0");
fprintf(lf, "},\n");
}
fprintf(lf, "\t0\n};\n");
fclose(lf);
fprintf(hf, "\n#endif\n");
fclose(hf);
return 0;
}
|