source: trunk/dll/valid.c@ 530

Last change on this file since 530 was 530, checked in by root, 19 years ago

Add NDFS32 support
Increased BUFFER_BYTES in CheckDrive to 8192 to fix NDFS32 scan failure

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