home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 09 / bob / bob.c next >
Text File  |  1991-07-11  |  2KB  |  90 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. #define BANNER    "Bob v1.0 - Copyright (c) 1991, by David Betz"
  12.  
  13. /* global variables */
  14. jmp_buf error_trap;
  15.  
  16. /* external variables */
  17. extern int decode,trace;
  18.  
  19. /* main - the main routine */
  20. main(argc,argv)
  21.   int argc; char *argv[];
  22. {
  23.     char fullname[20];
  24.     int i;
  25.  
  26.     /* display the banner */
  27.     osputs(BANNER);
  28.     osputs("\n");
  29.  
  30.     /* initialize */
  31.     initialize(SMAX,CMAX);
  32.  
  33.     /* load and execute some code */
  34.     for (i = 1; i < argc; ++i)
  35.     if (strcmp(argv[i],"-d") == 0)
  36.         decode = 1;
  37.     else if (strcmp(argv[i],"-t") == 0)
  38.         trace = 1;
  39.     else {
  40.         strcpy(fullname,argv[i]);
  41.         strcat(fullname,".bob");
  42.         compile_file(fullname);
  43.     }
  44.     execute("main");
  45. }
  46.  
  47. /* compile_file - compile definitions in a file */
  48. static compile_file(name)
  49.   char *name;
  50. {
  51.     FILE *ifp;
  52.     if ((ifp = fopen(name,"r")) != NULL) {
  53.     compile_definitions(fgetc,ifp);
  54.     fclose(ifp);
  55.     }
  56. }
  57.  
  58. /* info - display progress information */
  59. info(fmt,a1,a2,a3,a4,a5,a6)
  60.   char *fmt;
  61. {
  62.     char buf1[100],buf2[100];
  63.     sprintf(buf1,fmt,a1,a2,a3,a4,a5,a6);
  64.     sprintf(buf2,"[ %s ]\n",buf1);
  65.     osputs(buf2);
  66. }
  67.  
  68. /* error - print an error message and exit */
  69. error(fmt,a1,a2,a3,a4)
  70.   char *fmt;
  71. {
  72.     char buf1[100],buf2[100];
  73.     sprintf(buf1,fmt,a1,a2,a3,a4);
  74.     sprintf(buf2,"Error: %s\n",buf1);
  75.     osputs(buf2);
  76.     longjmp(error_trap,1);
  77. }
  78.  
  79. osputc(ch)
  80.   int ch;
  81. {
  82.     putc(ch,stdout);
  83. }
  84.  
  85. osputs(str)
  86.   char *str;
  87. {
  88.     fputs(str,stdout);
  89. }
  90.