home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 1.ddi / STARTUP.386 / CMAIN386.C next >
Encoding:
C/C++ Source or Header  |  1992-05-28  |  5.3 KB  |  156 lines

  1. /*
  2.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  *%       Copyright (C) 1986,1991 by WATCOM Systems Inc. All rights %
  4.  *%       reserved. No part of this software may be reproduced      %
  5.  *%       in any form or by any means - graphic, electronic or      %
  6.  *%       mechanical, including photocopying, recording, taping     %
  7.  *%       or information storage and retrieval systems - except     %
  8.  *%       with the written permission of WATCOM Systems Inc.        %
  9.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10.  
  11.   Modified:     By:             Reason:
  12.   ---------     ---             -------
  13.   22-nov-86     F.W.Crigger     Initial implementation
  14.   16-feb-87     M.Glaum         Fix Command Line
  15.   14-sep-87     F.W.Crigger     Don't remove quotes from parms
  16.   21-oct-87     F.W.Crigger     Added fcloseall routine
  17.   02-nov-87     A.F.Scian       made quoted parms like Microsoft and Turbo
  18.   12-nov-87     F.W.Crigger     Added call to _setenvp()
  19.   16-nov-87     F.W.Crigger     added fflush for stdxxx in exit.
  20.   02-dec-87     F.W.Crigger     added call to _clock_init().
  21.   08-dec-87     M.Glaum         added big data code
  22.   13-dec-87     A.F.Scian       made atexit fail to add more functions
  23.                                 if exit handling has been initiated
  24.   04-jan-88     F.W.Crigger     Allow '\\' in _SplitParms
  25.   04-feb-88     F.W.Crigger     Added _init_files routine
  26. ---------------------------------------------------------Version 6.0--------
  27.   03-apr-88     F.W.Crigger     set _amblksiz to 1 for memory allocations
  28.                                 done during initialization, then 8K for user.
  29.   25-may-88     F.W.Crigger     _init_files exported for Express
  30.   03-aug-88     A.F.Scian       moved DS expansion from CSTART to here
  31. ---------------------------------------------------------Version 6.5--------
  32.   24-oct-88     F.W.Crigger     _init_files - add logic for _NFILES > 20
  33.                                 _iomode array moved to this file
  34.   07-dec-88     F.W.Crigger     clock initialization done by cstart now
  35.                                 Do indirect call through _main_entry_ to
  36.                                 get to user's program instead of always
  37.                                 calling _init_argv and then main
  38.   19-dec-88     F.W.Crigger     __Null_argv() defined so main works in overlay
  39.   18-jan-89     F.W.Crigger     parms added to prototype for _main_entry
  40. ---------------------------------------------------------Version 7.0--------
  41.   17-apr-89     F.W.Crigger     Adapted for 386
  42.   89-05-25      John Dahms      split out _NFiles and iomode variables
  43.   13-jul-89     John Dahms      Added call to brk( _STACKTOP )
  44.   15-jan-91     F.W.Crigger     Must set _curbrk in cstart to _STACKTOP
  45.   03-apr-91     A.F.Scian       changed initial setting of _amblksiz to 32k
  46. ---------------------------------------------------------Version 8.5--------
  47.   03-dec-91    G. Coschi    support for OS/2 2.0
  48. ---------------------------------------------------------Version 9.0--------
  49.   04-mar-92    F.W.Crigger    ___Argc, ___Argv moved to separate module
  50.   19-may-92    F.W.Crigger    Added code to handle > 20 files in Windows
  51. */
  52.  
  53. #include <stdio.h>
  54. #include <stdlib.h>
  55. #include <io.h>
  56.  
  57. #if defined( __OS2__ )
  58.  #define  INCL_DOSFILEMGR
  59.  #include <wos2.h>
  60. #elif defined(__WINDOWS_386__)
  61.  #include <windows.h>
  62. #endif
  63.  
  64. extern  void            _init_files();
  65. extern    int        _set_errno(unsigned);
  66.  
  67. #if !defined( __DLL__ )
  68. extern    int    ___Argc;    /* argument count */
  69. extern    char **    ___Argv;    /* argument vector */
  70. #endif
  71. extern    unsigned __NFiles;
  72. extern  unsigned __near _iomode[_NFILES];
  73.  
  74. #if defined( __DLL__ )
  75.  
  76. extern    unsigned    __dll_initialize();
  77. extern    unsigned    __dll_terminate(void);
  78.  
  79.  
  80. unsigned     _DLLMainInit() {
  81. /*******************************/
  82.  
  83.     CommonInit();
  84.     return( __dll_initialize() );
  85. }
  86.  
  87.  
  88. unsigned     _DLLMainTerm() {
  89. /*******************************/
  90.  
  91.     return( __dll_terminate() );
  92. }
  93.  
  94. #else
  95.  
  96. extern    int    main( int, char ** );
  97.  
  98. #pragma aux     _CMain  "_*";
  99.  
  100.  
  101. void _CMain() {
  102. /*************/
  103.  
  104.     CommonInit();
  105.     exit( main( ___Argc, ___Argv ) );
  106. }
  107.  
  108. #endif
  109.  
  110.  
  111. static    void    CommonInit() {
  112. /****************************/
  113.  
  114.     _init_files();        /* check first 5 handles */
  115.     _amblksiz = 32 * 1024;    /* set minimum memory block allocation */
  116. }
  117.  
  118.  
  119. void _init_files() {
  120. /******************/
  121.     int        handle;
  122.  
  123. #if defined( __OS2__ )
  124.     long    ret_code;
  125.  
  126.     if( __NFiles > 20 ) {
  127.     ret_code = DosSetMaxFH( __NFiles );
  128.     if( ret_code != 0 ) {
  129.         _set_errno( ret_code );
  130.     }
  131.     }
  132. #elif defined(__WINDOWS_386__)
  133.     if( __NFiles > 20 ) {
  134.     __NFiles = SetHandleCount( __NFiles );
  135.     }
  136. #else
  137.     long    ret_code;
  138.     extern long _Set_File_Handle_Count(char,unsigned);
  139.  
  140. #pragma aux  _Set_File_Handle_Count = 0xcd 0x21 /* int 21h   */\
  141.                                       0xd1 0xd0 /* rcl eax,1 */\
  142.                                       0xd1 0xc8 /* ror eax,1 */\
  143.         parm caller     [ah] [ebx] value [eax];
  144.  
  145.     if( __NFiles > 20 ) {
  146.     ret_code = _Set_File_Handle_Count( 0x67, __NFiles );
  147.     if( ret_code < 0 ) {
  148.         _set_errno( (unsigned short)ret_code );
  149.     }
  150.     }
  151. #endif
  152.     for( handle = 0; handle < 5; ++handle ) {
  153.     if( isatty( handle ) )  _iomode[ handle ] |= _ISTTY;
  154.     }
  155. }
  156.