source: trunk/dll/valid.c@ 109

Last change on this file since 109 was 109, checked in by root, 21 years ago

Comments

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