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.

214 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Mode
  5. Abstract:
  6. Mode utility
  7. Author:
  8. Ramon Juan San Andres (ramonsa) 26-Jun-1991
  9. Revision History:
  10. --*/
  11. #include "mode.hxx"
  12. #include "system.hxx"
  13. //
  14. // Message stream
  15. //
  16. PSTREAM_MESSAGE Message;
  17. //
  18. // DeviceHandler is an array of pointers to the different device
  19. // handlers.
  20. //
  21. DEVICE_HANDLER DeviceHandler[ NUMBER_OF_DEVICE_TYPES ] = {
  22. LptHandler,
  23. ComHandler,
  24. ConHandler,
  25. CommonHandler
  26. };
  27. VOID
  28. InitializeMode (
  29. );
  30. VOID
  31. DeallocateResources (
  32. );
  33. PSTREAM
  34. Get_Standard_Input_Stream();
  35. PSTREAM
  36. Get_Standard_Output_Stream();
  37. PSTREAM
  38. Get_Standard_Error_Stream();
  39. VOID __cdecl
  40. main (
  41. )
  42. /*++
  43. Routine Description:
  44. Main function of the Mode utility
  45. Arguments:
  46. None.
  47. Return Value:
  48. None.
  49. Notes:
  50. --*/
  51. {
  52. PREQUEST_HEADER Request;
  53. //
  54. // Initialize whatever is necessary
  55. //
  56. InitializeMode();
  57. //
  58. // Verify the OS version
  59. //
  60. if ( !SYSTEM::IsCorrectVersion() ) {
  61. DisplayMessageAndExit( MODE_ERROR_INCORRECT_OS_VERSION,
  62. NULL,
  63. (ULONG)EXIT_ERROR );
  64. }
  65. //
  66. // Obtain a request from the command line. Note that the
  67. // first field of the request is the device type.
  68. //
  69. Request = GetRequest();
  70. DebugPtrAssert( Request );
  71. DebugAssert( Request->DeviceType <= DEVICE_TYPE_ALL );
  72. //
  73. // Let the device handler for the specified type take care of the
  74. // request.
  75. //
  76. DebugPtrAssert( DeviceHandler[ Request->DeviceType ] );
  77. DeviceHandler[ Request->DeviceType ]( Request );
  78. //
  79. // Deallocate resources
  80. //
  81. FREE( Request );
  82. DeallocateResources();
  83. //
  84. // We're done
  85. //
  86. ExitMode( EXIT_SUCCESS );
  87. }
  88. VOID
  89. InitializeMode (
  90. )
  91. /*++
  92. Routine Description:
  93. Allocates resources and initializes Mode structures
  94. Arguments:
  95. None.
  96. Return Value:
  97. None.
  98. Notes:
  99. --*/
  100. {
  101. if ( //
  102. // Construct and initialize a STREAM_MESSAGE.
  103. //
  104. !(Message = NEW STREAM_MESSAGE ) ||
  105. !Get_Standard_Output_Stream() ||
  106. !Message->Initialize( Get_Standard_Output_Stream(),
  107. Get_Standard_Input_Stream() )
  108. ) {
  109. //
  110. // We don't have Message, so we cannot display the error
  111. // text.
  112. //
  113. exit( EXIT_ERROR );
  114. }
  115. //
  116. // Allocate resources which are private to each type of device
  117. //
  118. ComAllocateStuff();
  119. }
  120. VOID
  121. DeallocateResources (
  122. )
  123. /*++
  124. Routine Description:
  125. Deallocates resources allocated in InitializeMode
  126. Arguments:
  127. None.
  128. Return Value:
  129. None.
  130. Notes:
  131. --*/
  132. {
  133. DELETE( Message );
  134. ComDeAllocateStuff();
  135. }