~ubuntu-branches/ubuntu/intrepid/dash/intrepid-updates

« back to all changes in this revision

Viewing changes to src/mksyntax.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-07-18 15:38:47 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070718153847-pef1uwy72j9gs9pw
Tags: 0.5.4-1ubuntu1
* Merge with Debian; remaining changes:
  - Build against glibc instead of dietlibc
  - Change default answer for "Install dash as /bin/sh?" question to true.

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
static FILE *cfile;
93
93
static FILE *hfile;
94
94
static char *syntax[513];
95
 
static int base;
96
 
static int size;        /* number of values which a char variable can have */
97
 
static int nbits;       /* number of bits in a character */
98
 
static int digit_contig;/* true if digits are contiguous */
99
95
 
100
96
static void filltable(char *);
101
97
static void init(void);
102
98
static void add(char *, char *);
103
99
static void print(char *);
104
 
static void output_type_macros(int);
105
 
static void digit_convert(void);
 
100
static void output_type_macros(void);
106
101
int main(int, char **);
107
102
 
108
103
int
109
104
main(int argc, char **argv)
110
105
{
111
 
#ifdef  TARGET_CHAR
112
 
        TARGET_CHAR c;
113
 
        TARGET_CHAR d;
114
 
#else
115
 
        char c;
116
 
        char d;
117
 
#endif
118
 
        int sign;
119
106
        int i;
120
107
        char buf[80];
121
108
        int pos;
122
 
        static char digit[] = "0123456789";
123
109
 
124
110
        /* Create output files */
125
111
        if ((cfile = fopen("syntax.c", "w")) == NULL) {
133
119
        fputs(writer, hfile);
134
120
        fputs(writer, cfile);
135
121
 
136
 
        /* Determine the characteristics of chars. */
137
 
        c = -1;
138
 
        if (c <= 0)
139
 
                sign = 1;
140
 
        else
141
 
                sign = 0;
142
 
        for (nbits = 1 ; ; nbits++) {
143
 
                d = (1 << nbits) - 1;
144
 
                if (d == c)
145
 
                        break;
146
 
        }
147
 
        printf("%s %d bit chars\n", sign? "signed" : "unsigned", nbits);
148
 
        if (nbits > 9) {
149
 
                fputs("Characters can't have more than 9 bits\n", stderr);
150
 
                exit(2);
151
 
        }
152
 
        size = (1 << nbits) + 1;
153
 
        base = 2;
154
 
        if (sign)
155
 
                base += 1 << (nbits - 1);
156
 
        digit_contig = 1;
157
 
        for (i = 0 ; i < 10 ; i++) {
158
 
                if (digit[i] != '0' + i)
159
 
                        digit_contig = 0;
160
 
        }
161
 
 
162
122
        fputs("#include <ctype.h>\n", hfile);
163
123
        fputs("\n", hfile);
164
124
        fputs("#ifdef CEOF\n", hfile);
185
145
                fprintf(hfile, "/* %s */\n", is_entry[i].comment);
186
146
        }
187
147
        putc('\n', hfile);
188
 
        fprintf(hfile, "#define SYNBASE %d\n", base);
189
 
        fprintf(hfile, "#define PEOF %d\n\n", -base);
190
 
        fprintf(hfile, "#define PEOA %d\n\n", -base + 1);
 
148
        fprintf(hfile, "#define SYNBASE %d\n", 130);
 
149
        fprintf(hfile, "#define PEOF %d\n\n", -130);
 
150
        fprintf(hfile, "#define PEOA %d\n\n", -129);
191
151
        putc('\n', hfile);
192
152
        fputs("#define BASESYNTAX (basesyntax + SYNBASE)\n", hfile);
193
153
        fputs("#define DQSYNTAX (dqsyntax + SYNBASE)\n", hfile);
194
154
        fputs("#define SQSYNTAX (sqsyntax + SYNBASE)\n", hfile);
195
155
        fputs("#define ARISYNTAX (arisyntax + SYNBASE)\n", hfile);
196
156
        putc('\n', hfile);
197
 
        output_type_macros(sign);               /* is_digit, etc. */
 
157
        output_type_macros();           /* is_digit, etc. */
198
158
        putc('\n', hfile);
199
159
 
200
160
        /* Generate the syntax tables. */
248
208
        add("_", "ISUNDER");
249
209
        add("#?$!-*@", "ISSPECL");
250
210
        print("is_type");
251
 
        if (! digit_contig)
252
 
                digit_convert();
253
211
        exit(0);
254
212
        /* NOTREACHED */
255
213
}
265
223
{
266
224
        int i;
267
225
 
268
 
        for (i = 0 ; i < size ; i++)
 
226
        for (i = 0 ; i < 257; i++)
269
227
                syntax[i] = dftval;
270
228
}
271
229
 
