Pristine Ack-5.5
[Ack-5.5.git] / util / topgen / main.c
1 /* $Id: main.c,v 1.5 1994/06/24 10:42:10 ceriel Exp $ */
2 /*
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".
5  */
6 /* m a i n . c
7  *
8  * Contains the main program, the error reporting routine, and a routine
9  * to check wether a constraint consists only of space
10  */
11 # include <stdio.h>
12
13 extern int lineno, newline;
14
15 FILE *genc, *genh, *input;
16 static int nerrors;
17 char *linedir = "#line %d \"%s\"\n";    /* format of line directive */
18 char *inpfile;
19
20 main(argc,argv) char *argv[]; {
21
22     newline = 1;
23     if (argc != 2) {
24         fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]);
25         exit(1);
26     }
27     if ((input = fopen(argv[1],"r")) == NULL) {
28         fprintf(stderr,"Fatal error : couldn't open %s\n",argv[1]);
29         exit(1);
30     }
31     if ((genc = fopen("gen.c","w")) == NULL) {
32         fputs("Fatal error : couldn't open gen.c\n",stderr);
33         exit(1);
34     }
35     if ((genh = fopen("gen.h","w")) == NULL) {
36         fputs("Fatal error : couldn't open gen.h\n",stderr);
37         exit(1);
38     }
39     inpfile = argv[1];          /* needed for line directives and errors */
40     LLparse();
41     exit(nerrors);
42 }
43
44 /* VARARGS1 */
45 error(s, s1) char *s, *s1; {
46     
47     nerrors++;
48     fprintf(stderr,"\"%s\", line %d: ",inpfile,lineno);
49     fprintf(stderr,s,s1);
50     putc('\n',stderr);
51 }
52
53 onlyspace(s) register char *s; {
54     
55     while (*s) {
56         if (*s != ' ' && *s != '\t' && *s != '\n') return 0;
57         s++;
58     }
59     return 1;
60 }