source: trunk/athena/bin/cxref/docxref.c @ 6954

Revision 6954, 2.0 KB checked in by probe, 31 years ago (diff)
Initial revision
  • Property svn:executable set to *
Line 
1/*
2** docxref.c
3**
4** Driver for lex based scanner.  Arranges for stdin to be each named
5** file in turn, so that yylex() never has to know about files.
6** Some of this code is not pretty, but it's not too bad.
7**
8** Arnold Robbins, Information and Computer Science, Georgia Tech
9**      gatech!arnold
10** Copyright (c) 1984 by Arnold Robbins.
11** All rights reserved.
12** This program may not be sold, but may be distributed
13** provided this header is included.
14*/
15
16#include <stdio.h>
17#include <ctype.h>
18
19#define TRUE    1
20#define FALSE   0
21
22extern char yytext[];
23extern int yyleng;
24
25int line_no = 1;        /* current line number */
26char *fname = NULL;     /* current file name */
27
28char *basename();       /* strips leading path of a file name */
29
30main(argc,argv)
31int argc;
32char **argv;
33{
34        FILE saved_in, *fp;
35        char *name;
36        int more_input = FALSE;         /* more files to process */
37        int read_stdin = FALSE;
38
39        name = basename(argv[0]);       /* save command name */
40        fname = "stdin";                /* assume stdin */
41
42        if(argc == 1)
43        {
44                yylex();
45                exit(0);
46        }
47
48        if(argv[1][0] == '-' && argv[1][1] != '\0')
49                        usage(argv[0]); /* will exit */
50
51        saved_in = *stdin;
52        /* save stdin in case "-" is found in middle of command line */
53
54        for(--argc, argv++; argc > 0; --argc, argv++)
55        {
56                if(fileno(stdin) != fileno((&saved_in)) || read_stdin)
57                        fclose(stdin);
58                /* free unix file descriptors */
59
60                if(strcmp(*argv, "-") == 0)
61                {
62                        *stdin = saved_in;
63                        fname = "stdin";
64                        read_stdin = TRUE;
65                        more_input = (argc - 1 > 0);
66                }
67                else if((fp = fopen(*argv,"r")) == NULL)
68                {
69                        fprintf(stderr,"%s: can't open %s\n", name, *argv);
70                        continue;
71                }
72                else
73                {
74                        *stdin = *fp;
75                        /* do it this way so that yylex() */
76                        /* never knows about files etc. */
77                        more_input = (argc - 1 > 0);
78                        fname = *argv;
79                }
80
81                yylex();        /* do the work */
82
83                if(more_input)
84                        line_no = 1;
85        }
86}
87
88outid()
89{
90        char *basename();
91
92        printf("%s\t%s\t%d\n", yytext, basename(fname), line_no);
93}
94
95usage(name)
96char *name;
97{
98        fprintf(stderr,"usage: %s [files]\n", name);
99        exit(1);
100}
101
102#include "basename.c"
Note: See TracBrowser for help on using the repository browser.