main.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* $Id$ */
  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 <stdlib.h>
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. extern int lineno, newline;
  15. FILE *genc, *genh, *input;
  16. static int nerrors;
  17. char *linedir = "#line %d \"%s\"\n"; /* format of line directive */
  18. char *inpfile;
  19. /* From Lexer */
  20. void LLparse(void);
  21. int main(int argc, char *argv[])
  22. {
  23. newline = 1;
  24. if (argc != 2) {
  25. fprintf(stderr,"Usage : %s targetoptimizerdescription\n",argv[0]);
  26. exit(1);
  27. }
  28. if ((input = fopen(argv[1],"r")) == NULL) {
  29. fprintf(stderr,"Fatal error : couldn't open %s\n",argv[1]);
  30. exit(1);
  31. }
  32. if ((genc = fopen("gen.c","w")) == NULL) {
  33. fputs("Fatal error : couldn't open gen.c\n",stderr);
  34. exit(1);
  35. }
  36. if ((genh = fopen("gen.h","w")) == NULL) {
  37. fputs("Fatal error : couldn't open gen.h\n",stderr);
  38. exit(1);
  39. }
  40. inpfile = argv[1]; /* needed for line directives and errors */
  41. LLparse();
  42. exit(nerrors);
  43. }
  44. /* VARARGS1 */
  45. void error(char *s, ...)
  46. {
  47. va_list va;
  48. nerrors++;
  49. fprintf(stderr,"\"%s\", line %d: ",inpfile,lineno);
  50. va_start(va, s);
  51. vfprintf(stderr, s, va);
  52. va_end(va);
  53. putc('\n',stderr);
  54. }
  55. int onlyspace(char *s)
  56. {
  57. while (*s) {
  58. if (*s != ' ' && *s != '\t' && *s != '\n') return 0;
  59. s++;
  60. }
  61. return 1;
  62. }