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