home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 159_01 / advent.c < prev    next >
C/C++ Source or Header  |  1990-06-01  |  4KB  |  172 lines

  1.  
  2. /*  program ADVENT.C    modified by LCC for V 1.43 by:
  3.         altering buffer sizes
  4.   
  5.         Changed call of exec() to static call for Eco-C88 (BW)
  6.         Added function initw() for Eco-C88                (BW)
  7.     Made function init() static for Eco-C88       (BW)
  8.  
  9. May 1990 - Bob Withers
  10.     - Ported code to Microsoft C V 5.10 and 6.00
  11.     - Placed all global variables in header ADVENT.H
  12.     - Removed most runtime variable initialization and replaced
  13.       by compile time initializers.
  14.     - Added file ADVENTDB.C to completely replace all the adventure
  15.       data base files.  This keeps all data in memory and eliminates
  16.       all disk accesses during game play.  All functions in DATABASE.C
  17.       were modified to access in memory data.
  18.     - Added code to support the BRIEF and VERBOSE verbs.
  19.     - Added code to ignore CTRL-C signal.
  20.     - Modified vocab search to use a binary search.
  21. */
  22.  
  23. #define DRIVER
  24.  
  25. #include "advent.h"
  26. #include <conio.h>
  27. #include <signal.h>
  28.  
  29. static VOID    NEAR PASCAL init(VOID);
  30. static VOID    NEAR PASCAL eadvent(VOID);
  31.  
  32.  
  33. int main(int argc, char **argv)
  34. {
  35.     auto     SHORT    rflag;        /* user restore request option */
  36.     auto     SHORT    dflag;        /* user restore request option */
  37.  
  38.     brief_sw = dbgflg = rflag = 0;
  39.     signal(SIGINT, SIG_IGN);
  40.  
  41.     while (--argc > 0)
  42.     {
  43.     if ((argv[argc])[0] == '-' || (argv[argc])[0] == '/')
  44.     {
  45.         switch (tolower((argv[argc])[1]))
  46.         {
  47.         case 'r':
  48.             ++rflag;
  49.             continue;
  50.         case 'd':
  51.             ++dbgflg;
  52.             printf("Debug enabled.\n");
  53.             continue;
  54.         case 'b':
  55.             ++brief_sw;
  56.             printf("Brief mode enabled.\n");
  57.             continue;
  58.         default:
  59.             printf("unknown flag: %c\n", (argv[argc])[1]);
  60.             continue;
  61.         }
  62.     }
  63.     }
  64.  
  65.     dflag = dbgflg;
  66.     init();
  67.  
  68.     if (!rflag)
  69.     {
  70.     printf("\nDo you want to restore a saved game? (Y/N) ");
  71.     do
  72.     {
  73.         rflag = getch();
  74.         rflag = toupper(rflag);
  75.     } while (!(rflag == 'Y' || rflag == 'N'));
  76.     putchar(rflag);
  77.     putchar('\n');
  78.     if (rflag == 'N')
  79.         rflag = 0;
  80.     }
  81.  
  82.     if (rflag)
  83.     restore();
  84.  
  85.     dbgflg = dflag;
  86.     eadvent();
  87.     return(0);
  88. }
  89.  
  90. /*  Initialization                            */
  91.  
  92. static VOID NEAR PASCAL init(VOID)
  93. {
  94.     dloc[DWARFMAX - 1] = chloc;
  95.     return;
  96. }
  97.  
  98. /*  restore saved game handler    */
  99.  
  100. VOID PASCAL restore(VOID)
  101. {
  102.     auto     char    username[14];
  103.     auto     FILE      *restfd;
  104.     auto     SHORT    c, cnt;
  105.     auto     char      *sptr;
  106.  
  107.     printf("What is your saved game name? ");
  108.     scanf("%8s", username);
  109.     for (sptr = username; *sptr; sptr++)
  110.     {
  111.         *sptr = (char) toupper(*sptr);
  112.     if ((!isprint(*sptr)) || *sptr == ' ')
  113.     {
  114.         *sptr = '\0';
  115.         break;
  116.     }
  117.     }
  118.  
  119.     if (strlen(username) == 0)
  120.     {
  121.     printf("\nNo name entered, restore request ignored.\n");
  122.     return;
  123.     }
  124.  
  125.     strcat(username, ".ADV");
  126.     printf("\nOpening save file \"%s\".\n", username);
  127.     if ((restfd = fopen(username, READ_BIN)) == 0)
  128.     {
  129.     printf("sorry, can't open save file...\n");
  130.     exit(1);
  131.     }
  132.     cnt = 0;
  133.     for (sptr = (char *) &turns; sptr < (char *) &lastglob; sptr++)
  134.     {
  135.     if ((c = getc(restfd)) == -1)
  136.     {
  137.         printf("Can't read save file...\n");
  138.         if (dbgflg)
  139.         printf("%d characters read\n", cnt);
  140.         fclose(restfd);
  141.         exit(1);
  142.     }
  143.     *sptr = (char) c;
  144.     cnt++;
  145.     }
  146.  
  147.     if (fclose(restfd) == -1)
  148.     printf("warning -- can't close save file...\n");
  149.  
  150.     printf("\n");
  151.     saveflg = 0;
  152.  
  153.     return;
  154. }
  155.  
  156.  
  157. static VOID NEAR PASCAL eadvent(VOID)
  158. {
  159.     srand(511);
  160.     if (yes(65, 1, 0))
  161.     limit = 1000;
  162.     else
  163.     limit = 330;
  164.  
  165.     while (!saveflg)
  166.     turn();
  167.  
  168.     if (saveflg)
  169.     saveadv();
  170.     return;
  171. }
  172.