source: trunk/dll/valid.c@ 551

Last change on this file since 551 was 551, checked in by Gregg Young, 18 years ago

Indentation cleanup

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