ReactOS 0.4.15-dev-8348-gc1b9bb5
replace.c File Reference
#include "replace.h"
Include dependency graph for replace.c:

Go to the source code of this file.

Enumerations

enum  {
  REPLACE_ADD = 0x001 , REPLACE_CONFIRM = 0x002 , REPLACE_READ_ONLY = 0x004 , REPLACE_SUBDIR = 0x008 ,
  REPLACE_DISK = 0x010 , REPLACE_UPDATE = 0x020
}
 

Functions

void invalid_switch (LPTSTR is)
 
void getPath (TCHAR *out, LPTSTR in)
 
INT replace (TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
 
INT recReplace (DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
 
INT recFindSubDirs (DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
 
INT cmd_replace (INT argc, WCHAR **argv)
 
static BOOL CALLBACK CtrlHandlerRoutine (DWORD dwCtrlType)
 
int wmain (int argc, WCHAR **argvW)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REPLACE_ADD 
REPLACE_CONFIRM 
REPLACE_READ_ONLY 
REPLACE_SUBDIR 
REPLACE_DISK 
REPLACE_UPDATE 

Definition at line 11 of file replace.c.

12{
13 REPLACE_ADD = 0x001, /* /A */
14 REPLACE_CONFIRM = 0x002, /* /P */
15 REPLACE_READ_ONLY = 0x004, /* /R */
16 REPLACE_SUBDIR = 0x008, /* /S */
17 REPLACE_DISK = 0x010, /* /W */
18 REPLACE_UPDATE = 0x020, /* /U */
19};
@ REPLACE_UPDATE
Definition: replace.c:18
@ REPLACE_READ_ONLY
Definition: replace.c:15
@ REPLACE_SUBDIR
Definition: replace.c:16
@ REPLACE_DISK
Definition: replace.c:17
@ REPLACE_ADD
Definition: replace.c:13
@ REPLACE_CONFIRM
Definition: replace.c:14

Function Documentation

◆ cmd_replace()

INT cmd_replace ( INT  argc,
WCHAR **  argv 
)

Definition at line 380 of file replace.c.

381{
382 LPTSTR *arg;
383 INT i, filesReplaced = 0, nFiles, srcIndex = -1, destIndex = -1;
384 DWORD dwFlags = 0;
385 TCHAR szDestPath[MAX_PATH], szSrcPath[MAX_PATH], tmpSrcPath[MAX_PATH];
386 BOOL doMore = TRUE;
387
388 --argc;
389 ++argv;
390
391 /* Help wanted? */
392 if (argc == 1 && !_tcscmp(argv[0], _T("/?")))
393 {
395 return EXIT_SUCCESS;
396 }
397
398 /* Divide the argument in to an array of c-strings */
399 arg = argv;
400 nFiles = argc;
401
402 /* Read options */
403 for (i = 0; i < argc; i++)
404 {
405 if (arg[i][0] == _T('/'))
406 {
407 if (_tcslen(arg[i]) == 2)
408 {
409 switch (_totupper(arg[i][1]))
410 {
411 case _T('A'):
413 break;
414 case _T('P'):
416 break;
417 case _T('R'):
419 break;
420 case _T('S'):
422 break;
423 case _T('W'):
425 break;
426 case _T('U'):
428 break;
429 default:
431 return 11; /* Error */
432 }
433 }
434 else
435 {
437 return 11; /* Error */
438 }
439 nFiles--;
440 }
441 else
442 {
443 if (srcIndex == -1)
444 {
445 srcIndex = i;
446 }
447 else if (destIndex == -1)
448 {
449 destIndex = i;
450 }
451 else
452 {
454 return 11; /* Error */
455 }
456 }
457 }
458
459 /* See so that at least source is there */
460 if (nFiles < 1)
461 {
464 return 11; /* Error */
465 }
466
467 /* Check so that not both update and add switch is added and subdir */
469 {
472 return 11; /* Error */
473 }
474
475 /* If we have a destination get the full path */
476 if (destIndex != -1)
477 {
478 if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':')
479 GetRootPath(arg[destIndex],szDestPath,MAX_PATH);
480 else
481 {
482 /* Check for wildcards in destination directory */
483 if (_tcschr (arg[destIndex], _T('*')) != NULL ||
484 _tcschr (arg[destIndex], _T('?')) != NULL)
485 {
488 return 3; /* Error */
489 }
490 getPath(szDestPath, arg[destIndex]);
491 /* Make sure that destination exists */
492 if (!IsExistingDirectory(szDestPath))
493 {
496 return 3; /* Error */
497 }
498 }
499 }
500 else
501 {
502 /* Dest is current dir */
503 GetCurrentDirectory(MAX_PATH,szDestPath);
504 }
505
506 /* Get the full source path */
507 if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':'))
508 getPath(szSrcPath, arg[srcIndex]);
509 else
510 _tcscpy(szSrcPath,arg[srcIndex]);
511
512 /* Source does not have wildcards */
513 if (_tcschr (arg[srcIndex], _T('*')) == NULL &&
514 _tcschr (arg[srcIndex], _T('?')) == NULL)
515 {
516 /* Check so that source is not a directory, because that is not allowed */
517 if (IsExistingDirectory(szSrcPath))
518 {
521 return 2; /* Error */
522 }
523 /* Check if the file exists */
524 if (!IsExistingFile(szSrcPath))
525 {
527 return 2; /* Error */
528 }
529 }
530
531 /* /w switch is set so wait for any key to be pressed */
532 if (dwFlags & REPLACE_DISK)
533 {
534 msg_pause();
535 cgetchar();
536 }
537
538 /* Add an extra \ to the destination path if needed */
539 if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\'))
540 _tcscat(szDestPath, _T("\\"));
541
542 /* Save source path */
543 _tcscpy(tmpSrcPath,szSrcPath);
544 /* Replace in dest dir */
545 filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore);
546 /* If subdir switch is set replace in the subdirs to */
547 if (dwFlags & REPLACE_SUBDIR && doMore)
548 {
549 filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore);
550 }
551
552 /* If source == dest write no more */
553 if (filesReplaced != -1)
554 {
555 /* No files replaced */
556 if (filesReplaced==0)
557 {
558 /* Add switch dependent output */
559 if (dwFlags & REPLACE_ADD)
561 else
563 }
564 /* Some files replaced */
565 else
566 {
567 /* Add switch dependent output */
568 if (dwFlags & REPLACE_ADD)
570 else
572 }
573 }
574
575 /* Return memory */
576 return EXIT_SUCCESS;
577}
static int argc
Definition: ServiceArgs.c:12
#define STRING_REPLACE_HELP1
Definition: resource.h:11
#define STRING_REPLACE_HELP7
Definition: resource.h:16
#define STRING_REPLACE_HELP3
Definition: resource.h:13
#define STRING_REPLACE_HELP4
Definition: resource.h:14
#define STRING_REPLACE_HELP2
Definition: resource.h:12
#define STRING_REPLACE_ERROR4
Definition: resource.h:6
#define STRING_REPLACE_ERROR6
Definition: resource.h:8
#define STRING_REPLACE_ERROR2
Definition: resource.h:4
#define STRING_REPLACE_HELP8
Definition: resource.h:17
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define MAX_PATH
Definition: compat.h:34
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define _totupper
Definition: tchar.h:1509
#define _tcschr
Definition: tchar.h:1406
#define argv
Definition: mplay32.c:18
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
void invalid_switch(LPTSTR is)
Definition: replace.c:22
INT recReplace(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:205
void getPath(TCHAR *out, LPTSTR in)
Definition: replace.c:29
INT recFindSubDirs(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:303
BOOL IsExistingDirectory(IN LPCTSTR pszPath)
Definition: util.c:104
BOOL IsExistingFile(IN LPCTSTR pszPath)
Definition: util.c:98
INT GetRootPath(IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
Definition: util.c:21
TCHAR cgetchar(VOID)
Definition: util.c:242
VOID msg_pause(VOID)
Definition: util.c:210
#define ConOutResPrintf(uID,...)
Definition: replace.h:31
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define GetCurrentDirectory
Definition: winbase.h:3805
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
void * arg
Definition: msvc.h:10
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define _tcslen
Definition: xmlstorage.h:198

Referenced by wmain().

◆ CtrlHandlerRoutine()

static BOOL CALLBACK CtrlHandlerRoutine ( DWORD  dwCtrlType)
static

Definition at line 580 of file replace.c.

581{
582 switch (dwCtrlType)
583 {
584 case CTRL_C_EVENT: /* Ctrl+C */
585 case CTRL_CLOSE_EVENT: /* Closing console? */
587 return TRUE; /* Handled */
588
589 default:
590 return FALSE; /* Ignored */
591 }
592}
#define FALSE
Definition: types.h:117
BOOL bCtrlBreak
Definition: util.c:11
#define CTRL_C_EVENT
Definition: wincon.h:68
#define CTRL_CLOSE_EVENT
Definition: wincon.h:70

Referenced by wmain().

◆ getPath()

void getPath ( TCHAR out,
LPTSTR  in 
)

Definition at line 29 of file replace.c.

30{
31 if (_tcslen(in) == 2 && in[1] == _T(':'))
33 else
35}
GLuint in
Definition: glext.h:9616
static FILE * out
Definition: regtests2xml.c:44
#define GetFullPathName
Definition: winbase.h:3821

Referenced by cmd_replace().

◆ invalid_switch()

void invalid_switch ( LPTSTR  is)

Definition at line 22 of file replace.c.

Referenced by cmd_replace().

◆ recFindSubDirs()

INT recFindSubDirs ( DWORD  dwFlags,
TCHAR  szSrcPath[MAX_PATH],
TCHAR  szDestPath[MAX_PATH],
BOOL doMore 
)

Definition at line 303 of file replace.c.

307{
309 WIN32_FIND_DATA findBuffer;
310 TCHAR tmpDestPath[MAX_PATH], tmpSrcPath[MAX_PATH];
311 INT filesReplaced = 0;
312 INT_PTR i;
313
314 /*
315 * Add a wildcard to dest end so the it will be easy to iterate
316 * over all the files and directorys in the dest directory.
317 */
318 _tcscat(szDestPath, _T("*"));
319
320 /* Get the first file in the directory */
321 hFile = FindFirstFile (szDestPath, &findBuffer);
322
323 /* Remove the star added earlier to dest path */
324 for(i = (_tcslen(szDestPath) - 1); i > -1; i--)
325 {
326 if (szDestPath[i] != _T('\\'))
327 szDestPath[i] = _T('\0');
328 else
329 break;
330 }
331
332 /* Iterate over all filed directories in the dest dir */
333 do
334 {
335 /* Save the source path so that it will not be wrecked */
336 _tcscpy(tmpSrcPath,szSrcPath);
337 /* Check for reading problems */
339 {
340 ConOutFormatMessage (GetLastError(), tmpSrcPath);
341 return filesReplaced;
342 }
343
344 /*
345 * Check if the we should enter the dir or if it is a file
346 * or . or .. if so thake the next object to process.
347 */
348 if (!_tcscmp (findBuffer.cFileName, _T(".")) ||
349 !_tcscmp (findBuffer.cFileName, _T(".."))||
350 IsExistingFile(findBuffer.cFileName))
351 continue;
352 /* Add the destpath and the new dir path to tempDestPath */
353 _tcscpy(tmpDestPath,szDestPath);
354 _tcscat (tmpDestPath, findBuffer.cFileName);
355 /* Make sure that we have a directory */
356 if (IsExistingDirectory(tmpDestPath))
357 {
358 /* Add a \ to the end or the path */
359 if (szDestPath[_tcslen(tmpDestPath) - 1] != _T('\\'))
360 _tcscat(tmpDestPath, _T("\\"));
361 /* Call the function to replace files in the new directory */
362 filesReplaced += recReplace(dwFlags, tmpSrcPath, tmpDestPath, doMore);
363 /* If there were problems break e.g. read-only file */
364 if (!*doMore)
365 break;
366 _tcscpy(tmpSrcPath,szSrcPath);
367 /* Control the next level of subdirs */
368 filesReplaced += recFindSubDirs(dwFlags,tmpSrcPath,tmpDestPath, doMore);
369 if (!*doMore)
370 break;
371 }
372 /* Get the next handle */
373 } while(FindNextFile (hFile, &findBuffer));
374
376
377 return filesReplaced;
378}
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
_In_ HANDLE hFile
Definition: mswsock.h:90
#define ConOutFormatMessage(MessageId,...)
Definition: replace.h:34
int32_t INT_PTR
Definition: typedefs.h:64
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3788
#define FindFirstFile
Definition: winbase.h:3782

Referenced by cmd_replace(), and recFindSubDirs().

◆ recReplace()

INT recReplace ( DWORD  dwFlags,
TCHAR  szSrcPath[MAX_PATH],
TCHAR  szDestPath[MAX_PATH],
BOOL doMore 
)

Definition at line 205 of file replace.c.

209{
210 TCHAR tmpDestPath[MAX_PATH], tmpSrcPath[MAX_PATH];
211 INT filesReplaced=0;
212 INT_PTR i;
213 DWORD dwAttrib = 0;
215 WIN32_FIND_DATA findBuffer;
216
217 /* Get file handle to the sourcefile(s) */
218 hFile = FindFirstFile (szSrcPath, &findBuffer);
219
220 /*
221 * Strip the paths back to the folder they are in, so that
222 * the different filenames can be added if more than one.
223 */
224 for(i = (_tcslen(szSrcPath) - 1); i > -1; i--)
225 {
226 if (szSrcPath[i] != _T('\\'))
227 szSrcPath[i] = _T('\0');
228 else
229 break;
230 }
231
232 /* Go through all the sourcefiles and copy/replace them */
233 do
234 {
235 if (bCtrlBreak)
236 return filesReplaced;
237
238 /* Problem with file handler */
240 return filesReplaced;
241
242 /* We do not want to replace any .. . ocr directory */
243 if (!_tcscmp (findBuffer.cFileName, _T(".")) ||
244 !_tcscmp (findBuffer.cFileName, _T(".."))||
245 findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
246 continue;
247
248 /* Add filename to destpath */
249 _tcscpy(tmpDestPath,szDestPath);
250 _tcscat (tmpDestPath, findBuffer.cFileName);
251
252 dwAttrib = GetFileAttributes(tmpDestPath);
253 /* Check add flag */
254 if (dwFlags & REPLACE_ADD)
255 {
256 if (IsExistingFile(tmpDestPath))
257 continue;
258 else
259 dwAttrib = 0;
260 }
261 else
262 {
263 if (!IsExistingFile(tmpDestPath))
264 continue;
265 }
266
267 /* Check if file is read only, if so check if that should be ignored */
268 if (dwAttrib & FILE_ATTRIBUTE_READONLY)
269 {
270 if (!(dwFlags & REPLACE_READ_ONLY))
271 {
273 *doMore = FALSE;
274 break;
275 }
276 }
277
278 /* Add filename to sourcepath, insted of wildcards */
279 _tcscpy(tmpSrcPath,szSrcPath);
280 _tcscat (tmpSrcPath, findBuffer.cFileName);
281
282 /* Make the replace */
283 if (replace(tmpSrcPath,tmpDestPath, dwFlags, doMore))
284 {
285 filesReplaced++;
286 }
287 else if (!*doMore)
288 {
289 /* The file to be replaced was the same as the source */
290 filesReplaced = -1;
291 break;
292 }
293
294 /* Take next sourcefile if any */
295 } while(FindNextFile (hFile, &findBuffer));
296
298
299 return filesReplaced;
300}
#define STRING_REPLACE_ERROR5
Definition: resource.h:7
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:38
#define GetFileAttributes
Definition: winbase.h:3815

Referenced by cmd_replace(), and recFindSubDirs().

◆ replace()

INT replace ( TCHAR  source[MAX_PATH],
TCHAR  dest[MAX_PATH],
DWORD  dwFlags,
BOOL doMore 
)

Definition at line 38 of file replace.c.

39{
42 HANDLE hFileSrc, hFileDest;
43 DWORD dwAttrib, dwRead, dwWritten;
45 BOOL bEof = FALSE;
46 FILETIME srcCreationTime, destCreationTime, srcLastAccessTime, destLastAccessTime;
47 FILETIME srcLastWriteTime, destLastWriteTime;
50 s[0] = _totupper(s[0]);
51 d[0] = _totupper(d[0]);
52 // ConOutPrintf(_T("old-src: %s\n"), s);
53 // ConOutPrintf(_T("old-dest: %s\n"), d);
54 // ConOutPrintf(_T("src: %s\n"), source);
55 // ConOutPrintf(_T("dest: %s\n"), dest);
56
57 /* Open up the sourcefile */
59 if (hFileSrc == INVALID_HANDLE_VALUE)
60 {
62 return 0;
63 }
64
65 /*
66 * Get the time from source file to be used in the comparison
67 * with dest time if update switch is set.
68 */
69 GetFileTime (hFileSrc, &srcCreationTime, &srcLastAccessTime, &srcLastWriteTime);
70
71 /*
72 * Retrieve the source attributes so that they later on
73 * can be inserted in to the destination.
74 */
75 dwAttrib = GetFileAttributes (source);
76
77 if (IsExistingFile (dest))
78 {
79 /*
80 * Resets the attributes to avoid problems with read only files,
81 * checks for read only has been made earlier.
82 */
84 /*
85 * Is the update flas set? The time has to be controled so that
86 * only older files are replaced.
87 */
89 {
90 /* Read destination time */
92 0, NULL);
93
94 if (hFileDest == INVALID_HANDLE_VALUE)
95 {
97 CloseHandle (hFileSrc);
98 return 0;
99 }
100
101 /* Compare time */
102 GetFileTime (hFileDest, &destCreationTime, &destLastAccessTime, &destLastWriteTime);
103 if (!((srcLastWriteTime.dwHighDateTime > destLastWriteTime.dwHighDateTime) ||
104 (srcLastWriteTime.dwHighDateTime == destLastWriteTime.dwHighDateTime &&
105 srcLastWriteTime.dwLowDateTime > destLastWriteTime.dwLowDateTime)))
106 {
107 CloseHandle (hFileSrc);
108 CloseHandle (hFileDest);
109 return 0;
110 }
111 CloseHandle (hFileDest);
112 }
113 /* Delete the old file */
115 }
116
117 /* Check confirm flag, and take appropriate action */
119 {
120 /* Output depending on add flag */
121 if (dwFlags & REPLACE_ADD)
123 else
125 if ( !FilePromptYNA (0))
126 {
127 CloseHandle (hFileSrc);
128 return 0;
129 }
130 }
131
132 /* Output depending on add flag */
133 if (dwFlags & REPLACE_ADD)
135 else
137
138 /* Make sure source and destination is not the same */
139 if (!_tcscmp(s, d))
140 {
142 CloseHandle (hFileSrc);
143 *doMore = FALSE;
144 return 0;
145 }
146
147 /* Open destination file to write to */
148 hFileDest = CreateFile (dest, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
149 if (hFileDest == INVALID_HANDLE_VALUE)
150 {
151 CloseHandle (hFileSrc);
153 *doMore = FALSE;
154 return 0;
155 }
156
157 /* Get buffer for the copy process */
159 if (buffer == NULL)
160 {
161 CloseHandle (hFileDest);
162 CloseHandle (hFileSrc);
164 return 0;
165 }
166
167 /* Put attribute and time to the new destination file */
168 SetFileAttributes (dest, dwAttrib);
169 SetFileTime (hFileDest, &srcCreationTime, &srcLastAccessTime, &srcLastWriteTime);
170 do
171 {
172 /* Read data from source */
173 ReadFile (hFileSrc, buffer, BUFF_SIZE, &dwRead, NULL);
174
175 /* Done? */
176 if (dwRead == 0)
177 break;
178
179 /* Write to destination file */
180 WriteFile (hFileDest, buffer, dwRead, &dwWritten, NULL);
181
182 /* Done! or ctrl break! */
183 if (dwWritten != dwRead || bCtrlBreak)
184 {
187 CloseHandle (hFileDest);
188 CloseHandle (hFileSrc);
189 return 0;
190 }
191 }
192 while (!bEof);
193
194 /* Return memory and close files */
196 CloseHandle (hFileDest);
197 CloseHandle (hFileSrc);
198
199 /* Return one file replaced */
200 return 1;
201}
#define STRING_ERROR_OUT_OF_MEMORY
Definition: resource.h:26
#define STRING_REPLACE_HELP11
Definition: resource.h:20
#define STRING_REPLACE_ERROR7
Definition: resource.h:9
#define STRING_COPY_ERROR1
Definition: resource.h:23
#define STRING_REPLACE_HELP5
Definition: resource.h:15
#define STRING_REPLACE_HELP9
Definition: resource.h:18
#define STRING_REPLACE_HELP10
Definition: resource.h:19
#define STRING_COPY_ERROR3
Definition: resource.h:24
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI SetFileTime(IN HANDLE hFile, CONST FILETIME *lpCreationTime OPTIONAL, CONST FILETIME *lpLastAccessTime OPTIONAL, CONST FILETIME *lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:948
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:896
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
GLdouble s
Definition: gl.h:2039
GLuint buffer
Definition: glext.h:5915
#define d
Definition: ke_i.h:81
#define CREATE_ALWAYS
Definition: disk.h:72
static char * dest
Definition: rtl.c:135
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define MEM_RELEASE
Definition: nt_native.h:1316
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_COMMIT
Definition: nt_native.h:1313
#define BUFF_SIZE
Definition: replace.h:26
#define ConOutResPuts(uID)
Definition: replace.h:28
INT FilePromptYNA(UINT resID)
Definition: util.c:110
VOID GetPathCase(TCHAR *Path, TCHAR *OutPath)
Definition: util.c:53
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
unsigned char * LPBYTE
Definition: typedefs.h:53
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119
#define SetFileAttributes
Definition: winbase.h:3909
#define DeleteFile
Definition: winbase.h:3764
#define CreateFile
Definition: winbase.h:3749

Referenced by AddMRUData(), cache_container_create_object_name(), dialog_find(), EmptyStore_add(), epm_register(), ept_insert(), ext4_fs_set_xattr(), format_replace(), HLPFILE_RtfAddText(), HTMLDocument_open(), HTMLWindow2_open(), IEHTMLWindow2_open(), MAIN_ReplaceString(), msi_set_sourcedir_props(), ParaNdis_DebugInitialize(), recReplace(), RegExp_Replace(), RmCpTest::replace0(), and RmCpTest::replace1().

◆ wmain()

int wmain ( int  argc,
WCHAR **  argvW 
)

Definition at line 594 of file replace.c.

595{
596 /* Handle Ctrl+C and console closing */
598
599 /* Initialize the Console Standard Streams */
601
602 return cmd_replace(argc, argvW);
603}
#define ConInitStdStreams()
Definition: fc.c:13
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2109
INT cmd_replace(INT argc, WCHAR **argv)
Definition: replace.c:380
static BOOL CALLBACK CtrlHandlerRoutine(DWORD dwCtrlType)
Definition: replace.c:580