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