~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/3rdparty/sge_depend/parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XConsortium: parse.c /main/33 1996/12/04 10:11:28 swick $ */
 
2
/*
 
3
 
 
4
Copyright (c) 1993, 1994  X Consortium
 
5
 
 
6
Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
of this software and associated documentation files (the "Software"), to deal
 
8
in the Software without restriction, including without limitation the rights
 
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
copies of the Software, and to permit persons to whom the Software is
 
11
furnished to do so, subject to the following conditions:
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of the X Consortium shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from the X Consortium.
 
26
 
 
27
*/
 
28
 
 
29
#include "def.h"
 
30
 
 
31
extern char   *directives[];
 
32
extern struct inclist   maininclist;
 
33
extern boolean show_where_not;
 
34
 
 
35
#if __STDC__
 
36
static int gobble(   struct filepointer *filep, 
 
37
                     struct inclist *file, 
 
38
                     struct inclist *file_red);
 
39
static int deftype(  char   *line,
 
40
                     struct filepointer *filep,
 
41
                     struct inclist *file_red, 
 
42
                     struct inclist *file,
 
43
                     int   parse_it);
 
44
static struct symtab **fdefined( char   *symbol,
 
45
                                 struct inclist   *file,
 
46
                                 struct inclist   **srcfile);
 
47
static int zero_value(  char   *exp,
 
48
                        struct filepointer *filep,
 
49
                        struct inclist *file_red);
 
50
 
 
51
static struct symtab **slookup( char *symbol, struct inclist *file);
 
52
 
 
53
static int merge2defines( struct inclist *file1, struct inclist *file2);
 
54
static void undefine( char *symbol, struct inclist *file);
 
55
static int match(char *str, char **list); 
 
56
static void add_include(struct filepointer *filep,
 
57
                        struct inclist  *file, 
 
58
                        struct inclist *file_red,
 
59
                        char *include,
 
60
                        boolean dot,
 
61
                        int failOK);
 
62
#else
 
63
static int gobble();
 
64
static int deftype();
 
65
static struct symtab **fdefined();
 
66
static int zero_value();
 
67
static struct symtab **slookup();
 
68
static int merge2defines();
 
69
static void undefine();
 
70
static int match(); 
 
71
static void add_include();
 
72
#endif
 
73
 
 
74
 
 
75
/*-------------------------------------------------------------------------*/
 
76
static int gobble(filep, file, file_red)
 
77
   register struct filepointer *filep;
 
78
   struct inclist      *file, *file_red;
 
79
{
 
80
   register char   *line;
 
81
   register int   type;
 
82
 
 
83
   while ((line = getline(filep))) {
 
84
      switch(type = deftype(line, filep, file_red, file, FALSE)) {
 
85
      case IF:
 
86
      case IFFALSE:
 
87
      case IFGUESSFALSE:
 
88
      case IFDEF:
 
89
      case IFNDEF:
 
90
         type = gobble(filep, file, file_red);
 
91
         while ((type == ELIF) || (type == ELIFFALSE) ||
 
92
                (type == ELIFGUESSFALSE))
 
93
             type = gobble(filep, file, file_red);
 
94
         if (type == ELSE)
 
95
                 (void)gobble(filep, file, file_red);
 
96
         break;
 
97
      case ELSE:
 
98
      case ENDIF:
 
99
         debug(0,("%s, line %d: #%s\n",
 
100
            file->i_file, filep->f_line,
 
101
            directives[type]));
 
102
         return(type);
 
103
      case DEFINE:
 
104
      case UNDEF:
 
105
      case INCLUDE:
 
106
      case INCLUDEDOT:
 
107
      case PRAGMA:
 
108
      case ERROR:
 
109
      case IDENT:
 
110
      case SCCS:
 
111
      case EJECT:
 
112
         break;
 
113
      case ELIF:
 
114
      case ELIFFALSE:
 
115
      case ELIFGUESSFALSE:
 
116
         return(type);
 
117
      case -1:
 
118
         warning("%s, line %d: unknown directive == \"%s\"\n",
 
119
            file_red->i_file, filep->f_line, line);
 
120
         break;
 
121
      }
 
122
   }
 
123
   return(-1);
 
124
}
 
