~ubuntu-branches/ubuntu/vivid/cproto/vivid

« back to all changes in this revision

Viewing changes to lex.l

  • Committer: Bazaar Package Importer
  • Author(s): Kenneth J. Pronovici
  • Date: 2004-03-30 19:58:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040330195833-loh9sgce2as79j67
Tags: 4.7c-1
* New upstream release.
  - Includes equivalent of patch as used to close #228801 (see below).
  - Supports -X option to filter out unwanted definitions (closes: #235824).
* Now configure using --enable-llib option, so we don't need lint installed.
* Added gcc to Depends: line since -X option requires GCC to work; I assume
  most users will already have gcc installed anyway, if they are developers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%{
2
 
/* $Id: lex.l,v 4.5.1.2 1999/12/19 23:49:32 tom Exp $
 
2
/* $Id: lex.l,v 4.6.1.3 2004/03/25 00:39:45 tom Exp tom $
3
3
 *
4
4
 * Lexical analyzer for C function prototype generator
5
5
 *
84
84
static IncludeStack inc_stack[MAX_INC_DEPTH];   /* stack of included files */
85
85
static SymbolTable *included_files;             /* files already included */
86
86
 
87
 
static int  type_of_name      ARGS((char *name));
88
 
static void startCpp          ARGS((int level));
89
 
static void finishCpp         ARGS((void));
 
87
static int  type_of_name      (char *name);
 
88
static void startCpp          (int level);
 
89
static void finishCpp         (void);
90
90
#if defined(apollo) || !OPT_LINTLIBRARY
91
 
static void absorb_special    ARGS((void));
 
91
static void absorb_special    (void);
92
92
#endif
93
93
#if OPT_LINTLIBRARY
94
 
static void gcc_attribute     ARGS((void));
 
94
static void gcc_attribute     (void);
95
95
#endif
96
 
static void update_line_num   ARGS((void));
97
 
static void save_text         ARGS((void));
98
 
static void save_text_offset  ARGS((void));
99
 
static void get_quoted        ARGS((void));
100
 
static void get_comment       ARGS((void));
101
 
static void get_cpp_directive ARGS((char *dest, unsigned n));
102
 
static void do_include        ARGS((char *f));
103
 
static void include_file      ARGS((char *name, int convert));
104
 
static void put_file          ARGS((FILE *outf));
105
 
static void put_quoted        ARGS((int c));
 
96
static void update_line_num   (void);
 
97
static void save_text         (void);
 
98
static void save_text_offset  (void);
 
99
static void get_quoted        (void);
 
100
static void get_comment       (void);
 
101
static void get_cpp_directive (char *dest, unsigned n);
 
102
static void do_include        (char *f);
 
103
static void include_file      (char *name, int convert);
 
104
static void put_file          (FILE *outf);
 
105
static void put_quoted        (int c);
106
106
 
107
107
#if OPT_LINTLIBRARY
108
 
static int decipher_comment   ARGS((char *keyword, int len));
 
108
static int decipher_comment   (char *keyword, int len);
109
109
#endif
110
110
 
111
111
#ifdef yywrap
112
112
#undef yywrap
113
113
#endif
114
 
int yywrap ARGS((void));
 
114
int yywrap (void);
115
115
%}
116
116
 
117
117
WS              [ \t]
148
148
                            char name[MAX_TEXT_SIZE], value[MAX_TEXT_SIZE];
149
149
 
150
150
                            save_text();
 
151
 
 
152
                            *name = 0;
151
153
                            sscanf(yytext, "define %s", name);
 
154
 
152
155
                            get_cpp_directive(buf, sizeof(buf));
 
156
 
 
157
                            *value = 0;
153
158
                            sscanf(buf, "%s", value);
 
159
 
154
160
                            new_symbol(define_names, name, value, DS_NONE);
155
161
                        }
156
162
 
171
177
 
172
178
<CPP1>line{WS}+[0-9]+{WS}+\".*$  {
173
179
                            save_text();
 
180
 
 
181
                            cur_file->file_name[0] = 0;
174
182
                            sscanf(yytext, "line %d \"%[^\"]\"",
175
 
                             &cur_file->line_num, cur_file->file_name);
 
183
                                           &cur_file->line_num,
 
184
                                           cur_file->file_name);
 
185
 
176
186
                            cur_file->line_num--;
177
187
                            track_in();
