home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gapcdrv6.zip / CDOOR.ZIP / CDOOR.C < prev    next >
C/C++ Source or Header  |  1992-02-21  |  14KB  |  339 lines

  1. /*
  2.     Copyright (C) 1989-1992 The GAP Development Company
  3.  
  4.     All Rights Reserved
  5.  
  6.  
  7.     CDOOR.C
  8.  
  9.     Demonstration program for GAPCDR
  10.  
  11.  
  12.     Microsoft
  13.  
  14.     To compile : cl /c cdoor.c
  15.     To link    : link cdoor,,NUL.MAP,+gapcdrs
  16.  
  17.     ----------------------------------------------------------
  18.  
  19.     Borland
  20.  
  21.     With Borland, YOU have to tell it which of its OWN
  22.     OBJ and LIB files to link in. It isn't smart enough to
  23.     KNOW which ones are required.
  24.  
  25.     Be sure that C0S.OBJ is linked first and that you NAME
  26.     the EXE file (otherwise it will be named C0S.EXE.
  27.  
  28.     To compile : bcc -ms -O -Z -d -c cdoor.c
  29.     To link    : tlink c0s+cdoor,cdoor.exe,NUL.MAP,+gapcdrbs+cs
  30.  
  31.  
  32.     Program will need access to CDOOR.CNF and DOOR.SYS
  33.  
  34. /*
  35.  
  36.  
  37. #define LINT_ARGS
  38.  
  39. #pragma check_stack(off)                  // we dont need stack checking
  40.                                           // IMPORTANT !!
  41. #pragma pack(1)                           // All structures must be packed
  42.                                           // IMPORTANT !!
  43.  
  44.  
  45.    /***********************************************************************/
  46.    /*  Before doing ANYTHING else, include the following files.           */
  47.    /***********************************************************************/
  48.  
  49. #include <stdio.h>                        // C standard header file
  50. #include <dos.h>
  51. #include <stdlib.h>
  52. #include <string.h>
  53.  
  54. #include "compiler.h"                     // defines compiler being used
  55. #include "gapcdr.h"                       // header file for GAPCDR
  56.  
  57.  
  58.    /***********************************************************************/
  59.    /*  Declare any global variables                                       */
  60.    /***********************************************************************/
  61.  
  62.    char anystring1 [250];                 // global garbage collector
  63.  
  64.    // We are placing our Menu inside the program.
  65.    // It can just as easily be a file that we would display.
  66.    // Notice that the Menu contains embedded ANSI codes.
  67.    // Also notice that we don't have a non-color version of the Menu.
  68.    // This is because if the caller is in mono mode, GAPCDR will filter
  69.    // the ANSI codes. It is important to realize that if you have ONLY
  70.    // a color version of a Menu or Display file, that the Menu contain
  71.    // ONLY ANSI color sequences. It cannot contain any other ANSI 
  72.    // sequences such as cursor movement commands. Notice that our
  73.    // Menu uses actual 'spaces' and no cursor sequences. If the Menu
  74.    // contained cursor movement commands and the caller is in non-color
  75.    // mode, the ANSI driver will remove the ANSI sequences (which includes
  76.    // the cursor movement commands) and the screen will not display
  77.    // correctly.
  78.  
  79.    char *menug [] =
  80.       {
  81.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  82.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  83.       "          ▒▒▒▒▒▒▒▒│              Main Menu               │▒▒▒▒▒▒▒▒▒▒",
  84.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  85.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  86.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  87.       "          ▒▒▒▒▒▒▒▒┌──────────────────────────────────────┐▒▒▒▒▒▒▒▒▒▒",
  88.       "          ▒▒▒▒▒▒▒▒│  [C]olor               [T]op Scores  ▒▒▒▒▒▒▒▒▒▒",
  89.       "          ▒▒▒▒▒▒▒▒│  [D]os Window          [S]how File   ▒▒▒▒▒▒▒▒▒▒",
  90.       "          ▒▒▒▒▒▒▒▒│  [X]code Example       [A]NSICMD's   ▒▒▒▒▒▒▒▒▒▒",
  91.       "          ▒▒▒▒▒▒▒▒│  [P]age Sysop          [Q]uit        ▒▒▒▒▒▒▒▒▒▒",
  92.       "          ▒▒▒▒▒▒▒▒└──────────────────────────────────────┘▒▒▒▒▒▒▒▒▒▒",
  93.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  94.       "          ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒",
  95.       "\0"
  96.       };
  97.  
  98.  
  99.    // declare functions
  100.  
  101.    static void _pascal _near dos_window(short how);
  102.  
  103.  
  104.  
  105.    /***********************************************************************/
  106.    /*  Begin main line code here                                          */
  107.    /***********************************************************************/
  108.  
  109. void main(void)
  110. {
  111.    short oldbell;                         // status of page bell flag
  112.    char **menu;                           // pointer to menu arrays
  113.    char response [80];                    // for getting responses
  114.    char prompt   [80];                    // for the prompt line
  115.  
  116.    FILE *doorcnf;                         // file pointer for cnf file
  117.  
  118.    // remember screen attributes for the DOS Window
  119.  
  120.    get_attr();                            // remember screen attribs
  121.  
  122.  
  123.    /***********************************************************************/
  124.    /*  Before doing ANYTHING else, initialize the door with the following */
  125.    /*  two function calls.                                                */
  126.    /*  Then, if you have any configuration options, read them in and then */
  127.    /*  close the file.                                                    */
  128.    /*  Note that we are hardcoding the name of the configuration file.    */
  129.    /*  Normally, this is passed as a command line parameter so you would  */
  130.    /*  call read_cnf like this :  doorcnf = read_cnf(argv[1]);            */
  131.    /***********************************************************************/
  132.  
  133.    doorcnf = read_cnf("CDOOR.CNF");       // read door configuration file
  134.    init_door();                           // initialize the door
  135.  
  136.    fclose(doorcnf);                       // we dont have any configuration
  137.                                           // options so we will just close
  138.  
  139.  
  140.    /***********************************************************************/
  141.    /*  Lets now build some menus all at once.                             */
  142.    /*  These menus were created with an ANSI editor.  This is perhaps the */
  143.    /*  fastest and easiest way to create menus.                           */
  144.    /***********************************************************************/
  145.  
  146.    do
  147.       {
  148.       // Format the prompt
  149.  
  150.       time_left();                        // get # of mins left
  151.  
  152.       sprintf(prompt,"\r\n%s[%s%d mins%s] Main Command : ",A_YELLOW,
  153.               A_BRED,timeleft,A_YELLOW);
  154.  
  155.       clear_scrn();                       // first clear the screen
  156.  
  157.       nl(2);                              // do a couple of blank lines
  158.  
  159.       menu = menug;                       // set pointer to our menu
  160.  
  161.       while (**menu)                      // now show the menu
  162.          show_mess(*menu++,NO,YES);
  163.  
  164.       show_mess(prompt,NO,NO);            // show the prompt
  165.  
  166.       empty(response,1);                  // initialize response
  167.       get_string(response);               // get user input
  168.  
  169.       switch (response[0])
  170.          {
  171.          case 'C' :                       // toggle color
  172.             if (color)                    // if in color already
  173.                color = 0;                 // turn color flag off
  174.             else                          // otherwise
  175.                color = 1;                 // turn it on
  176.  
  177.             fix_color();                  // tell ANSI driver what we did
  178.             break;
  179.  
  180.          case 'D' :                       // DOS Window
  181.             // show message on local screen so they know how to get
  182.             // back to program
  183.  
  184.             nl(1);
  185.             lputs(A_BWHITE);
  186.             lputs("                      Type 'Exit' to return to program");
  187.  
  188.             dos_window(0);                // make a DOS window
  189.             system("COMMAND");            // shell to DOS
  190.             dos_window(1);                // remove the DOS window
  191.             break;
  192.  
  193.          case 'P' :                       // page the sysop
  194.             oldbell = bell;               // remember original setting
  195.             bell = 1;                     // turn page bell on
  196.             pagesysop();                  // go page the sysop
  197.             bell = oldbell;               // restore setting
  198.             break;
  199.  
  200.          case 'T' :                       // show the scoreboard
  201.             read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  202.             
  203.             // add name to score board file
  204.  
  205.             strcpy(response,username);    // remember user name
  206.  
  207.             ansi(A_YELLOW);               // set a color
  208.  
  209.             show_mess("Please Enter Your Name : ", NO,NO);
  210.  
  211.             empty(username,30);           // initialize string
  212.             get_string(username);         // go get a name
  213.  
  214.             if (username[0] != 0)         // if name was entered
  215.                {
  216.                write_score("CDOOR.DAT",20220L);   // write the score
  217.  
  218.                ansi(A_BWHITE);            // set a color
  219.                nl(1);
  220.                show_mess("You are now a Top 10 Player!",NO,YES);
  221.                nl(1);
  222.                pause();
  223.                read_score("CDOOR.DAT","Top 10 Players Of Our Example Door");
  224.                }
  225.  
  226.             strcpy(username,response);    // restore name
  227.  
  228.             break;
  229.  
  230.          case 'A' :
  231.             clear_scrn();                 // clear local and remote screens
  232.             show_file("ANSICMD");         // pass base part of filename
  233.             pause();                      // make sure they've seen it
  234.             break;
  235.  
  236.          case 'X' :
  237.             clear_scrn();                 // clear local and remote screens
  238.             show_file("XCODES");          // pass base part of filename
  239.             pause();                      // make sure they've seen it
  240.             break;
  241.  
  242.          case 'S' :                       // show file
  243.             show_file("WELCOME");         // pass base part of filename
  244.             pause();                      // make sure they've seen it
  245.             break;
  246.  
  247.          case 'Q' :                       // quit
  248.             break;
  249.          }
  250.       }
  251.    while (response[0] != 'Q');
  252.  
  253.    leave(0);                              // must exit properly!
  254. }
  255.  
  256.    // makes or removes a DOS Window
  257.    // 0 = make window
  258.    // 1 = remove window
  259.  
  260.    // Our DOS window is 14 rows by 64 columns (including border) - 1792 bytes
  261.  
  262.    // NOTE: The program can NOT, under any circumstance, exit or abort 
  263.    // while the DOS window is being displayed. If it does, the computer
  264.    // will crash. This means that while the window is up, there can be
  265.    // NO input or output using GAPCDR since if carrier is dropped, GAPCDR
  266.    // will shut down, and the BIOS trap will still be operating. The end
  267.    // result is a locked up computer the next time a program is run
  268.  
  269.  
  270.    static unsigned short near dseg = 0;   // DOS stores segment address here
  271.  
  272.    static char near border [] =
  273.       {
  274.       "──────────────────────────────────────────────────────────────"
  275.       };
  276.  
  277.  
  278. static void _pascal _near dos_window(short how)
  279. {
  280.    short r;
  281.  
  282.    if (!how)                              // set up the screen
  283.       {
  284.       // # of bytes to allocate is 
  285.       // (((cols * 2) * rows) / 16) + 2 (for good measure)
  286.  
  287. #ifdef TC
  288.       if (allocmem(114,&dseg) != -1)      // get memory to hold screen
  289. #else
  290.       if (_dos_allocmem(114,&dseg) != 0)  // get memory to hold screen
  291. #endif
  292.          {                                // can't
  293.          dseg = 0;                        // NULL out pointer
  294.          return;                          // return now
  295.          }
  296.  
  297.       lputs("s");                       // remember cursor position for ANSI
  298.       save_screen(3,8,16,71,dseg);        // save underlying window
  299.       normal = 15;                        // Bright White border
  300.  
  301.       crscur = 0x0308;                    // cursor to row 3, column 8
  302.       sprintf(anystring1,"┌%s┐",border);
  303.       lputs(anystring1);                  // show top border
  304.  
  305.       for (r = 4; r < 17; r++)            // display sides of window
  306.          {
  307.          crscur = 0x0008 + (256 * r);     // next line
  308.          lputc('│');                      // left side
  309.          crscur += 62;                    // position cursor
  310.          lputc('│');                      // right side
  311.          }
  312.  
  313.       crscur = 0x1008;                    // cursor to row 16, column 8
  314.       sprintf(anystring1,"└%s┘",border);
  315.       lputs(anystring1);                  // show top border
  316.  
  317.       // set up the BIOS trap so that the cursor stays inside of the
  318.       // window
  319.  
  320.       set_int10();                        // set up BIOS handler
  321.       set_cord(4,9,15,70);                // set window co-ordinates (inside dimensions)
  322.       set_attr(14,1);                     // set window attributes (yellow on blue)
  323.       cls_all();                          // clear the window
  324.       }
  325.    else if (how && dseg != 0)             // remove the screen
  326.       {
  327.       rest_int10();                       // reset BIOS handler
  328.  
  329.       restore_screen(3,8,16,71,dseg);     // restore underlying window
  330. #ifdef TC
  331.       freemem(dseg);                      // free memory
  332. #else
  333.       _dos_freemem(dseg);                 // free memory
  334. #endif
  335.       dseg = 0;                           // NULL out pointer
  336.       lputs("u");                       // restore cursor
  337.       }
  338. }
  339.