source: trunk/dll/valid.c@ 328

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

Use Runtime_Error

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