125
 
 
126
 
 
127
/*---------------------------------------------------------------------------
 
128
   Decide what type of # directive this line is.
 
129
----------------------------------------------------------------------------*/
 
130
static int deftype (line, filep, file_red, file, parse_it)
 
131
   register char   *line;
 
132
   register struct filepointer *filep;
 
133
   register struct inclist *file_red, *file;
 
134
   int   parse_it;
 
135
{
 
136
   register char   *p;
 
137
   char   *directive, savechar;
 
138
   register int   ret;
 
139
 
 
140
   /*
 
141
    * Parse the directive...
 
142
    */
 
143
   directive=line+1;
 
144
   while (*directive == ' ' || *directive == '\t')
 
145
      directive++;
 
146
 
 
147
   p = directive;
 
148
   while (*p >= 'a' && *p <= 'z')
 
149
      p++;
 
150
   savechar = *p;
 
151
   *p = '\0';
 
152
   ret = match(directive, directives);
 
153
   *p = savechar;
 
154
 
 
155
   /* If we don't recognize this compiler directive or we happen to just
 
156
    * be gobbling up text while waiting for an #endif or #elif or #else
 
157
    * in the case of an #elif we must check the zero_value and return an
 
158
    * ELIF or an ELIFFALSE.
 
159
    */
 
160
 
 
161
   if (ret == ELIF && !parse_it)
 
162
   {
 
163
       while (*p == ' ' || *p == '\t')
 
164
      p++;
 
165
       /*
 
166
        * parse an expression.
 
167
        */
 
168
       debug(0,("%s, line %d: #elif %s ",
 
169
         file->i_file, filep->f_line, p));
 
170
       ret = zero_value(p, filep, file_red);
 
171
       if (ret != IF)
 
172
       {
 
173
      debug(0,("false...\n"));
 
174
      if (ret == IFFALSE)
 
175
          return(ELIFFALSE);
 
176
      else
 
177
          return(ELIFGUESSFALSE);
 
178
       }
 
179
       else
 
180
       {
 
181
      debug(0,("true...\n"));
 
182
      return(ELIF);
 
183
       }
 
184
   }
 
185
 
 
186
   if (ret < 0 || ! parse_it)
 
187
      return(ret);
 
188
 
 
189
   /*
 
190
    * now decide how to parse the directive, and do it.
 
191
    */
 
192
   while (*p == ' ' || *p == '\t')
 
193
      p++;
 
194
   switch (ret) {
 
195
   case IF:
 
196
      /*
 
197
       * parse an expression.
 
198
       */
 
199
      ret = zero_value(p, filep, file_red);
 
200
      debug(0,("%s, line %d: %s #if %s\n",
 
201
          file->i_file, filep->f_line, ret?"false":"true", p));
 
202
      break;
 
203
   case IFDEF:
 
204
   case IFNDEF:
 
205
      debug(0,("%s, line %d: #%s %s\n",
 
206
         file->i_file, filep->f_line, directives[ret], p));
 
207
   case UNDEF:
 
208
      /*
 
209
       * separate the name of a single symbol.
 
210
       */
 
211
      while (isalnum(*p) || *p == '_')
 
212
         *line++ = *p++;
 
213
      *line = '\0';
 
214
      break;
 
215
   case INCLUDE:
 
216
      debug(2,("%s, line %d: #include %s\n",
 
217
         file->i_file, filep->f_line, p));
 
218
 
 
219
      /* Support ANSI macro substitution */
 
220
      {
 
221
          struct symtab **sym = isdefined(p, file_red, NULL);
 
222
          while (sym) {
 
223
         p = (*sym)->s_value;
 
224
         debug(3,("%s : #includes SYMBOL %s = %s\n",
 
225
                file->i_incstring,
 
226
                (*sym) -> s_name,
 
227
                (*sym) -> s_value));
 
228
         /* mark file as having included a 'soft include' */
 
229
         file->i_flags |= INCLUDED_SYM; 
 
230
         sym = isdefined(p, file_red, NULL);
 
231
          }
 
232
      }
 
233
 
 
234
      /*
 
235
       * Separate the name of the include file.
 
236
       */
 
237
      while (*p && *p != '"' && *p != '<')
 
238
         p++;
 
239
      if (! *p)
 
240
         return(-2);
 
241
      if (*p++ == '"') {
 
242
         ret = INCLUDEDOT;
 
243
         while (*p && *p != '"')
 
244
            *line++ = *p++;
 
245
      } else
 
246
         while (*p && *p != '>')
 
247
            *line++ = *p++;
 
248
      *line = '\0';
 
249
      break;
 
250
   case DEFINE:
 
251
      /*
 
252
       * copy the definition back to the beginning of the line.
 
253
       */
 
254
      strcpy (line, p);
 
255
      break;
 
256
   case ELSE:
 
257
   case ENDIF:
 
258
   case ELIF:
 
259
   case PRAGMA:
 
260
   case ERROR:
 
261
   case IDENT:
 
262
   case SCCS:
 
263
   case EJECT:
 
264
      debug(0,("%s, line %d: #%s\n",
 
265
         file->i_file, filep->f_line, directives[ret]));
 
266
      /*
 
267
       * nothing to do.
 
268
       */
 
269
      break;
 
270
   }
 
271
   return(ret);
 
272
}
 
