home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / wincmdln.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  3KB  |  108 lines

  1. /***
  2. *wincmdln.c - process command line for WinMain
  3. *
  4. *       Copyright (c) 1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Prepare command line to be passed to [w]WinMain.
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <internal.h>
  12. #include <tchar.h>
  13.  
  14. #define SPACECHAR   _T(' ')
  15. #define DQUOTECHAR  _T('\"')
  16.  
  17. /*
  18.  * Flag to ensure multibyte ctype table is only initialized once
  19.  */
  20. extern int __mbctype_initialized;
  21.  
  22. /***
  23. *_[w]wincmdln
  24. *
  25. *Purpose:
  26. *       Extract the command line tail to be passed to WinMain.
  27. *
  28. *       Be warned! This code was originally implemented by the NT group and
  29. *       has remained pretty much unchanged since 12-91. It should be changed
  30. *       only with extreme care since there are undoubtedly many apps which
  31. *       depend on its historical behavior.
  32. *
  33. *Entry:
  34. *       The global variable _[a|w]cmdln is set to point at the complete
  35. *       command line.
  36. *
  37. *Exit:
  38. *       Returns a pointer to the command line tail.
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43.  
  44. _TUCHAR * __cdecl
  45. #ifdef WPRFLAG
  46. _wwincmdln(
  47. #else  /* WPRFLAG */
  48. _wincmdln(
  49. #endif  /* WPRFLAG */
  50.         void
  51.         )
  52. {
  53.         _TUCHAR *lpszCommandLine;
  54.  
  55. #ifdef _MBCS
  56.         /*
  57.          * If necessary, initialize the multibyte ctype table
  58.          */
  59.         if ( __mbctype_initialized == 0 )
  60.             __initmbctable();
  61. #endif  /* _MBCS */
  62.  
  63.         /*
  64.          * Skip past program name (first token in command line).
  65.          * Check for and handle quoted program name.
  66.          */
  67. #ifdef WPRFLAG
  68.         lpszCommandLine = (wchar_t *)_wcmdln;
  69. #else  /* WPRFLAG */
  70.         lpszCommandLine = (unsigned char *)_acmdln;
  71. #endif  /* WPRFLAG */
  72.  
  73.         if ( *lpszCommandLine == DQUOTECHAR ) {
  74.             /*
  75.              * Scan, and skip over, subsequent characters until
  76.              * another double-quote or a null is encountered.
  77.              */
  78.  
  79.             while ( (*(++lpszCommandLine) != DQUOTECHAR)
  80.                     && (*lpszCommandLine != _T('\0')) )
  81.             {
  82. #ifdef _MBCS
  83.                 if (_ismbblead(*lpszCommandLine))
  84.                     lpszCommandLine++;
  85. #endif  /* _MBCS */
  86.             }
  87.  
  88.             /*
  89.              * If we stopped on a double-quote (usual case), skip
  90.              * over it.
  91.              */
  92.             if ( *lpszCommandLine == DQUOTECHAR )
  93.                 lpszCommandLine++;
  94.         }
  95.         else {
  96.             while (*lpszCommandLine > SPACECHAR)
  97.                 lpszCommandLine++;
  98.         }
  99.  
  100.         /*
  101.          * Skip past any white space preceeding the second token.
  102.          */
  103.         while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
  104.             lpszCommandLine++;
  105.  
  106.         return lpszCommandLine;
  107. }
  108.