Source code of Windows XP (NT5)
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.

166 lines
3.6 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /*************************************************************************
  3. *
  4. * CMDLINE.C
  5. *
  6. * Command line parser for WinFrame User Configuration conversion utility.
  7. *
  8. * copyright notice: Copyright 1997, Citrix Systems Inc.
  9. *
  10. * Author: Bruce Fortune
  11. *
  12. * $Log: U:\NT\PRIVATE\UTILS\citrix\cnvrtuc\VCS\cmdline.c $
  13. *
  14. * Rev 1.5 May 04 1998 18:04:00 bills
  15. * Fixes for MS bug #2109, OEM->ANSI conversion and moving strings to the rc file.
  16. *
  17. * Rev 1.4 03 Nov 1997 18:23:54 scottn
  18. * MultiUser-->Terminal Server
  19. *
  20. * Rev 1.3 22 Aug 1997 14:48:36 scottn
  21. * Change WinFrame to Windows NT MultiUser
  22. *
  23. * Rev 1.2 Jun 26 1997 18:17:24 billm
  24. * move to WF40 tree
  25. *
  26. * Rev 1.1 23 Jun 1997 16:17:22 butchd
  27. * update
  28. *
  29. * Rev 1.0 15 Feb 1997 09:51:48 brucef
  30. * Initial revision.
  31. *
  32. *************************************************************************/
  33. /*
  34. * Includes
  35. */
  36. #undef UNICODE
  37. #define UNICODE 1
  38. #include <nt.h>
  39. #include <ntrtl.h>
  40. #include <nturtl.h>
  41. #include <windows.h>
  42. #include <winbase.h>
  43. #include <winerror.h>
  44. // #include <citrix\cxstatus.h>
  45. #include <winsta.h>
  46. #include <icadd.h>
  47. #include <icaapi.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <utilsub.h>
  51. #include "resource.h"
  52. #include <printfoa.h>
  53. #if MAX_COMPUTERNAME_LENGTH > DOMAIN_LENGTH
  54. #define _COMPUTERNAME_LENGTH MAX_COMPUTER_NAME_LENGTH
  55. #else
  56. #define _COMPUTERNAME_LENGTH DOMAIN_LENGTH
  57. #endif
  58. /*
  59. * Global variables
  60. */
  61. ULONG fHelp = FALSE;
  62. extern ULONG fAll;
  63. extern WCHAR UserName[ USERNAME_LENGTH + 1 ];
  64. extern WCHAR DomainName[ _COMPUTERNAME_LENGTH + 1 ];
  65. /*
  66. * Command line parsing strucutre
  67. */
  68. TOKMAP ptm[] =
  69. {
  70. {L"/DOMAIN",
  71. TMFLAG_REQUIRED,
  72. TMFORM_STRING,
  73. DOMAIN_LENGTH,
  74. &DomainName },
  75. {L"/USER",
  76. TMFLAG_OPTIONAL,
  77. TMFORM_STRING,
  78. USERNAME_LENGTH,
  79. &UserName },
  80. {L"/ALL",
  81. TMFLAG_OPTIONAL,
  82. TMFORM_BOOLEAN,
  83. sizeof(ULONG),
  84. &fAll },
  85. {L"/?",
  86. TMFLAG_OPTIONAL,
  87. TMFORM_BOOLEAN,
  88. sizeof(ULONG),
  89. &fHelp },
  90. {0, 0, 0, 0, 0 }
  91. };
  92. void Print( int nResourceID, ... );
  93. BOOLEAN
  94. ProcessCommandLine(
  95. int argc,
  96. char *argv[]
  97. )
  98. {
  99. WCHAR *CmdLine;
  100. WCHAR **argvW;
  101. NTSTATUS rc;
  102. LONG Error;
  103. int i;
  104. /*
  105. * We can't use argv[] because its always ANSI, regardless of UNICODE
  106. */
  107. CmdLine = GetCommandLineW();
  108. /*
  109. * Massage the new command line to look like an argv[] type
  110. * because ParseCommandLine() depends on this format
  111. */
  112. argvW = (WCHAR **)malloc( sizeof(WCHAR *) * (argc+1) );
  113. if( argvW == NULL )
  114. return( FALSE );
  115. argvW[0] = wcstok(CmdLine, L" ");
  116. for(i=1; i < argc; i++){
  117. argvW[i] = wcstok(0, L" ");
  118. OEM2ANSIW(argvW[i], wcslen(argvW[i]));
  119. }
  120. argvW[argc] = NULL;
  121. /*
  122. * parse the cmd line without parsing the program name (argc-1, argv+1)
  123. */
  124. rc = ParseCommandLine( argc-1, argvW+1, ptm, PCL_FLAG_NO_CLEAR_MEMORY );
  125. /*
  126. * Check for error from ParseCommandLine
  127. */
  128. if ( fHelp ||
  129. rc ||
  130. DomainName[0] == L'\0' ||
  131. (fAll && UserName[0] != L'\0') ||
  132. (!fAll && UserName[0] == L'\0') ) {
  133. Print(IDS_NEWLINE);
  134. Print(IDS_USAGE1, argv[0] );
  135. Print(IDS_NEWLINE);
  136. Print(IDS_USAGE2, argv[0] );
  137. Print(IDS_USAGE3);
  138. Print(IDS_USAGE4);
  139. Print(IDS_USAGE5);
  140. Print(IDS_USAGE6);
  141. Print(IDS_USAGE7);
  142. Print(IDS_NEWLINE);
  143. Print(IDS_USAGE8);
  144. Print(IDS_USAGE9);
  145. Print(IDS_NEWLINE);
  146. return(FALSE );
  147. }
  148. return( TRUE );
  149. }