home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / bob13st / bob.c next >
C/C++ Source or Header  |  1991-12-24  |  2KB  |  108 lines

  1. /* bob.c - the main routine */
  2. /*
  3.     Copyright (c) 1991, by David Michael Betz
  4.     All rights reserved
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <setjmp.h>
  9. #include "bob.h"
  10.  
  11. /* Revision history
  12.  
  13.     1.0        08/15/91    Initial version for DDJ article
  14.     1.1        08/20/91    Fixed do_for to allow null statements
  15.     1.2        08/28/91    Fixed problem with newobject()
  16.     1.3        09/27/91    Fixed a bug in compact_vector()
  17.     1.3ST    12/25/91    Ported to Mark Williams C for Atari ST
  18.                         Added external reference for fgetc
  19. */
  20.  
  21. #define BANNER    "Bob v1.3ST - Copyright (c) 1991, by David Betz\n             Atari ST 1991, by Peter Ismen"
  22.  
  23. /* global variables */
  24. jmp_buf      error_trap;
  25. char    **bobargv;
  26. int          bobargc;
  27.  
  28. /* external variables */
  29. extern int decode,trace;
  30. extern  FILE fgetc();
  31.  
  32. /* main - the main routine */
  33. main(argc,argv)
  34. int   argc;
  35. char *argv[];
  36. {
  37.     char fullname[20];
  38.     int i;
  39.  
  40.     osputs(BANNER);                         /* display the banner */
  41.     osputs("\n");
  42.  
  43.     initialize(SMAX,CMAX);                 /* initialize */
  44.     bobargc = argc - 1;
  45.     bobargv = argv + 1;
  46.  
  47.     for (i = 1; i < argc; ++i)             /* load and execute some code */
  48.     {
  49.         if (strcmp(argv[i],"-d") == 0)
  50.             decode = 1;
  51.         else
  52.         {
  53.             if (strcmp(argv[i],"-t") == 0)
  54.                 trace = 1;
  55.             else 
  56.             {
  57.                 strcpy(fullname,argv[i]);
  58.                 strcat(fullname,".bob");
  59.                 compile_file(fullname);
  60.             }
  61.         }    
  62.     }        
  63.     if (!execute("main"))
  64.         printf("Can't execute 'main'\n");
  65. }
  66.  
  67. /* compile_file - compile definitions in a file */
  68. static compile_file(name)
  69. char *name;
  70. {
  71.     FILE *ifp;
  72.     
  73.     if ((ifp = fopen(name,"r")) != NULL) 
  74.     {
  75.         compile_definitions(fgetc,ifp);
  76.         fclose(ifp);
  77.     }
  78. }
  79.  
  80. /* info - display progress information */
  81. info(fmt,a1,a2,a3,a4,a5,a6)
  82. char *fmt;
  83. {
  84.     char buf1[100],buf2[100];
  85.     
  86.     sprintf(buf1,fmt,a1,a2,a3,a4,a5,a6);
  87.     sprintf(buf2,"[ %s ]\n",buf1);
  88.     osputs(buf2);
  89. }
  90.  
  91. /* error - print an error message and exit */
  92. error(fmt,a1,a2,a3,a4)
  93. char *fmt;
  94. {
  95.     char buf1[100],buf2[100];
  96.     
  97.     sprintf(buf1,fmt,a1,a2,a3,a4);
  98.     sprintf(buf2,"Error: %s\n",buf1);
  99.     osputs(buf2);
  100.     longjmp(error_trap,1);
  101. }
  102.  
  103. osputs(str)
  104. char *str;
  105. {
  106.     fputs(str,stderr);
  107. }
  108.