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