ack/util/cpp/main.c

123 lines
2.2 KiB
C
Raw Normal View History

1987-03-10 11:49:39 +00:00
/* $Header$ */
1987-03-09 19:15:41 +00:00
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
1987-01-06 15:16:53 +00:00
/* MAIN PROGRAM */
#include <alloc.h>
#include <em_arith.h>
#include <assert.h>
1987-01-06 15:16:53 +00:00
#include "file_info.h"
#include "idfsize.h"
#include "mkdep.h"
#ifdef MKDEP
#include "idf.h"
#include "macro.h"
#endif
1987-01-06 15:16:53 +00:00
extern char *symbol2str();
1987-01-16 16:14:22 +00:00
extern char *getwdir();
1987-01-06 15:16:53 +00:00
extern int err_occurred;
int idfsize = IDFSIZE;
extern char options[];
1987-01-06 15:16:53 +00:00
arith ifval;
1987-01-06 15:16:53 +00:00
char *prog_name;
extern char **inctable;
extern int inc_max, inc_total;
1987-01-06 15:16:53 +00:00
main(argc, argv)
char *argv[];
{
/* parse and interpret the command line options */
prog_name = argv[0];
init_idf();
inctable = (char **) Malloc(10 * sizeof(char *));
inc_max = 10;
inc_total = 2;
inctable[0] = "";
inctable[1] = "/usr/include";
1987-01-06 15:16:53 +00:00
init_pp(); /* initialise the preprocessor macros */
/* Note: source file "-" indicates that the source is supplied
as standard input. This is only allowed if INP_READ_IN_ONE is
not defined!
*/
while (argc > 1 && *argv[1] == '-' && argv[1][1] != '\0') {
char *par = &argv[1][1];
if (*par == '-')
par++;
do_option(par);
argc--, argv++;
}
#ifdef MKDEP
options['P'] = 1;
#endif
1987-01-06 15:16:53 +00:00
compile(argc - 1, &argv[1]);
exit(err_occurred);
1987-01-06 15:16:53 +00:00
}
compile(argc, argv)
char *argv[];
{
register char *source = 0;
char *dummy;
switch (argc) {
case 1:
source = argv[0];
FileName = source;
break;
case 0:
FileName = "";
1987-03-02 16:43:19 +00:00
WorkingDir = 0;
1987-01-06 15:16:53 +00:00
break;
default:
FileName = argv[0];
1987-01-06 15:16:53 +00:00
fatal("use: %s [options] [source]", prog_name);
break;
}
if (!InsertFile(source, (char **) 0, &dummy)) /* read the source file */
fatal("%s: no source file %s\n", prog_name,
source ? source : "stdin");
1987-03-02 16:43:19 +00:00
if (source) WorkingDir = getwdir(dummy);
1987-01-06 15:16:53 +00:00
preprocess(source);
#ifdef MKDEP
list_files();
#endif
1987-01-06 15:16:53 +00:00
}
#ifdef MKDEP
struct idf *file_head;
list_files()
{
register struct idf *p = file_head;
while (p) {
assert(p->id_resmac == K_FILE);
print("%s\n", p->id_text);
p = p->id_file;
}
}
add_file(s)
char *s;
{
register struct idf *p = str2idf(s, 0);
if (! p->id_resmac) {
p->id_resmac = K_FILE;
p->id_file = file_head;
file_head = p;
}
}
#endif