Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.0 KiB

  1. /***
  2. *wincmdln.c - process command line for WinMain
  3. *
  4. * Copyright (c) 1997-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Prepare command line to be passed to [w]WinMain.
  8. *
  9. *Revision History:
  10. * 06-23-97 GJF Module created by extracting the code from crt0.c
  11. * 03-24-01 PML Protect against null _[aw]cmdln (vs7#229081)
  12. *
  13. *******************************************************************************/
  14. #include <internal.h>
  15. #include <tchar.h>
  16. #define SPACECHAR _T(' ')
  17. #define DQUOTECHAR _T('\"')
  18. /*
  19. * Flag to ensure multibyte ctype table is only initialized once
  20. */
  21. extern int __mbctype_initialized;
  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. _TUCHAR * __cdecl
  44. #ifdef WPRFLAG
  45. _wwincmdln(
  46. #else
  47. _wincmdln(
  48. #endif
  49. void
  50. )
  51. {
  52. _TUCHAR *lpszCommandLine;
  53. #ifdef _MBCS
  54. /*
  55. * If necessary, initialize the multibyte ctype table
  56. */
  57. if ( __mbctype_initialized == 0 )
  58. __initmbctable();
  59. #endif
  60. /*
  61. * Skip past program name (first token in command line).
  62. * Check for and handle quoted program name.
  63. */
  64. #ifdef WPRFLAG
  65. lpszCommandLine = _wcmdln == NULL ? L"" : (wchar_t *)_wcmdln;
  66. #else
  67. lpszCommandLine = _acmdln == NULL ? "" : (unsigned char *)_acmdln;
  68. #endif
  69. if ( *lpszCommandLine == DQUOTECHAR ) {
  70. /*
  71. * Scan, and skip over, subsequent characters until
  72. * another double-quote or a null is encountered.
  73. */
  74. while ( (*(++lpszCommandLine) != DQUOTECHAR)
  75. && (*lpszCommandLine != _T('\0')) )
  76. {
  77. #ifdef _MBCS
  78. if (_ismbblead(*lpszCommandLine))
  79. lpszCommandLine++;
  80. #endif
  81. }
  82. /*
  83. * If we stopped on a double-quote (usual case), skip
  84. * over it.
  85. */
  86. if ( *lpszCommandLine == DQUOTECHAR )
  87. lpszCommandLine++;
  88. }
  89. else {
  90. while (*lpszCommandLine > SPACECHAR)
  91. lpszCommandLine++;
  92. }
  93. /*
  94. * Skip past any white space preceeding the second token.
  95. */
  96. while (*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
  97. lpszCommandLine++;
  98. return lpszCommandLine;
  99. }