178
188
                            finishCpp();
179
189
                        }
180
190
<CPP1>[0-9]+{WS}+\".*$  {
181
191
                            save_text();
182
 
                            sscanf(yytext, "%d \"%[^\"]\"", &cur_file->line_num,
183
 
                             cur_file->file_name);
 
192
 
 
193
                            cur_file->file_name[0] = 0;
 
194
                            sscanf(yytext, "%d \"%[^\"]\"",
 
195
                                           &cur_file->line_num,
 
196
                                           cur_file->file_name);
 
197
 
184
198
                            cur_file->line_num--;
185
199
                            track_in();
186
200
                            finishCpp();
334
348
%%
335
349
 
336
350
static void
337
 
startCpp (level)
338
 
int level;
 
351
startCpp (int level)
339
352
{
340
353
    save_cpp = level;
341
354
    in_cpp = TRUE;
343
356
}
344
357
 
345
358
static void
346
 
finishCpp()
 
359
finishCpp(void)
347
360
{
348
361
    in_cpp = FALSE;
349
362
    if (save_cpp)
357
370
 */
358
371
#if defined(apollo) || !OPT_LINTLIBRARY
359
372
static void
360
 
absorb_special ()
 
373
absorb_special (void)
361
374
{
362
375
    int c;
363
376
    int nest    = 0;
383
396
 * avoid spurious matches with non-gcc compilers).
384
397
 */
385
398
static void
386
 
gcc_attribute ()
 
399
gcc_attribute (void)
387
400
{
388
401
    int c, num1, num2;
389
402
    int nest = 0;
390
 
    int len = 0;
 
403
    unsigned len = 0;
391
404
    char bfr[BUFSIZ];
392
405
 
393
406
    while ((c = input()) > 0) {
416
429
/* Decode the current token according to the type-of-name
417
430
 */
418
431
static int
419
 
type_of_name (name)
420
 
char *name;
 
432
type_of_name (char *name)
421
433
{
422
434
    if (find_symbol(type_qualifiers, name) != NULL)
423
435
        return T_TYPE_QUALIFIER;
430
442
}
431
443
 
432
444
boolean
433
 
is_typedef_name (name)
434
 
char *name;
 
445
is_typedef_name (char *name)
435
446
{
436
447
    return (find_symbol(typedef_names, name) != NULL);
437
448
}
440
451
 * current line number.
441
452
 */
442
453
static void
443
 
update_line_num ()
 
454
update_line_num (void)
444
455
{
445
456
    char *p = yytext;
446
457
    while (*p != '\0') {
452
463
/* Save the matched text in the temporary file.
453
464
 */
454
465
static void
455
 
save_text ()
 
466
save_text (void)
456
467
{
457
468
#if OPT_LINTLIBRARY
458
469
    if (!in_cpp)
467
478
 * to the file.
468
479
 */
469
480
static void
470
 
save_text_offset ()
 
481
save_text_offset (void)
471
482
{
472
483
    (void)strcpy(yylval.text.text, yytext);
473
484
#if OPT_LINTLIBRARY
491
502
} cmtVal;
492
503
 
493
504
static int
494
 
decipher_comment (keyword, len)
495
 
char *keyword;
496
 
int len;
 
505
decipher_comment (char *keyword, int len)
497
506
{
498
507
    if (len != 0) {
499
508
        int value;
534
543
#endif
535
544
 
536
545
static void
537
 
put_quoted (c)
538
 
int c;
 
546
put_quoted (int c)
539
547
{
540
548
    /* Modifying 'yytext[]' doesn't work well with FLEX, which simply
541
549
     * maintains 'yytext' as a pointer into its input buffer.  LEX copies
579
587
 * we don't try to eat them in the lexical rules.
580
588
 */
581
589
static void
582
 
get_quoted ()
 
590
get_quoted (void)
583
591
{
584
592
    int delim = *yytext;
585
593
    int c;
610
618
/* Scan to end of comment.
611
619
 */
612
620
static void
613
 
get_comment ()
 
621
get_comment (void)
614
622
{
615
623
    int c, lastc = '\0';
616
624
 
617
625
#if OPT_LINTLIBRARY
618
 
    int len = 0;
 
626
    unsigned len = 0;
619
627
    char keyword[BUFSIZ];
620
628
 
621
629
    keyword[len] = '\0';
695
703
 * the text in the buffer pointed to by <dest> having size <n>.
696
704
 */
697
705
static void
698
 
get_cpp_directive (dest, n)
699
 
char *dest;             /* buffer to store directive text */
700
 
unsigned n;             /* size of buffer to store directive text */
 
706
get_cpp_directive (
 
707
char *dest,             /* buffer to store directive text */
 
708
unsigned n)             /* size of buffer to store directive text */
701
709
{
702
710
    char c, lastc[4];
703
711
 
737
745
/* Return a pointer to the current file name.
738
746
 */
739
747
char *
740
 
cur_file_name ()
 
748
cur_file_name (void)
741
749
{
742
750
    return cur_file->file_name;
743
751
}
745
753
/* Return the current line number.
746
754
 */
747
755
unsigned
748
 
cur_line_num ()
 
756
cur_line_num (void)
749
757
{
750
758
    return cur_file->line_num;
751
759
}
753
761
/* Return the current temporary output file.
754
762
 */
755
763
FILE *
756
 
cur_tmp_file ()
 
764
cur_tmp_file (void)
757
765
{
758
766
    return cur_file->tmp_file;
759
767
}
761
769
/* Set the modify flag for the current file.
762
770
 */
763
771
void
764
 
cur_file_changed ()
 
772
cur_file_changed (void)
765
773
{
766
774
    cur_file->changed = TRUE;
767
775
}
769
777
/* Return the temporary file offset of beginning of the current comment.
770
778
 */
771
779
long
772
 
cur_begin_comment ()
 
780
cur_begin_comment (void)
773
781
{
774
782
    return cur_file->begin_comment;
775
783
}
777
785
/* Return the text of the current lexical token.
778
786
 */
779
787
char *
780
 
cur_text ()
 
788
cur_text (void)
781
789
{
782
790
    return yytext;
783
791
}
789
797
 *
790
798
 * Not all systems have the ANSI tmpfile() function yet...
791
799
 *
792
 
 * DaviD W. Sanderson (dws@cs.wisc.edu)
 
800
 * David W. Sanderson (dws@cs.wisc.edu)
793
801
 */
794
802
FILE *
795
 
tmpfile ()
 
803
tmpfile (void)
796
804
{
797
805
    char name[MAX_TEXT_SIZE];
798
806
    char *tmpdir;
824
832
 * point to the file.
825
833
 */
826
834
static void
827
 
include_file (name, convert)
828
 
char *name;             /* file name */
829
 
int convert;            /* if TRUE, convert function definitions */
 
835
include_file (char *name,       /* file name */
 
836
              int convert)      /* if TRUE, convert function definitions */
830
837
{
831
838
    ++inc_depth;
832
839
    cur_file = inc_stack + inc_depth;
833
840
    cur_file->file = yyin;
834
841
    cur_file->base_name = xstrdup(name);
835
 
    cur_file->file_name = strcpy(xmalloc(MAX_TEXT_SIZE), name);
 
842
    cur_file->file_name = strcpy(xmalloc(strlen(name) + MAX_TEXT_SIZE), name);
836
843
    cur_file->line_num = 1;
837
844
    cur_file->convert = convert;
838
845
    cur_file->changed = FALSE;
857
864
/* Copy converted C source from the temporary file to the output stream.
858
865
 */
859
866
static void
860
 
put_file (outf)
861
 
FILE *outf;
 
867
put_file (FILE *outf)
862
868
{
863
869
    char block[BLOCK_SIZE];
864
870
    long filesize;
879
885
/* Remove the top of the include stack.
880
886
 */
881
887
void
882
 
pop_file (closed)
883
 
int closed;
 
888
pop_file (int closed)
884
889
{
885
890
    FILE *outf;
886
891
 
922
927
/* Process include directive.
923
928
 */
924
929
static void
925
 
do_include (file_spec)
926
 
char *file_spec;        /* path surrounded by "" or <> */
 
930
do_include (char *file_spec)    /* path surrounded by "" or <> */
927
931
{
928
932
    int stdinc;         /* 1 = path surrounded by <> */
929
933
    char file[MAX_TEXT_SIZE], path[MAX_TEXT_SIZE];
981
985
 * nested include file.
982
986
 */
983
987
int
984
 
yywrap ()
 
988
yywrap (void)
985
989
{
986
990
    if (inc_depth > 0) {
987
991
        pop_file(FALSE);