273
 
 
274
/*-------------------------------------------------------------------------*/
 
275
static struct symtab **fdefined(symbol, file, srcfile)
 
276
   register char   *symbol;
 
277
   struct inclist   *file;
 
278
   struct inclist   **srcfile;
 
279
{
 
280
   register struct inclist   **ip;
 
281
   register struct symtab   **val;
 
282
   register int   i;
 
283
   static int   recurse_lvl = 0;
 
284
 
 
285
   if (file->i_flags & DEFCHECKED)
 
286
      return(NULL);
 
287
   file->i_flags |= DEFCHECKED;
 
288
   if ((val = slookup(symbol, file)))
 
289
      debug(1,("%s defined in %s as %s\n",
 
290
          symbol, file->i_file, (*val)->s_value));
 
291
   if (val == NULL && file->i_list)
 
292
      {
 
293
      for (ip = file->i_list, i=0; i < file->i_listlen; i++, ip++)
 
294
         if (file->i_merged[i]==FALSE) {
 
295
            val = fdefined(symbol, *ip, srcfile);
 
296
            if ((*ip)->i_flags & FINISHED) {
 
297
               merge2defines(file,*ip);
 
298
               file->i_merged[i]=TRUE;
 
299
                }
 
300
            if (val!=NULL) break;
 
301
         }
 
302
      }
 
303
   else if (val != NULL && srcfile != NULL) *srcfile = file;
 
304
   recurse_lvl--;
 
305
   file->i_flags &= ~DEFCHECKED;
 
306
 
 
307
   return(val);
 
308
}
 
309
 
 
310
/*-------------------------------------------------------------------------*/
 
311
struct symtab **isdefined(symbol, file, srcfile)
 
312
   register char   *symbol;
 
313
   struct inclist   *file;
 
314
   struct inclist   **srcfile;
 
315
{
 
316
   register struct symtab   **val;
 
317
 
 
318
   if ((val = slookup(symbol, &maininclist))) {
 
319
      debug(1,("%s defined on command line\n", symbol));
 
320
      if (srcfile != NULL) *srcfile = &maininclist;
 
321
      return(val);
 
322
   }
 
323
   if ((val = fdefined(symbol, file, srcfile)))
 
324
      return(val);
 
325
   debug(1,("%s not defined in %s\n", symbol, file->i_file));
 
326
   return(NULL);
 
327
}
 
