source: trunk/dll/copyf.c@ 1443

Last change on this file since 1443 was 1443, checked in by Steven Levine, 16 years ago

Drop obsolete code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: copyf.c 1443 2009-07-16 21:19:04Z stevenhl $
5
6 Copy functions
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2009 Steven H.Levine
10
11 14 Sep 02 SHL Drop obsolete debug code
12 14 Oct 02 SHL Drop obsolete debug code
13 10 Nov 02 SHL docopyf - don't forget to terminate longname
14 optimize longname logic
15 01 Aug 04 SHL Rework lstrip/rstrip usage
16 28 May 05 SHL Drop debug code
17 14 Jul 06 SHL Use Runtime_Error
18 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
19 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
20 29 Feb 08 GKY Use xfree where appropriate
21 19 Jul 08 GKY Modify MakeTempName for use making temp directory names
22 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
23 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
24 12 Jul 09 GKY Add xDosQueryAppType and xDoxAlloc... to allow FM/2 to load in high memory
25 13 Jul 09 SHL Drop obsolete code
26
27***********************************************************************/
28
29#include <stdlib.h>
30#include <string.h>
31#include <stdarg.h>
32#include <ctype.h>
33
34#define INCL_DOS
35#define INCL_DOSERRORS
36#define INCL_WIN
37#define INCL_LONGLONG
38
39#include "fm3dll.h"
40#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
41#include "killproc.h" // Data declaration(s)
42#include "notebook.h" // Data declaration(s)
43#include "info.h" // Data declaration(s)
44#include "init.h" // Data declaration(s)
45#include "arccnrs.h"
46#include "fm3str.h"
47#include "errutil.h" // Dos_Error...
48#include "strutil.h" // GetPString
49#include "copyf.h"
50#include "literal.h" // fixup
51#include "misc.h" // Broadcast
52#include "valid.h" // MakeFullName
53#include "wrappers.h" // xDosSetPathInfo
54#include "strips.h" // bstrip
55#include "fortify.h"
56#include "pathutil.h" // AddBackslashToPath
57
58static PSZ pszSrcFile = __FILE__;
59
60static CHAR *GetLongName(CHAR * oldname, CHAR * buffer);
61static CHAR *TruncName(CHAR * oldname, CHAR * buffer);
62
63//static CHAR default_disk(VOID);
64//static INT unlink_allf(CHAR * string, ...);
65
66#ifndef WinMoveObject
67HOBJECT APIENTRY WinMoveObject(HOBJECT hObjectofObject,
68 HOBJECT hObjectofDest, ULONG ulReserved);
69#endif
70#ifndef WinCopyObject
71HOBJECT APIENTRY WinCopyObject(HOBJECT hObjectofObject,
72 HOBJECT hObjectofDest, ULONG ulReserved);
73#endif
74
75char *MakeTempName(char *buffer, char *temproot, INT type)
76{
77 FILESTATUS3 fs3;
78 APIRET rc;
79 char *p, *o;
80
81 if (strlen(buffer) > 3) // && buffer[strlen(buffer) - 1] != '\\')
82 AddBackslashToPath(buffer);
83 //strcat(buffer, "\\");
84 p = o = buffer + strlen(buffer);
85 switch (type) {
86 case 0:
87 sprintf(p, "%08lx.%03lx", rand() & 4095L, mypid);
88 break;
89 case 1:
90 sprintf(p, "%s%04lx.%03lx", "$FM2", rand() & 4095L, mypid);
91 break;
92 case 2:
93 sprintf(p, "%s.%03x", temproot, (rand() & 4095));
94 break;
95 default:
96 break;
97 }
98 p = buffer + (strlen(buffer) - 1);
99 for (;;) {
100 DosError(FERR_DISABLEHARDERR);
101 rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
102 if (rc == ERROR_DISK_CHANGE) {
103 DosError(FERR_ENABLEHARDERR);
104 rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
105 }
106 if (rc)
107 break;
108 Loop:
109 if (p < o) {
110 *buffer = 0;
111 return NULL;
112 }
113 if ((*p) + 1 < 'Z' + 1) {
114 (*p)++;
115 while (strchr("*?<>\":/\\|+=;,[]. ", *p))
116 (*p)++;
117 *p = toupper(*p);
118 }
119 else {
120 p--;
121 if (p >= o && *p == '.')
122 p--;
123 goto Loop;
124 }
125 }
126 return buffer;
127}
128
129CHAR *TruncName(CHAR * oldname, CHAR * buffer)
130{
131 CHAR *p, *f, *s, *o;
132 FILESTATUS3 fs3;
133 APIRET rc;
134
135 if (!buffer || !oldname || !*oldname) {
136 if (buffer)
137 *buffer = 0;
138 return NULL;
139 }
140 strcpy(buffer, oldname);
141 f = strrchr(buffer, '\\');
142 if (!f)
143 f = strrchr(buffer, '/');
144 if (!f)
145 f = buffer;
146 else
147 f++;
148 p = f;
149 o = p;
150 f = oldname + (f - buffer);
151 strupr(buffer);
152 while (*f == '.') /* skip leading '.'s */
153 f++;
154 s = f;
155 while (*f && *f != '.' && f < s + 8) { /* skip past rootname */
156 *p = toupper(*f);
157 p++;
158 f++;
159 }
160 while (*f == '.')
161 f++;
162 s = f;
163 f = strrchr(f, '.');
164 if (f) {
165 while (*f == '.')
166 f++;
167 }
168 if (f && *(f + 1))
169 s = f;
170 else
171 f = s;
172 if (*f) {
173 *p = '.';
174 p++;
175 while (*f && *f != '.' && f < s + 3) {
176 *p = toupper(*f);
177 p++;
178 f++;
179 }
180 }
181 *p = 0;
182
183 p = o;
184 while (*p) {
185 if (strchr("*?<>\":/\\|+=;,[] ", *p) || *p < 0x20)
186 *p = '_';
187 if (*p == '.' && *(p + 1) == '.')
188 *(p + 1) = '_';
189 p++;
190 }
191
192 p = o + (strlen(o) - 1);
193 for (;;) {
194 DosError(FERR_DISABLEHARDERR);
195 rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
196 if (rc == ERROR_DISK_CHANGE) {
197 DosError(FERR_ENABLEHARDERR);
198 rc = DosQueryPathInfo(buffer, FIL_STANDARD, &fs3, sizeof(fs3));
199 }
200 if (rc)
201 break;
202 Loop:
203 if (p < o) {
204 *buffer = 0;
205 return NULL;
206 }
207 if ((*p) + 1 < 'Z' + 1) {
208 (*p)++;
209 while (strchr("*?<>\":/\\|+=;,[]. ", *p))
210 (*p)++;
211 *p = toupper(*p);
212 }
213 else {
214 p--;
215 if (p >= o && *p == '.')
216 p--;
217 goto Loop;
218 }
219 }
220 return buffer;
221}
222
223CHAR *GetLongName(CHAR * oldname, CHAR * longname)
224{
225 if (!longname)
226 return NULL;
227 *longname = 0;
228 if (!oldname || !*oldname)
229 return NULL;
230 if (IsFullName(oldname)) {
231
232 APIRET rc;
233 EAOP2 eaop;
234 PGEA2LIST pgealist;
235 PFEA2LIST pfealist;
236 PGEA2 pgea;
237 PFEA2 pfea;
238 CHAR *value;
239
240 strcpy(longname, oldname);
241 value = longname;
242 while (*value) {
243 if (*value == '/')
244 *value = '\\';
245 value++;
246 }
247 value = strrchr(longname, '\\');
248 if (value) {
249 value++;
250 *value = 0;
251 }
252 pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
253 if (pgealist) {
254 pgea = &pgealist->list[0];
255 strcpy(pgea->szName, LONGNAME);
256 pgea->cbName = strlen(pgea->szName);
257 pgea->oNextEntryOffset = 0L;
258 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
259 pfealist = xmallocz(1536, pszSrcFile, __LINE__);
260 if (pfealist) {
261 pfealist->cbList = 1024;
262 eaop.fpGEA2List = pgealist;
263 eaop.fpFEA2List = pfealist;
264 eaop.oError = 0L;
265 DosError(FERR_DISABLEHARDERR);
266 rc = DosQueryPathInfo(oldname,
267 FIL_QUERYEASFROMLIST,
268 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
269 if (!rc) {
270 pfea = &eaop.fpFEA2List->list[0];
271 value = pfea->szName + pfea->cbName + 1;
272 value[pfea->cbValue] = 0;
273 if (*(USHORT *) value == EAT_ASCII)
274 strncat(longname,
275 value + (sizeof(USHORT) * 2),
276 CCHMAXPATH - strlen(longname));
277 longname[CCHMAXPATH - 1] = 0;
278 }
279 free(pfealist);
280 }
281 free(pgealist);
282 }
283 }
284 return longname;
285}
286
287BOOL ZapLongName(char *filename)
288{
289 return WriteLongName(filename, NullStr);
290}
291
292BOOL WriteLongName(CHAR * filename, CHAR * longname)
293{
294 APIRET rc;
295 EAOP2 eaop;
296 PFEA2LIST pfealist = NULL;
297 ULONG ealen;
298 USHORT len;
299 CHAR *eaval, *p;
300
301 if (!filename || !*filename || !longname)
302 return FALSE;
303 p = strrchr(longname, '\\');
304 if (p)
305 memmove(longname, p + 1, strlen(p + 1) + 1);
306 p = strrchr(longname, '/');
307 if (p)
308 memmove(longname, p + 1, strlen(p + 1) + 1);
309 bstrip(longname);
310 len = strlen(longname);
311 if (len)
312 ealen = sizeof(FEA2LIST) + 10 + len + 4;
313 else
314 ealen = sizeof(FEALIST) + 10;
315 rc = xDosAllocMem((PPVOID) & pfealist,
316 ealen + 32L, PAG_COMMIT | PAG_READ | PAG_WRITE,
317 pszSrcFile, __LINE__);
318 if (rc)
319 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
320 GetPString(IDS_OUTOFMEMORY));
321 else {
322 memset(pfealist, 0, ealen + 1);
323 pfealist->cbList = ealen;
324 pfealist->list[0].oNextEntryOffset = 0;
325 pfealist->list[0].fEA = 0;
326 pfealist->list[0].cbName = 9;
327 strcpy(pfealist->list[0].szName, LONGNAME);
328 if (len) {
329 eaval = pfealist->list[0].szName + 10;
330 *(USHORT *) eaval = (USHORT) EAT_ASCII;
331 eaval += sizeof(USHORT);
332 *(USHORT *) eaval = (USHORT) len;
333 eaval += sizeof(USHORT);
334 memcpy(eaval, longname, len);
335 pfealist->list[0].cbValue = len + (sizeof(USHORT) * 2);
336 }
337 else
338 pfealist->list[0].cbValue = 0;
339 eaop.fpGEA2List = (PGEA2LIST) 0;
340 eaop.fpFEA2List = pfealist;
341 eaop.oError = 0L;
342 DosError(FERR_DISABLEHARDERR);
343 rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
344 &eaop, sizeof(eaop), DSPI_WRTTHRU);
345 DosFreeMem(pfealist);
346 if (rc)
347 return FALSE;
348 }
349 return TRUE;
350}
351
352BOOL AdjustWildcardName(CHAR * oldname, CHAR * newname)
353{
354 BOOL ret = FALSE;
355
356 /* NOTE: newname should be CCHMAXPATH chars long! */
357
358 if (strchr(newname, '*') || strchr(newname, '?')) {
359
360 CHAR srce[CCHMAXPATHCOMP], dest[CCHMAXPATHCOMP], result[CCHMAXPATHCOMP],
361 *p;
362
363 p = strrchr(newname, '\\');
364 if (p && *(p + 1)) {
365 strcpy(dest, p + 1);
366 p = strrchr(oldname, '\\');
367 if (p && *(p + 1)) {
368 strcpy(srce, p + 1);
369 DosError(FERR_DISABLEHARDERR);
370 if (!DosEditName(1L, srce, dest, (PBYTE)result, (ULONG)sizeof(result))) {
371 p = strrchr(newname, '\\');
372 p++;
373 strcpy(p, result);
374 ret = TRUE;
375 }
376 }
377 }
378 }
379 return ret;
380}
381
382APIRET docopyf(INT type, CHAR *oldname, CHAR *newname)
383{
384 /*
385 * returns:
386 * 0: success
387 * -1: bad string parameter(s)
388 * -2: source didn't exist
389 * -3: bad type
390 * anything else: API return
391 */
392
393 CHAR longname[CCHMAXPATH], shortname[CCHMAXPATH];
394 CHAR olddisk, newdisk, dir[CCHMAXPATH], *p, *pp;
395 APIRET ret = -1, rc;
396 FILESTATUS3L st, st2, dummy;
397 BOOL diskchange = FALSE, zaplong = FALSE;
398
399 *shortname = *dir = 0;
400
401 if (!oldname || !*oldname || !*newname) /* bad string args */
402 return (APIRET) - 1;
403
404 DosError(FERR_DISABLEHARDERR);
405 if (DosQueryPathInfo(oldname, FIL_STANDARDL, &st, sizeof(FILESTATUS3L)))
406 return (APIRET) - 2; /* no source */
407
408 AdjustWildcardName(oldname, newname);
409 MakeFullName(oldname);
410 MakeFullName(newname);
411 olddisk = toupper(*oldname); /* source drive */
412 newdisk = toupper(*newname); /* destination drive */
413 if (!(driveflags[toupper(*oldname) - 'A'] & DRIVE_NOLONGNAMES))
414 *longname = 0;
415 else {
416 GetLongName(oldname, longname);
417 if (*longname) {
418 p = RootName(longname);
419 if (p != longname)
420 memmove(longname, p, strlen(p) + 1);
421 }
422 }
423 /* If root name changed make sure longname EA goes away */
424 p = RootName(oldname);
425 pp = RootName(newname);
426 if (stricmp(p, pp)) {
427 zaplong = TRUE;
428 }
429
430 DosError(FERR_DISABLEHARDERR);
431 switch (type) {
432 case WPSMOVE:
433 {
434 HOBJECT hobjsrc;
435 HOBJECT hobjdest;
436
437 ret = ERROR_FILE_NOT_FOUND;
438 hobjsrc = WinQueryObject(oldname);
439 if (hobjsrc) {
440 strcpy(dir, newname);
441 p = strrchr(dir, '\\');
442 if (p < dir + 3)
443 p++;
444 *p = 0;
445 ret = ERROR_PATH_NOT_FOUND;
446 hobjdest = WinQueryObject(dir);
447 if (hobjdest) {
448 ret = ERROR_GEN_FAILURE;
449 hobjsrc = WinMoveObject(hobjsrc, hobjdest, 0);
450 if (hobjsrc)
451 ret = 0;
452 }
453 }
454 }
455 return ret;
456
457 case WPSCOPY:
458 {
459 HOBJECT hobjsrc;
460 HOBJECT hobjdest;
461
462 ret = ERROR_FILE_NOT_FOUND;
463 hobjsrc = WinQueryObject(oldname);
464 if (hobjsrc) {
465 strcpy(dir, newname);
466 p = strrchr(dir, '\\');
467 if (p < dir + 3)
468 p++;
469 *p = 0;
470 ret = ERROR_PATH_NOT_FOUND;
471 hobjdest = WinQueryObject(dir);
472 if (hobjdest) {
473 ret = ERROR_GEN_FAILURE;
474 hobjsrc = WinCopyObject(hobjsrc, hobjdest, 0);
475 if (hobjsrc)
476 ret = 0;
477 }
478 }
479 }
480 return ret;
481
482 case MOVE:
483 *dir = 0;
484 if (olddisk == newdisk) { /* same drive */
485 /* make temporary copy in case move fails */
486 if (IsFile(newname) != -1 && stricmp(oldname, newname)) {
487 strcpy(dir, newname);
488 AddBackslashToPath(dir);
489 //p = strrchr(dir, '\\');
490 //if (p)
491 // *p = 0;
492 //strcat(dir, "\\");
493 MakeTempName(dir, NULL, 0);
494 if (DosMove(newname, dir))
495 *dir = 0;
496 }
497 DosError(FERR_DISABLEHARDERR);
498 ret = DosMove(oldname, newname); /* move it */
499 if (ret && *dir) { /* failed -- clean up */
500 DosError(FERR_DISABLEHARDERR);
501 if (!DosMove(dir, newname))
502 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
503 }
504 else if (!ret && *dir) {
505 if (!IsFile(dir)) {
506 if (!strchr(dir, '?') && !strchr(dir, '*'))
507 wipeallf("%s\\*", dir);
508 DosError(FERR_DISABLEHARDERR);
509 if (DosDeleteDir(dir)) {
510 make_deleteable(dir);
511 DosDeleteDir(dir);
512 }
513 }
514 else if (IsFile(dir) > 0) {
515 DosError(FERR_DISABLEHARDERR);
516 if (DosForceDelete(dir)) {
517 make_deleteable(dir);
518 DosForceDelete(dir);
519 }
520 if (zaplong)
521 ZapLongName(dir);
522 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(dir), MPVOID);
523 }
524 }
525 }
526 else { /* different drives */
527 DosError(FERR_DISABLEHARDERR);
528 ret = DosCopy(oldname, newname, DCPY_EXISTING); /* <=-NOTE! */
529 if (ret == ERROR_DISK_CHANGE) {
530 DosError(FERR_ENABLEHARDERR);
531 ret = DosCopy(oldname, newname, DCPY_EXISTING);
532 diskchange = TRUE;
533 }
534 if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
535 if (TruncName(newname, shortname)) { /* make 8.3 filename */
536 DosError(FERR_DISABLEHARDERR);
537 ret = DosCopy(oldname, shortname, DCPY_EXISTING);
538 if (!ret) { /* success -- write longname ea */
539 WriteLongName(shortname, newname);
540 strcpy(newname, shortname);
541 /* broadcast fixup msg to windows */
542 Broadcast((HAB) 0,
543 hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
544 }
545 }
546 }
547 else if (!ret && *longname) {
548
549 CHAR fixname[CCHMAXPATH];
550
551 strcpy(fixname, newname);
552 p = strrchr(fixname, '\\');
553 if (p) {
554 p++;
555 *p = 0;
556 }
557 strcat(fixname, longname);
558 DosError(FERR_DISABLEHARDERR);
559 DosMove(newname, fixname);
560 strcpy(newname, fixname);
561 if (zaplong)
562 ZapLongName(fixname);
563 Broadcast((HAB) 0,
564 hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
565 }
566 if (!ret) { /* double-check success */
567 DosError(FERR_DISABLEHARDERR);
568 rc = DosQueryPathInfo(newname,
569 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
570 if (rc == ERROR_DISK_CHANGE) {
571 DosError(FERR_ENABLEHARDERR);
572 rc = DosQueryPathInfo(newname,
573 FIL_STANDARDL, &st2, sizeof(FILESTATUS3L));
574 }
575 if (!rc && st2.cbFile == st.cbFile) { /* seems to have worked... */
576 DosError(FERR_DISABLEHARDERR);
577 if (diskchange) {
578 DosError(FERR_ENABLEHARDERR);
579 DosQueryPathInfo(oldname, FIL_STANDARDL, &dummy, sizeof(FILESTATUS3L)); /* force disk change */
580 }
581 if (!(st2.attrFile & FILE_DIRECTORY)) /* erase file */
582 unlinkf(oldname);
583 else { /* remove directory */
584 wipeallf("%s\\*", oldname);
585 DosError(FERR_DISABLEHARDERR);
586 if (DosDeleteDir(oldname)) {
587 make_deleteable(oldname);
588 DosDeleteDir(oldname);
589 }
590 }
591 }
592 }
593 }
594 return ret;
595
596 case COPY:
597 DosError(FERR_DISABLEHARDERR);
598 ret = DosCopy(oldname, newname, DCPY_EXISTING); /* <=-NOTE! */
599 if (ret == ERROR_DISK_CHANGE) {
600 DosError(FERR_ENABLEHARDERR);
601 ret = DosCopy(oldname, newname, DCPY_EXISTING);
602 diskchange = TRUE;
603 }
604 if (ret == ERROR_INVALID_NAME || ret == ERROR_FILENAME_EXCED_RANGE) {
605 if (TruncName(newname, shortname)) {
606 DosError((diskchange) ? FERR_ENABLEHARDERR : FERR_DISABLEHARDERR);
607 ret = DosCopy(oldname, shortname, DCPY_EXISTING);
608 if (!ret) {
609 WriteLongName(shortname, newname);
610 strcpy(newname, shortname);
611 Broadcast((HAB) 0,
612 hwndMain, UM_UPDATERECORD, MPFROMP(shortname), MPVOID);
613 }
614 }
615 }
616 else if (!ret && *longname) {
617
618 CHAR fixname[CCHMAXPATH];
619
620 strcpy(fixname, newname);
621 p = strrchr(fixname, '\\');
622 if (p) {
623 p++;
624 *p = 0;
625 }
626 strcat(fixname, longname);
627 DosError(FERR_DISABLEHARDERR);
628 DosMove(newname, fixname);
629 if (zaplong)
630 ZapLongName(fixname);
631 Broadcast((HAB) 0, hwndMain, UM_UPDATERECORD, MPFROMP(fixname), MPVOID);
632 }
633 return ret;
634
635 default: /* shouldn't happen */
636 Runtime_Error(pszSrcFile, __LINE__, "bad case %u", type);
637 break;
638 }
639 return (APIRET) - 3; /* bad type */
640}
641
642INT make_deleteable(CHAR * filename)
643{
644 INT ret = -1;
645 FILESTATUS3 fsi;
646
647 DosError(FERR_DISABLEHARDERR);
648 if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsi, sizeof(fsi))) {
649 fsi.attrFile = 0;
650 DosError(FERR_DISABLEHARDERR);
651 if (!xDosSetPathInfo(filename, FIL_STANDARD, &fsi, sizeof(fsi), 0))
652 ret = 0;
653 }
654 return ret;
655}
656
657INT wipeallf(CHAR *string, ...)
658{
659 /* unlink everything from directory on down... */
660
661 FILEFINDBUF3 *f;
662 HDIR search_handle;
663 ULONG num_matches;
664 CHAR *p, *ss, *str;
665 CHAR s[CCHMAXPATH], mask[257];
666 va_list ap;
667 INT rc;
668
669 va_start(ap, string);
670 vsprintf(s, string, ap);
671 va_end(ap);
672
673 if (!*s)
674 return -1;
675 p = s;
676 while ((p = strchr(p, '/')) != NULL) {
677 *p = '\\';
678 p++;
679 }
680
681 str = xstrdup(s, pszSrcFile, __LINE__);
682 if (!str)
683 return -1;
684
685 { /* safety net -- disallow deleting a root dir or partial name */
686 CHAR temp;
687
688 p = strrchr(str, '\\');
689 if (p) {
690 p++;
691 temp = *p;
692 *p = 0;
693 if (IsRoot(str) || !IsFullName(str)) {
694 /* under no circumstances! */
695 Runtime_Error(pszSrcFile, __LINE__, "bad name %s", str);
696 free(str);
697 return -1;
698 }
699 *p = temp;
700 }
701 }
702
703 p = s;
704 p = strrchr(s, '\\'); /* strip s to just path */
705 if (!p)
706 p = strrchr(s, ':');
707 if (p) {
708 p++;
709 strncpy(mask, p, 256);
710 mask[256] = 0;
711 *p = 0;
712 }
713 else {
714 *mask = 0;
715 *s = 0;
716 }
717
718 ss = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
719 f = xmalloc(sizeof(FILEFINDBUF3), pszSrcFile, __LINE__);
720 if (!ss || !f) {
721 xfree(ss, pszSrcFile, __LINE__);
722 xfree(f, pszSrcFile, __LINE__);
723 free(str);
724 return -1;
725 }
726
727 search_handle = HDIR_CREATE;
728 num_matches = 1;
729
730 DosError(FERR_DISABLEHARDERR);
731 if (!DosFindFirst(str, &search_handle, FILE_NORMAL | FILE_DIRECTORY |
732 FILE_SYSTEM | FILE_READONLY | FILE_HIDDEN | FILE_ARCHIVED,
733 f, sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
734
735 strcpy(ss, s);
736 p = &ss[strlen(ss)];
737
738 do {
739 strcpy(p, f->achName);
740 if (f->attrFile & FILE_DIRECTORY) {
741 if (strcmp(f->achName, ".") && strcmp(f->achName, "..")) {
742 wipeallf("%s/%s", ss, mask); /* recurse to wipe files */
743 DosError(FERR_DISABLEHARDERR);
744 if (DosDeleteDir(ss)) { /* remove directory */
745 make_deleteable(ss);
746 DosError(FERR_DISABLEHARDERR);
747 DosDeleteDir(ss);
748 }
749 }
750 }
751 else {
752 DosError(FERR_DISABLEHARDERR);
753 if (DosForceDelete(ss)) {
754 make_deleteable(ss);
755 DosError(FERR_DISABLEHARDERR);
756 rc = (INT) DosForceDelete(ss);
757 if (rc)
758 return rc;
759 }
760 }
761 num_matches = 1;
762 DosError(FERR_DISABLEHARDERR);
763 } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
764 &num_matches));
765 DosFindClose(search_handle);
766 }
767
768 free(f);
769 free(ss);
770 free(str);
771 return 0;
772}
773
774#if 0 // JBS 11 Sep 08
775INT unlink_allf(CHAR * string, ...)
776{
777 /* wildcard delete */
778
779 FILEFINDBUF3 *f;
780 HDIR search_handle;
781 ULONG num_matches;
782 CHAR *p, *ss, *str;
783 CHAR s[CCHMAXPATH];
784 va_list ap;
785
786 va_start(ap, string);
787 vsprintf(s, string, ap);
788 va_end(ap);
789
790 if (!*s)
791 return -1;
792 p = s;
793 while ((p = strchr(p, '/')) != NULL) {
794 *p = '\\';
795 p++;
796 }
797
798 str = xstrdup(s, pszSrcFile, __LINE__);
799 if (!str)
800 return -1;
801
802 p = s;
803 p = strrchr(s, '\\'); /* strip s to just path */
804 if (!p)
805 p = strrchr(s, ':');
806 if (p) {
807 p++;
808 *p = 0;
809 }
810 else
811 *s = 0;
812
813 ss = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
814 f = xmalloc(sizeof(FILEFINDBUF3), pszSrcFile, __LINE__);
815 if (!ss || !f) {
816 xfree(ss, pszSrcFile, __LINE__);
817 xfree(f, pszSrcFile, __LINE__);
818 free(str);
819 return -1;
820 }
821
822 search_handle = HDIR_CREATE;
823 num_matches = 1;
824
825 DosError(FERR_DISABLEHARDERR);
826 if (!DosFindFirst(str, &search_handle, FILE_NORMAL, f,
827 sizeof(FILEFINDBUF3), &num_matches, FIL_STANDARD)) {
828
829 strcpy(ss, s);
830 p = &ss[strlen(ss)];
831
832 do {
833 strcpy(p, f->achName);
834 unlinkf("%s", ss);
835 num_matches = 1;
836 DosError(FERR_DISABLEHARDERR);
837 } while (!DosFindNext(search_handle, f, sizeof(FILEFINDBUF3),
838 &num_matches));
839 DosFindClose(search_handle);
840 }
841
842 free(f);
843 free(ss);
844 free(str);
845 return 0;
846}
847#endif
848
849INT unlinkf(CHAR *string)
850{
851
852 if (!strstr(string, ArcTempRoot)) {
853 DosError(FERR_DISABLEHARDERR);
854 if (DosDelete(string)) {
855 make_deleteable(string);
856 DosError(FERR_DISABLEHARDERR);
857 return DosDelete(string);
858 }
859 }
860 else {
861 DosError(FERR_DISABLEHARDERR);
862 if (DosForceDelete(string)) {
863 make_deleteable(string);
864 DosError(FERR_DISABLEHARDERR);
865 return DosForceDelete(string);
866 }
867 }
868 return 0;
869}
870
871#pragma alloc_text(LONGNAMES,TruncName,GetLongName,WriteLongName)
872#pragma alloc_text(LONGNAMES,ZapLongName,AdjustWildcardName)
873#pragma alloc_text(COPYF,default_disk,docopyf,MakeTempName)
874#pragma alloc_text(UNLINKF,unlinkf,unlink_allf,make_deleteable,wipeallf)
Note: See TracBrowser for help on using the repository browser.