14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*10898Sroland.mainz@nrubsig.org * Copyright (c) 1985-2009 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 78462SApril.Chin@Sun.COM * by AT&T Intellectual Property * 84887Schin * * 94887Schin * A copy of the License is available at * 104887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 124887Schin * * 134887Schin * Information and Software Systems Research * 144887Schin * AT&T Research * 154887Schin * Florham Park NJ * 164887Schin * * 174887Schin * Glenn Fowler <gsf@research.att.com> * 184887Schin * David Korn <dgk@research.att.com> * 194887Schin * Phong Vo <kpv@research.att.com> * 204887Schin * * 214887Schin ***********************************************************************/ 224887Schin /* 234887Schin * generate <lc.h> implementation tables from lc.tab 244887Schin * this must make it through vanilla cc with no -last 254887Schin * 264887Schin * # comment 274887Schin * :charset: 284887Schin * code name ms-codepage 294887Schin * :language: 304887Schin * code name alt1|alt2... charset|... attr1|attr2|... 314887Schin * ... 324887Schin * :territory: 334887Schin * code name lang1|lang2... 344887Schin * :abbreviation: 354887Schin */ 364887Schin 374887Schin #include <stdio.h> 384887Schin #include <ctype.h> 394887Schin #ifdef __STDC__ 404887Schin #include <stdlib.h> 414887Schin #include <string.h> 424887Schin #endif 434887Schin 444887Schin typedef struct Link_s 454887Schin { 464887Schin struct Link_s* next; 474887Schin char* code; 484887Schin int index; 494887Schin } Link_t; 504887Schin 514887Schin typedef struct Table_s 524887Schin { 534887Schin Link_t* root; 544887Schin int count; 554887Schin } Table_t; 564887Schin 574887Schin typedef struct Abbreviation_s 584887Schin { 594887Schin Link_t link; 604887Schin char* value; 614887Schin } Abbreviation_t; 624887Schin 634887Schin typedef struct Attribute_s 644887Schin { 654887Schin Link_t link; 664887Schin } Attribute_t; 674887Schin 684887Schin typedef struct Attribute_list_s 694887Schin { 704887Schin struct Attribute_list_s*next; 714887Schin Attribute_t* attribute; 724887Schin } Attribute_list_t; 734887Schin 744887Schin typedef struct Charset_s 754887Schin { 764887Schin Link_t link; 774887Schin char* alternates; 784887Schin char* ms; 794887Schin } Charset_t; 804887Schin 814887Schin typedef struct Language_s 824887Schin { 834887Schin Link_t link; 844887Schin char* name; 854887Schin char* alternates; 864887Schin Charset_t* charset; 874887Schin Attribute_list_t* attributes; 884887Schin } Language_t; 894887Schin 904887Schin typedef struct Language_list_s 914887Schin { 924887Schin struct Language_list_s* next; 934887Schin Language_t* language; 944887Schin } Language_list_t; 954887Schin 964887Schin typedef struct Territory_s 974887Schin { 984887Schin Link_t link; 994887Schin char* name; 1004887Schin Language_list_t* languages; 1014887Schin int primary; 1024887Schin int index; 1034887Schin } Territory_t; 1044887Schin 1054887Schin typedef struct Map_s 1064887Schin { 1074887Schin Link_t link; 1084887Schin Language_t* language; 1094887Schin Territory_t* territory; 1104887Schin Charset_t* charset; 1114887Schin Attribute_t* attribute; 1124887Schin } Map_t; 1134887Schin 1144887Schin static struct State_s 1154887Schin { 1164887Schin Table_t attribute; 1174887Schin Table_t charset; 1184887Schin Table_t language; 1194887Schin Table_t territory; 1204887Schin Table_t map; 1214887Schin } state; 1224887Schin 1234887Schin #define INIT 0 1244887Schin #define CHARSET 1 1254887Schin #define LANGUAGE 2 1264887Schin #define TERRITORY 3 1274887Schin #define MAP 4 1284887Schin 1294887Schin #define elementsof(x) (sizeof(x)/sizeof(x[0])) 1304887Schin #define newof(p,t,n,x) ((t*)malloc(sizeof(t)*(n)+(x))) 1314887Schin 1324887Schin static Link_t* 1334887Schin #if defined(__STDC__) || defined(__cplusplus) 1344887Schin enter(register Table_t* tab, register Link_t* v) 1354887Schin #else 1364887Schin enter(tab, v) 1374887Schin register Table_t* tab; 1384887Schin register Link_t* v; 1394887Schin #endif 1404887Schin { 1414887Schin register Link_t* x; 1424887Schin register Link_t* p; 1434887Schin 1444887Schin for (p = 0, x = tab->root; x; p = x, x = x->next) 1454887Schin if (!strcmp(x->code, v->code)) 1464887Schin return x; 1474887Schin if (p) 1484887Schin p->next = v; 1494887Schin else 1504887Schin tab->root = v; 1514887Schin v->next = 0; 1524887Schin v->index = tab->count++; 1534887Schin return v; 1544887Schin } 1554887Schin 1564887Schin static Link_t* 1574887Schin #if defined(__STDC__) || defined(__cplusplus) 1584887Schin lookup(register Table_t* tab, register char* s) 1594887Schin #else 1604887Schin lookup(tab, s) 1614887Schin register Table_t* tab; 1624887Schin register char* s; 1634887Schin #endif 1644887Schin { 1654887Schin register Link_t* x; 1664887Schin 1674887Schin for (x = tab->root; x; x = x->next) 1684887Schin if (!strcmp(x->code, s)) 1694887Schin return x; 1704887Schin return 0; 1714887Schin } 1724887Schin 1734887Schin static char* 1744887Schin #if defined(__STDC__) || defined(__cplusplus) 1754887Schin copy(char** p, register char* f) 1764887Schin #else 1774887Schin copy(p, f) 1784887Schin char** p; 1794887Schin register char* f; 1804887Schin #endif 1814887Schin { 1824887Schin register char* t; 1834887Schin char* b; 1844887Schin 1854887Schin if (!f) 1864887Schin return 0; 1874887Schin b = t = *p; 1884887Schin while (*t++ = *f++); 1894887Schin *p = t; 1904887Schin return b; 1914887Schin } 1924887Schin 1934887Schin static void 1944887Schin #if defined(__STDC__) || defined(__cplusplus) 1954887Schin macro(FILE* f, char* p1, char* p2, char* p3) 1964887Schin #else 1974887Schin macro(f, p1, p2, p3) 1984887Schin FILE* f; 1994887Schin char* p1; 2004887Schin char* p2; 2014887Schin char* p3; 2024887Schin #endif 2034887Schin { 2044887Schin register int c; 2054887Schin register char* s; 2064887Schin register char* b; 2074887Schin register char* e; 2084887Schin int i; 2094887Schin int m; 2104887Schin int n; 2114887Schin char* part[4]; 2124887Schin char buf[128]; 2134887Schin 2144887Schin part[0] = p1; 2154887Schin part[1] = p2; 2164887Schin part[2] = p3; 2174887Schin part[3] = 0; 2184887Schin n = 0; 2194887Schin fprintf(f, "\n"); 2204887Schin do 2214887Schin { 2224887Schin i = m = 0; 2234887Schin b = buf; 2244887Schin e = &buf[sizeof(buf)-1]; 2254887Schin while (b < e) 2264887Schin { 2274887Schin if (!(s = part[i++])) 2284887Schin break; 2294887Schin if (i > 1) 2304887Schin *b++ = '_'; 2314887Schin while ((c = *s++) && b < e) 2324887Schin { 2334887Schin if (c == '|') 2344887Schin { 2354887Schin part[i-1] = s; 2364887Schin m = 1; 2374887Schin break; 2384887Schin } 2394887Schin else if (islower(c)) 2404887Schin c = toupper(c); 2414887Schin else if (!isalnum(c)) 2424887Schin c = '_'; 2434887Schin *b++ = c; 2444887Schin } 2454887Schin } 2464887Schin *b = 0; 2474887Schin fprintf(f, "#ifdef %s\n%s,\n#else\n", buf, buf); 2484887Schin n++; 2494887Schin } while (m); 2504887Schin fprintf(f, "0,\n"); 2514887Schin while (n-- > 0) 2524887Schin fprintf(f, "#endif\n"); 2534887Schin } 2544887Schin 2554887Schin #if defined(__STDC__) || defined(__cplusplus) 2564887Schin int 2574887Schin main(int argc, char** argv) 2584887Schin #else 2594887Schin int 2604887Schin main(argc, argv) 2614887Schin int argc; 2624887Schin char** argv; 2634887Schin #endif 2644887Schin { 2654887Schin register char* s; 2664887Schin register char** vp; 2674887Schin register char** ve; 2684887Schin Attribute_t* ap; 2694887Schin Attribute_list_t* al; 2704887Schin Attribute_list_t* az; 2714887Schin Charset_t* cp; 2724887Schin Territory_t* tp; 2734887Schin Language_t* lp; 2744887Schin Language_list_t* ll; 2754887Schin Language_list_t* lz; 2764887Schin Map_t* mp; 2774887Schin char* b; 2784887Schin char* f; 2794887Schin char* command; 2804887Schin char* hdr; 2814887Schin char* lib; 2824887Schin FILE* hf; 2834887Schin FILE* lf; 2844887Schin int c; 2854887Schin int i; 2864887Schin int line; 2874887Schin int type; 2884887Schin int language_attribute_max; 2894887Schin int territory_language_max; 2904887Schin char* arg[5]; 2914887Schin char buf[1024]; 2924887Schin 2934887Schin command = *argv++; 2944887Schin line = 0; 2954887Schin if (!(hdr = *argv++) || !(lib = *argv++) || *argv) 2964887Schin { 2978462SApril.Chin@Sun.COM fprintf(stderr, "%s: { hdr lib tab } arguments expected\n", command); 2984887Schin return 1; 2994887Schin } 3004887Schin if (!(hf = fopen(hdr, "w"))) 3014887Schin { 3024887Schin fprintf(stderr, "%s: %s: cannot write\n", command, hdr); 3034887Schin return 1; 3044887Schin } 3054887Schin if (!(lf = fopen(lib, "w"))) 3064887Schin { 3074887Schin fprintf(stderr, "%s: %s: cannot write\n", command, lib); 3084887Schin return 1; 3094887Schin } 3104887Schin type = 0; 3114887Schin language_attribute_max = 0; 3124887Schin territory_language_max = 0; 3134887Schin state.language.count = 2; 3144887Schin state.territory.count = 2; 3154887Schin ve = &arg[elementsof(arg)]; 3164887Schin fprintf(hf, "/* : : generated by %s : : */\n", command); 3174887Schin fprintf(hf, "#pragma prototyped\n"); 3184887Schin fprintf(hf, "\n"); 3194887Schin fprintf(hf, "#ifndef _LC_H\n"); 3204887Schin fprintf(hf, "#define _LC_H\t\t\t1\n"); 3214887Schin fprintf(hf, "\n"); 3224887Schin fprintf(hf, "#include <ast.h>\n"); 3234887Schin fprintf(hf, "\n"); 3244887Schin fprintf(hf, "#define LC_abbreviated\t\t0x00001\n"); 3254887Schin fprintf(hf, "#define LC_checked\t\t0x00002\n"); 326*10898Sroland.mainz@nrubsig.org fprintf(hf, "#define LC_debug\t\t0x00004\n"); 327*10898Sroland.mainz@nrubsig.org fprintf(hf, "#define LC_default\t\t0x00008\n"); 328*10898Sroland.mainz@nrubsig.org fprintf(hf, "#define LC_defined\t\t0x00010\n"); 3294887Schin fprintf(hf, "#define LC_local\t\t0x00020\n"); 3304887Schin fprintf(hf, "#define LC_primary\t\t0x00040\n"); 3314887Schin fprintf(hf, "#define LC_qualified\t\t0x00080\n"); 3324887Schin fprintf(hf, "#define LC_undefined\t\t0x00100\n"); 333*10898Sroland.mainz@nrubsig.org fprintf(hf, "#define LC_utf8\t\t\t0x00200\n"); 334*10898Sroland.mainz@nrubsig.org fprintf(hf, "#define LC_verbose\t\t0x00400\n"); 3354887Schin fprintf(hf, "#define LC_user\t\t\t0x10000\n"); 3364887Schin fprintf(lf, "/* : : generated by %s : : */\n", command); 3378462SApril.Chin@Sun.COM fprintf(lf, "\n"); 3388462SApril.Chin@Sun.COM fprintf(lf, "#include \"lclib.h\"\n"); 3398462SApril.Chin@Sun.COM fprintf(lf, "#include \"lclang.h\"\n"); 3408462SApril.Chin@Sun.COM fprintf(lf, "\n"); 3414887Schin while (s = fgets(buf, sizeof(buf), stdin)) 3424887Schin { 3434887Schin line++; 3444887Schin while (isspace(*s)) 3454887Schin s++; 3464887Schin if (!*s || *s == '#') 3474887Schin continue; 3484887Schin b = s; 3494887Schin vp = arg; 3504887Schin for (;;) 3514887Schin { 3524887Schin for (*vp++ = s; *s && !isspace(*s); s++); 3534887Schin if (!*s) 3544887Schin break; 3554887Schin for (*s++ = 0; isspace(*s); s++); 3564887Schin if (!strcmp(*(vp - 1), "-")) 3574887Schin *(vp - 1) = 0; 3584887Schin if (!*s || vp >= ve) 3594887Schin break; 3604887Schin } 3614887Schin while (vp < ve) 3624887Schin *vp++ = 0; 3634887Schin if (*arg[0] == ':') 3644887Schin { 3654887Schin if (!strcmp(arg[0], ":map:")) 3664887Schin { 3674887Schin if (type != TERRITORY) 3684887Schin { 3694887Schin fprintf(stderr, "%s: %d: %s: must be specified after :territory:\n", command, line, arg[0]); 3704887Schin return 1; 3714887Schin } 3724887Schin type = MAP; 3734887Schin continue; 3744887Schin } 3754887Schin else if (!strcmp(arg[0], ":charset:")) 3764887Schin { 3774887Schin if (type != INIT) 3784887Schin { 3794887Schin fprintf(stderr, "%s: %d: %s must be specified first\n", command, line, arg[0]); 3804887Schin return 1; 3814887Schin } 3824887Schin type = CHARSET; 3834887Schin continue; 3844887Schin } 3854887Schin else if (!strcmp(arg[0], ":territory:")) 3864887Schin { 3874887Schin if (type != LANGUAGE) 3884887Schin { 3894887Schin fprintf(stderr, "%s: %d: %s: must be specified after :language:\n", command, line, arg[0]); 3904887Schin return 1; 3914887Schin } 3924887Schin type = TERRITORY; 3934887Schin continue; 3944887Schin } 3954887Schin else if (!strcmp(arg[0], ":language:")) 3964887Schin { 3974887Schin if (type != CHARSET) 3984887Schin { 3994887Schin fprintf(stderr, "%s: %d: %s must be specified after :charset:\n", command, line, arg[0]); 4004887Schin return 1; 4014887Schin } 4024887Schin type = LANGUAGE; 4034887Schin continue; 4044887Schin } 4054887Schin else 4064887Schin { 4074887Schin fprintf(stderr, "%s: %d: %s invalid\n", command, line, arg[0]); 4084887Schin return 1; 4094887Schin } 4104887Schin } 4114887Schin if (!arg[1]) 4124887Schin { 4134887Schin fprintf(stderr, "%s: %d: at least two arguments expected\n", command, line); 4144887Schin return 1; 4154887Schin } 4164887Schin switch (type) 4174887Schin { 4184887Schin case CHARSET: 4194887Schin if (!(cp = newof(0, Charset_t, 1, s - b + 1))) 4204887Schin { 4214887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 4224887Schin return 1; 4234887Schin } 4244887Schin b = (char*)(cp + 1); 4254887Schin cp->link.code = copy(&b, arg[0]); 4264887Schin cp->alternates = copy(&b, arg[1]); 4274887Schin cp->ms = copy(&b, arg[2]); 4284887Schin if (cp != (Charset_t*)enter(&state.charset, (Link_t*)cp)) 4294887Schin { 4304887Schin fprintf(stderr, "%s: %d: %s: duplicate charset\n", command, line, cp->link.code); 4314887Schin return 1; 4324887Schin } 4334887Schin break; 4344887Schin case TERRITORY: 4354887Schin if (!(tp = newof(0, Territory_t, 1, s - b + 1))) 4364887Schin { 4374887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 4384887Schin return 1; 4394887Schin } 4404887Schin b = (char*)(tp + 1); 4414887Schin tp->link.code = copy(&b, arg[0]); 4424887Schin tp->name = copy(&b, arg[1]); 4434887Schin tp->languages = 0; 4444887Schin if (s = copy(&b, arg[2])) 4454887Schin { 4464887Schin i = 0; 4474887Schin while (*(b = s)) 4484887Schin { 4494887Schin for (; *s && *s != ':' && *s != '|'; s++); 4504887Schin if (c = *s) 4514887Schin *s++ = 0; 4524887Schin if (!(lp = (Language_t*)lookup(&state.language, b))) 4534887Schin { 4544887Schin fprintf(stderr, "%s: %d: %s: unknown language\n", command, line, b); 4554887Schin return 1; 4564887Schin } 4574887Schin if (!(ll = newof(0, Language_list_t, 1, 0))) 4584887Schin { 4594887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 4604887Schin return 1; 4614887Schin } 4624887Schin if (!tp->languages) 4634887Schin tp->languages = ll; 4644887Schin else 4654887Schin lz->next = ll; 4664887Schin lz = ll; 4674887Schin ll->language = lp; 4684887Schin ll->next = 0; 4694887Schin i++; 4704887Schin if (c == ':') 4714887Schin { 4724887Schin for (b = s; *s && *s != '|'; s++); 4734887Schin if (*s) 4744887Schin *s++ = 0; 4754887Schin if (!strcmp(b, "primary")) 4764887Schin tp->primary = 1; 4774887Schin } 4784887Schin } 4794887Schin if (territory_language_max < i) 4804887Schin territory_language_max = i; 4814887Schin } 4824887Schin if (tp != (Territory_t*)enter(&state.territory, (Link_t*)tp)) 4834887Schin { 4844887Schin fprintf(stderr, "%s: %d: %s: duplicate territory\n", command, line, tp->link.code); 4854887Schin return 1; 4864887Schin } 4874887Schin break; 4884887Schin case LANGUAGE: 4894887Schin if (!(lp = newof(0, Language_t, 1, s - b + 1))) 4904887Schin { 4914887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 4924887Schin return 1; 4934887Schin } 4944887Schin b = (char*)(lp + 1); 4954887Schin lp->link.code = copy(&b, arg[0]); 4964887Schin lp->name = copy(&b, arg[1]); 4974887Schin lp->alternates = copy(&b, arg[2]); 4984887Schin if (!arg[3]) 4994887Schin lp->charset = 0; 5004887Schin else if (!(lp->charset = (Charset_t*)lookup(&state.charset, arg[3]))) 5014887Schin { 5024887Schin fprintf(stderr, "%s: %d: %s: unknown charset\n", command, line, arg[3]); 5034887Schin return 1; 5044887Schin } 5054887Schin lp->attributes = 0; 5064887Schin if (s = copy(&b, arg[4])) 5074887Schin { 5084887Schin i = 0; 5098462SApril.Chin@Sun.COM fprintf(lf, "\nconst Lc_attribute_t attribute_%s[] =\n{\n", lp->link.code); 5104887Schin while (*(b = s)) 5114887Schin { 5124887Schin for (f = 0; *s && *s != '|'; s++) 5134887Schin if (*s == ':') 5144887Schin { 5154887Schin *s++ = 0; 5164887Schin f = s; 5174887Schin } 5184887Schin if (*s) 5194887Schin *s++ = 0; 5204887Schin fprintf(lf, "{\"%s\",", b); 5214887Schin if (f) 5224887Schin fprintf(lf, "LC_%s,", f); 5234887Schin else 5244887Schin fprintf(lf, "0,"); 5254887Schin if (!(ap = newof(0, Attribute_t, 1, 0))) 5264887Schin { 5274887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 5284887Schin return 1; 5294887Schin } 5304887Schin ap->link.code = b; 5314887Schin ap->link.index = i++; 5324887Schin if (!(al = newof(0, Attribute_list_t, 1, 0))) 5334887Schin { 5344887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 5354887Schin return 1; 5364887Schin } 5374887Schin if (!lp->attributes) 5384887Schin lp->attributes = al; 5394887Schin else 5404887Schin az->next = al; 5414887Schin az = al; 5424887Schin al->attribute = ap; 5434887Schin al->next = 0; 5444887Schin macro(lf, "SUBLANG", lp->name, b); 5454887Schin fprintf(lf, "\n},\n"); 5464887Schin } 5474887Schin if (language_attribute_max < i) 5484887Schin language_attribute_max = i; 5494887Schin fprintf(lf, "};\n"); 5504887Schin } 5514887Schin if (lp != (Language_t*)enter(&state.language, (Link_t*)lp)) 5524887Schin { 5534887Schin fprintf(stderr, "%s: %d: %s: duplicate language\n", command, line, lp->link.code); 5544887Schin return 1; 5554887Schin } 5564887Schin break; 5574887Schin case MAP: 5584887Schin if (!(mp = newof(0, Map_t, 1, s - b + 1))) 5594887Schin { 5604887Schin fprintf(stderr, "%s: %d: out of space\n", command, line); 5614887Schin return 1; 5624887Schin } 5634887Schin b = (char*)(mp + 1); 5644887Schin mp->link.code = copy(&b, arg[0]); 5654887Schin if (!arg[2]) 5664887Schin { 5674887Schin fprintf(stderr, "%s: %d: territory code expected\n", command, line); 5684887Schin return 1; 5694887Schin } 5704887Schin if (!(mp->language = (Language_t*)lookup(&state.language, arg[1]))) 5714887Schin { 5724887Schin fprintf(stderr, "%s: %d: %s: unknown language\n", command, line, arg[1]); 5734887Schin return 1; 5744887Schin } 5754887Schin if (!(mp->territory = (Territory_t*)lookup(&state.territory, arg[2]))) 5764887Schin { 5774887Schin fprintf(stderr, "%s: %d: %s: unknown territory\n", command, line, arg[2]); 5784887Schin return 1; 5794887Schin } 5804887Schin if (!arg[3]) 5814887Schin mp->charset = 0; 5824887Schin else if (!(mp->charset = (Charset_t*)lookup(&state.charset, arg[3]))) 5834887Schin { 5844887Schin fprintf(stderr, "%s: %d: %s: unknown charset\n", command, line, arg[3]); 5854887Schin return 1; 5864887Schin } 5874887Schin mp->attribute = 0; 5884887Schin if (arg[4]) 5894887Schin { 5904887Schin for (al = mp->language->attributes; al; al = al->next) 5914887Schin if (!strcmp(al->attribute->link.code, arg[4])) 5924887Schin { 5934887Schin mp->attribute = al->attribute; 5944887Schin break; 5954887Schin } 5964887Schin if (!mp->attribute) 5974887Schin { 5984887Schin fprintf(stderr, "%s: %d: %s: unknown attribute\n", command, line, arg[4]); 5994887Schin return 1; 6004887Schin } 6014887Schin } 6024887Schin if (mp != (Map_t*)enter(&state.map, (Link_t*)mp)) 6034887Schin { 6044887Schin fprintf(stderr, "%s: %d: %s: duplicate map\n", command, line, mp->link.code); 6054887Schin return 1; 6064887Schin } 6074887Schin break; 6084887Schin } 6094887Schin } 6104887Schin fprintf(hf, "#define LC_language_attribute_max\t\t%d\n", language_attribute_max); 6114887Schin fprintf(hf, "#define LC_territory_language_max\t\t%d\n", territory_language_max); 6124887Schin fprintf(hf, "\nstruct Lc_s;\n"); 6134887Schin fprintf(hf, "\ntypedef struct Lc_info_s\n{\n"); 6144887Schin fprintf(hf, "\tconst struct Lc_s*\tlc;\n"); 6154887Schin fprintf(hf, "\tunsigned long\t\tnumber;\n"); 6164887Schin fprintf(hf, "\tvoid*\t\t\tdata;\n"); 6174887Schin fprintf(hf, "} Lc_info_t;\n"); 6184887Schin fprintf(hf, "\ntypedef struct Lc_attribute_s\n{\n"); 6194887Schin fprintf(hf, "\tconst char*\t\tname;\n"); 6204887Schin fprintf(hf, "\tunsigned long\t\tflags;\n"); 6214887Schin fprintf(hf, "\tunsigned long\t\tindex;\n"); 6224887Schin fprintf(hf, "} Lc_attribute_t;\n"); 6234887Schin fprintf(hf, "\ntypedef struct Lc_charset_s\n{\n"); 6244887Schin fprintf(hf, "\tconst char*\t\tcode;\n"); 6254887Schin fprintf(hf, "\tconst char*\t\talternates;\n"); 6264887Schin fprintf(hf, "\tconst char*\t\tms;\n"); 6274887Schin fprintf(hf, "\tunsigned long\t\tindex;\n"); 6284887Schin fprintf(hf, "} Lc_charset_t;\n"); 6294887Schin fprintf(hf, "\ntypedef struct Lc_language_s\n{\n"); 6304887Schin fprintf(hf, "\tconst char*\t\tcode;\n"); 6314887Schin fprintf(hf, "\tconst char*\t\tname;\n"); 6324887Schin fprintf(hf, "\tconst char*\t\talternates;\n"); 6334887Schin fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n"); 6344887Schin fprintf(hf, "\tunsigned long\t\tflags;\n"); 6354887Schin fprintf(hf, "\tunsigned long\t\tindex;\n"); 6364887Schin fprintf(hf, "\tconst Lc_attribute_t*\tattributes[LC_language_attribute_max];\n"); 6374887Schin fprintf(hf, "} Lc_language_t;\n"); 6384887Schin fprintf(hf, "\ntypedef struct Lc_territory_s\n{\n"); 6394887Schin fprintf(hf, "\tconst char*\t\tcode;\n"); 6404887Schin fprintf(hf, "\tconst char*\t\tname;\n"); 6414887Schin fprintf(hf, "\tunsigned long\t\tflags;\n"); 6424887Schin fprintf(hf, "\tunsigned long\t\tindex;\n"); 6434887Schin fprintf(hf, "\tconst Lc_language_t*\tlanguages[LC_territory_language_max];\n"); 6444887Schin fprintf(hf, "#ifdef _LC_TERRITORY_PRIVATE_\n"); 6454887Schin fprintf(hf, "\t_LC_TERRITORY_PRIVATE_\n"); 6464887Schin fprintf(hf, "#endif\n"); 6474887Schin fprintf(hf, "} Lc_territory_t;\n"); 6484887Schin fprintf(hf, "\ntypedef struct Lc_map_s\n{\n"); 6494887Schin fprintf(hf, "\tconst char*\t\tcode;\n"); 6504887Schin fprintf(hf, "\tconst Lc_language_t*\tlanguage;\n"); 6514887Schin fprintf(hf, "\tconst Lc_territory_t*\tterritory;\n"); 6524887Schin fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n"); 6534887Schin fprintf(hf, "\tconst Lc_attribute_t*\tattribute;\n"); 6544887Schin fprintf(hf, "} Lc_map_t;\n"); 6554887Schin fprintf(hf, "\ntypedef struct Lc_attribute_list_s\n{\n"); 6564887Schin fprintf(hf, "\tstruct Lc_attribute_list_s*\tnext;\n"); 6574887Schin fprintf(hf, "\tconst Lc_attribute_t*\t\tattribute;\n"); 6584887Schin fprintf(hf, "} Lc_attribute_list_t;\n"); 6594887Schin fprintf(hf, "\ntypedef struct Lc_s\n{\n"); 6604887Schin fprintf(hf, "\tconst char*\t\tname;\n"); 6614887Schin fprintf(hf, "\tconst char*\t\tcode;\n"); 6624887Schin fprintf(hf, "\tconst Lc_language_t*\tlanguage;\n"); 6634887Schin fprintf(hf, "\tconst Lc_territory_t*\tterritory;\n"); 6644887Schin fprintf(hf, "\tconst Lc_charset_t*\tcharset;\n"); 6654887Schin fprintf(hf, "\tconst Lc_attribute_list_t*\tattributes;\n"); 6664887Schin fprintf(hf, "\tunsigned long\t\tflags;\n"); 6674887Schin fprintf(hf, "\tunsigned long\t\tindex;\n"); 6684887Schin fprintf(hf, "#ifdef _LC_PRIVATE_\n"); 6694887Schin fprintf(hf, "\t_LC_PRIVATE_\n"); 6704887Schin fprintf(hf, "#endif\n"); 6714887Schin fprintf(hf, "} Lc_t;\n"); 6724887Schin fprintf(hf, "\nstruct Lc_category_s;\n"); 6734887Schin fprintf(hf, "\ntypedef int (*Lc_category_set_f)(struct Lc_category_s*);\n"); 6744887Schin fprintf(hf, "\ntypedef struct Lc_category_s\n{\n"); 6754887Schin fprintf(hf, "\tconst char*\t\tname;\n"); 6764887Schin fprintf(hf, "\tint\t\t\texternal;\n"); 6774887Schin fprintf(hf, "\tint\t\t\tinternal;\n"); 6784887Schin fprintf(hf, "\tLc_category_set_f\tsetf;\n"); 6794887Schin fprintf(hf, "\tLc_t*\t\t\tprev;\n"); 6804887Schin fprintf(hf, "} Lc_category_t;\n"); 6814887Schin fprintf(hf, "\n"); 6824887Schin fprintf(hf, "#if _BLD_ast && defined(__EXPORT__)\n"); 6834887Schin fprintf(hf, "#define extern\t\t__EXPORT__\n"); 6844887Schin fprintf(hf, "#endif\n"); 6854887Schin fprintf(hf, "\n"); 6864887Schin fprintf(hf, "extern size_t\t\tlccanon(Lc_t*, unsigned long flags, char*, size_t);\n"); 6874887Schin fprintf(hf, "extern Lc_category_t*\tlccategories(void);\n"); 6884887Schin fprintf(hf, "extern int\t\tlcindex(int, int);\n"); 6894887Schin fprintf(hf, "extern Lc_info_t*\tlcinfo(int);\n"); 6904887Schin fprintf(hf, "extern Lc_t*\t\tlcmake(const char*);\n"); 6914887Schin fprintf(hf, "extern Lc_t*\t\tlcscan(Lc_t*);\n"); 6924887Schin fprintf(hf, "\n"); 6934887Schin fprintf(hf, "#undef\textern\n"); 6948462SApril.Chin@Sun.COM fprintf(lf, "\nconst Lc_charset_t lc_charsets[] =\n{\n"); 6954887Schin for (cp = (Charset_t*)state.charset.root; cp; cp = (Charset_t*)cp->link.next) 6964887Schin { 6974887Schin fprintf(lf, "{\"%s\",", cp->link.code); 6984887Schin if (cp->alternates) 6994887Schin fprintf(lf, "\"%s\",", cp->alternates); 7004887Schin else 7014887Schin fprintf(lf, "0,"); 7024887Schin if (cp->ms) 7034887Schin fprintf(lf, "\"%s\",", cp->ms); 7044887Schin else 7054887Schin fprintf(lf, "0"); 7064887Schin fprintf(lf, "},\n"); 7074887Schin } 7084887Schin fprintf(lf, "\t0\n};\n"); 7098462SApril.Chin@Sun.COM fprintf(lf, "\nconst Lc_language_t lc_languages[] =\n{\n"); 7108462SApril.Chin@Sun.COM fprintf(lf, "{\"C\",\"C\",\"POSIX\",&lc_charsets[0],LC_default,0,"); 7114887Schin for (i = 0; i < language_attribute_max; i++) 7124887Schin fprintf(lf, "0,"); 7134887Schin fprintf(lf, "},\n"); 7148462SApril.Chin@Sun.COM fprintf(lf, "{\"debug\",\"debug\",0,&lc_charsets[0],LC_debug,0,"); 7154887Schin for (i = 0; i < language_attribute_max; i++) 7164887Schin fprintf(lf, "0,"); 7174887Schin fprintf(lf, "},\n"); 7184887Schin for (lp = (Language_t*)state.language.root; lp; lp = (Language_t*)lp->link.next) 7194887Schin { 7204887Schin fprintf(lf, "{\"%s\",\"%s\",", lp->link.code, lp->name); 7214887Schin if (lp->alternates) 7224887Schin fprintf(lf, "\"%s\",", lp->alternates); 7234887Schin else 7244887Schin fprintf(lf, "0,"); 7258462SApril.Chin@Sun.COM fprintf(lf, "&lc_charsets[%d],0,", lp->charset ? lp->charset->link.index : 0); 7264887Schin macro(lf, "LANG", lp->name, (char*)0); 7274887Schin for (i = 0, al = lp->attributes; al; al = al->next, i++) 7284887Schin fprintf(lf, "&attribute_%s[%d],", lp->link.code, al->attribute->link.index); 7294887Schin for (; i < language_attribute_max; i++) 7304887Schin fprintf(lf, "0,"); 7314887Schin fprintf(lf, "\n},\n"); 7324887Schin } 7334887Schin fprintf(lf, "\t0\n};\n"); 7348462SApril.Chin@Sun.COM fprintf(lf, "\nconst Lc_territory_t lc_territories[] =\n{\n"); 7358462SApril.Chin@Sun.COM fprintf(lf, "{\"C\",\"C\",LC_default,0,&lc_languages[0],"); 7364887Schin for (i = 1; i < 2 * territory_language_max; i++) 7374887Schin fprintf(lf, "0,"); 7384887Schin fprintf(lf, "},\n"); 7398462SApril.Chin@Sun.COM fprintf(lf, "{\"debug\",\"debug\",LC_debug,0,&lc_languages[1],"); 7404887Schin for (i = 1; i < 2 * territory_language_max; i++) 7414887Schin fprintf(lf, "0,"); 7424887Schin fprintf(lf, "},\n"); 7434887Schin for (tp = (Territory_t*)state.territory.root; tp; tp = (Territory_t*)tp->link.next) 7444887Schin { 7454887Schin fprintf(lf, "{\"%s\",\"%s\",", tp->link.code, tp->name); 7464887Schin if (tp->primary) 7474887Schin fprintf(lf, "LC_primary,"); 7484887Schin else 7494887Schin fprintf(lf, "0,"); 7504887Schin macro(lf, "CTRY", tp->name, (char*)0); 7514887Schin for (i = 0, ll = tp->languages; ll; ll = ll->next, i++) 7528462SApril.Chin@Sun.COM fprintf(lf, "&lc_languages[%d],", ll->language->link.index); 7534887Schin for (; i < territory_language_max; i++) 7544887Schin fprintf(lf, "0,"); 7554887Schin for (i = 0, ll = tp->languages; ll; ll = ll->next, i++) 7564887Schin macro(lf, "SUBLANG", ll->language->name, tp->name); 7574887Schin for (; i < territory_language_max; i++) 7584887Schin fprintf(lf, "0,"); 7594887Schin fprintf(lf, "\n},\n"); 7604887Schin } 7614887Schin fprintf(lf, "\t0\n};\n"); 7628462SApril.Chin@Sun.COM fprintf(lf, "\nconst Lc_map_t lc_maps[] =\n{\n"); 7634887Schin for (mp = (Map_t*)state.map.root; mp; mp = (Map_t*)mp->link.next) 7644887Schin { 7654887Schin fprintf(lf, "{\"%s\",", mp->link.code); 7668462SApril.Chin@Sun.COM fprintf(lf, "&lc_languages[%d],", mp->language->link.index); 7678462SApril.Chin@Sun.COM fprintf(lf, "&lc_territories[%d],", mp->territory->link.index); 7688462SApril.Chin@Sun.COM fprintf(lf, "&lc_charsets[%d],", mp->charset ? mp->charset->link.index : 0); 7694887Schin if (mp->attribute) 7704887Schin fprintf(lf, "&attribute_%s[%d]", mp->language->link.code, mp->attribute->link.index); 7714887Schin else 7724887Schin fprintf(lf, "0"); 7734887Schin fprintf(lf, "},\n"); 7744887Schin } 7754887Schin fprintf(lf, "\t0\n};\n"); 7764887Schin fclose(lf); 7774887Schin fprintf(hf, "\n#endif\n"); 7784887Schin fclose(hf); 7794887Schin return 0; 7804887Schin } 781