home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / os2 / consolio / worms.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  23KB  |  838 lines

  1. /*=========================================================================\
  2.  *                                                                         *
  3.  *       FILE:worms.c                                                      *
  4.  *                                                                         *
  5.  *       DESCRIPTION:    Full Screen Mixed-mode programming sample         *
  6.  *                                                                         *
  7.  *      Created 1991  IBM Corp.                                            *
  8.  *                                                                         *
  9.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  10.  *      sample code created by IBM Corporation. This sample code is not    *
  11.  *      part of any standard or IBM product and is provided to you solely  *
  12.  *      for  the purpose of assisting you in the development of your       *    *
  13.  *      applications.  The code is provided "AS IS", without               *
  14.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  15.  *      arising out of your use of the sample code, even if they have been *
  16.  *      advised of the possibility of   such damages.                      *                               *
  17.  *                                                                         *
  18.  *-------------------------------------------------------------------------*
  19.  *  This source file contains the following functions:
  20.  *
  21.  *  main
  22.  *  WormsMainProcess
  23.  *  ProcessCmdLine
  24.  *  ErrorMessage
  25.  *  WormsExit
  26.  *
  27. \*==============================================================*/
  28.  
  29. /*--------------------------------------------------------------*\
  30.  *  Include files, macros, defined constants, and externs
  31. \*--------------------------------------------------------------*/
  32.  
  33.  
  34. #define  INCL_VIO
  35. #define  INCL_KBD
  36. #define  INCL_MOU
  37. #define  INCL_DOSPROCESS
  38. #define  INCL_DOSSEMAPHORES
  39.  
  40.  
  41. #include <os2.h>
  42. #include <string.h>
  43. #include <stddef.h>
  44. #include <string.h>
  45. #include <stdlib.h>
  46. #include "worms.h"
  47. #include "wrmthrd.h"
  48. #include "init.h"
  49. #include "wrmhelp.h"
  50.  
  51. /*--------------------------------------------------------------*\
  52.  *Global definitions for this module
  53. \*--------------------------------------------------------------*/
  54.  
  55.  
  56. #define STACK_SIZE_WORMTHRD    32678
  57. #define BOX_ROW 6
  58. #define BOX_COL 10
  59. #define HEIGHT_BOX 9
  60. #define BOX_WIDTH  70
  61. #define DEBUG   1
  62.  
  63. /*--------------------------------------------------------------*\
  64.  *  Global  variables for this module
  65. \*--------------------------------------------------------------*/
  66.  
  67. INT    CurrentThread = 0;
  68. BOOL   fThreadsContinue = TRUE;
  69. BOOL   fSilent = FALSE;
  70. INT    StartWorms = 1;
  71. BOOL   fQuit  = FALSE;                        /*Global quit flag all threads*/
  72. BOOL   fDraw  = TRUE;                         /*Global draw flag all threads*/
  73. BOOL   bHelpEnabled  = FALSE;
  74. BOOL   bMessage      = FALSE;
  75.  
  76. VIOCURSORINFO viociCursor;
  77. VIOMODEINFO   VioModeInfo;
  78. HVIO  hvio = 0 ;
  79. THREAD_DATA ThreadData[] =
  80. /*                                       background/text                           */
  81. /*  TID Active Row           Col          Attribute               sCurrentDirection*/
  82. {
  83.     0L, FALSE, BOT_ROW  / 2 ,FIRST_COL  ,MKATRB(WM_BLUE,WM_RED)        ,0,
  84.     0L, FALSE, FIRST_ROW    ,RGT_COL    ,MKATRB(WM_BROWN,WM_CYAN)      ,0,
  85.     0L, FALSE, BOT_ROW      ,RGT_COL / 2,MKATRB(WM_MAGENTA,WM_PALEGRAY),0,
  86.     0L, FALSE, FIRST_ROW + 5,RGT_COL / 4,MKATRB(WM_LRED,WM_GREEN)      ,0,
  87.     0L, FALSE, BOT_ROW      ,RGT_COL - 3,MKATRB(WM_YELLOW,WM_WHITE)    ,0,
  88.     0L, FALSE, BOT_ROW  - 4 ,FIRST_COL  ,MKATRB(WM_GREEN,WM_LBLUE)     ,0,
  89.     0L, FALSE, FIRST_ROW + 4,RGT_COL    ,MKATRB(WM_BROWN,WM_YELLOW)    ,0,
  90.     0L, FALSE, BOT_ROW  - 2 ,RGT_COL / 2,MKATRB(WM_DKGREY,WM_GREEN)    ,0,
  91.     0L, FALSE, FIRST_ROW    ,RGT_COL / 4,MKATRB(WM_BLUE,WM_RED)        ,0,
  92.     0L, FALSE, BOT_ROW  - 3 ,RGT_COL - 3,MKATRB(WM_WHITE,WM_LBLUE)     ,0,
  93.  
  94.     0L, FALSE, BOT_ROW  / 2 ,FIRST_COL  ,MKATRB(WM_BLUE,WM_RED)        ,0,
  95.     0L, FALSE, FIRST_ROW    ,RGT_COL    ,MKATRB(WM_BROWN,WM_CYAN)      ,0,
  96.     0L, FALSE, BOT_ROW      ,RGT_COL / 2,MKATRB(WM_MAGENTA,WM_PALEGRAY),0,
  97.     0L, FALSE, FIRST_ROW + 5,RGT_COL / 4,MKATRB(WM_LRED,WM_GREEN)      ,0,
  98.     0L, FALSE, BOT_ROW      ,RGT_COL - 3,MKATRB(WM_YELLOW,WM_WHITE)    ,0,
  99.     0L, FALSE, BOT_ROW  - 4 ,FIRST_COL  ,MKATRB(WM_GREEN,WM_LBLUE)     ,0,
  100.     0L, FALSE, FIRST_ROW + 4,RGT_COL    ,MKATRB(WM_BROWN,WM_YELLOW)    ,0,
  101.     0L, FALSE, BOT_ROW  - 2 ,RGT_COL / 2,MKATRB(WM_DKGREY,WM_GREEN)    ,0,
  102.     0L, FALSE, FIRST_ROW    ,RGT_COL / 4,MKATRB(WM_BLUE,WM_RED)        ,0,
  103.     0L, FALSE, BOT_ROW  - 3 ,RGT_COL - 3,MKATRB(WM_WHITE,WM_LBLUE)     ,0,
  104.  
  105.     0L, FALSE, BOT_ROW  / 2 ,FIRST_COL  ,MKATRB(WM_BLUE,WM_RED)        ,0,
  106.     0L, FALSE, FIRST_ROW    ,RGT_COL    ,MKATRB(WM_BROWN,WM_CYAN)      ,0,
  107.     0L, FALSE, BOT_ROW      ,RGT_COL / 2,MKATRB(WM_MAGENTA,WM_PALEGRAY),0,
  108.     0L, FALSE, FIRST_ROW + 5,RGT_COL / 4,MKATRB(WM_LRED,WM_GREEN)      ,0,
  109.     0L, FALSE, BOT_ROW      ,RGT_COL - 3,MKATRB(WM_YELLOW,WM_WHITE)    ,0,
  110.     0L, FALSE, BOT_ROW  - 4 ,FIRST_COL  ,MKATRB(WM_GREEN,WM_LBLUE)     ,0,
  111.     0L, FALSE, FIRST_ROW + 4,RGT_COL    ,MKATRB(WM_BROWN,WM_YELLOW)    ,0,
  112.     0L, FALSE, BOT_ROW  - 2 ,RGT_COL / 2,MKATRB(WM_DKGREY,WM_GREEN)    ,0,
  113.     0L, FALSE, FIRST_ROW    ,RGT_COL / 4,MKATRB(WM_BLUE,WM_RED)        ,0,
  114.     0L, FALSE, BOT_ROW  - 3 ,RGT_COL - 3,MKATRB(WM_WHITE,WM_LBLUE)     ,0,
  115. };
  116. CHAR *pszBox [HEIGHT_BOX]=
  117. {
  118. "╔════════════════════════════════════════════════════════╗",
  119. "║                                                        ║",
  120. "║               Process  Message:                        ║",
  121. "║                                                        ║",
  122. "║                                                        ║",
  123. "║                                                        ║",
  124. "║                                                        ║",
  125. "║                                                        ║",
  126. "╚════════════════════════════════════════════════════════╝",
  127. };
  128. CHAR *pszWormMessages [] =
  129. {
  130.      "Worms Mixed-Mode Program Normal Exit",
  131.      "Undetermined Error Occurred",
  132.      "Worms Mixed Mode Program Initialization Failure",
  133.      "Maximum Number of Threads Reached for this Process",
  134.      "Error Creating Thread",
  135.      "Unable To Display Help Screen",
  136.      "Unable To Create  Mouse Event Thread",
  137.      "Hit Any Key to Exit Process",
  138.      "Waiting for Threads To Exit",
  139.      "Any Key to Continue",
  140. };
  141.  
  142. #define    MAX_ERROR_MSGS (sizeof (pszErrorMessage) )
  143. #define    MAX_THREADS    (( sizeof(ThreadData) / sizeof(THREAD_DATA)) - 1)
  144. /*--------------------------------------------------------------*\
  145.  *  Entry point declarations
  146. \*--------------------------------------------------------------*/
  147. INT
  148. main (SHORT sArgc , CHAR *ppArgv[]);
  149. VOID
  150. WormsExit(SHORT sExitStatus);
  151. BOOL
  152. WormsMainProcess(SHORT *psStatus);
  153. BOOL
  154. ProcessCmdLine(SHORT sArgc,CHAR **ppArgv);
  155.  
  156. /****************************************************************\
  157.  *  Routine Name:main()
  158.  *--------------------------------------------------------------
  159.  *
  160.  *  Name: main()
  161.  *
  162.  *  Purpose:Main entry point for  the worms program
  163.  *
  164.  *
  165.  *
  166.  *  Usage: Main entry point for the worms program.
  167.  *
  168.  *  Method:
  169.  *          -
  170.  *
  171.  *          -
  172.  *          -
  173.  *
  174.  *          -
  175.  *          -
  176.  *
  177.  *  Returns:
  178.  *
  179.  *
  180. \****************************************************************/
  181. INT
  182. main (SHORT sArgc,CHAR  *ppArgv[])
  183. {
  184.  
  185.     SHORT     sExitStatus = WRM_NORMAL_EXIT;
  186.  
  187.     for(;;)
  188.     {
  189.          /*
  190.           *process the command line
  191.           */
  192.          if(ProcessCmdLine(sArgc,ppArgv) )
  193.          {
  194.                break;
  195.          }
  196.  
  197.          /*
  198.           *initialize resources
  199.           */
  200.          if(Init(&sExitStatus) )
  201.          {
  202.                ErrorMessage(sExitStatus,TRUE);
  203.                break;
  204.          }
  205.          /*
  206.           *start up the main process
  207.           */
  208.          if(WormsMainProcess(&sExitStatus) )
  209.          {
  210.                ErrorMessage(sExitStatus,TRUE);
  211.                break;
  212.          }
  213.          break;
  214.     };
  215.     WormsExit(WRM_NORMAL_EXIT);
  216.  
  217.     return( (INT) sExitStatus);
  218. }      /*  end of main()  */
  219.  
  220. /****************************************************************\
  221.  *
  222.  *--------------------------------------------------------------
  223.  *
  224.  *  Name:WormsMainProcess
  225.  *
  226.  *  Purpose:
  227.  *
  228.  *
  229.  *
  230.  *  Usage:
  231.  *
  232.  *  Method:
  233.  *          -
  234.  *
  235.  *          -
  236.  *          -
  237.  *
  238.  *          -
  239.  *          -
  240.  *
  241.  *  Returns:
  242.  *          FALSE - if sucessful execution completed
  243.  *          TRUE  - if error ,See *psStatus for error definition
  244. \****************************************************************/
  245. BOOL
  246. WormsMainProcess(SHORT *psStatus)
  247. {
  248.     BOOL fError = FALSE;
  249.     KBDKEYINFO    kbdkeyinfo;
  250.     USHORT      usId;
  251.     ULONG ulPosts;
  252.  
  253.  
  254.     do
  255.     {
  256.           /*
  257.            *sit here and wait on
  258.            *user input
  259.            */
  260.           KbdCharIn(&kbdkeyinfo,IO_WAIT,
  261.                      0) ;
  262.           /*
  263.            *if help was enabled don't allow any other input
  264.            */
  265.           if(!bHelpEnabled && !bMessage)
  266.           {
  267.                /*
  268.                 *regular keys
  269.                 */
  270.                if( kbdkeyinfo.chChar )
  271.                {
  272.                     switch(kbdkeyinfo.chChar)
  273.                     {
  274.                     case 'd':
  275.                     case 'D':
  276.                            WormDelete();
  277.                            break;
  278.                     case 'e':
  279.                     case 'E':
  280.                          fQuit = TRUE;
  281.                          fDraw = FALSE;
  282.                          break;
  283.                     case 'a':
  284.                     case 'A':
  285.                          WormCreate();
  286.                          break;
  287.                     case 'h':
  288.                     case 'H':
  289.                          if( WormHelp() )
  290.                          {
  291.                               ErrorMessage(ERROR_DISP_HELP,TRUE);
  292.                          }
  293.                          break;
  294.                     default:
  295.                          DosBeep(1200,175);
  296.                          break;
  297.                     }
  298.                }
  299.                /*
  300.                 *extended keys
  301.                 */
  302.                else
  303.                {
  304.                     switch(kbdkeyinfo.chScan )
  305.                     {
  306.                     case F1:
  307.                          if( WormHelp() )
  308.                          {
  309.                               ErrorMessage(ERROR_DISP_HELP,TRUE);
  310.                          }
  311.                          break;
  312.                     default:
  313.                          DosBeep(1200,175);
  314.                          break;
  315.                     }
  316.                }
  317.  
  318.           }
  319.           /*
  320.            *another threads  waiting for keyboard input
  321.            *free them up
  322.            */
  323.           else
  324.           {
  325.                DosPostEventSem(hevWormSem);
  326.           }
  327.  
  328.     }while(!fQuit );
  329.  
  330.     /*
  331.      *set each thread as inactive
  332.      */
  333.     for(usId = 2; usId <= MAX_THREADS + 2; usId++)
  334.     {
  335.           ThreadData[usId - 2].fActive = FALSE;
  336.     }
  337.  
  338.      /*
  339.       *make sure we don't get
  340.       *pre-empted
  341.       */
  342.      DosEnterCritSec();
  343.      ulPosts = 0;
  344.      DosResetEventSem(hevDrawOk,&ulPosts);
  345.      DosExitCritSec();
  346.  
  347.      /*
  348.       *wait till all of the
  349.       *threads have
  350.       *posted on the way out
  351.       */
  352.      while(ulPosts < CurrentThread)
  353.      {
  354.           DosWaitEventSem(hevDrawOk,SEM_INDEFINITE_WAIT);
  355.           DosQueryEventSem(hevDrawOk,&ulPosts);
  356.      }
  357.     /*
  358.      *display message that process is shutting down
  359.      */
  360.     Message(WAITING_THREADS_EXIT,FALSE,FALSE,TRUE,FALSE);
  361.     return ( fError) ;
  362. }/*main process loop */
  363.  
  364. /****************************************************************\
  365.  *
  366.  *--------------------------------------------------------------
  367.  *
  368.  *  Name: WormCreate()
  369.  *
  370.  *  Purpose:
  371.  *
  372.  *
  373.  *
  374.  *  Usage:
  375.  *
  376.  *  Method:
  377.  *          -
  378.  *
  379.  *          -
  380.  *          -
  381.  *
  382.  *          -
  383.  *          -
  384.  *
  385.  *  Returns:
  386.  *          TRUE   - Error occurred
  387.  *          FALSE  - No error occurred
  388. \****************************************************************/
  389. BOOL
  390. WormCreate(VOID )
  391. {
  392.  
  393.     if(CurrentThread  == MAX_THREADS)
  394.     {
  395.           /*
  396.            *thread limit exceeeded
  397.            */
  398.            ErrorMessage(MAX_THREADS_EXCEEDED,TRUE );
  399.            return(TRUE);
  400.  
  401.     }
  402.     ThreadData[CurrentThread].fActive = TRUE;
  403.     ThreadData[CurrentThread].tidWorm =
  404.                             _beginthread( WormThread,
  405.                                        NULL,
  406.                                        STACK_SIZE_WORMTHRD,
  407.                                        &ThreadData[CurrentThread]);
  408.     if(ThreadData[CurrentThread].tidWorm ==  -1 )
  409.     {
  410.           ErrorMessage(ERROR_CREATING_THREAD,TRUE );
  411.           return(TRUE);
  412.     }
  413.     CurrentThread++;
  414.  
  415.     return(FALSE);
  416.  
  417. }
  418. /****************************************************************\
  419.  *
  420.  *--------------------------------------------------------------
  421.  *
  422.  *  Name: ErrorMessage()
  423.  *
  424.  *  Purpose: Display Error Messages to the user.
  425.  *
  426.  *
  427.  *
  428.  *  Usage: sErrorMessage - Message number to display.
  429.  *         fBeep         - Beep or not.
  430.  *
  431.  *  Method:
  432.  *          -
  433.  *
  434.  *          -
  435.  *          -
  436.  *
  437.  *          -
  438.  *          -
  439.  *
  440.  *  Returns:   VOID
  441. \****************************************************************/
  442. VOID ErrorMessage(SHORT sErrorMessage,BOOL fBeep)
  443.  
  444. {
  445.  
  446.     KBDKEYINFO    kbdkeyinfo;
  447.     BYTE  bAttr  = MKATRB(WM_RED,WM_WHITE );
  448.     USHORT usAttrib = VP_WAIT | VP_OPAQUE;
  449.     USHORT  usRow,usIndex;
  450.     USHORT  usStatus = MOUSE_DISABLED;
  451.     BYTE bCell[2];
  452.     PVOID pvSaveWindBuf;
  453.     PTIB   ptib ;
  454.     PPIB   ppib  ;
  455.     ULONG  ulPosts;
  456.  
  457.     bCell[0] = 0x20;
  458.     bCell[1] = WM_BACKGROUND;
  459.     bMessage = TRUE;
  460.  
  461.  
  462.     if(fBeep)
  463.     {
  464.           DosBeep(675,1200);
  465.     }
  466.  
  467.      /*
  468.       *freeze all threads
  469.       *while pop-up is up
  470.       */
  471.      SuspendAllThreads();
  472.      /*
  473.       *make sure each thread has had enough time
  474.       *to complete
  475.       *what they are doin before waiting on the drawing semaphore
  476.       */
  477. //   DosSleep(PAUSE_TIME * 40);
  478.      /*
  479.       *read the screen and save
  480.       *it
  481.       */
  482.      if(SaveScreen(&pvSaveWindBuf) )
  483.      {
  484.           return;
  485.      }
  486.  
  487.      VioScrollDn(0,0,0xFFFF,0xFFFF,0xFFFF,bCell,hvio);
  488.  
  489.  
  490.     /*
  491.      *put up the  message box
  492.      */
  493.      for(usRow = BOX_ROW,usIndex = 0;usIndex < HEIGHT_BOX; usIndex++,
  494.                                                           usRow++ )
  495.      {
  496.         VioWrtCharStrAtt(pszBox[usIndex],strlen(pszBox[usIndex]),
  497.                      usRow,
  498.                      BOX_COL,
  499.                      &bAttr,
  500.                      hvio );
  501.      }
  502.  
  503.      /*
  504.       *display
  505.       *error message
  506.       */
  507.       VioWrtCharStrAtt( pszWormMessages[sErrorMessage],
  508.                          strlen(pszWormMessages[sErrorMessage]),
  509.                          BOX_ROW + 5,
  510.                          ( ((LAST_COL - FIRST_COL ) -
  511.                                     strlen(pszWormMessages[sErrorMessage])) / 2) ,
  512.                          &bAttr,
  513.                          hvio );
  514.        /*
  515.         *any key to continue
  516.         */
  517.        VioWrtCharStrAtt( pszWormMessages[ANY_KEY_TO_CONTINUE],
  518.                          strlen(pszWormMessages[ANY_KEY_TO_CONTINUE]),
  519.                          BOX_ROW + 6,
  520.                          ( ((LAST_COL - FIRST_COL ) -
  521.                                     strlen(pszWormMessages[ANY_KEY_TO_CONTINUE])) / 2) ,
  522.                          &bAttr,
  523.                          hvio );
  524.  
  525.       DosGetInfoBlocks(&ptib,&ppib);
  526.       /*
  527.        *if we are not
  528.        *calling from thread
  529.        *one suspend the calling thread
  530.        *so only one thread at a time
  531.        *is hitting the keyboard queue
  532.        */
  533.       if(ptib->tib_ptib2->tib2_ultid != 1 )
  534.       {
  535.           DosWaitEventSem(hevWormSem,SEM_INDEFINITE_WAIT);
  536.           DosResetEventSem(hevWormSem,&ulPosts);
  537.       }
  538.       else
  539.       {
  540.          /*
  541.           *wait for any
  542.           *response if thread 1
  543.           */
  544.           KbdCharIn(&kbdkeyinfo,IO_WAIT,
  545.                          0) ;
  546.       }
  547.  
  548.       VioScrollDn(0,0,0xFFFF,0xFFFF,0xFFFF,bCell,hvio);
  549.       /*
  550.        *restore the screen
  551.        */
  552.       ReDisplayScreen(pvSaveWindBuf);
  553.  
  554.        /*
  555.         *resume all threads
  556.         */
  557.      ResumeAllThreads();
  558.  
  559.      bMessage = FALSE;
  560. }
  561.  
  562. /****************************************************************\
  563.  *
  564.  *--------------------------------------------------------------
  565.  *
  566.  *  Name: Message()
  567.  *
  568.  *  Purpose:Generic message routine. Allows all threads to continue,
  569.  *          while message is up.
  570.  *
  571.  *
  572.  *
  573.  *  Usage:
  574.  *
  575.  *  Method:
  576.  *          -
  577.  *
  578.  *          -
  579.  *          -
  580.  *
  581.  *          -
  582.  *          -
  583.  *
  584.  *  Returns:   VOID
  585.  *
  586.  *
  587. \****************************************************************/
  588. VOID Message( SHORT sErrorMessage,BOOL fBeep,BOOL fKeyBoardWait,
  589.                    BOOL fClsConsole,BOOL fSuspendThreads )
  590. {
  591.     KBDKEYINFO    kbdkeyinfo;
  592.     BYTE  bAttr  = MKATRB(WM_RED,WM_WHITE );
  593.     USHORT usAttrib = VP_WAIT | VP_OPAQUE;
  594.     USHORT  usRow,usIndex;
  595.     BYTE bCell[2];
  596.     BYTE bhAttr = WM_BACKGROUND;
  597.  
  598.     bCell[0] = 0x20;
  599.     bCell[1] = WM_BACKGROUND;
  600.  
  601.      /*
  602.       *display
  603.       *the error message to the
  604.       *screen
  605.       */
  606.       if(fBeep)
  607.       {
  608.           DosBeep(675,1200);
  609.       }
  610.  
  611.       if(fSuspendThreads)
  612.       {
  613.           SuspendAllThreads();
  614.       }
  615.  
  616.       DosSleep(1000L);
  617.       if(fClsConsole)
  618.       {
  619.           /*
  620.            *clear the screen
  621.            */
  622.           VioScrollDn(0,0,0xFFFF,0xFFFF,0xFFFF,bCell,hvio);
  623.       }
  624.  
  625.        /*
  626.         *put up the  message box
  627.         */
  628.  
  629.        for(usRow = BOX_ROW,usIndex = 0;usIndex < HEIGHT_BOX; usIndex++,
  630.                                                              usRow++ )
  631.        {
  632.           VioWrtCharStrAtt(pszBox[usIndex],strlen(pszBox[usIndex]),
  633.                         usRow,
  634.                         BOX_COL,
  635.                         &bAttr,
  636.                         hvio );
  637.        }
  638.  
  639.        /*
  640.         *display
  641.         *message
  642.         */
  643.        VioWrtCharStrAtt( pszWormMessages[sErrorMessage],
  644.                          strlen(pszWormMessages[sErrorMessage]),
  645.                          BOX_ROW + 5,
  646.                          ( ((LAST_COL - FIRST_COL ) -
  647.                                     strlen(pszWormMessages[sErrorMessage])) / 2) ,
  648.                          &bAttr,
  649.                          hvio );
  650.  
  651.        /*
  652.         *sit here and wait on
  653.         *user input
  654.         */
  655.        if(fKeyBoardWait)
  656.        {
  657.  
  658.            VioWrtCharStrAtt( pszWormMessages[sErrorMessage],
  659.                              strlen(pszWormMessages[sErrorMessage]),
  660.                              BOX_ROW + 6,
  661.                              ( ((LAST_COL - FIRST_COL ) -
  662.                                         strlen(pszWormMessages[ANY_KEY_TO_CONTINUE])) / 2) ,
  663.                              &bAttr,
  664.                              hvio );
  665.            KbdCharIn(&kbdkeyinfo,IO_WAIT,
  666.                       0 ) ;
  667.        }
  668.  
  669. }
  670.  
  671. /****************************************************************\
  672.  *
  673.  *--------------------------------------------------------------
  674.  *
  675.  *  Name:WormsExit()
  676.  *
  677.  *  Purpose: Generic exit routine. All exit processing should be done
  678.  *           at this point.
  679.  *
  680.  *
  681.  *
  682.  *  Usage:
  683.  *
  684.  *  Method:
  685.  *          -
  686.  *
  687.  *          -
  688.  *          -
  689.  *
  690.  *          -
  691.  *          -
  692.  *
  693.  *  Returns:   VOID
  694.  *
  695.  *
  696. \****************************************************************/
  697. VOID
  698. WormsExit(SHORT sExitStatus)
  699. {
  700.  
  701.      USHORT usRow,usCol;
  702.      BYTE bCell[2];
  703.      BYTE bhAttr = MKATRB(WM_BLUE,WM_RED);
  704.  
  705.      bCell[0] = 0x20;
  706.      bCell[1] = WM_BACKGROUND;
  707.  
  708.  
  709.      /*
  710.       *do any clean up
  711.       *necessary
  712.       */
  713.  
  714.  
  715.      /*
  716.       *clear the screen
  717.       */
  718.      VioScrollDn(0,0,0xFFFF,0xFFFF,0xFFFF,bCell,hvio);
  719.  
  720.      /*
  721.       *reset the old
  722.       *cursor
  723.       */
  724.      VioSetCurType(&viociCursor,hvio);
  725.      /*
  726.       *display the exit message
  727.       */
  728.      VioWrtCharStrAtt( pszWormMessages[sExitStatus],
  729.                        strlen(pszWormMessages[sExitStatus]),
  730.                        2,1,
  731.                        &bhAttr,hvio );
  732.      VioSetCurPos(3,2,hvio);
  733.  
  734. }
  735. /****************************************************************\
  736.  *
  737.  *--------------------------------------------------------------
  738.  *
  739.  *  Name:ProcessCmdLine()
  740.  *
  741.  *  Purpose:Parse arguments passed on the command line.
  742.  *
  743.  *
  744.  *
  745.  *  Usage:
  746.  *
  747.  *  Method:
  748.  *          -
  749.  *
  750.  *          -
  751.  *          -
  752.  *
  753.  *          -
  754.  *          -
  755.  *
  756.  *  Returns:
  757.  *        FALSE   - at present time
  758.  *
  759. \****************************************************************/
  760. BOOL ProcessCmdLine(SHORT sArgc,CHAR **ppArgv)
  761. {
  762.      SHORT sArgnum = 1;
  763.      BOOL  fError = FALSE;
  764.  
  765.      while(--sArgc )
  766.      {
  767.           if( *ppArgv[sArgnum] == '-'   ||
  768.               *ppArgv[sArgnum] == '/' )
  769.           {
  770.  
  771.                switch(*(ppArgv[sArgnum] + 1) )
  772.                {
  773.                case 'S':
  774.                case 's':
  775.                     fSilent = TRUE;
  776.                     break;
  777.                case '1':
  778.                case '2':
  779.                case '3':
  780.                case '4':
  781.                case '5':
  782.                case '6':
  783.                case '7':
  784.                case '8':
  785.                case '9':
  786.                     StartWorms = atoi(ppArgv[sArgnum] + 1);
  787.                     if(StartWorms > MAX_THREADS )
  788.                     {
  789.                          StartWorms = MAX_THREADS;
  790.                     }
  791.                     break;
  792.                }
  793.           }
  794.           sArgnum++;
  795.      }
  796.      return(fError);
  797. }
  798. /****************************************************************\
  799.  *
  800.  *--------------------------------------------------------------
  801.  *
  802.  *  Name:WormDelete()
  803.  *
  804.  *  Purpose:Set the active flag to false for the last active
  805.  *  thread to FALSE.
  806.  *
  807.  *
  808.  *  Usage:
  809.  *
  810.  *  Method:
  811.  *          -
  812.  *
  813.  *          -
  814.  *          -
  815.  *
  816.  *          -
  817.  *          -
  818.  *
  819.  *  Returns:
  820.  *
  821.  *          VOID
  822. \****************************************************************/
  823. VOID WormDelete(VOID)
  824. {
  825.  
  826.       if(CurrentThread > 0)
  827.       {
  828.          ThreadData[--CurrentThread].fActive = FALSE;
  829.       }
  830.       else
  831.       {
  832.           DosBeep(675,1200);
  833.       }
  834. }    /*  end of WormDelete()  */
  835.  
  836.  
  837.  
  838.