home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sniff16.zip / TESTAPP / INIT.C < prev    next >
C/C++ Source or Header  |  1993-03-12  |  7KB  |  280 lines

  1. /*=========================================================================\
  2.  *                                                                         *
  3.  *       FILE:init.c                                                       *
  4.  *                                                                         *
  5.  *       DESCRIPTION: This file handles all initialization necessary       *
  6.  *                    for the worms program                                *
  7.  *                                                                         *
  8.  *      Copyright 1992 IBM Corp.                                           *
  9.  *                                                                         *
  10.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        *
  11.  *      sample code created by IBM Corporation. This sample code is not    *
  12.  *      part of any standard or IBM product and is provided to you solely  *
  13.  *      for  the purpose of assisting you in the development of your       *    *
  14.  *      applications.  The code is provided "AS IS", without               *
  15.  *      warranty of any kind.  IBM shall not be liable for any damages     *
  16.  *      arising out of your use of the sample code, even if they have been *
  17.  *      advised of the possibility of   such damages.                      *                               *
  18.  *-------------------------------------------------------------------------*
  19.  *
  20.  *
  21.  *
  22.  *
  23.  *
  24.  *
  25.  *
  26.  *
  27.  *
  28.  *
  29.  *
  30.  *--------------------------------------------------------------
  31.  *
  32.  *  This source file contains the following functions:
  33.  *
  34.  *
  35.  *  Init()
  36.  *
  37.  *
  38. \*==============================================================*/
  39.  
  40. /*--------------------------------------------------------------*\
  41.  *  Include files, macros, defined constants, and externs
  42. \*--------------------------------------------------------------*/
  43. #define  INCL_VIO
  44. #define  INCL_DOSPROCESS
  45. #define  INCL_MOU
  46. #define  INCL_DOSSEMAPHORES
  47.  
  48. #include <os2.h>
  49. #include <stdlib.h>
  50. #include "worms.h"
  51. #include "disp.h"
  52. #include "init.h"
  53. #include "wmouse.h"
  54.  
  55.  
  56.  
  57.  
  58. /*--------------------------------------------------------------*\
  59.  *  Global variables  and definitions for this file
  60. \*--------------------------------------------------------------*/
  61.  
  62. #define CREATE_MOUSE  1
  63. #define STACK_SIZE_MOUTHRD  32768
  64. #define WORM_SEM_NAME  NULL
  65. #define WORM_DRAW_NAME NULL
  66. HEV   hevWormSem;
  67. HEV   hevDrawSem;
  68. HEV   hevDrawOk;
  69.  
  70.  
  71.  
  72.  
  73.  
  74. /*--------------------------------------------------------------*\
  75.  *  Entry point declarations
  76. \*--------------------------------------------------------------*/
  77.  
  78. BOOL
  79. create_wmThread(VOID );
  80.  
  81. BOOL bStartWorms(VOID );
  82. /****************************************************************\
  83.  *  Routine Name:Init()
  84.  *--------------------------------------------------------------
  85.  *
  86.  *  Name:
  87.  *
  88.  *  Purpose:
  89.  *
  90.  *
  91.  *
  92.  *  Usage:
  93.  *
  94.  *  Method:
  95.  *          -
  96.  *
  97.  *          -
  98.  *          -
  99.  *
  100.  *          -
  101.  *          -
  102.  *
  103.  *  Returns:
  104.  *       TRUE  - Error Occurred
  105.  *       FALSE - No error occurred
  106. \****************************************************************/
  107. BOOL
  108. Init(PSHORT psErrorMessage)
  109. {
  110.      BOOL fError = FALSE;
  111.      VIOCURSORINFO viociTemp;
  112.  
  113.      /*
  114.       *get the current configuration
  115.       */
  116.      VioModeInfo.cb = sizeof(VioModeInfo);
  117.      VioGetMode(&VioModeInfo,hvio );
  118.  
  119.      /*
  120.       *save the cursor type
  121.       */
  122.      VioGetCurType(&viociCursor,hvio);
  123.      VioGetCurType(&viociTemp,hvio);
  124.  
  125.      /*
  126.       *turn off the cursor
  127.       */
  128.       viociTemp.attr = 0xFFFF;
  129.       VioSetCurType(&viociTemp,hvio);
  130.  
  131.  
  132.  
  133.      /*
  134.       *display the main default window
  135.       */
  136.      WindMainDisp();
  137.  
  138.      if(create_wmThread() )
  139.      {
  140.           ErrorMessage(ERROR_CREATING_WREADTHRD,TRUE);
  141.      }
  142.  
  143.      /*
  144.       *create a general purpose
  145.       *semaphore
  146.       */
  147.      if(DosCreateEventSem(WORM_SEM_NAME,
  148.                            &hevWormSem,
  149.                            0,
  150.                            FALSE ) )
  151.      {
  152.           fError = TRUE;
  153.      }
  154.      /*
  155.       *create a sem
  156.       *to contro the threads that
  157.       *draw to the screen
  158.       */
  159.      if(DosCreateEventSem(WORM_DRAW_NAME,
  160.                            &hevDrawSem,
  161.                            0,
  162.                            TRUE) )
  163.      {
  164.           fError = TRUE;
  165.      }
  166.  
  167.      if(DosCreateEventSem(NULL,
  168.                            &hevDrawOk,
  169.                            DC_SEM_SHARED,
  170.                            FALSE ) )
  171.      {
  172.           fError = TRUE;
  173.      }
  174.  
  175.      /*
  176.       *start up
  177.       *the number of worms
  178.       *specified on the command
  179.       *line
  180.       */
  181.      bStartWorms();
  182.  
  183.      return(fError);
  184.  
  185. }
  186. /****************************************************************\
  187.  *
  188.  *--------------------------------------------------------------
  189.  *
  190.  *  Name:create_wmThread()
  191.  *
  192.  *  Purpose:
  193.  *
  194.  *
  195.  *
  196.  *  Usage:
  197.  *
  198.  *  Method:
  199.  *          -
  200.  *
  201.  *          -
  202.  *          -
  203.  *
  204.  *          -
  205.  *          -
  206.  *
  207.  *  Returns:
  208.  *          FALSE - if sucessful execution completed
  209.  *          TRUE  - if error
  210. \****************************************************************/
  211. BOOL
  212. create_wmThread(VOID )
  213. {
  214.     SHORT sValue;
  215.  
  216.     if( _beginthread( WReadMouse,
  217.                       NULL,
  218.                       STACK_SIZE_MOUTHRD,
  219.                       &sValue) == -1 )
  220.     {
  221.           return(TRUE);
  222.     }
  223.  
  224.     return(FALSE);
  225.  
  226.  
  227. }
  228. /****************************************************************\
  229.  *
  230.  *--------------------------------------------------------------
  231.  *
  232.  *  Name:bStartWorms()
  233.  *
  234.  *  Purpose:Kick off the number off worms that was specified on the command
  235.  *          line
  236.  *
  237.  *
  238.  *
  239.  *  Usage:
  240.  *
  241.  *  Method:
  242.  *          -
  243.  *
  244.  *          -
  245.  *          -
  246.  *
  247.  *          -
  248.  *          -
  249.  *
  250.  *  Returns:
  251.  *          TRUE  - An error occurred
  252.  *          FALSE - No error  occurred
  253. \****************************************************************/
  254. BOOL bStartWorms(VOID )
  255. {
  256.  
  257.      USHORT usWorms;
  258.  
  259.  
  260.      for(usWorms = 0; usWorms < sStartWorms;usWorms ++ )
  261.      {
  262.           if( WormCreate() )
  263.           {
  264.                return(TRUE);
  265.  
  266.           }
  267.      }
  268.      return(FALSE);
  269. }
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277. /*--------------------------------------------------------------*\
  278.  *  End of file : init.c
  279. \*--------------------------------------------------------------*/
  280.