1 /* $Id: main.c,v 1.22 1995/08/17 13:33:55 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
12 #include "file_info.h"
17 extern char *symbol2str();
18 extern char *getwdir();
19 extern int err_occurred;
20 extern int do_dependencies;
21 extern char *dep_file;
22 int idfsize = IDFSIZE;
23 extern char options[];
24 static File *dep_fd = STDOUT;
30 extern char **inctable;
31 extern int inc_max, inc_total;
36 /* parse and interpret the command line options */
41 inctable = (char **) Malloc(10 * sizeof(char *));
45 inctable[1] = "/usr/include";
47 init_pp(); /* initialise the preprocessor macros */
49 /* Note: source file "-" indicates that the source is supplied
50 as standard input. This is only allowed if INP_READ_IN_ONE is
53 while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') {
54 char *par = &argv[1][1];
61 compile(argc - 1, &argv[1]);
68 register char *source = 0;
82 fatal("use: %s [options] [source]", prog_name);
86 if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */
87 fatal("%s: no source file %s", prog_name,
88 source ? source : "stdin");
89 if (source) WorkingDir = getwdir(dummy);
91 if (do_dependencies) list_dependencies(source);
94 struct idf *file_head;
95 extern char *strrindex();
97 list_dependencies(source)
100 register struct idf *p = file_head;
103 register char *s = strrindex(source, '.');
109 /* the source may be in another directory than the
110 * object generated, so don't include the pathname
113 if (s = strrindex(source, '/')) {
119 if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) {
120 fatal("could not open %s", dep_file);
123 assert(p->id_resmac == K_FILE);
124 dependency(p->id_text, source);
132 register struct idf *p = str2idf(s, 0);
134 if (! p->id_resmac) {
135 p->id_resmac = K_FILE;
136 p->id_file = file_head;
141 dependency(s, source)
144 if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
147 if (options['m'] && source) {
148 fprint(dep_fd, "%s: %s\n", source, s);
150 else fprint(dep_fd, "%s\n", s);