source: trunk/dll/valid.c@ 847

Last change on this file since 847 was 847, checked in by Gregg Young, 18 years ago

Removed large file APIs from code where hey are not needed.

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