328
 
 
329
/*---------------------------------------------------------------------------
 
330
   Return type based on if the #if expression evaluates to 0
 
331
----------------------------------------------------------------------------*/
 
332
static int zero_value(exp, filep, file_red)
 
333
   register char   *exp;
 
334
   register struct filepointer *filep;
 
335
   register struct inclist *file_red;
 
336
{
 
337
   if (cppsetup(exp, filep, file_red))
 
338
       return(IFFALSE);
 
339
   else
 
340
       return(IF);
 
341
}
 
342
 
 
343
/*-------------------------------------------------------------------------*/
 
344
void define2(name, val, file)
 
345
   char   *name, *val;
 
346
   struct inclist   *file;
 
347
{
 
348
    int first, last, below;
 
349
    register struct symtab **sp = NULL, **dest;
 
350
    struct symtab *stab;
 
351
 
 
352
    /* Make space if it's needed */
 
353
    if (file->i_defs == NULL)
 
354
    {
 
355
   file->i_defs = (struct symtab **)
 
356
         malloc(sizeof (struct symtab*) * SYMTABINC);
 
357
   file->i_ndefs = 0;
 
358
    }
 
359
    else if (!(file->i_ndefs % SYMTABINC))
 
360
   file->i_defs = (struct symtab **)
 
361
         realloc(file->i_defs,
 
362
            sizeof(struct symtab*)*(file->i_ndefs+SYMTABINC));
 
363
 
 
364
    if (file->i_defs == NULL)
 
365
   fatalerr("malloc()/realloc() failure in insert_defn()\n");
 
366
 
 
367
    below = first = 0;
 
368
    last = file->i_ndefs - 1;
 
369
    while (last >= first)
 
370
    {
 
371
   /* Fast inline binary search */
 
372
   register char *s1;
 
373
   register char *s2;
 
374
   register int middle = (first + last) / 2;
 
375
 
 
376
   /* Fast inline strchr() */
 
377
   s1 = name;
 
378
   s2 = file->i_defs[middle]->s_name;
 
379
   while (*s1++ == *s2++)
 
380
       if (s2[-1] == '\0') break;
 
381
 
 
382
   /* If exact match, set sp and break */
 
383
   if (*--s1 == *--s2) 
 
384
   {
 
385
       sp = file->i_defs + middle;
 
386
       break;
 
387
   }
 
388
 
 
389
   /* If name > i_defs[middle] ... */
 
390
   if (*s1 > *s2) 
 
391
   {
 
392
       below = first;
 
393
       first = middle + 1;
 
394
   }
 
395
   /* else ... */
 
396
   else
 
397
   {
 
398
       below = last = middle - 1;
 
399
   }
 
400
    }
 
401
 
 
402
    /* Search is done.  If we found an exact match to the symbol name,
 
403
       just replace its s_value */
 
404
    if (sp != NULL)
 
405
    {
 
406
   free((*sp)->s_value);
 
407
   (*sp)->s_value = copy(val);
 
408
   return;
 
409
    }
 
410
 
 
411
    sp = file->i_defs + file->i_ndefs++;
 
412
    dest = file->i_defs + below + 1;
 
413
    while (sp > dest)
 
414
    {
 
415
   *sp = sp[-1];
 
416
   sp--;
 
417
    }
 
418
    stab = (struct symtab *) malloc(sizeof (struct symtab));
 
419
    if (stab == NULL)
 
420
   fatalerr("malloc()/realloc() failure in insert_defn()\n");
 
421
 
 
422
    stab->s_name = copy(name);
 
423
    stab->s_value = copy(val);
 
424
    *sp = stab;
 
425
}
 
426
 
 
427
/*-------------------------------------------------------------------------*/
 
428
void define(def, file)
 
429
   char   *def;
 
430
   struct inclist   *file;
 
431
{
 
432
    char *val;
 
433
 
 
434
    /* Separate symbol name and its value */
 
435
    val = def;
 
436
    while (isalnum(*val) || *val == '_')
 
437
   val++;
 
438
    if (*val)
 
439
   *val++ = '\0';
 
440
    while (*val == ' ' || *val == '\t')
 
441
   val++;
 
442
 
 
443
    if (!*val)
 
444
   val = "1";
 
445
    define2(def, val, file);
 
446
}
 
