source: trunk/dll/valid.c@ 551

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

Indentation cleanup

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