source: trunk/dll/valid.c@ 184

Last change on this file since 184 was 184, checked in by root, 20 years ago

Drop CD_DEBUG logic

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