447
 
 
448
/*-------------------------------------------------------------------------*/
 
449
static struct symtab **slookup(symbol, file)
 
450
   register char   *symbol;
 
451
   register struct inclist   *file;
 
452
{
 
453
   register int first = 0;
 
454
   register int last = file->i_ndefs - 1;
 
455
 
 
456
   if (file) while (last >= first)
 
457
   {
 
458
       /* Fast inline binary search */
 
459
       register char *s1;
 
460
       register char *s2;
 
461
       register int middle = (first + last) / 2;
 
462
 
 
463
       /* Fast inline strchr() */
 
464
       s1 = symbol;
 
465
       s2 = file->i_defs[middle]->s_name;
 
466
       while (*s1++ == *s2++)
 
467
           if (s2[-1] == '\0') break;
 
468
 
 
469
       /* If exact match, we're done */
 
470
       if (*--s1 == *--s2) 
 
471
       {
 
472
           return file->i_defs + middle;
 
473
       }
 
474
 
 
475
       /* If symbol > i_defs[middle] ... */
 
476
       if (*s1 > *s2) 
 
477
       {
 
478
           first = middle + 1;
 
479
       }
 
480
       /* else ... */
 
481
       else
 
482
       {
 
483
           last = middle - 1;
 
484
       }
 
485
   }
 
486
   return(NULL);
 
487
}
 
488
 
 
489
/*-------------------------------------------------------------------------*/
 
490
static int merge2defines(file1, file2)
 
491
   struct inclist   *file1;
 
492
   struct inclist   *file2;
 
493
{
 
494
   if ((file1!=NULL) && (file2!=NULL)) 
 
495
        {
 
496
      int first1 = 0;
 
497
      int last1 = file1->i_ndefs - 1;
 
498
 
 
499
      int first2 = 0;
 
500
      int last2 = file2->i_ndefs - 1;
 
501
 
 
502
                int first=0;
 
503
                struct symtab** i_defs = NULL;
 
504
      int deflen=file1->i_ndefs+file2->i_ndefs;
 
505
 
 
506
                if (deflen>0)
 
507
                { 
 
508
                   /* make sure deflen % SYMTABINC == 0 is still true */
 
509
                   deflen += (SYMTABINC - deflen % SYMTABINC) % SYMTABINC;
 
510
                   i_defs=(struct symtab**)
 
511
             malloc(deflen*sizeof(struct symtab*));
 
512
                   if (i_defs==NULL) return 0;
 
513
           }
 
514
 
 
515
           while ((last1 >= first1) && (last2 >= first2))
 
516
           {
 
517
             char *s1=file1->i_defs[first1]->s_name;
 
518
             char *s2=file2->i_defs[first2]->s_name;
 
519
 
 
520
              if (strcmp(s1,s2) < 0)
 
521
                           i_defs[first++]=file1->i_defs[first1++];
 
522
              else if (strcmp(s1,s2) > 0)
 
523
                           i_defs[first++]=file2->i_defs[first2++];
 
524
                        else /* equal */
 
525
                        {
 
526
                           i_defs[first++]=file2->i_defs[first2++];
 
527
                                first1++;
 
528
                        }
 
529
           }
 
530
           while (last1 >= first1)
 
531
           {
 
532
                        i_defs[first++]=file1->i_defs[first1++];
 
533
           }
 
534
           while (last2 >= first2)
 
535
           {
 
536
                        i_defs[first++]=file2->i_defs[first2++];
 
537
           }
 
538
 
 
539
                if (file1->i_defs) free(file1->i_defs);
 
540
                file1->i_defs=i_defs;
 
541
                file1->i_ndefs=first;
 
542
                
 
543
      return 1;
 
544
     }
 
545
   return 0;
 
546
}
 
