]> gcc.gnu.org Git - gcc.git/blob - gcc/f/fini.c
f685df1847a298cdceb83340cbf4829d8220a922
[gcc.git] / gcc / f / fini.c
1 /* fini.c
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
4
5 This file is part of GNU Fortran.
6
7 GNU Fortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Fortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #define USE_HCONFIG
23
24 #include "proj.h"
25 #include "malloc.h"
26
27 #undef MAXNAMELEN
28 #define MAXNAMELEN 100
29
30 typedef struct _name_ *name;
31
32 struct _name_
33 {
34 name next;
35 name previous;
36 name next_alpha;
37 name previous_alpha;
38 int namelen;
39 int kwlen;
40 char kwname[MAXNAMELEN];
41 char name_uc[MAXNAMELEN];
42 char name_lc[MAXNAMELEN];
43 char name_ic[MAXNAMELEN];
44 };
45
46 struct _name_root_
47 {
48 name first;
49 name last;
50 };
51
52 struct _name_alpha_
53 {
54 name ign1;
55 name ign2;
56 name first;
57 name last;
58 };
59
60 static FILE *in;
61 static FILE *out;
62 static char prefix[32];
63 static char postfix[32];
64 static char storage[32];
65 static const char *xspaces[]
66 =
67 {
68 "", /* 0 */
69 " ", /* 1 */
70 " ", /* 2 */
71 " ", /* 3 */
72 " ", /* 4 */
73 " ", /* 5 */
74 " ", /* 6 */
75 " ", /* 7 */
76 "\t", /* 8 */
77 "\t ", /* 9 */
78 "\t ", /* 10 */
79 "\t ", /* 11 */
80 "\t ", /* 12 */
81 "\t ", /* 13 */
82 "\t ", /* 14 */
83 "\t ", /* 15 */
84 "\t\t", /* 16 */
85 "\t\t ", /* 17 */
86 "\t\t ", /* 18 */
87 "\t\t ", /* 19 */
88 "\t\t ", /* 20 */
89 "\t\t ", /* 21 */
90 "\t\t ", /* 22 */
91 "\t\t ", /* 23 */
92 "\t\t\t", /* 24 */
93 "\t\t\t ", /* 25 */
94 "\t\t\t ", /* 26 */
95 "\t\t\t ", /* 27 */
96 "\t\t\t ", /* 28 */
97 "\t\t\t ", /* 29 */
98 "\t\t\t ", /* 30 */
99 "\t\t\t ", /* 31 */
100 "\t\t\t\t", /* 32 */
101 "\t\t\t\t ", /* 33 */
102 "\t\t\t\t ", /* 34 */
103 "\t\t\t\t ", /* 35 */
104 "\t\t\t\t ", /* 36 */
105 "\t\t\t\t ", /* 37 */
106 "\t\t\t\t ", /* 38 */
107 "\t\t\t\t ", /* 39 */
108 "\t\t\t\t\t", /* 40 */
109 "\t\t\t\t\t ", /* 41 */
110 "\t\t\t\t\t ", /* 42 */
111 "\t\t\t\t\t ", /* 43 */
112 "\t\t\t\t\t ", /* 44 */
113 "\t\t\t\t\t ", /* 45 */
114 "\t\t\t\t\t ", /* 46 */
115 "\t\t\t\t\t ", /* 47 */
116 "\t\t\t\t\t\t", /* 48 */
117 "\t\t\t\t\t\t ", /* 49 */
118 "\t\t\t\t\t\t ", /* 50 */
119 "\t\t\t\t\t\t ", /* 51 */
120 "\t\t\t\t\t\t ", /* 52 */
121 "\t\t\t\t\t\t ", /* 53 */
122 "\t\t\t\t\t\t ", /* 54 */
123 "\t\t\t\t\t\t ", /* 55 */
124 "\t\t\t\t\t\t\t", /* 56 */
125 "\t\t\t\t\t\t\t ", /* 57 */
126 "\t\t\t\t\t\t\t ", /* 58 */
127 "\t\t\t\t\t\t\t ", /* 59 */
128 "\t\t\t\t\t\t\t ", /* 60 */
129 "\t\t\t\t\t\t\t ", /* 61 */
130 "\t\t\t\t\t\t\t ", /* 62 */
131 "\t\t\t\t\t\t\t ", /* 63 */
132 "\t\t\t\t\t\t\t\t", /* 64 */
133 "\t\t\t\t\t\t\t\t ", /* 65 */
134 "\t\t\t\t\t\t\t\t ", /* 66 */
135 "\t\t\t\t\t\t\t\t ", /* 67 */
136 "\t\t\t\t\t\t\t\t ", /* 68 */
137 "\t\t\t\t\t\t\t\t ", /* 69 */
138 "\t\t\t\t\t\t\t\t ", /* 70 */
139 "\t\t\t\t\t\t\t\t ", /* 71 */
140 "\t\t\t\t\t\t\t\t\t", /* 72 */
141 "\t\t\t\t\t\t\t\t\t ", /* 73 */
142 "\t\t\t\t\t\t\t\t\t ", /* 74 */
143 "\t\t\t\t\t\t\t\t\t ", /* 75 */
144 "\t\t\t\t\t\t\t\t\t ", /* 76 */
145 "\t\t\t\t\t\t\t\t\t ", /* 77 */
146 "\t\t\t\t\t\t\t\t\t ", /* 78 */
147 "\t\t\t\t\t\t\t\t\t ", /* 79 */
148 "\t\t\t\t\t\t\t\t\t\t", /* 80 */
149 "\t\t\t\t\t\t\t\t\t\t ", /* 81 */
150 "\t\t\t\t\t\t\t\t\t\t ", /* 82 */
151 "\t\t\t\t\t\t\t\t\t\t ", /* 83 */
152 "\t\t\t\t\t\t\t\t\t\t ", /* 84 */
153 "\t\t\t\t\t\t\t\t\t\t ", /* 85 */
154 "\t\t\t\t\t\t\t\t\t\t ", /* 86 */
155 "\t\t\t\t\t\t\t\t\t\t ",/* 87 */
156 "\t\t\t\t\t\t\t\t\t\t\t", /* 88 */
157 "\t\t\t\t\t\t\t\t\t\t\t ", /* 89 */
158 "\t\t\t\t\t\t\t\t\t\t\t ", /* 90 */
159 "\t\t\t\t\t\t\t\t\t\t\t ", /* 91 */
160 "\t\t\t\t\t\t\t\t\t\t\t ", /* 92 */
161 "\t\t\t\t\t\t\t\t\t\t\t ",/* 93 */
162 "\t\t\t\t\t\t\t\t\t\t\t ", /* 94 */
163 "\t\t\t\t\t\t\t\t\t\t\t ", /* 95 */
164 "\t\t\t\t\t\t\t\t\t\t\t\t", /* 96 */
165 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 97 */
166 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 98 */
167 "\t\t\t\t\t\t\t\t\t\t\t\t ",/* 99 */
168 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 100 */
169 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 101 */
170 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 102 */
171 "\t\t\t\t\t\t\t\t\t\t\t\t ", /* 103 */
172 "\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 104 */
173 "\t\t\t\t\t\t\t\t\t\t\t\t\t ",/* 105 */
174 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 106 */
175 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 107 */
176 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 108 */
177 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 109 */
178 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 110 */
179 "\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 111 */
180 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 112 */
181 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 113 */
182 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 114 */
183 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 115 */
184 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 116 */
185 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 117 */
186 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 118 */
187 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 119 */
188 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 120 */
189 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 121 */
190 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 122 */
191 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 123 */
192 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 124 */
193 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 125 */
194 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 126 */
195 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 127 */
196 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 128 */
197 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 129 */
198 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 130 */
199 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 131 */
200 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 132 */
201 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 133 */
202 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 134 */
203 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 135 */
204 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 136 */
205 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 137 */
206 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 138 */
207 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 139 */
208 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 140 */
209 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 141 */
210 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 142 */
211 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 143 */
212 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 144 */
213 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 145 */
214 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 146 */
215 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 147 */
216 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 148 */
217 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 149 */
218 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 150 */
219 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 151 */
220 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", /* 152 */
221 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 153 */
222 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 154 */
223 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 155 */
224 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 156 */
225 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 157 */
226 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 158 */
227 "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t ", /* 159 */
228 };
229
230 void testname (bool nested, int indent, name first, name last);
231 void testnames (bool nested, int indent, int len, name first, name last);
232
233 int
234 main (int argc, char **argv)
235 {
236 char buf[MAXNAMELEN];
237 char last_buf[MAXNAMELEN];
238 char kwname[MAXNAMELEN];
239 char routine[32];
240 char type[32];
241 int i;
242 int count;
243 int len;
244 struct _name_root_ names[200];
245 struct _name_alpha_ names_alpha;
246 name n;
247 name newname;
248 char *input_name;
249 char *output_name;
250 char *include_name;
251 FILE *incl;
252 int fixlengths;
253 int total_length;
254 int do_name; /* TRUE if token may be NAME. */
255 int do_names; /* TRUE if token may be NAMES. */
256 int cc;
257 bool do_exit = FALSE;
258
259 last_buf[0] = '\0';
260
261 for (i = 0; ((size_t) i) < ARRAY_SIZE (names); ++i)
262 { /* Initialize length/name ordered list roots. */
263 names[i].first = (name) &names[i];
264 names[i].last = (name) &names[i];
265 }
266 names_alpha.first = (name) &names_alpha; /* Initialize name order. */
267 names_alpha.last = (name) &names_alpha;
268
269 if (argc != 4)
270 {
271 fprintf (stderr, "Command form: fini input output-code output-include\n");
272 return (1);
273 }
274
275 input_name = argv[1];
276 output_name = argv[2];
277 include_name = argv[3];
278
279 in = fopen (input_name, "r");
280 if (in == NULL)
281 {
282 fprintf (stderr, "Cannot open \"%s\"\n", input_name);
283 return (1);
284 }
285 out = fopen (output_name, "w");
286 if (out == NULL)
287 {
288 fclose (in);
289 fprintf (stderr, "Cannot open \"%s\"\n", output_name);
290 return (1);
291 }
292 incl = fopen (include_name, "w");
293 if (incl == NULL)
294 {
295 fclose (in);
296 fprintf (stderr, "Cannot open \"%s\"\n", include_name);
297 return (1);
298 }
299
300 /* Get past the initial block-style comment (man, this parsing code is just
301 _so_ lame, but I'm too lazy to improve it). */
302
303 for (;;)
304 {
305 cc = getc (in);
306 if (cc == '{')
307 {
308 while (((cc = getc (in)) != '}') && (cc != EOF))
309 ;
310 }
311 else if (cc != EOF)
312 {
313 while (((cc = getc (in)) != EOF) && (! ISALNUM (cc)))
314 ;
315 ungetc (cc, in);
316 break;
317 }
318 else
319 {
320 assert ("EOF too soon!" == NULL);
321 return (1);
322 }
323 }
324
325 fscanf (in, "%s %s %s %s %s %d %d", prefix, postfix, storage, type, routine,
326 &do_name, &do_names);
327
328 if (storage[0] == '\0')
329 storage[1] = '\0';
330 else
331 /* Assume string is quoted somehow, replace ending quote with space. */
332 {
333 if (storage[2] == '\0')
334 storage[1] = '\0';
335 else
336 storage[strlen (storage) - 1] = ' ';
337 }
338
339 if (postfix[0] == '\0')
340 postfix[1] = '\0';
341 else /* Assume string is quoted somehow, strip off
342 ending quote. */
343 postfix[strlen (postfix) - 1] = '\0';
344
345 for (i = 1; storage[i] != '\0'; ++i)
346 storage[i - 1] = storage[i];
347 storage[i - 1] = '\0';
348
349 for (i = 1; postfix[i] != '\0'; ++i)
350 postfix[i - 1] = postfix[i];
351 postfix[i - 1] = '\0';
352
353 fixlengths = strlen (prefix) + strlen (postfix);
354
355 while (TRUE)
356 {
357 count = fscanf (in, "%s %s", buf, kwname);
358 if (count == EOF)
359 break;
360 len = strlen (buf);
361 if (len == 0)
362 continue; /* Skip empty lines. */
363 if (buf[0] == ';')
364 continue; /* Skip commented-out lines. */
365 for (i = strlen (buf) - 1; i > 0; --i)
366 cc = buf[i];
367
368 /* Make new name object to store name and its keyword. */
369
370 newname = (name) malloc (sizeof (*newname));
371 newname->namelen = strlen (buf);
372 newname->kwlen = strlen (kwname);
373 total_length = newname->kwlen + fixlengths;
374 if (total_length >= 32) /* Else resulting keyword name too long. */
375 {
376 fprintf (stderr, "%s: %s%s%s is 31+%d chars long\n", input_name,
377 prefix, kwname, postfix, total_length - 31);
378 do_exit = TRUE;
379 }
380 strcpy (newname->kwname, kwname);
381 for (i = 0; i < newname->namelen; ++i)
382 {
383 cc = buf[i];
384 if (ISALPHA (cc))
385 {
386 newname->name_uc[i] = TOUPPER (cc);
387 newname->name_lc[i] = TOLOWER (cc);
388 newname->name_ic[i] = cc;
389 }
390 else
391 newname->name_uc[i] = newname->name_lc[i] = newname->name_ic[i]
392 = cc;
393 }
394 newname->name_uc[i] = newname->name_lc[i] = newname->name_ic[i] = '\0';
395
396 /* Warn user if names aren't alphabetically ordered. */
397
398 if ((last_buf[0] != '\0')
399 && (strcmp (last_buf, newname->name_uc) >= 0))
400 {
401 fprintf (stderr, "%s: \"%s\" precedes \"%s\"\n", input_name,
402 last_buf, newname->name_uc);
403 do_exit = TRUE;
404 }
405 strcpy (last_buf, newname->name_uc);
406
407 /* Append name to end of alpha-sorted list (assumes names entered in
408 alpha order wrt name, not kwname, even though kwname is output from
409 this list). */
410
411 n = names_alpha.last;
412 newname->next_alpha = n->next_alpha;
413 newname->previous_alpha = n;
414 n->next_alpha->previous_alpha = newname;
415 n->next_alpha = newname;
416
417 /* Insert name in appropriate length/name ordered list. */
418
419 n = (name) &names[len];
420 while ((n->next != (name) &names[len])
421 && (strcmp (buf, n->next->name_uc) > 0))
422 n = n->next;
423 if (strcmp (buf, n->next->name_uc) == 0)
424 {
425 fprintf (stderr, "%s: extraneous \"%s\"\n", input_name, buf);
426 do_exit = TRUE;
427 }
428 newname->next = n->next;
429 newname->previous = n;
430 n->next->previous = newname;
431 n->next = newname;
432 }
433
434 #if 0
435 for (len = 0; len < ARRAY_SIZE (name); ++len)
436 {
437 if (names[len].first == (name) &names[len])
438 continue;
439 printf ("Length %d:\n", len);
440 for (n = names[len].first; n != (name) &names[len]; n = n->next)
441 printf (" %s %s %s\n", n->name_uc, n->name_lc, n->name_ic);
442 }
443 #endif
444
445 if (do_exit)
446 return (1);
447
448 /* First output the #include file. */
449
450 for (n = names_alpha.first; n != (name) &names_alpha; n = n->next_alpha)
451 {
452 fprintf (incl, "#define %sl%s%s %d\n", prefix, n->kwname, postfix,
453 n->namelen);
454 }
455
456 fprintf (incl,
457 "\
458 \n\
459 enum %s_\n\
460 {\n\
461 %sNone%s,\n\
462 ",
463 type, prefix, postfix);
464
465 for (n = names_alpha.first; n != (name) &names_alpha; n = n->next_alpha)
466 {
467 fprintf (incl,
468 "\
469 %s%s%s,\n\
470 ",
471 prefix, n->kwname, postfix);
472 }
473
474 fprintf (incl,
475 "\
476 %s%s\n\
477 };\n\
478 typedef enum %s_ %s;\n\
479 ",
480 prefix, postfix, type, type);
481
482 /* Now output the C program. */
483
484 fprintf (out,
485 "\
486 %s%s\n\
487 %s (ffelexToken t)\n\
488 %c\n\
489 char *p;\n\
490 int c;\n\
491 \n\
492 p = ffelex_token_text (t);\n\
493 \n\
494 ",
495 storage, type, routine, '{');
496
497 if (do_name)
498 {
499 if (do_names)
500 fprintf (out,
501 "\
502 if (ffelex_token_type (t) == FFELEX_typeNAME)\n\
503 {\n\
504 switch (ffelex_token_length (t))\n\
505 \t{\n\
506 "
507 );
508 else
509 fprintf (out,
510 "\
511 assert (ffelex_token_type (t) == FFELEX_typeNAME);\n\
512 \n\
513 switch (ffelex_token_length (t))\n\
514 {\n\
515 "
516 );
517
518 /* Now output the length as a case, followed by the binary search within that length. */
519
520 for (len = 0; ((size_t) len) < ARRAY_SIZE (names); ++len)
521 {
522 if (names[len].first != (name) &names[len])
523 {
524 if (do_names)
525 fprintf (out,
526 "\
527 \tcase %d:\n\
528 ",
529 len);
530 else
531 fprintf (out,
532 "\
533 case %d:\n\
534 ",
535 len);
536 testname (FALSE, do_names ? 10 : 6, names[len].first, names[len].last);
537 if (do_names)
538 fprintf (out,
539 "\
540 \t break;\n\
541 "
542 );
543 else
544 fprintf (out,
545 "\
546 break;\n\
547 "
548 );
549 }
550 }
551
552 if (do_names)
553 fprintf (out,
554 "\
555 \t}\n\
556 return %sNone%s;\n\
557 }\n\
558 \n\
559 ",
560 prefix, postfix);
561 else
562 fprintf (out,
563 "\
564 }\n\
565 \n\
566 return %sNone%s;\n\
567 }\n\
568 ",
569 prefix, postfix);
570 }
571
572 if (do_names)
573 {
574 fputs ("\
575 assert (ffelex_token_type (t) == FFELEX_typeNAMES);\n\
576 \n\
577 switch (ffelex_token_length (t))\n\
578 {\n\
579 default:\n\
580 ",
581 out);
582
583 /* Find greatest non-empty length list. */
584
585 for (len = ARRAY_SIZE (names) - 1;
586 names[len].first == (name) &names[len];
587 --len)
588 ;
589
590 /* Now output the length as a case, followed by the binary search within that length. */
591
592 if (len > 0)
593 {
594 for (; len != 0; --len)
595 {
596 fprintf (out,
597 "\
598 case %d:\n\
599 ",
600 len);
601 if (names[len].first != (name) &names[len])
602 testnames (FALSE, 6, len, names[len].first, names[len].last);
603 }
604 if (names[1].first == (name) &names[1])
605 fprintf (out,
606 "\
607 ;\n\
608 "
609 ); /* Need empty statement after an empty case
610 1: */
611 }
612
613 fprintf (out,
614 "\
615 }\n\
616 \n\
617 return %sNone%s;\n\
618 }\n\
619 ",
620 prefix, postfix);
621 }
622
623 if (out != stdout)
624 fclose (out);
625 if (incl != stdout)
626 fclose (incl);
627 if (in != stdin)
628 fclose (in);
629 return (0);
630 }
631
632 void
633 testname (bool nested, int indent, name first, name last)
634 {
635 name n;
636 name nhalf;
637 int num;
638 int numhalf;
639
640 assert (!nested || indent >= 2);
641 assert (((size_t) indent) + 4 < ARRAY_SIZE (xspaces));
642
643 num = 0;
644 numhalf = 0;
645 for (n = first, nhalf = first; n != last->next; n = n->next)
646 {
647 if ((++num & 1) == 0)
648 {
649 nhalf = nhalf->next;
650 ++numhalf;
651 }
652 }
653
654 if (nested)
655 fprintf (out,
656 "\
657 %s{\n\
658 ",
659 xspaces[indent - 2]);
660
661 fprintf (out,
662 "\
663 %sif ((c = ffesrc_strcmp_2c (ffe_case_match (), p, \"%s\", \"%s\", \"%s\")) == 0)\n\
664 %sreturn %s%s%s;\n\
665 ",
666 xspaces[indent], nhalf->name_uc, nhalf->name_lc, nhalf->name_ic,
667 xspaces[indent + 2], prefix, nhalf->kwname, postfix);
668
669 if (num != 1)
670 {
671 fprintf (out,
672 "\
673 %selse if (c < 0)\n\
674 ",
675 xspaces[indent]);
676
677 if (numhalf == 0)
678 fprintf (out,
679 "\
680 %s;\n\
681 ",
682 xspaces[indent + 2]);
683 else
684 testname (TRUE, indent + 4, first, nhalf->previous);
685
686 if (num - numhalf > 1)
687 {
688 fprintf (out,
689 "\
690 %selse\n\
691 ",
692 xspaces[indent]);
693
694 testname (TRUE, indent + 4, nhalf->next, last);
695 }
696 }
697
698 if (nested)
699 fprintf (out,
700 "\
701 %s}\n\
702 ",
703 xspaces[indent - 2]);
704 }
705
706 void
707 testnames (bool nested, int indent, int len, name first, name last)
708 {
709 name n;
710 name nhalf;
711 int num;
712 int numhalf;
713
714 assert (!nested || indent >= 2);
715 assert (((size_t) indent) + 4 < ARRAY_SIZE (xspaces));
716
717 num = 0;
718 numhalf = 0;
719 for (n = first, nhalf = first; n != last->next; n = n->next)
720 {
721 if ((++num & 1) == 0)
722 {
723 nhalf = nhalf->next;
724 ++numhalf;
725 }
726 }
727
728 if (nested)
729 fprintf (out,
730 "\
731 %s{\n\
732 ",
733 xspaces[indent - 2]);
734
735 fprintf (out,
736 "\
737 %sif ((c = ffesrc_strncmp_2c (ffe_case_match (), p, \"%s\", \"%s\", \"%s\", %d)) == 0)\n\
738 %sreturn %s%s%s;\n\
739 ",
740 xspaces[indent], nhalf->name_uc, nhalf->name_lc, nhalf->name_ic,
741 len, xspaces[indent + 2], prefix, nhalf->kwname, postfix);
742
743 if (num != 1)
744 {
745 fprintf (out,
746 "\
747 %selse if (c < 0)\n\
748 ",
749 xspaces[indent]);
750
751 if (numhalf == 0)
752 fprintf (out,
753 "\
754 %s;\n\
755 ",
756 xspaces[indent + 2]);
757 else
758 testnames (TRUE, indent + 4, len, first, nhalf->previous);
759
760 if (num - numhalf > 1)
761 {
762 fprintf (out,
763 "\
764 %selse\n\
765 ",
766 xspaces[indent]);
767
768 testnames (TRUE, indent + 4, len, nhalf->next, last);
769 }
770 }
771
772 if (nested)
773 fprintf (out,
774 "\
775 %s}\n\
776 ",
777 xspaces[indent - 2]);
778 }
This page took 0.066154 seconds and 4 git commands to generate.