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.

176 lines
3.9 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 "change.h"
  25. /*-----------------------------------------------------------------------
  26. -- Supported commands (now obtained from registry)
  27. ------------------------------------------------------------------------*/
  28. PPROGRAMCALL pProgList = NULL;
  29. /*
  30. * Local function prototypes.
  31. */
  32. void Usage( BOOLEAN bError );
  33. /*************************************************************************
  34. *
  35. * main
  36. * Main function and entry point of the text-based CHANGE menu utility.
  37. *
  38. * ENTRY:
  39. * argc (input)
  40. * count of the command line arguments.
  41. * argv (input)
  42. * vector of strings containing the command line arguments;
  43. * (not used due to always being ANSI strings).
  44. *
  45. * EXIT
  46. * (int) exit code: SUCCESS for success; FAILURE for error.
  47. *
  48. *************************************************************************/
  49. int __cdecl
  50. main( INT argc,
  51. CHAR **argv )
  52. {
  53. PWCHAR arg, *argvW;
  54. PPROGRAMCALL pProg, pProgramCall = NULL;
  55. int len, j, status = FAILURE;
  56. LONG regstatus;
  57. CHAR unused;
  58. setlocale(LC_ALL, ".OCP");
  59. /*
  60. * Obtain the supported CHANGE commands from registry.
  61. */
  62. if ( (regstatus =
  63. RegQueryUtilityCommandList( UTILITY_REG_NAME_CHANGE, &pProgList ))
  64. != ERROR_SUCCESS ) {
  65. ErrorPrintf(IDS_ERROR_REGISTRY_FAILURE, UTILITY_NAME, regstatus);
  66. goto exit;
  67. }
  68. /*
  69. * Massage the command line.
  70. */
  71. argvW = MassageCommandLine((DWORD)argc);
  72. if (argvW == NULL) {
  73. ErrorPrintf(IDS_ERROR_MALLOC);
  74. goto exit;
  75. }
  76. /*
  77. * Check for valid utility name and execute.
  78. */
  79. if ( argc > 1 && *(argvW[1]) ) {
  80. len = wcslen(arg = argvW[1]);
  81. for ( pProg = pProgList->pFirst; pProg != NULL; pProg = pProg->pNext ) {
  82. if ( (len >= pProg->CommandLen) &&
  83. !_wcsnicmp( arg, pProg->Command, len ) ) {
  84. pProgramCall = pProg;
  85. break;
  86. }
  87. }
  88. if ( pProgramCall ) {
  89. if ( ExecProgram(pProgramCall, argc - 2, &argvW[2]) )
  90. goto exit;
  91. } else if ( ((arg[0] == L'-') || (arg[0] == L'/')) &&
  92. (arg[1] == L'?') ) {
  93. /*
  94. * Help requested.
  95. */
  96. Usage(FALSE);
  97. status = SUCCESS;
  98. goto exit;
  99. } else {
  100. /*
  101. * Bad command line.
  102. */
  103. Usage(TRUE);
  104. goto exit;
  105. }
  106. } else {
  107. /*
  108. * Nothing on command line.
  109. */
  110. Usage(TRUE);
  111. goto exit;
  112. }
  113. exit:
  114. if ( pProgList )
  115. RegFreeUtilityCommandList(pProgList); // let's be tidy
  116. return(status);
  117. } /* main() */
  118. /*******************************************************************************
  119. *
  120. * Usage
  121. *
  122. * Output the usage message for this utility.
  123. *
  124. * ENTRY:
  125. * bError (input)
  126. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  127. * message and the output go to stderr; FALSE for no such error
  128. * string and output goes to stdout.
  129. *
  130. * EXIT:
  131. *
  132. *
  133. ******************************************************************************/
  134. void
  135. Usage( BOOLEAN bError )
  136. {
  137. if ( bError ) {
  138. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  139. }
  140. ProgramUsage(UTILITY_NAME, pProgList, bError);
  141. } /* Usage() */