2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: main.c,v 1.9 1994/06/24 11:37:44 ceriel Exp $ */
14 #include "file_info.h"
19 extern char *symbol2str();
20 extern char *getwdir();
21 extern int err_occurred;
22 extern int do_dependencies;
23 extern char *dep_file;
24 int idfsize = IDFSIZE;
25 extern char options[];
26 static File *dep_fd = STDOUT;
32 extern char **inctable;
33 extern int inc_max, inc_total;
38 /* parse and interpret the command line options */
43 inctable = (char **) Malloc(10 * sizeof(char *));
47 inctable[1] = "/usr/include";
48 inctable[2] = (char *) 0;
49 init_pp(); /* initialise the preprocessor macros */
51 /* Note: source file "-" indicates that the source is supplied
52 as standard input. This is only allowed if INP_READ_IN_ONE is
55 while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') {
56 char *par = &argv[1][1];
63 compile(argc - 1, &argv[1]);
64 sys_stop(err_occurred ? S_EXIT : S_END);
71 register char *source = 0;
85 fatal("use: %s [options] [source]", prog_name);
89 if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */
90 fatal("%s: no source file %s\n", prog_name,
91 source ? source : "stdin");
92 if (source) WorkingDir = getwdir(dummy);
94 if (do_dependencies) list_dependencies(source);
97 struct idf *file_head;
98 extern char *strrindex();
100 list_dependencies(source)
103 register struct idf *p = file_head;
106 register char *s = strrindex(source, '.');
112 /* the source may be in another directory than the
113 * object generated, so don't include the pathname
116 if (s = strrindex(source, '/')) {
122 if (dep_file && !sys_open(dep_file, OP_WRITE, &dep_fd)) {
123 fatal("could not open %s", dep_file);
126 assert(p->id_resmac == K_FILE);
127 dependency(p->id_text, source);
135 register struct idf *p = str2idf(s, 0);
137 if (! p->id_resmac) {
138 p->id_resmac = K_FILE;
139 p->id_file = file_head;
144 dependency(s, source)
147 if (options['i'] && !strncmp(s, "/usr/include/", 13)) {
150 if (options['m'] && source) {
151 fprint(dep_fd, "%s: %s\n", source, s);
153 else fprint(dep_fd, "%s\n", s);
157 No_Mem() /* called by alloc package */
159 fatal("out of memory");