source: trunk/dll/valid.c@ 70

Last change on this file since 70 was 70, checked in by root, 22 years ago

Add JFS and FAT32 support

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