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.

171 lines
3.9 KiB

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