home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / advsys.zip / ADVINT.C < prev    next >
Text File  |  1987-06-28  |  2KB  |  89 lines

  1. /* advint.c - an interpreter for adventure games */
  2. /*
  3.     Copyright (c) 1986, by David Michael Betz
  4.     All rights reserved
  5. */
  6.  
  7. #include <setjmp.h>
  8. #include "advint.h"
  9. #include "advdbs.h"
  10.  
  11. #define BANNER \
  12. "ADVINT v1.2a - Copyright (c) 1987, by David Betz"
  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 dname[50],lname[50];
  29.     int rows,cols;
  30.  
  31.     /* initialize */
  32.     advinit(BANNER,argc,argv,dname,lname,&rows,&cols);
  33.  
  34.     /* initialize terminal i/o */
  35.     trm_init(rows,cols,lname[0] ? lname : NULL);
  36.  
  37.     /* initialize the database */
  38.     db_init(dname);
  39.  
  40.     /* play the game */
  41.     play();
  42. }
  43.  
  44. /* play - the main loop */
  45. play()
  46. {
  47.     /* establish the restart point */
  48.     setjmp(restart);
  49.  
  50.     /* execute the initialization code */
  51.     execute(h_init);
  52.  
  53.     /* turn handling loop */
  54.     for (;;) {
  55.  
  56.     /* execute the update code */
  57.     execute(h_update);
  58.  
  59.     /* parse the next input command */
  60.     if (parse()) {
  61.         if (single())
  62.         while (next() && single())
  63.             ;
  64.     }
  65.  
  66.     /* parse error, call the error handling code */
  67.     else
  68.         execute(h_error);
  69.     }
  70. }
  71.  
  72. /* single - handle a single action */
  73. int single()
  74. {
  75.     /* execute the before code */
  76.     switch (execute(h_before)) {
  77.     case ABORT:    /* before handler aborted sequence */
  78.     return (FALSE);
  79.     case CHAIN:    /* execute the action handler */
  80.     if (execute(getafield(getvalue(V_ACTION),A_CODE)) == ABORT)
  81.         return (FALSE);
  82.     case FINISH:/* execute the after code */
  83.     if (execute(h_after) == ABORT)
  84.         return (FALSE);
  85.     break;
  86.     }
  87.     return (TRUE);
  88. }
  89.