home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / ckit176c / ckitdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-06  |  19.0 KB  |  527 lines

  1. #include    "ckit.h"             /* Include CKIT Header file!      */
  2. #include    "ckitdemo.h"         /* Include file for demo          */
  3. #pragma check_stack (off)
  4.  
  5.  
  6. /******************************************************************************
  7.  *                     Start of Main Program                                  *
  8.  *****************************************************************************/
  9. /* The main function MUST be prototyped as below using C's argc and
  10.  * argv array in your door program for use with CKIT.LIB.
  11.  */
  12.  
  13. main(int argc, char **argv) {     /* MUST HAVE MAIN PROTOTYPED AS SHOWN!  */
  14.  
  15. /******************************************************************************
  16. *                        USER adjustments                                     *
  17. * You will need to set these according to how you want CKIT to handle certain *
  18. * options.  See the CKIT.DOC for more information                             *
  19. * Also see CKITDEMO.H for program name                                        *
  20. *******************************************************************************/
  21.     FORCEOFFHOOK = TRUE;  /* Force modem off-hook on dropped carrier          */
  22.     USERSFILE = FALSE;    /* optional, set to TRUE if user file info desired  */
  23.  
  24.     if (argc > 0) {
  25.         debug_on();
  26.         logoff_color = (green);       /* Logoff message equals green          */
  27.         strcpy(logoff_msg, "Returning to system, Please wait...");
  28.  
  29.                                       /* The 1st arg. must be the system file. */
  30.                                       /* If you do want user file info for     */
  31.                                       /* your door, you should set             */
  32.                                       /* the USERSFILE=TRUE, and pass the      */
  33.                                       /* users path\name as argv[2] to open_   */
  34.                                       /* door. i.e open_door(argv[1],argv[2]); */
  35.         open_door(argv[1], argv[2]);  /* The portnumber could be any argument  */
  36.                                       /* except the first argv[1], (must be    */
  37.                                       /* the system file), the second arg[2]   */
  38.                                       /* could be the users file or port       */
  39.                                       /* change, or the third argument would   */
  40.                                       /* be a port change if the users file    */
  41.                                       /* was needed to be opened.              */
  42.  /*  Below is some examples of how your program would/could be called up       */
  43.  /*  and how the open_door() function would be called.  Notice PORT is always  */
  44.  /*  the second or third (last) argument to be passed if a user of your door   */
  45.  /*  program wanted to use it.                                                 */
  46.  /*  Note also it does not matter which order on the cmd line the arguments    */
  47.  /*  are listed. The only thing that matters is which order they are passed    */
  48.  /*  to the open_door() function itself.                                       */
  49.  
  50.  /* ckitdemo PORT:03F8:4 c:\pcb\pcboard.sys d:\main\users                      */
  51.  /* open_door(argv[2], argv[3], argv[1]);                                      */
  52.  
  53.  /* ckitdemo pcboard.sys port03F8:04                                           */
  54.  /* open_door(argv[1], argv[2];                                                */
  55.  
  56.  /* ckitdemo door.cfg pcboard.sys                                              */
  57.  /* open_door(argv[2]);                                                        */
  58.  
  59.  /* ckitdemo pcboard.sys users                                                 */
  60.  /* open_door(argv[1], argv[2];                                                */
  61.  
  62.  /* Passing a config file for your door as the second arg. and some other      */
  63.  /* parameter as the 3rd parameter on the cmd line and port as 4th             */
  64.  
  65.  /* ckitdemo pcboard.sys door.cfg door.inf PORT:03F8:4                         */
  66.  /* open_door(argv[1], argv[4];                                                */
  67.  
  68.         display_info();               /* Display user information  */
  69.         errmsg_ptr = &error_msg11[0]; /* File error msg pointer  */
  70.         menu();                       /* Main program loop         */
  71.         close_door();                 /* Close file, reset vectors */
  72.         exit(0);                      /* Back to DOS               */
  73.     }
  74.  }
  75. /******************************************************************************
  76. *                       End of Main Program                                   *
  77. ******************************************************************************/
  78.  
  79. /******************************************************************************
  80. *                       Main Menu                                             *
  81. ******************************************************************************/
  82. void    menu(void) {
  83.  
  84.     newline();
  85.     if(display_file("ckit.m")) {   /* If error display_file() return NON_ZERO */
  86.         newline();
  87.     }
  88.     force_enter();
  89.     /* main command loop */
  90.     while(DUMP_USER != TRUE) {
  91.           /* prompt for input only if there is not a stacked command pending */
  92.         if ( strlen(cmdline) == 0) {
  93.             color(white);
  94.             newline();
  95.             s_puts("Main menu:\r\n");
  96.             color(red);
  97.             s_puts(" (I)  Display system information\r\n");
  98.             color(green);
  99.             s_puts(" (C)  Take a chance for more time online\r\n");
  100.             color(magenta);
  101.             s_puts(" (T)  Display a test pattern\r\n");
  102.             color(cyan);
  103.             s_puts(" (A)  Ansi graphics demo\r\n");
  104.             color(violet);
  105.             s_puts(" (D)  Display information on CKIT\r\n");
  106.             color(green);
  107.             s_puts(" (F)  Download CKIT.DOC using Zmodem \r\n");
  108.             color(yellow);
  109.             s_puts(" (M)  Graphics Mode On/Off \r\n");
  110.             color(red);
  111.             s_puts(" (Q)  Return to PCBoard\r\n");
  112.             color(green);
  113.             s_puts(" (G)  Logoff  (Disconnect)\r\n");
  114.             color(cyan);
  115.             s_puts("\r\n\
  116. While you are sitting here at the command line. Press some extended key\
  117. board \r\nkeys. If you are on the remote end using Qmodem, go into the DOORWAY\r\n\
  118. mode. Remember this is just a demo/usage for scan_code, so it's nothing \
  119. fancy.\r\n");
  120.             color(yellow);
  121.             do {
  122.                 newline();
  123.                 display_time();
  124.                 color(green);
  125.                 s_puts("Command? ");
  126.                 get_cmdline();          /* read input into 'cmdline'  */
  127.  
  128.             } while((DUMP_USER != TRUE) && (strlen(cmdline) == 0) && (scan_code == 0));
  129.         }
  130.         if (DUMP_USER == TRUE) {
  131.             close_door();
  132.             exit(1);
  133.         }
  134.         if (scan_code != 0) {
  135.             color(white);
  136.             read_scancode();
  137.             newline();
  138.         }
  139.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  140.             newline();
  141.       /* process commands */
  142.             switch ( par[0] ) {
  143.                 case 'A':
  144.                 ansi_demo();
  145.                 break;
  146.                 case 'C':
  147.                 take_chance();
  148.                 break;
  149.                 case 'I':
  150.                 display_info();
  151.                 break;
  152.                 case 'T':
  153.                 test_pattern();
  154.                 break;
  155.                 case 'D':
  156.                 color(cyan);
  157.                 strcpy(error_msg11, "\a\nUnable to locate CKIT.DOC");
  158.                 if(display_file(doc_filename)) {
  159.                     newline();
  160.                 };
  161.                 *errmsg_ptr = '\0';  /* Switch back to standard error msg */
  162.                 break;
  163.                 case 'F':
  164.                 color(cyan);
  165.                 filexfer();
  166.                 break;
  167.                 case 'M':
  168.                 graphics = graphics ^ TRUE;
  169.                 break;
  170.                 case 'Q':
  171.                 option = EXITDOOR;
  172.                 close_door();
  173.                 exit(0);
  174.                 break;
  175.                 case 'G':
  176.                 option = LOGOFF;
  177.                 logoff();
  178.                 close_door();
  179.                 exit(0);
  180.                 break;
  181.                 default:
  182.                 newline();
  183.                 color(magenta);
  184.                 s_putv("(",par,") is not allowed!  Try again:", NULL);
  185.                 *cmdline = 0;
  186.                 break;
  187.             }
  188.         }
  189.     }
  190. }
  191.  
  192. /******************************************************************************
  193. *                       Display User information                              *
  194. ******************************************************************************/
  195. void display_info(void) {
  196.  
  197.     char    s_out_str[34];      /* Temp. work buffer for itoa function */
  198.     clr_screen();
  199.     newline();
  200.     color(white);
  201.     s_putv(firstname,", Here is your User information:",NULL);
  202.     color(green);
  203.     newline();
  204.     s_putv("  Fullname        = ",fullname,"\r\n",NULL);
  205.  
  206. /*    if(!GENERIC) { */
  207.         if (!PCB) {
  208.             s_puts("  Phone number(s) = ");
  209.         }
  210.         if (!WILDCAT && !PCB) {
  211.             s_putv(user.bphone," \  ",NULL);
  212.         }
  213.         if (!PCB) {
  214.             s_puts(user.phone);
  215.             newline();
  216.             s_putv("  City            = ",user.city,"\r\n",NULL);
  217.         }
  218.         s_putv("  Modem Baud Rate = ",baud_rate,"\r\n",NULL);
  219.         s_putv("  DTE Baud Rate   = ",bps_open,"\r\n",NULL);
  220.         s_putv("  Minutes left    = ",itoa(min_left+time_credit,s_out_str,10),"\r\n",NULL);
  221.  
  222.         if (!PCB) {
  223.             s_putv("  Protocol is     = ",protocol,"\r\n",NULL);
  224.         }
  225.  
  226.         if (!WILDCAT && !PCB) {
  227.             s_putv("  Last call date  = ",user.last_date,"\r\n",NULL);
  228.         }
  229.  
  230.         if (!PCB && !WILDCAT) {
  231.             s_putv("  Event runs at   = ",event_time,"\r\n",NULL);
  232.             s_putv("  Total K bytes   = ",download_Kbytes,NULL);
  233.             newline();
  234.             s_putv("  Total K bytes   = ",upload_Kbytes,"\r\n",NULL);
  235.         }
  236.         if (!PCB) {
  237.             s_putv("  # of Downloads  = ",dload_total, NULL);
  238.             s_putv("  Today's K bytes = ",daily_bytes,"\r\n",NULL);
  239.             s_putv("  Allowed K bytes = ",itoa(dload_limit,s_out_str,10),"\r\n",NULL);
  240.             s_putv("  # of Uploads    = ",upload_total,"\r\n", NULL);
  241.             s_putv("  Your birthday   = ",caller_bday,"\r\n", NULL);
  242.             s_putv("  Last file scan  = ", last_file_scan,"\r\n", NULL);
  243.         }
  244.         if (WILDCAT) {
  245.             s_putv("  Monitor type    = ", monitor_type,"\r\n",NULL);
  246.             s_putv("  High msg. read  = ", high_msg,"\r\n", NULL);
  247.             s_putv("  Door opened     = ", door_opened, "\r\n", NULL);
  248.         }
  249.         s_puts("  Graphic         = ");
  250.         if  (graphics) {
  251.             s_puts("ON");
  252.         } else {
  253.             s_puts("OFF");
  254.         }
  255.         newline();
  256.         s_putv("  Connected to port ", aport, NULL);
  257.         newline();
  258.         s_puts("  Error correction = ");
  259.         if  (error_connection) {
  260.             s_puts("YES");
  261.         } else {
  262.             s_puts("NO");
  263.         }
  264.         newline();
  265.         s_putv("  Page length      = ", \
  266.         itoa(page_length,s_out_str,10),"\r\n", NULL);
  267.         color(yellow);
  268.         newline();
  269.         force_enter();
  270. /*
  271.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  272.  */
  273.  
  274. /*    } */
  275. }
  276.  
  277. /******************************************************************************
  278. *                       ANSI Demo                                             *
  279. ******************************************************************************/
  280. void ansi_demo(void) {
  281.  
  282.     short x,y;
  283.     register    short  i;
  284.  
  285.     if (graphics) {                 /* Check if user is in graphics mode */
  286.         clr_screen();
  287.         for (y=2; y < 24; y++) {
  288.             pos_cursor(y,1);
  289.             s_puts("│");
  290.             pos_cursor(y,79);
  291.             s_puts("│");
  292.         }
  293.         x = 2;
  294.         pos_cursor(1,x);
  295.         for(i = 0; i <= 1; i++) {
  296.             while(x < 79) {
  297.                 s_puts("─");
  298.                 x++;
  299.             }
  300.             x = 2;
  301.             pos_cursor(23,x);
  302.         }
  303.         pos_cursor(1,1);
  304.         s_puts("┌");
  305.         pos_cursor(1,79);
  306.         s_puts("┐");
  307.         pos_cursor(23,1);
  308.         s_puts("└");
  309.         pos_cursor(23,79);
  310.         s_puts("┘");
  311.  
  312.         for(i = blue; i <= white; i++) {
  313.             color(i);
  314.             pos_cursor(i-8+3,11);
  315.             s_puts("ANSI Color display");
  316.         }
  317.         for(i = grey; i >= dkblue; i--) {
  318.             color(i);
  319.             pos_cursor(i+3, 50);
  320.             s_puts("ANSI Color display");
  321.         }
  322.         color(red);
  323.         pos_cursor(13,34);
  324.         s_puts("C - K I T");
  325.         color(yellow);
  326.         pos_cursor(16,14);
  327.         s_puts("This is only a SMALL sample of what C-Kit can do! ");
  328.         color(red);
  329.         pos_cursor(20,26);
  330.     } else {
  331.         newline();
  332.         s_puts("ANSI demo available only in GRAPHICS mode.\r\n");
  333.     }
  334.     force_enter();
  335.  
  336. /*
  337.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  338.  */
  339.     clr_screen();
  340. }
  341.  
  342. /*****************************************************************************
  343.  *  Open  door                                                               *
  344.  *****************************************************************************/
  345. void    test_pattern(void) {
  346.     int  i;
  347.  
  348.     newline();
  349.     for (i = 1; i < 21; i++) {
  350.            s_puts("(1234567890-abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789)\r\n");
  351.     }
  352. /*
  353.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  354.  */
  355.  
  356. }
  357.  
  358.  
  359. /*****************************************************************************
  360.  *  Filexfer doc file                                                        *
  361.  *****************************************************************************/
  362. void    filexfer(void) {
  363.     char xfer_file[46];
  364.     strcpy(xfer_file, zmodem_send);
  365.     strcat(xfer_file, doc_filename);
  366.     color(green);
  367.     s_putv("\nReady to send ", doc_filename, ". Press <ENTER> to begin.", NULL);
  368.     while(DUMP_USER != TRUE) {
  369.           if( check_CR() ) {
  370.             break;
  371.         }
  372.     }
  373.     if(dos_shell(xfer_file)) {
  374.         s_puts("\n\aTransfer aborted");
  375.     } else {
  376.         s_puts("\nTransfer complete");
  377.     }
  378. /*
  379.  *  *cmdline = NULL;  Use this if you don't want cmd stacking
  380.  */
  381. }
  382.  
  383. /******************************************************************************
  384. *  Demostrate scan_code usage                                                 *
  385. ******************************************************************************/
  386. void    read_scancode(void) {
  387.  
  388.      newline();
  389.      newline();
  390.       /* process scancodes */
  391.     switch(scan_code) {
  392.         case 0x3B00:
  393.         s_puts("You pressed F1");
  394.         break;
  395.         case 0x3C00:
  396.         s_puts("You pressed F2");
  397.         break;
  398.         case 0x3D00:
  399.         s_puts("You pressed F3");
  400.         break;
  401.         case 0x3E00:
  402.         s_puts("You pressed F4");
  403.         break;
  404.         case 0x3F00:
  405.         s_puts("You pressed F5");
  406.         break;
  407.         case 0x4000:
  408.         s_puts("You pressed F6");
  409.         break;
  410.         case 0x4100:
  411.         s_puts("You pressed F7");
  412.         break;
  413.         case 0x4200:
  414.         s_puts("You pressed F8");
  415.         break;
  416.         case 0x4300:
  417.         s_puts("You pressed F9");
  418.         break;
  419.         case 0x4400:
  420.         s_puts("You pressed F10");
  421.         break;
  422.         case 0x4800:
  423.         s_puts("You pressed UP Arrow");
  424.         break;
  425.         case 0x5000:
  426.         s_puts("You pressed Dn Arrow");
  427.         break;
  428.         case 0x4D00:
  429.         s_puts("You pressed R Arrow");
  430.         break;
  431.         case 0x4B00:
  432.         s_puts("You pressed L Arrow");
  433.         break;
  434.         case 0x4900:
  435.         s_puts("You pressed PgUp");
  436.         break;
  437.         case 0x5100:
  438.         s_puts("You pressed PgDn");
  439.         break;
  440.         case 0x5200:
  441.         s_puts("You pressed Insert");
  442.         break;
  443.         case 0x5300:
  444.         s_puts("You pressed Delete");
  445.         break;
  446.         case 0x4700:
  447.         s_puts("You pressed Home");
  448.         break;
  449.         case 0x4F00:
  450.         s_puts("You pressed End");
  451.         break;
  452.         case 0x4A00:
  453.         s_puts("You pressed Grey - ");
  454.         break;
  455.         case 0x4E00:
  456.         s_puts("You pressed Grey + ");
  457.         break;
  458.         default:
  459.         break;
  460.     }
  461.     newline();
  462.     s_puts(" - Press a key to continue - ");
  463.     newline();
  464.     while(!(wait_keypress())) {
  465.     }
  466. }
  467.  
  468.  
  469. /*****************************************************************************
  470.  *  Take a chance on on-line time                                            *
  471.  *****************************************************************************/
  472. void    take_chance(void) {
  473.     char    thinking_of[5];
  474.  
  475.     if(PCB) {
  476.         *cmdline = 0;
  477.         itoa(random(10),thinking_of,10);
  478.         if ( strlen(cmdline) == 0) {
  479.             color(cyan);
  480.             s_puts("I'm thinking of a number from 0 to 9.  If you guess the\r\n");
  481.             s_puts("number, you will be given an extra 10 minutes online.  If you\r\n");
  482.             s_puts("get it wrong, your time will be reduced by 2 minutes.\r\n");
  483.             newline();
  484.             color(yellow);
  485.             s_puts("What's your guess? ");
  486.             get_cmdline();
  487.             newline();
  488.         }
  489.         if (get_nextpar()) {  /* scan next parameter from cmdline into par */
  490.             if (!strcmpi(thinking_of, par)) {
  491.                 color(green);
  492.                 s_puts("That's right!  You get a 10 minute bonus!");
  493.                 adjust_time_allowed(10);
  494.             } else {
  495.                 color(blue);
  496.                 s_putv("Wrong! You lose 2 minutes! I was thinking of ", thinking_of,".",NULL);
  497.                 adjust_time_allowed(-2);
  498.             }
  499.         }
  500.     } else {
  501.             newline();
  502.             s_puts("Take chance only available with PCBOARD.SYS usage.\r\n");
  503.     }
  504. }
  505.  
  506.  
  507. /****************************************************************************
  508.  *      IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF IF         *
  509.  * This #if is needed since TURBOC has it's own random() function           *
  510.  * This is needed for this demo source code only.                           *
  511.  ****************************************************************************/
  512. #if COMPILER == MICROSOFT
  513. int   random(short Modulo) {
  514.     short   seed;
  515.     check_time_left();
  516.     seed = system_time_HHMMSS[7] - 0x30;    /* Strip ASCII off */
  517.     return(RAND(seed));
  518. }
  519. #endif
  520.  
  521. /****************************************************************************
  522.  *     ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF    *
  523.  ****************************************************************************/
  524.  
  525. /****************************************************************************/
  526. /************************ E N D  O F   M O D U L E **************************/
  527.