547
 
 
548
/*-------------------------------------------------------------------------*/
 
549
static void undefine(symbol, file)
 
550
   char   *symbol;
 
551
   register struct inclist   *file;
 
552
{
 
553
   register struct symtab **ptr;
 
554
   struct inclist *srcfile;
 
555
   while ((ptr = isdefined(symbol, file, &srcfile)) != NULL)
 
556
   {
 
557
       srcfile->i_ndefs--;
 
558
       for (; ptr < srcfile->i_defs + srcfile->i_ndefs; ptr++)
 
559
      *ptr = ptr[1];
 
560
   }
 
561
}
 
562
 
 
563
/*-------------------------------------------------------------------------*/
 
564
int find_includes(filep, file, file_red, recursion, failOK)
 
565
   struct filepointer   *filep;
 
566
   struct inclist      *file, *file_red;
 
567
   int         recursion;
 
568
   boolean         failOK;
 
569
{
 
570
   register char   *line;
 
571
   register int   type;
 
572
   boolean recfailOK;
 
573
 
 
574
   while ((line = getline(filep))) {
 
575
      switch(type = deftype(line, filep, file_red, file, TRUE)) {
 
576
      case IF:
 
577
      doif:
 
578
         type = find_includes(filep, file,
 
579
            file_red, recursion+1, failOK);
 
580
         while ((type == ELIF) || (type == ELIFFALSE) ||
 
581
                (type == ELIFGUESSFALSE))
 
582
            type = gobble(filep, file, file_red);
 
583
         if (type == ELSE)
 
584
            gobble(filep, file, file_red);
 
585
         break;
 
586
      case IFFALSE:
 
587
      case IFGUESSFALSE:
 
588
          doiffalse:
 
589
         if (type == IFGUESSFALSE || type == ELIFGUESSFALSE)
 
590
             recfailOK = TRUE;
 
591
         else
 
592
             recfailOK = failOK;
 
593
         type = gobble(filep, file, file_red);
 
594
         if (type == ELSE)
 
595
             find_includes(filep, file,
 
596
                 file_red, recursion+1, recfailOK);
 
597
         else
 
598
         if (type == ELIF)
 
599
             goto doif;
 
600
         else
 
601
         if ((type == ELIFFALSE) || (type == ELIFGUESSFALSE))
 
602
             goto doiffalse;
 
603
         break;
 
604
      case IFDEF:
 
605
      case IFNDEF:
 
606
         if ((type == IFDEF && 
 
607
                isdefined(line, file_red, (struct inclist **) NULL))
 
608
          || (type == IFNDEF && 
 
609
                !isdefined(line, file_red, (struct inclist **) NULL))) {
 
610
            debug(1,(type == IFNDEF ?
 
611
                "line %d: %s !def'd in %s via %s%s\n" : "",
 
612
                filep->f_line, line,
 
613
                file->i_file, file_red->i_file, ": doit"));
 
614
            type = find_includes(filep, file,
 
615
               file_red, recursion+1, failOK);
 
616
            while (type == ELIF || type == ELIFFALSE || type == ELIFGUESSFALSE)
 
617
               type = gobble(filep, file, file_red);
 
618
            if (type == ELSE)
 
619
               gobble(filep, file, file_red);
 
620
         }
 
621
         else {
 
622
            debug(1,(type == IFDEF ?
 
623
                "line %d: %s !def'd in %s via %s%s\n" : "",
 
624
                filep->f_line, line,
 
625
                file->i_file, file_red->i_file, ": gobble"));
 
626
            type = gobble(filep, file, file_red);
 
627
            if (type == ELSE)
 
628
               find_includes(filep, file,
 
629
                  file_red, recursion+1, failOK);
 
630
            else if (type == ELIF)
 
631
                   goto doif;
 
632
            else if (type == ELIFFALSE || type == ELIFGUESSFALSE)
 
633
                   goto doiffalse;
 
634
         }
 
635
         break;
 
636
      case ELSE:
 
637
      case ELIFFALSE:
 
638
      case ELIFGUESSFALSE:
 
639
      case ELIF:
 
640
         if (!recursion)
 
641
            gobble(filep, file, file_red);
 
642
      case ENDIF:
 
643
         if (recursion)
 
644
            return(type);
 
645
      case DEFINE:
 
646
         define(line, file);
 
647
         break;
 
648
      case UNDEF:
 
649
         if (!*line) {
 
650
             warning("%s, line %d: incomplete undef == \"%s\"\n",
 
651
            file_red->i_file, filep->f_line, line);
 
652
             break;
 
653
         }
 
654
         undefine(line, file_red);
 
655
         break;
 
656
      case INCLUDE:
 
657
         if (!local_include)
 
658
            add_include(filep, file, file_red, line, FALSE, failOK);
 
659
         break;
 
660
      case INCLUDEDOT:
 
661
         add_include(filep, file, file_red, line, TRUE, failOK);
 
662
         break;
 
663
      case ERROR:
 
664
             warning("%s: %d: %s\n", file_red->i_file,
 
665
             filep->f_line, line);
 
666
             break;
 
667
          
 
668
      case PRAGMA:
 
669
      case IDENT:
 
670
      case SCCS:
 
671
      case EJECT:
 
672
         break;
 
673
      case -1:
 
674
         warning("%s", file_red->i_file);
 
675
         if (file_red != file)
 
676
             warning1(" (reading %s)", file->i_file);
 
677
         warning1(", line %d: unknown directive == \"%s\"\n",
 
678
             filep->f_line, line);
 
679
         break;
 
680
      case -2:
 
681
         warning("%s", file_red->i_file);
 
682
         if (file_red != file)
 
683
             warning1(" (reading %s)", file->i_file);
 
684
         warning1(", line %d: incomplete include == \"%s\"\n",
 
685
             filep->f_line, line);
 
686
         break;
 
687
      }
 
688
   }
 
689
   file->i_flags |= FINISHED;
 
690
   return(-1);
 
691
}
 
