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