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