692
 
 
693
/*-------------------------------------------------------------------------*/
 
694
static int match(str, list)
 
695
   register char   *str, **list;
 
696
{
 
697
   register int   i;
 
698
 
 
699
   for (i=0; *list; i++, list++)
 
700
      if (strcmp(str, *list) == 0)
 
701
         return(i);
 
702
   return(-1);
 
703
}
 
704
 
 
705
/*-------------------------------------------------------------------------*/
 
706
static void add_include(filep, file, file_red, include, dot, failOK)
 
707
        struct filepointer      *filep;
 
708
        struct inclist  *file, *file_red;
 
709
        char    *include;
 
710
        boolean dot;
 
711
   int failOK;
 
712
{
 
713
        register struct inclist *newfile;
 
714
        register struct filepointer     *content;
 
715
 
 
716
        /*
 
717
         * First decide what the pathname of this include file really is.
 
718
         */
 
719
        newfile = inc_path(file->i_file, include, dot);
 
720
        if (newfile == NULL) {
 
721
                if (failOK)
 
722
                    return;
 
723
                if (file != file_red)
 
724
                        warning("%s (reading %s, line %d): ",
 
725
                                file_red->i_file, file->i_file, filep->f_line);
 
726
                else
 
727
                        warning("%s, line %d: ", file->i_file, filep->f_line);
 
728
                warning1("cannot find include file \"%s\"\n", include);
 
729
                show_where_not = TRUE;
 
730
                newfile = inc_path(file->i_file, include, dot);
 
731
                show_where_not = FALSE;
 
732
        }
 
733
 
 
734
        if (newfile) {
 
735
                included_by(file, newfile);
 
736
                if (!(newfile->i_flags & SEARCHED)) {
 
737
                        newfile->i_flags |= SEARCHED;
 
738
                        content = getfile(newfile->i_file);
 
739
                        find_includes(content, newfile, file_red, 0, failOK);
 
740
                        freefile(content);
 
741
                }
 
742
        }
 
743
}
 
744