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.

289 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Replace
  5. Abstract:
  6. This module contains the definition for the REPLACE class, which
  7. implements the DOS5-compatible Replace utility.
  8. Author:
  9. Ramon Juan San Andres (ramonsa) 01-May-1990
  10. Revision History:
  11. --*/
  12. #if !defined( _REPLACE_ )
  13. #define _REPLACE_
  14. #include "object.hxx"
  15. #include "keyboard.hxx"
  16. #include "program.hxx"
  17. //
  18. // Exit codes
  19. //
  20. #define EXIT_NORMAL 0
  21. #define EXIT_FILE_NOT_FOUND 2
  22. #define EXIT_PATH_NOT_FOUND 3
  23. #define EXIT_ACCESS_DENIED 5
  24. #define EXIT_NO_MEMORY 8
  25. #define EXIT_COMMAND_LINE_ERROR 11
  26. #define EXIT_INVALID_DRIVE 15
  27. //
  28. // Forward references
  29. //
  30. DECLARE_CLASS( ARRAY );
  31. DECLARE_CLASS( FSN_DIRECTORY );
  32. DECLARE_CLASS( FSNODE );
  33. DECLARE_CLASS( KEYBOARD );
  34. DECLARE_CLSSS( PATH );
  35. DECLARE_CLASS( WSTRING );
  36. DECLARE_CLASS( REPLACE );
  37. class REPLACE : public PROGRAM {
  38. public:
  39. DECLARE_CONSTRUCTOR( REPLACE );
  40. NONVIRTUAL
  41. ~REPLACE (
  42. );
  43. NONVIRTUAL
  44. BOOLEAN
  45. Initialize (
  46. );
  47. NONVIRTUAL
  48. BOOLEAN
  49. DoReplace (
  50. );
  51. private:
  52. NONVIRTUAL
  53. VOID
  54. AbortIfCtrlC(
  55. VOID
  56. );
  57. NONVIRTUAL
  58. BOOLEAN
  59. AddFiles (
  60. IN OUT PFSN_DIRECTORY DestinationDirectory
  61. );
  62. NONVIRTUAL
  63. VOID
  64. CheckArgumentConsistency (
  65. );
  66. NONVIRTUAL
  67. BOOLEAN
  68. CopyTheFile (
  69. IN PCPATH SrcPath,
  70. IN PCPATH DstPath
  71. );
  72. NONVIRTUAL
  73. VOID
  74. CtrlCHandler (
  75. IN ULONG CtrlType
  76. );
  77. NONVIRTUAL
  78. VOID
  79. DeallocateThings (
  80. );
  81. NONVIRTUAL
  82. VOID
  83. DisplayMessageAndExit (
  84. IN MSGID MsgId,
  85. IN PCWSTRING String,
  86. IN ULONG ExitCode
  87. );
  88. NONVIRTUAL
  89. VOID
  90. ExitWithError(
  91. IN DWORD ErrorCode
  92. );
  93. NONVIRTUAL
  94. VOID
  95. GetArgumentsCmd(
  96. );
  97. NONVIRTUAL
  98. VOID
  99. GetDirectoryAndPattern(
  100. IN PPATH Path,
  101. OUT PFSN_DIRECTORY *Directory,
  102. OUT PWSTRING *Pattern
  103. );
  104. NONVIRTUAL
  105. VOID
  106. GetDirectory(
  107. IN PCPATH Path,
  108. OUT PFSN_DIRECTORY *Directory
  109. );
  110. NONVIRTUAL
  111. PARRAY
  112. GetFileArray(
  113. IN PFSN_DIRECTORY Directory,
  114. IN PWSTRING Pattern
  115. );
  116. NONVIRTUAL
  117. VOID
  118. InitializeThings (
  119. );
  120. NONVIRTUAL
  121. VOID
  122. ParseArguments(
  123. IN PWSTRING CmdLine,
  124. OUT PARRAY ArgArray
  125. );
  126. NONVIRTUAL
  127. BOOLEAN
  128. Prompt (
  129. IN MSGID MessageId,
  130. IN PCPATH Path
  131. );
  132. NONVIRTUAL
  133. PWSTRING
  134. QueryMessageString (
  135. IN MSGID MsgId
  136. );
  137. NONVIRTUAL
  138. BOOLEAN
  139. ReplaceFiles (
  140. IN OUT PFSN_DIRECTORY DestinationDirectory
  141. );
  142. STATIC
  143. BOOLEAN
  144. Replacer (
  145. IN PVOID This,
  146. IN OUT PFSNODE DirectoryNode,
  147. IN PPATH DummyPath
  148. );
  149. NONVIRTUAL
  150. VOID
  151. SetArguments(
  152. );
  153. //
  154. // Command-line things
  155. //
  156. PPATH _SourcePath;
  157. PPATH _DestinationPath;
  158. BOOLEAN _AddSwitch;
  159. BOOLEAN _PromptSwitch;
  160. BOOLEAN _ReadOnlySwitch;
  161. BOOLEAN _SubdirSwitch;
  162. BOOLEAN _CompareTimeSwitch;
  163. BOOLEAN _WaitSwitch;
  164. //
  165. // Counter of Added/Replaced files
  166. //
  167. ULONG _FilesAdded;
  168. ULONG _FilesReplaced;
  169. //
  170. // Source directory and corresponding filename pattern
  171. //
  172. PFSN_DIRECTORY _SourceDirectory;
  173. PWSTRING _Pattern;
  174. //
  175. // Array of files in source directory
  176. //
  177. PARRAY _FilesInSrc;
  178. //
  179. // Buffers to hold strings in PSTR form
  180. //
  181. LPWSTR _PathString1;
  182. ULONG _PathString1Size;
  183. LPWSTR _PathString2;
  184. ULONG _PathString2Size;
  185. //
  186. // The keyboard
  187. //
  188. PKEYBOARD _Keyboard;
  189. DSTRING _AddPattern;
  190. DSTRING _PromptPattern;
  191. DSTRING _ReadOnlyPattern;
  192. DSTRING _SubdirPattern;
  193. DSTRING _CompareTimePattern;
  194. DSTRING _WaitPattern;
  195. DSTRING _HelpPattern;
  196. DSTRING _Switches;
  197. DSTRING _MultipleSwitch;
  198. };
  199. INLINE
  200. VOID
  201. REPLACE::AbortIfCtrlC (
  202. VOID
  203. )
  204. /*++
  205. Routine Description:
  206. Aborts the program if Ctrl-C was hit.
  207. Arguments:
  208. None.
  209. Return Value:
  210. None.
  211. Notes:
  212. --*/
  213. {
  214. if ( _Keyboard->GotABreak() ) {
  215. exit( EXIT_PATH_NOT_FOUND );
  216. }
  217. }
  218. #endif // _REPLACE_