| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: valid.c 793 2007-08-21 02:53:38Z gyoung $ | 
|---|
| 5 |  | 
|---|
| 6 | File name manipulation routines | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993, 1998 M. Kimes | 
|---|
| 9 | Copyright (c) 2002, 2007 Steven H.Levine | 
|---|
| 10 |  | 
|---|
| 11 | 23 Nov 02 SHL RootName: rework for sanity | 
|---|
| 12 | 27 Nov 02 SHL MakeFullName: correct typo | 
|---|
| 13 | 11 Jun 03 SHL Add JFS and FAT32 support | 
|---|
| 14 | 15 Jun 04 SHL Implement Jim Read's removable logic | 
|---|
| 15 | 31 Jul 04 SHL Comments | 
|---|
| 16 | 01 Aug 04 SHL Rework lstrip/rstrip usage | 
|---|
| 17 | 03 Jun 05 SHL Drop CD_DEBUG logic | 
|---|
| 18 | 28 Nov 05 SHL MakeValidDir: correct DosQuerySysInfo args | 
|---|
| 19 | 22 Jul 06 SHL Use Runtime_Error | 
|---|
| 20 | 22 Oct 06 GKY Add NDFS32 support | 
|---|
| 21 | 22 Oct 06 GKY Increased BUFFER_BYTES in CheckDrive to 8192 to fix NDFS32 scan failure | 
|---|
| 22 | 07 Jan 07 GKY Move error strings etc. to string file | 
|---|
| 23 | 18 Feb 07 GKY Add more drive types and icons | 
|---|
| 24 | 16 Jun 07 SHL Update for OpenWatcom | 
|---|
| 25 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| 26 |  | 
|---|
| 27 | ***********************************************************************/ | 
|---|
| 28 |  | 
|---|
| 29 | #define INCL_DOS | 
|---|
| 30 | #define INCL_WIN | 
|---|
| 31 | #define INCL_DOSDEVICES                 // DosDevIOCtl | 
|---|
| 32 | #define INCL_DOSDEVIOCTL                // DosDevIOCtl | 
|---|
| 33 | #include <os2.h> | 
|---|
| 34 |  | 
|---|
| 35 | #include <stdlib.h> | 
|---|
| 36 | #include <stdio.h> | 
|---|
| 37 | #include <string.h> | 
|---|
| 38 | #include <ctype.h> | 
|---|
| 39 |  | 
|---|
| 40 | #include "fm3dll.h" | 
|---|
| 41 | #include "fm3str.h" | 
|---|
| 42 |  | 
|---|
| 43 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 44 |  | 
|---|
| 45 | APIRET MakeFullName(char *pszFileName) | 
|---|
| 46 | { | 
|---|
| 47 | /* pszFileName must be CCHMAXPATH long minimum! */ | 
|---|
| 48 |  | 
|---|
| 49 | char szPathName[CCHMAXPATH]; | 
|---|
| 50 | APIRET rc; | 
|---|
| 51 |  | 
|---|
| 52 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 53 | rc = DosQueryPathInfo(pszFileName, | 
|---|
| 54 | FIL_QUERYFULLNAME, szPathName, sizeof(szPathName)); | 
|---|
| 55 | if (!rc) | 
|---|
| 56 | strcpy(pszFileName, szPathName);    // Pass back actual name | 
|---|
| 57 | return rc; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | char *RootName(char *filename) | 
|---|
| 61 | { | 
|---|
| 62 | char *p = NULL, *pp; | 
|---|
| 63 |  | 
|---|
| 64 | // Return filename, strip path parts | 
|---|
| 65 | // Return empty string when filename ends with backslash | 
|---|
| 66 |  | 
|---|
| 67 | if (filename) { | 
|---|
| 68 | p = strrchr(filename, '\\'); | 
|---|
| 69 | pp = strrchr(filename, '/'); | 
|---|
| 70 | p = (p) ? (pp) ? (p > pp) ? p : pp : p : pp; | 
|---|
| 71 | } | 
|---|
| 72 | if (!p)                               /* name is itself a root */ | 
|---|
| 73 | p = filename; | 
|---|
| 74 | else                                  /* skip past backslash */ | 
|---|
| 75 | p++; | 
|---|
| 76 | return p; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | int TestDates(char *file1, char *file2) | 
|---|
| 80 | { | 
|---|
| 81 | /* | 
|---|
| 82 | * return 1 (file2 newer than file1), | 
|---|
| 83 | * 0 (files same) | 
|---|
| 84 | * or -1 (file1 newer than file2) | 
|---|
| 85 | */ | 
|---|
| 86 |  | 
|---|
| 87 | int comp = 0; | 
|---|
| 88 | FILESTATUS3 fs3o, fs3n; | 
|---|
| 89 |  | 
|---|
| 90 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 91 | if (!DosQueryPathInfo(file1, FIL_STANDARD, &fs3o, sizeof(fs3o))) { | 
|---|
| 92 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 93 | if (!DosQueryPathInfo(file2, FIL_STANDARD, &fs3n, sizeof(fs3n))) { | 
|---|
| 94 | comp = (fs3n.fdateLastWrite.year > | 
|---|
| 95 | fs3o.fdateLastWrite.year) ? 1 : | 
|---|
| 96 | (fs3n.fdateLastWrite.year < | 
|---|
| 97 | fs3o.fdateLastWrite.year) ? -1 : | 
|---|
| 98 | (fs3n.fdateLastWrite.month > | 
|---|
| 99 | fs3o.fdateLastWrite.month) ? 1 : | 
|---|
| 100 | (fs3n.fdateLastWrite.month < | 
|---|
| 101 | fs3o.fdateLastWrite.month) ? -1 : | 
|---|
| 102 | (fs3n.fdateLastWrite.day > | 
|---|
| 103 | fs3o.fdateLastWrite.day) ? 1 : | 
|---|
| 104 | (fs3n.fdateLastWrite.day < | 
|---|
| 105 | fs3o.fdateLastWrite.day) ? -1 : | 
|---|
| 106 | (fs3n.ftimeLastWrite.hours > | 
|---|
| 107 | fs3o.ftimeLastWrite.hours) ? 1 : | 
|---|
| 108 | (fs3n.ftimeLastWrite.hours < | 
|---|
| 109 | fs3o.ftimeLastWrite.hours) ? -1 : | 
|---|
| 110 | (fs3n.ftimeLastWrite.minutes > | 
|---|
| 111 | fs3o.ftimeLastWrite.minutes) ? 1 : | 
|---|
| 112 | (fs3n.ftimeLastWrite.minutes < | 
|---|
| 113 | fs3o.ftimeLastWrite.minutes) ? -1 : | 
|---|
| 114 | (fs3n.ftimeLastWrite.twosecs > | 
|---|
| 115 | fs3o.ftimeLastWrite.twosecs) ? 1 : | 
|---|
| 116 | (fs3n.ftimeLastWrite.twosecs < fs3o.ftimeLastWrite.twosecs) ? -1 : 0; | 
|---|
| 117 | } | 
|---|
| 118 | } | 
|---|
| 119 | return comp; | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | BOOL IsNewer(char *file1, char *file2) | 
|---|
| 123 | { | 
|---|
| 124 | /* return TRUE if file2 is newer than file1 */ | 
|---|
| 125 |  | 
|---|
| 126 | return (TestDates(file1, file2) > 0); | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | BOOL IsDesktop(HAB hab, HWND hwnd) | 
|---|
| 130 | { | 
|---|
| 131 | HWND hwndDesktop; | 
|---|
| 132 |  | 
|---|
| 133 | if (hwnd == HWND_DESKTOP) | 
|---|
| 134 | return TRUE; | 
|---|
| 135 | hwndDesktop = WinQueryDesktopWindow(hab, NULLHANDLE); | 
|---|
| 136 | if (hwnd == hwndDesktop) | 
|---|
| 137 | return TRUE; | 
|---|
| 138 | return FALSE; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 | BOOL ParentIsDesktop(HWND hwnd, HWND hwndParent) | 
|---|
| 142 | { | 
|---|
| 143 | HWND hwndDesktop; | 
|---|
| 144 | BOOL ret = FALSE; | 
|---|
| 145 |  | 
|---|
| 146 | if (!hwndParent) | 
|---|
| 147 | hwndParent = WinQueryWindow(hwnd, QW_PARENT); | 
|---|
| 148 | if (hwndParent == HWND_DESKTOP) | 
|---|
| 149 | ret = TRUE; | 
|---|
| 150 | else { | 
|---|
| 151 | hwndDesktop = WinQueryDesktopWindow(WinQueryAnchorBlock(hwnd), (HWND) 0); | 
|---|
| 152 | if (hwndDesktop == hwndParent) | 
|---|
| 153 | ret = TRUE; | 
|---|
| 154 | } | 
|---|
| 155 | return ret; | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | /* CheckDrive | 
|---|
| 159 | * @param chDrive drive letter | 
|---|
| 160 | * @param pszFileSystem pointer to buffer to return file system type or NULL | 
|---|
| 161 | * @param pulType pointer to long word to return drive flags or NULL | 
|---|
| 162 | * @returns removability flag, 1 = removable, 0 = not removable, -1 = error | 
|---|
| 163 | */ | 
|---|
| 164 |  | 
|---|
| 165 | INT CheckDrive(CHAR chDrive, CHAR * pszFileSystem, ULONG * pulType) | 
|---|
| 166 | { | 
|---|
| 167 | CHAR szPath[3]; | 
|---|
| 168 | VOID *pvBuffer = NULL; | 
|---|
| 169 | CHAR *pfsn; | 
|---|
| 170 | CHAR *pfsd; | 
|---|
| 171 | ULONG clBufferSize; | 
|---|
| 172 | APIRET rc; | 
|---|
| 173 | ULONG ulAction; | 
|---|
| 174 | ULONG clParmBytes; | 
|---|
| 175 | ULONG clDataBytes; | 
|---|
| 176 | HFILE hDev; | 
|---|
| 177 |  | 
|---|
| 178 | # pragma pack(1) | 
|---|
| 179 | struct | 
|---|
| 180 | { | 
|---|
| 181 | BYTE Cmd; | 
|---|
| 182 | BYTE Unit; | 
|---|
| 183 | } | 
|---|
| 184 | parmPkt = | 
|---|
| 185 | { | 
|---|
| 186 | 0, 0}; | 
|---|
| 187 | # define BPB_REMOVABLE_MEDIA    0x08    // 3 - Media is removable | 
|---|
| 188 | struct | 
|---|
| 189 | { | 
|---|
| 190 | BIOSPARAMETERBLOCK bpb; | 
|---|
| 191 | USHORT cCylinders;          // Documented but not implemented | 
|---|
| 192 | BYTE bDeviceType;           // Documented but not implemented | 
|---|
| 193 | USHORT fsDeviceAttr;        // Documented but not implemented | 
|---|
| 194 | } | 
|---|
| 195 | dataPkt; | 
|---|
| 196 |  | 
|---|
| 197 | # pragma pack() | 
|---|
| 198 | BYTE NonRemovable; | 
|---|
| 199 | PFSQBUFFER2 pfsq; | 
|---|
| 200 |  | 
|---|
| 201 | if (pszFileSystem) | 
|---|
| 202 | *pszFileSystem = 0; | 
|---|
| 203 |  | 
|---|
| 204 | if (pulType) | 
|---|
| 205 | *pulType = 0; | 
|---|
| 206 |  | 
|---|
| 207 | # define BUFFER_BYTES 8192 | 
|---|
| 208 | rc = DosAllocMem(&pvBuffer, BUFFER_BYTES, | 
|---|
| 209 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); | 
|---|
| 210 | if (rc) { | 
|---|
| 211 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| 212 | GetPString(IDS_OUTOFMEMORY)); | 
|---|
| 213 | return -1;                          // Say failed | 
|---|
| 214 | } | 
|---|
| 215 |  | 
|---|
| 216 | szPath[0] = chDrive; | 
|---|
| 217 | szPath[1] = ':'; | 
|---|
| 218 | szPath[2] = 0; | 
|---|
| 219 | clBufferSize = BUFFER_BYTES; | 
|---|
| 220 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 221 | rc = DosQueryFSAttach(szPath, 0, FSAIL_QUERYNAME, | 
|---|
| 222 | (PFSQBUFFER2) pvBuffer, &clBufferSize); | 
|---|
| 223 | if (rc) { | 
|---|
| 224 | /* can't get any info at all */ | 
|---|
| 225 | DosFreeMem(pvBuffer); | 
|---|
| 226 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 227 | return -1;                          // Say failed | 
|---|
| 228 | } | 
|---|
| 229 |  | 
|---|
| 230 | pfsq = (PFSQBUFFER2) pvBuffer; | 
|---|
| 231 | pfsn = (PCHAR)(pfsq->szName) + pfsq->cbName + 1; | 
|---|
| 232 | pfsd = pfsn + pfsq->cbFSDName + 1; | 
|---|
| 233 |  | 
|---|
| 234 | if (pszFileSystem) { | 
|---|
| 235 | strncpy(pszFileSystem, pfsn, CCHMAXPATH); | 
|---|
| 236 | pszFileSystem[CCHMAXPATH - 1] = 0; | 
|---|
| 237 | } | 
|---|
| 238 |  | 
|---|
| 239 | if (pulType && (!strcmp(pfsn, CDFS) || !strcmp(pfsn, ISOFS))) | 
|---|
| 240 | *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE; | 
|---|
| 241 | if (pulType && !strcmp(pfsn, NTFS)) | 
|---|
| 242 | *pulType |= DRIVE_NOTWRITEABLE; | 
|---|
| 243 | if (pulType && !strcmp(pfsn, NDFS32)){ | 
|---|
| 244 | *pulType |= DRIVE_VIRTUAL; | 
|---|
| 245 | } | 
|---|
| 246 | if (pulType && !strcmp(pfsn, RAMFS)){ | 
|---|
| 247 | *pulType |= DRIVE_RAMDISK; | 
|---|
| 248 | } | 
|---|
| 249 | if (((PFSQBUFFER2) pvBuffer)->iType == FSAT_REMOTEDRV && | 
|---|
| 250 | (strcmp(pfsn, CDFS) || strcmp(pfsn, ISOFS))) { | 
|---|
| 251 | if (pulType) | 
|---|
| 252 | *pulType |= DRIVE_REMOTE; | 
|---|
| 253 |  | 
|---|
| 254 | if (pulType && !strcmp(pfsn, CBSIFS)) { | 
|---|
| 255 | *pulType |= DRIVE_ZIPSTREAM; | 
|---|
| 256 | *pulType &= ~DRIVE_REMOTE; | 
|---|
| 257 | *pulType |= DRIVE_NOLONGNAMES; | 
|---|
| 258 | if (pfsq->cbFSAData) { | 
|---|
| 259 | ULONG FType; | 
|---|
| 260 |  | 
|---|
| 261 | if (CheckDrive(*pfsd, NULL, &FType) != -1) { | 
|---|
| 262 | if (FType & DRIVE_REMOVABLE) | 
|---|
| 263 | *pulType |= DRIVE_REMOVABLE; | 
|---|
| 264 | if (~FType & DRIVE_NOLONGNAMES) | 
|---|
| 265 | *pulType &= ~DRIVE_NOLONGNAMES; | 
|---|
| 266 | } | 
|---|
| 267 |  | 
|---|
| 268 | } | 
|---|
| 269 | } | 
|---|
| 270 | if (pulType && | 
|---|
| 271 | (!strcmp(pfsn, HPFS) || | 
|---|
| 272 | !strcmp(pfsn, JFS) || | 
|---|
| 273 | !strcmp(pfsn, FAT32) || | 
|---|
| 274 | !strcmp(pfsn, RAMFS) || | 
|---|
| 275 | !strcmp(pfsn, NDFS32) || | 
|---|
| 276 | !strcmp(pfsn, NTFS) || | 
|---|
| 277 | !strcmp(pfsn, HPFS386))) { | 
|---|
| 278 | *pulType &= ~DRIVE_NOLONGNAMES; | 
|---|
| 279 | } | 
|---|
| 280 |  | 
|---|
| 281 | DosFreeMem(pvBuffer); | 
|---|
| 282 | return 0;                           // Remotes are non-removable | 
|---|
| 283 | } | 
|---|
| 284 |  | 
|---|
| 285 | // Local drive | 
|---|
| 286 | if (strcmp(pfsn, HPFS) && | 
|---|
| 287 | strcmp(pfsn, JFS) && | 
|---|
| 288 | strcmp(pfsn, CDFS) && | 
|---|
| 289 | strcmp(pfsn, ISOFS) && | 
|---|
| 290 | strcmp(pfsn, RAMFS) && | 
|---|
| 291 | strcmp(pfsn, FAT32) && | 
|---|
| 292 | strcmp(pfsn, NDFS32) && | 
|---|
| 293 | strcmp(pfsn, NTFS) && | 
|---|
| 294 | strcmp(pfsn, HPFS386)) { | 
|---|
| 295 | if (pulType) | 
|---|
| 296 | (*pulType) |= DRIVE_NOLONGNAMES;  // Others can not have long names | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 |  | 
|---|
| 300 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 301 | rc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN, | 
|---|
| 302 | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE | | 
|---|
| 303 | OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0); | 
|---|
| 304 | if (rc) { | 
|---|
| 305 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 306 | if (pulType) | 
|---|
| 307 | *pulType |= DRIVE_REMOVABLE;      // Assume removable if can not access | 
|---|
| 308 | DosFreeMem(pvBuffer); | 
|---|
| 309 | return 1;                           // Say removable | 
|---|
| 310 | } | 
|---|
| 311 |  | 
|---|
| 312 | clParmBytes = sizeof(parmPkt.Cmd); | 
|---|
| 313 | clDataBytes = sizeof(NonRemovable); | 
|---|
| 314 | NonRemovable = 1;                     // Preset as non removable | 
|---|
| 315 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 316 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE, &parmPkt.Cmd,  /*  Address of the command-specific argument list. */ | 
|---|
| 317 | sizeof(parmPkt.Cmd), /*  Length, in bytes, of pParams. */ | 
|---|
| 318 | &clParmBytes,        /*  Pointer to the length of parameters. */ | 
|---|
| 319 | &NonRemovable,       /*  Address of the data area. */ | 
|---|
| 320 | sizeof(NonRemovable),        /*  Length, in bytes, of pData. */ | 
|---|
| 321 | &clDataBytes);       /*  Pointer to the length of data. */ | 
|---|
| 322 |  | 
|---|
| 323 | if (!rc && NonRemovable) { | 
|---|
| 324 | // Could be USB so check BPB flags | 
|---|
| 325 | clParmBytes = sizeof(parmPkt.Cmd); | 
|---|
| 326 | clDataBytes = sizeof(dataPkt); | 
|---|
| 327 | memset(&dataPkt, 0xff, sizeof(dataPkt)); | 
|---|
| 328 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 329 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS, &parmPkt.Cmd,       /*  Address of the command-specific argument list. */ | 
|---|
| 330 | sizeof(parmPkt.Cmd),       /*  Length, in bytes, of pParams. */ | 
|---|
| 331 | &clParmBytes,      /*  Pointer to the length of parameters. */ | 
|---|
| 332 | &dataPkt,          /*  Address of the data area. */ | 
|---|
| 333 | sizeof(dataPkt),   /*  Length, in bytes, of pData. */ | 
|---|
| 334 | &clDataBytes);     /*  Pointer to the length of data. */ | 
|---|
| 335 |  | 
|---|
| 336 | if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA)) | 
|---|
| 337 | NonRemovable = 0; | 
|---|
| 338 | } | 
|---|
| 339 |  | 
|---|
| 340 | DosClose(hDev); | 
|---|
| 341 |  | 
|---|
| 342 | if (!NonRemovable && pulType) | 
|---|
| 343 | *pulType |= DRIVE_REMOVABLE; | 
|---|
| 344 |  | 
|---|
| 345 | DosFreeMem(pvBuffer); | 
|---|
| 346 |  | 
|---|
| 347 | return NonRemovable ? 0 : 1; | 
|---|
| 348 | } | 
|---|
| 349 |  | 
|---|
| 350 | BOOL IsFileSame(CHAR * filename1, CHAR * filename2) | 
|---|
| 351 | { | 
|---|
| 352 | /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */ | 
|---|
| 353 |  | 
|---|
| 354 | FILESTATUS3 fsa1, fsa2; | 
|---|
| 355 | APIRET ret; | 
|---|
| 356 |  | 
|---|
| 357 | if (filename1 && filename2) { | 
|---|
| 358 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 359 | ret = DosQueryPathInfo(filename1, FIL_STANDARD, &fsa1, | 
|---|
| 360 | (ULONG) sizeof(fsa1)); | 
|---|
| 361 | if (!ret) { | 
|---|
| 362 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 363 | ret = DosQueryPathInfo(filename2, FIL_STANDARD, &fsa2, | 
|---|
| 364 | (ULONG) sizeof(fsa2)); | 
|---|
| 365 | if (!ret) { | 
|---|
| 366 | if (fsa1.cbFile == fsa2.cbFile && | 
|---|
| 367 | (fsa1.attrFile & (~FILE_ARCHIVED)) == | 
|---|
| 368 | (fsa2.attrFile & (~FILE_ARCHIVED))) | 
|---|
| 369 | return TRUE; | 
|---|
| 370 | } | 
|---|
| 371 | } | 
|---|
| 372 | } | 
|---|
| 373 | return FALSE; | 
|---|
| 374 | } | 
|---|
| 375 |  | 
|---|
| 376 | INT IsFile(CHAR * filename) | 
|---|
| 377 | { | 
|---|
| 378 | /* returns:  -1 (error), 0 (is a directory), or 1 (is a file) */ | 
|---|
| 379 |  | 
|---|
| 380 | FILESTATUS3 fsa; | 
|---|
| 381 | APIRET ret; | 
|---|
| 382 |  | 
|---|
| 383 | if (filename && *filename) { | 
|---|
| 384 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 385 | ret = DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)); | 
|---|
| 386 | if (!ret) | 
|---|
| 387 | return ((fsa.attrFile & FILE_DIRECTORY) == 0); | 
|---|
| 388 | else if (IsValidDrive(*filename) && IsRoot(filename)) | 
|---|
| 389 | return 0; | 
|---|
| 390 | } | 
|---|
| 391 | return -1;                            /* error; doesn't exist or can't read or null filename */ | 
|---|
| 392 | } | 
|---|
| 393 |  | 
|---|
| 394 | BOOL IsFullName(CHAR * filename) | 
|---|
| 395 | { | 
|---|
| 396 | return (filename) ? | 
|---|
| 397 | (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : 0; | 
|---|
| 398 | } | 
|---|
| 399 |  | 
|---|
| 400 | BOOL IsRoot(CHAR * filename) | 
|---|
| 401 | { | 
|---|
| 402 | return (filename && isalpha(*filename) && filename[1] == ':' && | 
|---|
| 403 | filename[2] == '\\' && !filename[3]); | 
|---|
| 404 | } | 
|---|
| 405 |  | 
|---|
| 406 | BOOL IsValidDir(CHAR * path) | 
|---|
| 407 | { | 
|---|
| 408 | CHAR fullname[CCHMAXPATH]; | 
|---|
| 409 | FILESTATUS3 fs; | 
|---|
| 410 |  | 
|---|
| 411 | if (path) { | 
|---|
| 412 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 413 | if (!DosQueryPathInfo(path, | 
|---|
| 414 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) { | 
|---|
| 415 | if (IsValidDrive(*fullname)) { | 
|---|
| 416 | if (!IsRoot(fullname)) { | 
|---|
| 417 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 418 | if (!DosQueryPathInfo(fullname, | 
|---|
| 419 | FIL_STANDARD, | 
|---|
| 420 | &fs, | 
|---|
| 421 | sizeof(fs)) && (fs.attrFile & FILE_DIRECTORY)) | 
|---|
| 422 | return TRUE; | 
|---|
| 423 | } | 
|---|
| 424 | else | 
|---|
| 425 | return TRUE; | 
|---|
| 426 | } | 
|---|
| 427 | } | 
|---|
| 428 | } | 
|---|
| 429 | return FALSE; | 
|---|
| 430 | } | 
|---|
| 431 |  | 
|---|
| 432 | BOOL IsValidDrive(CHAR drive) | 
|---|
| 433 | { | 
|---|
| 434 | CHAR Path[] = " :", Buffer[256]; | 
|---|
| 435 | APIRET Status; | 
|---|
| 436 | ULONG Size; | 
|---|
| 437 | ULONG ulDriveNum, ulDriveMap; | 
|---|
| 438 |  | 
|---|
| 439 | if (!isalpha(drive) || | 
|---|
| 440 | (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID))) | 
|---|
| 441 | return FALSE; | 
|---|
| 442 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 443 | Status = DosQCurDisk(&ulDriveNum, &ulDriveMap); | 
|---|
| 444 | if (!Status) { | 
|---|
| 445 | if (!(ulDriveMap & (1 << (ULONG) (toupper(drive) - 'A')))) | 
|---|
| 446 | return FALSE; | 
|---|
| 447 | Path[0] = toupper(drive); | 
|---|
| 448 | Size = sizeof(Buffer); | 
|---|
| 449 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 450 | Status = DosQueryFSAttach(Path, | 
|---|
| 451 | 0, | 
|---|
| 452 | FSAIL_QUERYNAME, (PFSQBUFFER2) Buffer, &Size); | 
|---|
| 453 | } | 
|---|
| 454 | return (Status == 0); | 
|---|
| 455 | } | 
|---|
| 456 |  | 
|---|
| 457 | //=== MakeValidDir() build valid directory name === | 
|---|
| 458 |  | 
|---|
| 459 | CHAR *MakeValidDir(CHAR * path) | 
|---|
| 460 | { | 
|---|
| 461 | ULONG ulDrv; | 
|---|
| 462 | CHAR *p; | 
|---|
| 463 | FILESTATUS3 fs; | 
|---|
| 464 | APIRET rc; | 
|---|
| 465 |  | 
|---|
| 466 | if (!MakeFullName(path)) { | 
|---|
| 467 | if (IsValidDrive(*path)) { | 
|---|
| 468 | // Passed name is valid - trim to directory | 
|---|
| 469 | for (;;) { | 
|---|
| 470 | if (IsRoot(path)) | 
|---|
| 471 | return path; | 
|---|
| 472 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 473 | rc = DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs)); | 
|---|
| 474 | if (!rc && (fs.attrFile & FILE_DIRECTORY)) | 
|---|
| 475 | return path; | 
|---|
| 476 | p = strrchr(path, '\\'); | 
|---|
| 477 | if (p) { | 
|---|
| 478 | if (p < path + 3) | 
|---|
| 479 | p++; | 
|---|
| 480 | *p = 0; | 
|---|
| 481 | } | 
|---|
| 482 | else | 
|---|
| 483 | break; | 
|---|
| 484 | } | 
|---|
| 485 | } | 
|---|
| 486 | } | 
|---|
| 487 | // Fall back to boot drive | 
|---|
| 488 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 489 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulDrv, sizeof(ulDrv))) { | 
|---|
| 490 | ulDrv += '@'; | 
|---|
| 491 | if (ulDrv < 'C') | 
|---|
| 492 | ulDrv = 'C'; | 
|---|
| 493 | strcpy(path, " :\\"); | 
|---|
| 494 | *path = (CHAR) ulDrv; | 
|---|
| 495 | } | 
|---|
| 496 | else | 
|---|
| 497 | save_dir2(path);                    // Fall back to fm3.ini drive or current dir - should never occur | 
|---|
| 498 | return path; | 
|---|
| 499 | } | 
|---|
| 500 |  | 
|---|
| 501 | BOOL IsExecutable(CHAR * filename) | 
|---|
| 502 | { | 
|---|
| 503 | register CHAR *p; | 
|---|
| 504 | APIRET ret; | 
|---|
| 505 | ULONG apptype; | 
|---|
| 506 |  | 
|---|
| 507 | if (filename) { | 
|---|
| 508 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 509 | p = strrchr(filename, '.'); | 
|---|
| 510 | if (p) | 
|---|
| 511 | ret = DosQueryAppType(filename, &apptype); | 
|---|
| 512 | else { | 
|---|
| 513 |  | 
|---|
| 514 | char fname[CCHMAXPATH + 2]; | 
|---|
| 515 |  | 
|---|
| 516 | strcpy(fname, filename); | 
|---|
| 517 | strcat(fname, "."); | 
|---|
| 518 | ret = DosQueryAppType(fname, &apptype); | 
|---|
| 519 | } | 
|---|
| 520 | if ((!ret && (!apptype || | 
|---|
| 521 | (apptype & | 
|---|
| 522 | (FAPPTYP_NOTWINDOWCOMPAT | | 
|---|
| 523 | FAPPTYP_WINDOWCOMPAT | | 
|---|
| 524 | FAPPTYP_WINDOWAPI | | 
|---|
| 525 | FAPPTYP_BOUND | | 
|---|
| 526 | FAPPTYP_DOS | | 
|---|
| 527 | FAPPTYP_WINDOWSREAL | | 
|---|
| 528 | FAPPTYP_WINDOWSPROT | | 
|---|
| 529 | FAPPTYP_32BIT | | 
|---|
| 530 | 0x1000)))) || | 
|---|
| 531 | (p && (!stricmp(p, ".CMD") || !stricmp(p, ".BAT")))) | 
|---|
| 532 | return TRUE; | 
|---|
| 533 | } | 
|---|
| 534 | return FALSE; | 
|---|
| 535 | } | 
|---|
| 536 |  | 
|---|
| 537 | VOID ArgDriveFlags(INT argc, CHAR ** argv) | 
|---|
| 538 | { | 
|---|
| 539 | INT x; | 
|---|
| 540 |  | 
|---|
| 541 | for (x = 1; x < argc; x++) { | 
|---|
| 542 | if (*argv[x] == '/' && isalpha(argv[x][1])) { | 
|---|
| 543 |  | 
|---|
| 544 | CHAR *p = &argv[x][1]; | 
|---|
| 545 |  | 
|---|
| 546 | while (isalpha(*p)) { | 
|---|
| 547 | driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE; | 
|---|
| 548 | p++; | 
|---|
| 549 | } | 
|---|
| 550 | } | 
|---|
| 551 | else if (*argv[x] == ';' && isalpha(argv[x][1])) { | 
|---|
| 552 |  | 
|---|
| 553 | CHAR *p = &argv[x][1]; | 
|---|
| 554 |  | 
|---|
| 555 | while (isalpha(*p)) { | 
|---|
| 556 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN; | 
|---|
| 557 | p++; | 
|---|
| 558 | } | 
|---|
| 559 | } | 
|---|
| 560 | else if (*argv[x] == '`' && isalpha(argv[x][1])) { | 
|---|
| 561 |  | 
|---|
| 562 | CHAR *p = &argv[x][1]; | 
|---|
| 563 |  | 
|---|
| 564 | while (isalpha(*p)) { | 
|---|
| 565 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOSTATS; | 
|---|
| 566 | p++; | 
|---|
| 567 | } | 
|---|
| 568 | } | 
|---|
| 569 | else if (*argv[x] == ',' && isalpha(argv[x][1])) { | 
|---|
| 570 |  | 
|---|
| 571 | CHAR *p = &argv[x][1]; | 
|---|
| 572 |  | 
|---|
| 573 | while (isalpha(*p)) { | 
|---|
| 574 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS; | 
|---|
| 575 | p++; | 
|---|
| 576 | } | 
|---|
| 577 | } | 
|---|
| 578 | else if (*argv[x] == '-' && isalpha(argv[x][1])) { | 
|---|
| 579 |  | 
|---|
| 580 | CHAR *p = &argv[x][1]; | 
|---|
| 581 |  | 
|---|
| 582 | while (isalpha(*p)) { | 
|---|
| 583 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS; | 
|---|
| 584 | p++; | 
|---|
| 585 | } | 
|---|
| 586 | } | 
|---|
| 587 | else if (*argv[x] == '\'' && isalpha(argv[x][1])) { | 
|---|
| 588 |  | 
|---|
| 589 | CHAR *p = &argv[x][1]; | 
|---|
| 590 |  | 
|---|
| 591 | while (isalpha(*p)) { | 
|---|
| 592 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS; | 
|---|
| 593 | p++; | 
|---|
| 594 | } | 
|---|
| 595 | } | 
|---|
| 596 | } | 
|---|
| 597 | } | 
|---|
| 598 |  | 
|---|
| 599 | VOID DriveFlagsOne(INT x) | 
|---|
| 600 | { | 
|---|
| 601 | INT removable; | 
|---|
| 602 | CHAR szDrive[] = " :\\", FileSystem[CCHMAXPATH]; | 
|---|
| 603 | ULONG drvtype; | 
|---|
| 604 |  | 
|---|
| 605 | *szDrive = (CHAR) (x + 'A'); | 
|---|
| 606 | *FileSystem = 0; | 
|---|
| 607 | drvtype = 0; | 
|---|
| 608 | removable = CheckDrive(*szDrive, FileSystem, &drvtype); | 
|---|
| 609 | driveserial[x] = -1; | 
|---|
| 610 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS | | 
|---|
| 611 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | | 
|---|
| 612 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS); | 
|---|
| 613 | if (removable != -1) { | 
|---|
| 614 | struct | 
|---|
| 615 | { | 
|---|
| 616 | ULONG serial; | 
|---|
| 617 | CHAR volumelength; | 
|---|
| 618 | CHAR volumelabel[CCHMAXPATH]; | 
|---|
| 619 | } | 
|---|
| 620 | volser; | 
|---|
| 621 |  | 
|---|
| 622 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 623 | if (!DosQueryFSInfo((ULONG) x + 1, FSIL_VOLSER, &volser, sizeof(volser))) | 
|---|
| 624 | driveserial[x] = volser.serial; | 
|---|
| 625 | else | 
|---|
| 626 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 627 | } | 
|---|
| 628 | else | 
|---|
| 629 | driveflags[x] |= DRIVE_INVALID; | 
|---|
| 630 | driveflags[x] |= ((removable == -1 || removable == 1) ? | 
|---|
| 631 | DRIVE_REMOVABLE : 0); | 
|---|
| 632 | if (drvtype & DRIVE_REMOTE) | 
|---|
| 633 | driveflags[x] |= DRIVE_REMOTE; | 
|---|
| 634 | if(!stricmp(FileSystem,NDFS32)){ | 
|---|
| 635 | driveflags[x] |= DRIVE_VIRTUAL; | 
|---|
| 636 | driveflags[x] &= (~DRIVE_REMOTE); | 
|---|
| 637 | } | 
|---|
| 638 | if(!stricmp(FileSystem,RAMFS)){ | 
|---|
| 639 | driveflags[x] |= DRIVE_RAMDISK; | 
|---|
| 640 | driveflags[x] &= (~DRIVE_REMOTE); | 
|---|
| 641 | } | 
|---|
| 642 | if(!stricmp(FileSystem,NTFS)) | 
|---|
| 643 | driveflags[x] |= DRIVE_NOTWRITEABLE; | 
|---|
| 644 | if (strcmp(FileSystem, HPFS) && | 
|---|
| 645 | strcmp(FileSystem, JFS) && | 
|---|
| 646 | strcmp(FileSystem, CDFS) && | 
|---|
| 647 | strcmp(FileSystem, ISOFS) && | 
|---|
| 648 | strcmp(FileSystem, RAMFS) && | 
|---|
| 649 | strcmp(FileSystem, FAT32) && | 
|---|
| 650 | strcmp(FileSystem, NTFS) && | 
|---|
| 651 | strcmp(FileSystem, NDFS32) && | 
|---|
| 652 | strcmp(FileSystem, HPFS386)) { | 
|---|
| 653 | driveflags[x] |= DRIVE_NOLONGNAMES; | 
|---|
| 654 | } | 
|---|
| 655 |  | 
|---|
| 656 | if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) { | 
|---|
| 657 | removable = 1; | 
|---|
| 658 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM); | 
|---|
| 659 | } | 
|---|
| 660 | else if (!stricmp(FileSystem, CBSIFS)) { | 
|---|
| 661 | driveflags[x] |= DRIVE_ZIPSTREAM; | 
|---|
| 662 | driveflags[x] &= (~DRIVE_REMOTE); | 
|---|
| 663 | if (drvtype & DRIVE_REMOVABLE) | 
|---|
| 664 | driveflags[x] |= DRIVE_REMOVABLE; | 
|---|
| 665 | if (!(drvtype & DRIVE_NOLONGNAMES)) | 
|---|
| 666 | driveflags[x] &= (~DRIVE_NOLONGNAMES); | 
|---|
| 667 | } | 
|---|
| 668 | } | 
|---|
| 669 |  | 
|---|
| 670 | VOID FillInDriveFlags(VOID * dummy) | 
|---|
| 671 | { | 
|---|
| 672 | ULONG ulDriveNum, ulDriveMap; | 
|---|
| 673 | register INT x; | 
|---|
| 674 |  | 
|---|
| 675 | for (x = 0; x < 26; x++) | 
|---|
| 676 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS | | 
|---|
| 677 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS | | 
|---|
| 678 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS); | 
|---|
| 679 | memset(driveserial, -1, sizeof(driveserial)); | 
|---|
| 680 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 681 | DosQCurDisk(&ulDriveNum, &ulDriveMap); | 
|---|
| 682 | for (x = 0; x < 26; x++) { | 
|---|
| 683 | if (ulDriveMap & (1 << x) && !(driveflags[x] & DRIVE_IGNORE)) { | 
|---|
| 684 | { | 
|---|
| 685 | CHAR s[80]; | 
|---|
| 686 | ULONG flags = 0, size = sizeof(ULONG); | 
|---|
| 687 |  | 
|---|
| 688 | sprintf(s, "%c.DriveFlags", (CHAR) (x + 'A')); | 
|---|
| 689 | if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) && | 
|---|
| 690 | size == sizeof(ULONG)) | 
|---|
| 691 | driveflags[x] |= flags; | 
|---|
| 692 | } | 
|---|
| 693 |  | 
|---|
| 694 | if (x > 1) { | 
|---|
| 695 | if (!(driveflags[x] & DRIVE_NOPRESCAN)) | 
|---|
| 696 | DriveFlagsOne(x); | 
|---|
| 697 | else | 
|---|
| 698 | driveserial[x] = -1; | 
|---|
| 699 | } | 
|---|
| 700 | else { | 
|---|
| 701 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES); | 
|---|
| 702 | driveserial[x] = -1; | 
|---|
| 703 | } | 
|---|
| 704 | } | 
|---|
| 705 | else if (!(ulDriveMap & (1 << x))) | 
|---|
| 706 | driveflags[x] |= DRIVE_INVALID; | 
|---|
| 707 | } | 
|---|
| 708 | { | 
|---|
| 709 | ULONG startdrive = 3L; | 
|---|
| 710 |  | 
|---|
| 711 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 712 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, | 
|---|
| 713 | (PVOID) & startdrive, (ULONG) sizeof(ULONG)); | 
|---|
| 714 | if (startdrive) | 
|---|
| 715 | driveflags[startdrive - 1] |= DRIVE_BOOT; | 
|---|
| 716 | } | 
|---|
| 717 | } | 
|---|
| 718 |  | 
|---|
| 719 | CHAR *assign_ignores(CHAR * s) | 
|---|
| 720 | { | 
|---|
| 721 | register INT x; | 
|---|
| 722 | register CHAR *p, *pp; | 
|---|
| 723 |  | 
|---|
| 724 | *s = '/'; | 
|---|
| 725 | s[1] = 0; | 
|---|
| 726 | p = s + 1; | 
|---|
| 727 | if (s) { | 
|---|
| 728 | for (x = 0; x < 26; x++) { | 
|---|
| 729 | if ((driveflags[x] & DRIVE_IGNORE) != 0) { | 
|---|
| 730 | *p = (CHAR) x + 'A'; | 
|---|
| 731 | p++; | 
|---|
| 732 | *p = 0; | 
|---|
| 733 | } | 
|---|
| 734 | } | 
|---|
| 735 | } | 
|---|
| 736 | if (!s[1]) { | 
|---|
| 737 | *s = 0; | 
|---|
| 738 | pp = s; | 
|---|
| 739 | } | 
|---|
| 740 | else { | 
|---|
| 741 | pp = &s[strlen(s)]; | 
|---|
| 742 | *pp = ' '; | 
|---|
| 743 | pp++; | 
|---|
| 744 | } | 
|---|
| 745 | *pp = ';'; | 
|---|
| 746 | pp[1] = 0; | 
|---|
| 747 | p = pp + 1; | 
|---|
| 748 | if (pp) { | 
|---|
| 749 | for (x = 0; x < 26; x++) { | 
|---|
| 750 | if ((driveflags[x] & DRIVE_NOPRESCAN) != 0) { | 
|---|
| 751 | *p = (CHAR) x + 'A'; | 
|---|
| 752 | p++; | 
|---|
| 753 | *p = 0; | 
|---|
| 754 | } | 
|---|
| 755 | } | 
|---|
| 756 | } | 
|---|
| 757 | if (!pp[1]) | 
|---|
| 758 | *pp = 0; | 
|---|
| 759 | pp = &s[strlen(s)]; | 
|---|
| 760 | *pp = ' '; | 
|---|
| 761 | pp++; | 
|---|
| 762 | *pp = ','; | 
|---|
| 763 | pp[1] = 0; | 
|---|
| 764 | p = pp + 1; | 
|---|
| 765 | if (pp) { | 
|---|
| 766 | for (x = 0; x < 26; x++) { | 
|---|
| 767 | if ((driveflags[x] & DRIVE_NOLOADICONS) != 0) { | 
|---|
| 768 | *p = (CHAR) x + 'A'; | 
|---|
| 769 | p++; | 
|---|
| 770 | *p = 0; | 
|---|
| 771 | } | 
|---|
| 772 | } | 
|---|
| 773 | } | 
|---|
| 774 | if (!pp[1]) | 
|---|
| 775 | *pp = 0; | 
|---|
| 776 | pp = &s[strlen(s)]; | 
|---|
| 777 | *pp = ' '; | 
|---|
| 778 | pp++; | 
|---|
| 779 | *pp = '-'; | 
|---|
| 780 | pp[1] = 0; | 
|---|
| 781 | p = pp + 1; | 
|---|
| 782 | if (pp) { | 
|---|
| 783 | for (x = 0; x < 26; x++) { | 
|---|
| 784 | if ((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) { | 
|---|
| 785 | *p = (CHAR) x + 'A'; | 
|---|
| 786 | p++; | 
|---|
| 787 | *p = 0; | 
|---|
| 788 | } | 
|---|
| 789 | } | 
|---|
| 790 | } | 
|---|
| 791 | if (!pp[1]) | 
|---|
| 792 | *pp = 0; | 
|---|
| 793 | pp = &s[strlen(s)]; | 
|---|
| 794 | *pp = ' '; | 
|---|
| 795 | pp++; | 
|---|
| 796 | *pp = '`'; | 
|---|
| 797 | pp[1] = 0; | 
|---|
| 798 | p = pp + 1; | 
|---|
| 799 | if (pp) { | 
|---|
| 800 | for (x = 0; x < 26; x++) { | 
|---|
| 801 | if ((driveflags[x] & DRIVE_NOSTATS) != 0) { | 
|---|
| 802 | *p = (CHAR) x + 'A'; | 
|---|
| 803 | p++; | 
|---|
| 804 | *p = 0; | 
|---|
| 805 | } | 
|---|
| 806 | } | 
|---|
| 807 | } | 
|---|
| 808 | if (!pp[1]) | 
|---|
| 809 | *pp = 0; | 
|---|
| 810 | pp = &s[strlen(s)]; | 
|---|
| 811 | *pp = ' '; | 
|---|
| 812 | pp++; | 
|---|
| 813 | *pp = '\''; | 
|---|
| 814 | pp[1] = 0; | 
|---|
| 815 | p = pp + 1; | 
|---|
| 816 | if (pp) { | 
|---|
| 817 | for (x = 0; x < 26; x++) { | 
|---|
| 818 | if ((driveflags[x] & DRIVE_NOLOADLONGS) != 0) { | 
|---|
| 819 | *p = (CHAR) x + 'A'; | 
|---|
| 820 | p++; | 
|---|
| 821 | *p = 0; | 
|---|
| 822 | } | 
|---|
| 823 | } | 
|---|
| 824 | } | 
|---|
| 825 | if (!pp[1]) | 
|---|
| 826 | *pp = 0; | 
|---|
| 827 | bstrip(s); | 
|---|
| 828 | return s; | 
|---|
| 829 | } | 
|---|
| 830 |  | 
|---|
| 831 | BOOL needs_quoting(register CHAR * f) | 
|---|
| 832 | { | 
|---|
| 833 | register CHAR *p = " &|<>"; | 
|---|
| 834 |  | 
|---|
| 835 | while (*p) { | 
|---|
| 836 | if (strchr(f, *p)) | 
|---|
| 837 | return TRUE; | 
|---|
| 838 | p++; | 
|---|
| 839 | } | 
|---|
| 840 | return FALSE; | 
|---|
| 841 | } | 
|---|
| 842 |  | 
|---|
| 843 | BOOL IsBinary(register CHAR * str, ULONG len) | 
|---|
| 844 | { | 
|---|
| 845 | register ULONG x = 0; | 
|---|
| 846 |  | 
|---|
| 847 | if (str) { | 
|---|
| 848 | while (x < len) { | 
|---|
| 849 | if (str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t' | 
|---|
| 850 | && str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07' | 
|---|
| 851 | && str[x] != '\x0c') | 
|---|
| 852 | return TRUE; | 
|---|
| 853 | x++; | 
|---|
| 854 | } | 
|---|
| 855 | } | 
|---|
| 856 | return FALSE; | 
|---|
| 857 | } | 
|---|
| 858 |  | 
|---|
| 859 | BOOL TestBinary(CHAR * filename) | 
|---|
| 860 | { | 
|---|
| 861 | HFILE handle; | 
|---|
| 862 | ULONG ulAction; | 
|---|
| 863 | ULONG len; | 
|---|
| 864 | APIRET rc; | 
|---|
| 865 | CHAR buff[512]; | 
|---|
| 866 |  | 
|---|
| 867 | if (filename) { | 
|---|
| 868 | if (!DosOpen(filename, &handle, &ulAction, 0, 0, | 
|---|
| 869 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, | 
|---|
| 870 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT | | 
|---|
| 871 | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE | | 
|---|
| 872 | OPEN_ACCESS_READONLY, 0)) { | 
|---|
| 873 | len = 512; | 
|---|
| 874 | rc = DosRead(handle, buff, len, &len); | 
|---|
| 875 | DosClose(handle); | 
|---|
| 876 | if (!rc && len) | 
|---|
| 877 | return IsBinary(buff, len); | 
|---|
| 878 | } | 
|---|
| 879 | } | 
|---|
| 880 | return FALSE; | 
|---|
| 881 | } | 
|---|
| 882 |  | 
|---|
| 883 | char *IsVowel(char a) | 
|---|
| 884 | { | 
|---|
| 885 | return (strchr("aeiouAEIOU", a) != NULL) ? "n" : NullStr; | 
|---|
| 886 | } | 
|---|
| 887 |  | 
|---|
| 888 | VOID GetDesktopName(CHAR * objectpath, ULONG size) | 
|---|
| 889 | { | 
|---|
| 890 | PFN WQDPath; | 
|---|
| 891 | HMODULE hmod = 0; | 
|---|
| 892 | APIRET rc; | 
|---|
| 893 | ULONG startdrive = 3; | 
|---|
| 894 | CHAR objerr[CCHMAXPATH]; | 
|---|
| 895 |  | 
|---|
| 896 | if (!objectpath) { | 
|---|
| 897 | Runtime_Error(pszSrcFile, __LINE__, "null pointer"); | 
|---|
| 898 | return; | 
|---|
| 899 | } | 
|---|
| 900 | *objectpath = 0; | 
|---|
| 901 | if (OS2ver[0] > 20 || (OS2ver[0] == 20 && OS2ver[1] >= 30)) { | 
|---|
| 902 | /* | 
|---|
| 903 | * if running under warp, we can get the desktop name | 
|---|
| 904 | * this way... | 
|---|
| 905 | */ | 
|---|
| 906 | rc = DosLoadModule(objerr, sizeof(objerr), "PMWP", &hmod); | 
|---|
| 907 | if (!rc) { | 
|---|
| 908 | rc = DosQueryProcAddr(hmod, 262, NULL, &WQDPath); | 
|---|
| 909 | if (!rc) | 
|---|
| 910 | WQDPath(objectpath, size); | 
|---|
| 911 | DosFreeModule(hmod); | 
|---|
| 912 | } | 
|---|
| 913 | } | 
|---|
| 914 | if (!*objectpath) { | 
|---|
| 915 | // Fall back to INI content | 
|---|
| 916 | if (!PrfQueryProfileString(HINI_SYSTEMPROFILE, | 
|---|
| 917 | "FolderWorkareaRunningObjects", | 
|---|
| 918 | NULL, | 
|---|
| 919 | "\0", | 
|---|
| 920 | (PVOID) objectpath, sizeof(objectpath))) { | 
|---|
| 921 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
| 922 | "PrfQueryProfileString"); | 
|---|
| 923 | *objectpath = 0; | 
|---|
| 924 | } | 
|---|
| 925 | else if (!*objectpath || IsFile(objectpath)) { | 
|---|
| 926 | Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects"); | 
|---|
| 927 | *objectpath = 0; | 
|---|
| 928 | } | 
|---|
| 929 | if (!*objectpath) { | 
|---|
| 930 | // Fall back | 
|---|
| 931 | DosError(FERR_DISABLEHARDERR); | 
|---|
| 932 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, | 
|---|
| 933 | (PVOID) & startdrive, (ULONG) sizeof(ULONG)); | 
|---|
| 934 | sprintf(objectpath, GetPString(IDS_PATHTODESKTOP), ((CHAR) startdrive) + '@'); | 
|---|
| 935 | } | 
|---|
| 936 | } | 
|---|
| 937 | } | 
|---|
| 938 |  | 
|---|
| 939 | #pragma alloc_text(VALID,CheckDrive,IsRoot,IsFile,IsFullName,needsquoting) | 
|---|
| 940 | #pragma alloc_text(VALID,IsValidDir,IsValidDrive,MakeValidDir,IsVowel) | 
|---|
| 941 | #pragma alloc_text(VALID,IsFileSame,IsNewer,TestDates,RootName,MakeFullName) | 
|---|
| 942 | #pragma alloc_text(VALID,IsExecutable,IsBinary,IsDesktop,ParentIsDesktop) | 
|---|
| 943 | #pragma alloc_text(FILLFLAGS,FillInDriveFlags,assign_ignores) | 
|---|
| 944 | #pragma alloc_text(FILLFLAGS,ArgDriveFlags,DriveFlagsOne) | 
|---|
| 945 | #pragma alloc_text(FINDDESK,GetDesktopName) | 
|---|