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.

192 lines
4.7 KiB

  1. // Copyright (c) 1998-1999 Microsoft Corporation
  2. /*************************************************************************
  3. *
  4. * CHANGE.C
  5. * This module is the CHANGE utility code.
  6. *
  7. *
  8. *************************************************************************/
  9. #include <windows.h>
  10. #include <winnt.h>
  11. #include <stdio.h>
  12. // #include <ntddkbd.h>
  13. // #include <ntddmou.h>
  14. #include <winsta.h>
  15. #include <regapi.h>
  16. #include <stdlib.h>
  17. #include <time.h>
  18. #include <utilsub.h>
  19. #include <process.h>
  20. #include <string.h>
  21. #include <malloc.h>
  22. #include <printfoa.h>
  23. #include <locale.h>
  24. #include <winnlsp.h>
  25. #include "change.h"
  26. // max length of the locale string
  27. #define MAX_LOCALE_STRING 64
  28. /*-----------------------------------------------------------------------
  29. -- Supported commands (now obtained from registry)
  30. ------------------------------------------------------------------------*/
  31. PPROGRAMCALL pProgList = NULL;
  32. /*
  33. * Local function prototypes.
  34. */
  35. void Usage( BOOLEAN bError );
  36. /*************************************************************************
  37. *
  38. * main
  39. * Main function and entry point of the text-based CHANGE menu utility.
  40. *
  41. * ENTRY:
  42. * argc (input)
  43. * count of the command line arguments.
  44. * argv (input)
  45. * vector of strings containing the command line arguments;
  46. * (not used due to always being ANSI strings).
  47. *
  48. * EXIT
  49. * (int) exit code: SUCCESS for success; FAILURE for error.
  50. *
  51. *************************************************************************/
  52. int __cdecl
  53. main( INT argc,
  54. CHAR **argv )
  55. {
  56. PWCHAR arg, *argvW;
  57. PPROGRAMCALL pProg, pProgramCall = NULL;
  58. int len, j, status = FAILURE;
  59. LONG regstatus;
  60. CHAR unused;
  61. WCHAR wszString[MAX_LOCALE_STRING + 1];
  62. setlocale(LC_ALL, ".OCP");
  63. // We don't want LC_CTYPE set the same as the others or else we will see
  64. // garbage output in the localized version, so we need to explicitly
  65. // set it to correct console output code page
  66. _snwprintf(wszString, sizeof(wszString)/sizeof(WCHAR), L".%d", GetConsoleOutputCP());
  67. wszString[sizeof(wszString)/sizeof(WCHAR) - 1] = L'\0';
  68. _wsetlocale(LC_CTYPE, wszString);
  69. SetThreadUILanguage(0);
  70. /*
  71. * Obtain the supported CHANGE commands from registry.
  72. */
  73. if ( (regstatus =
  74. RegQueryUtilityCommandList( UTILITY_REG_NAME_CHANGE, &pProgList ))
  75. != ERROR_SUCCESS ) {
  76. ErrorPrintf(IDS_ERROR_REGISTRY_FAILURE, UTILITY_NAME, regstatus);
  77. goto exit;
  78. }
  79. /*
  80. * Massage the command line.
  81. */
  82. argvW = MassageCommandLine((DWORD)argc);
  83. if (argvW == NULL) {
  84. ErrorPrintf(IDS_ERROR_MALLOC);
  85. goto exit;
  86. }
  87. /*
  88. * Check for valid utility name and execute.
  89. */
  90. if ( argc > 1 && *(argvW[1]) ) {
  91. len = wcslen(arg = argvW[1]);
  92. for ( pProg = pProgList->pFirst; pProg != NULL; pProg = pProg->pNext ) {
  93. if ( (len >= pProg->CommandLen) &&
  94. !_wcsnicmp( arg, pProg->Command, len ) ) {
  95. pProgramCall = pProg;
  96. break;
  97. }
  98. }
  99. if ( pProgramCall ) {
  100. if ( ExecProgram(pProgramCall, argc - 2, &argvW[2]) )
  101. goto exit;
  102. } else if ( ((arg[0] == L'-') || (arg[0] == L'/')) &&
  103. (arg[1] == L'?') ) {
  104. /*
  105. * Help requested.
  106. */
  107. Usage(FALSE);
  108. status = SUCCESS;
  109. goto exit;
  110. } else {
  111. /*
  112. * Bad command line.
  113. */
  114. Usage(TRUE);
  115. goto exit;
  116. }
  117. } else {
  118. /*
  119. * Nothing on command line.
  120. */
  121. Usage(TRUE);
  122. goto exit;
  123. }
  124. exit:
  125. if ( pProgList )
  126. RegFreeUtilityCommandList(pProgList); // let's be tidy
  127. return(status);
  128. } /* main() */
  129. /*******************************************************************************
  130. *
  131. * Usage
  132. *
  133. * Output the usage message for this utility.
  134. *
  135. * ENTRY:
  136. * bError (input)
  137. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  138. * message and the output go to stderr; FALSE for no such error
  139. * string and output goes to stdout.
  140. *
  141. * EXIT:
  142. *
  143. *
  144. ******************************************************************************/
  145. void
  146. Usage( BOOLEAN bError )
  147. {
  148. if ( bError ) {
  149. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  150. }
  151. ProgramUsage(UTILITY_NAME, pProgList, bError);
  152. } /* Usage() */