283
241
        syntax[0] = "CEOF";
284
242
        syntax[1] = "CIGN";
285
243
        for (ctl = CTL_FIRST; ctl <= CTL_LAST; ctl++ )
286
 
#ifdef TARGET_CHAR
287
 
                syntax[base + (TARGET_CHAR)ctl ] = "CCTL";
288
 
#else
289
 
                syntax[base + ctl] = "CCTL";
290
 
#endif /* TARGET_CHAR */
 
244
                syntax[130 + ctl] = "CCTL";
291
245
}
292
246
 
293
247
 
299
253
add(char *p, char *type)
300
254
{
301
255
        while (*p)
302
 
                syntax[*p++ + base] = type;
 
256
                syntax[(signed char)*p++ + 130] = type;
303
257
}
304
258
 
305
259
 
315
269
        int col;
316
270
 
317
271
        fprintf(hfile, "extern const char %s[];\n", name);
318
 
        fprintf(cfile, "const char %s[%d] = {\n", name, size);
 
272
        fprintf(cfile, "const char %s[%d] = {\n", name, 257);
319
273
        col = 0;
320
 
        for (i = 0 ; i < size ; i++) {
 
274
        for (i = 0 ; i < 257; i++) {
321
275
                if (i == 0) {
322
276
                        fputs("      ", cfile);
323
277
                } else if ((i & 03) == 0) {
342
296
 */
343
297
 
344
298
static char *macro[] = {
345
 
        "#define is_digit(c)\t((is_type+SYNBASE)[(signed char)(c)] & ISDIGIT)\n",
 
299
        "#define is_digit(c)\t((unsigned)((c) - '0') <= 9)\n",
346
300
        "#define is_alpha(c)\tisalpha((unsigned char)(c))\n",
347
301
        "#define is_name(c)\t((c) == '_' || isalpha((unsigned char)(c)))\n",
348
302
        "#define is_in_name(c)\t((c) == '_' || isalnum((unsigned char)(c)))\n",
351
305
};
352
306
 
353
307
static void
354
 
output_type_macros(int sign)
 
308
output_type_macros(void)
355
309
{
356
310
        char **pp;
357
311
 
358
 
        if (digit_contig)
359
 
                macro[0] = "#define is_digit(c)\t((unsigned)((c) - '0') <= 9)\n";
360
312
        for (pp = macro ; *pp ; pp++)
361
 
                fprintf(hfile, *pp, sign ? "char" : "unsigned char");
362
 
        if (digit_contig)
363
 
                fputs("#define digit_val(c)\t((c) - '0')\n", hfile);
364
 
        else
365
 
                fputs("#define digit_val(c)\t(digit_value[(unsigned char)(c)])\n", hfile);
366
 
}
367
 
 
368
 
 
369
 
 
370
 
/*
371
 
 * Output digit conversion table (if digits are not contiguous).
372
 
 */
373
 
 
374
 
static void
375
 
digit_convert(void)
376
 
{
377
 
        int maxdigit;
378
 
        static char digit[] = "0123456789";
379
 
        char *p;
380
 
        int i;
381
 
 
382
 
        maxdigit = 0;
383
 
        for (p = digit ; *p ; p++)
384
 
                if (*p > maxdigit)
385
 
                        maxdigit = *p;
386
 
        fputs("extern const char digit_value[];\n", hfile);
387
 
        fputs("\n\nconst char digit_value[] = {\n", cfile);
388
 
        for (i = 0 ; i <= maxdigit ; i++) {
389
 
                for (p = digit ; *p && *p != i ; p++);
390
 
                if (*p == '\0')
391
 
                        p = digit;
392
 
                fprintf(cfile, "      %ld,\n", (long)(p - digit));
393
 
        }
394
 
        fputs("};\n", cfile);
 
313
                fputs(*pp, hfile);
 
314
        fputs("#define digit_val(c)\t((c) - '0')\n", hfile);
395
315
}