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.

173 lines
3.9 KiB

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