Annotation of researchv10no/cmd/xref/xrefa.l, revision 1.1.1.1

1.1       root        1: %k 100
                      2: %a 1000
                      3: %o 1000
                      4: %n 300
                      5: %e 500
                      6: %p 3000
                      7: %{
                      8: char   *filename="-";
                      9: int    pflag=0;
                     10: int    lflag=0;
                     11: int    level=0;
                     12: 
                     13: main(argc,argv)
                     14: int    argc;
                     15: char   *argv[];
                     16: {
                     17:        register int rc=0;
                     18:        if(argc<=1) {
                     19:                yylex();
                     20:        }else{
                     21:                while(argc>1) {
                     22:                        if(strcmp(argv[1],"-p")==0) {
                     23:                                pflag++;
                     24:                        }else if(strcmp(argv[1],"-l")==0) {
                     25:                                lflag++;
                     26:                        }else if(freopen(argv[1],"r",stdin)==NULL) {
                     27:                                fprintf(stderr,"xref: %s: cannot open\n", argv[1]);
                     28:                                rc++;
                     29:                        }else{
                     30:                                filename=argv[1];
                     31:                                yylineno=1;
                     32:                                yylex();
                     33:                        }
                     34:                        argc--; argv++;
                     35:                }
                     36:        }
                     37:        return(rc);
                     38: }
                     39: fndef()
                     40: {
                     41:        /* fn defs */
                     42:        register char *p = &yytext[yyleng];
                     43:        *--p=0; /* remove ) */
                     44:        while(*--p!='(');
                     45:        while(*p==' ' || *p=='\t') {
                     46:                p--;
                     47:                if(p<yytext) break;
                     48:        }
                     49:        while(*p!=' ' && *p!='\t') {
                     50:                p--;
                     51:                if(p<yytext) break;
                     52:        }
                     53:        p++;
                     54:        printf("%s", p);
                     55:        if(p!=yytext) {
                     56:                *--p=0;
                     57:                printf("/%s", yytext);
                     58:        }
                     59:        printf(":%s:+%d\n", filename, yylineno-1);
                     60: }
                     61: %}
                     62: %%
                     63: "/*"                           {
                     64:                                /* comments */
                     65:                                char c;
                     66:                                while(c=yyinput())
                     67:                                        if(c=='*' && yyinput()=='/')
                     68:                                                break;
                     69:                                }
                     70: "\""                           {
                     71:                                /* strings */
                     72:                                char c;
                     73:                                while(c=yyinput())
                     74:                                        if(c=='"')
                     75:                                                break;
                     76:                                        else if(c=='\\') yyinput();
                     77:                                }
                     78: "{"                            {
                     79:                                /* brace */
                     80:                                if(lflag) level++;
                     81:                                }
                     82: "}"                            {
                     83:                                if(lflag) level--;
                     84:                                }
                     85: ^[a-zA-Z_][a-zA-Z0-9 \t_]*"("[a-zA-Z0-9, ]*")"\n       {
                     86:                                        fndef();
                     87:                                }
                     88: if[ \t]*"("    ;
                     89: return[ \t]*"("        ;
                     90: while[ \t]*"(" ;
                     91: for[ \t]*"("   ;
                     92: switch[ \t]*"("        ;
                     93: break          ;
                     94: extern         ;
                     95: short          ;
                     96: ifdef          ;
                     97: endif          ;
                     98: long           ;
                     99: return         ;
                    100: register       ;
                    101: include                ;
                    102: define         ;
                    103: continue       ;
                    104: int            ;
                    105: char           ;
                    106: float          ;
                    107: static         ;
                    108: auto           ;
                    109: unsigned       ;
                    110: double         ;
                    111: else           ;
                    112: do             ;
                    113: default                ;
                    114: struct         ;
                    115: union          ;
                    116: [a-zA-Z_][a-zA-Z0-9_]*[ \t]*"("        {
                    117:                                /* fn calls */
                    118:                                if(level==0)
                    119:                                        printf("%s):%s:%d\n", yytext, filename, yylineno);
                    120:                                }
                    121: [a-zA-Z_][a-zA-Z0-9_]*         {
                    122:                                /* id references */
                    123:                                if(pflag==0 && level==0)
                    124:                                        printf("%s:%s:%d\n", yytext, filename, yylineno);
                    125:                                }
                    126: .      ;
                    127: \n     ;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.