home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c496 / 1.img / STARTUP.386 / CMAIN386.C next >
Encoding:
C/C++ Source or Header  |  1991-08-20  |  4.8 KB  |  114 lines

  1. /*
  2.  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3.  *%       Copyright (C) 1986,1989 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. */
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <io.h>
  50. #include <malloc.h>
  51.  
  52.  
  53. extern  void near       *brk( unsigned ); /* set up curbrk variable */
  54. extern  void            _init_files();
  55.  
  56. extern  int  (*_main_entry_)(char near *, char near *);
  57.  
  58. #pragma aux     _CMain  "_*"    parm routine [eax] [edx];
  59.  
  60.  
  61. extern  unsigned __near _iomode[_NFILES];
  62.  
  63. void _CMain( parm, pgmname )
  64.         char near *parm;        /* DOS command line string */
  65.         char near *pgmname;     /* program name to be placed in argv[0] */
  66.     {
  67.         _init_files();          /* check first 5 handles */
  68.         _amblksiz = 32 * 1024;   /* set minimum memory block allocation */
  69. /*
  70.         If main is defined with no parms, then _main_entry_ contains the
  71.         address of "__Null_Argv", otherwise it contains the address of
  72.         "__Init_Argv" which parses the command line, and then calls "main"
  73.         directly.  This makes programs that don't use argc, argv smaller.
  74. */
  75.         exit( (*_main_entry_)( parm, pgmname ) );
  76.     }
  77.  
  78.  
  79. int __Null_Argv()
  80.     {
  81.         extern  int main(void);
  82.  
  83.         return( main() );
  84.     }
  85.  
  86.  
  87. void _init_files()
  88.     {
  89.         register int handle;
  90.  
  91. #if _NFILES > 20
  92.  
  93.         /* increase the number of file handles beyond 20 */
  94.         /* NOTE: iob.c must also be recompiled */
  95.  
  96.         long ret_code;
  97.         extern int  _set_errno(unsigned);
  98.         extern long _Set_File_Handle_Count(char,unsigned);
  99.  
  100. #pragma aux  _Set_File_Handle_Count = 0xcd 0x21 /* int 21h   */\
  101.                                       0xd1 0xd0 /* rcl eax,1 */\
  102.                                       0xd1 0xc8 /* ror eax,1 */\
  103.         parm caller     [ah] [ebx] value [eax];
  104.  
  105.         ret_code = _Set_File_Handle_Count( 0x67, _NFILES );
  106.         if( ret_code < 0 ) {
  107.             _set_errno( (unsigned short)ret_code );
  108.         }
  109. #endif
  110.         for( handle = 0; handle < 5; ++handle ) {
  111.             if( isatty( handle ) )  _iomode[ handle ] |= _ISTTY;
  112.         }
  113.     }
  114.