home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume2 / advsys / part03 / advint.c < prev    next >
C/C++ Source or Header  |  1987-10-23  |  2KB  |  134 lines

  1.  
  2. /* advint.c - an interpreter for adventure games */
  3. /*
  4.     Copyright (c) 1986, by David Michael Betz
  5.     All rights reserved
  6. */
  7.  
  8. #include "advint.h"
  9. #include "advdbs.h"
  10. #ifndef MAC
  11. #include <setjmp.h>
  12. #endif
  13.  
  14. /* global variables */
  15. jmp_buf restart;
  16.  
  17. /* external variables */
  18. extern int h_init;
  19. extern int h_update;
  20. extern int h_before;
  21. extern int h_after;
  22. extern int h_error;
  23.  
  24. /* main - the main routine */
  25. main(argc,argv)
  26.   int argc; char *argv[];
  27. {
  28.     char *fname,*lname;
  29.     int rows,cols,i;
  30.  
  31. #ifdef MAC
  32.     char name[50];
  33.     macinit(name);
  34.     fname = name;
  35.     lname = NULL;
  36.     rows = 20;
  37.     cols = 80;
  38. #else
  39.     printf("ADVINT v1.2 - Copyright (c) 1986, by David Betz\n");
  40.     fname = NULL;
  41.     lname = NULL;
  42.     rows = 24;
  43.     cols = 80;
  44.  
  45.     /* parse the command line */
  46.     for (i = 1; i < argc; i++)
  47.     if (argv[i][0] == '-')
  48.         switch (argv[i][1]) {
  49.         case 'r':
  50.         case 'R':
  51.             rows = atoi(&argv[i][2]);
  52.             break;
  53.         case 'c':
  54.         case 'C':
  55.             cols = atoi(&argv[i][2]);
  56.             break;
  57.         case 'l':
  58.         case 'L':
  59.             lname = &argv[i][2];
  60.                 break;
  61.         }
  62.     else
  63.         fname = argv[i];
  64.     if (fname == NULL) {
  65.     printf("usage: advint [-r<rows>] [-c<columns>] [-l<log-file>] <file>\n");
  66.     exit();
  67.     }
  68. #endif
  69.  
  70.     /* initialize terminal i/o */
  71.     trm_init(rows,cols,lname);
  72.  
  73.     /* initialize the database */
  74.     db_init(fname);
  75.  
  76.     /* play the game */
  77.     play();
  78. }
  79.  
  80. /* play - the main loop */
  81. play()
  82. {
  83.     /* establish the restart point */
  84.     setjmp(restart);
  85.  
  86.     /* execute the initialization code */
  87.     execute(h_init);
  88.  
  89.     /* turn handling loop */
  90.     for (;;) {
  91.  
  92.     /* execute the update code */
  93.     execute(h_update);
  94.  
  95.     /* parse the next input command */
  96.     if (parse()) {
  97.         if (single())
  98.         while (next() && single())
  99.             ;
  100.     }
  101.  
  102.     /* parse error, call the error handling code */
  103.     else
  104.         execute(h_error);
  105.     }
  106. }
  107.  
  108. /* single - handle a single action */
  109. int single()
  110. {
  111.     /* execute the before code */
  112.     switch (execute(h_before)) {
  113.     case ABORT:    /* before handler aborted sequence */
  114.     return (FALSE);
  115.     case CHAIN:    /* execute the action handler */
  116.     if (execute(getafield(getvalue(V_ACTION),A_CODE)) == ABORT)
  117.         return (FALSE);
  118.     case FINISH:/* execute the after code */
  119.     if (execute(h_after) == ABORT)
  120.         return (FALSE);
  121.     break;
  122.     }
  123.     return (TRUE);
  124. }
  125.  
  126. /* error - print an error message and exit */
  127. error(msg)
  128.   char *msg;
  129. {
  130.     trm_str(msg);
  131.     trm_chr('\n');
  132.     exit();
  133. }
  134.