main.c (1034B)
1 #include <errno.h> 2 #include <stdarg.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include <scc/arg.h> 8 #include <scc/scc.h> 9 #include "cc2.h" 10 #include "error.h" 11 12 char *argv0; 13 int noswtch; 14 15 void 16 error(unsigned nerror, ...) 17 { 18 va_list va; 19 va_start(va, nerror); 20 fputs("cc2:", stderr); 21 vfprintf(stderr, errlist[nerror], va); 22 va_end(va); 23 putc('\n', stderr); 24 exit(1); 25 } 26 27 static int 28 moreinput(void) 29 { 30 int c; 31 32 repeat: 33 if (ferror(stdin)) 34 error(EFERROR, strerror(errno)); 35 if (feof(stdin)) 36 return 0; 37 if ((c = getchar()) == '\n' || c == EOF) 38 goto repeat; 39 ungetc(c, stdin); 40 return 1; 41 } 42 43 static void 44 usage(void) 45 { 46 fputs("usage: cc2 [irfile]\n", stderr); 47 exit(1); 48 } 49 50 int 51 main(int argc, char *argv[]) 52 { 53 ARGBEGIN { 54 case 'd': 55 DBGON(); 56 break; 57 default: 58 usage(); 59 } ARGEND 60 61 if (argv[0] && !freopen(argv[0], "r", stdin)) 62 die("cc2: %s: %s", argv[0], strerror(errno)); 63 64 while (moreinput()) { 65 parse(); 66 if (curfun) { 67 genaddr(); 68 gencfg(); 69 genasm(); 70 peephole(); 71 writeout(); 72 } 73 } 74 return 0; 75 }