Subversion Repositories Kolibri OS

Rev

Rev 952 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Implementation of __NTMain().
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <malloc.h>
  38. #include <windows.h>
  39.  
  40. #include "kolibri.h"
  41.  
  42. //#include "sigtab.h"
  43. #include "initfini.h"
  44. #include "initarg.h"
  45.  
  46. int  __appcwdlen;
  47. char* __appcwd;
  48. extern char *LpCmdLine;
  49. extern char *LpPgmName;
  50.  
  51. _WCRTLINK void (*__process_fini)(unsigned,unsigned) = 0;
  52.  
  53. #ifdef __SW_BR
  54.     _WCRTLINK extern    void    (*__process_fini)( unsigned, unsigned );
  55.     extern      void    __CommonInit( void );
  56.     extern      int     wmain( int, wchar_t ** );
  57.     extern      int     main( int, char ** );
  58. #else
  59.     extern      void            __NTMainInit( void *, void * );
  60.     #ifdef __WIDECHAR__
  61.         extern  void            __wCMain( void );
  62.         #if defined(_M_IX86)
  63.             #pragma aux __wCMain  "*"
  64.         #endif
  65.     #else
  66.         extern  void            __CMain( void );
  67.         #if defined(_M_IX86)
  68.             #pragma aux __CMain  "*"
  69.         #endif
  70.     #endif
  71.     extern      unsigned        __ThreadDataSize;
  72. #endif
  73.  
  74. void __F_NAME(__NTMain,__wNTMain)( void )
  75. /***************************************/
  76. {
  77.  
  78.    init_heap();
  79.  
  80.     __process_fini = &__FiniRtns;
  81.    __InitRtns( 255 );
  82.    __CommonInit();
  83.    __initPOSIXHandles();
  84.    __appcwdlen = strrchr(_LpPgmName, '/') - _LpPgmName + 1;
  85.    __appcwdlen = __appcwdlen > 512 ? 512 : __appcwdlen;
  86.    __appcwd= (char*)malloc(__appcwdlen);
  87.    strncpy(__appcwd, _LpPgmName, __appcwdlen);
  88.    __appcwd[__appcwdlen] = 0;
  89.    ___Argv[0] = _LpPgmName;
  90.    if( *_LpCmdLine != 0)
  91.    {
  92.       ___Argc = 2;
  93.       ___Argv[1] = _LpCmdLine;
  94.    } else ___Argc = 1;
  95.  
  96.    #ifdef __WIDECHAR__
  97.       exit( wmain( ___wArgc, ___wArgv ) );
  98.    #else
  99.       exit( main( ___Argc, ___Argv ) );
  100.    #endif
  101. }
  102.  
  103. #ifdef __WIDECHAR__
  104.     #if defined(_M_IX86)
  105.         #pragma aux __wNTMain "*"
  106.     #endif
  107. #else
  108.     #if defined(_M_IX86)
  109.         #pragma aux __NTMain "*"
  110.     #endif
  111. #endif
  112.  
  113. #pragma aux __exit aborts;
  114.  
  115. _WCRTLINK void __exit( unsigned ret_code )
  116. {
  117.   __FiniRtns( 0, FINI_PRIORITY_EXIT-1 );
  118.   _asm
  119.   {
  120.     mov eax, -1
  121.     int 0x40
  122.   }
  123. }
  124.  
  125.  
  126.