1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: autoview.c 846 2007-09-27 21:16:00Z stevenhl $
|
---|
5 |
|
---|
6 | Auto view
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2001, 2006 Steven H.Levine
|
---|
10 |
|
---|
11 | 12 Sep 02 SHL AutoObjProc: catch buff2 overflows
|
---|
12 | 25 Oct 02 SHL CreateHexDump: catch buffer overflow
|
---|
13 | 12 Feb 03 SHL AutoObjProc: standardize EA math
|
---|
14 | 23 May 05 SHL Use QWL_USER
|
---|
15 | 29 May 06 SHL Sync with archiver.bb2 mods
|
---|
16 | 22 Jul 06 SHL Check more run time errors
|
---|
17 | 15 Aug 06 SHL Use Runtime_Error more
|
---|
18 | 03 Nov 06 SHL Renames
|
---|
19 | 30 Mar 07 GKY Remove GetPString for window class names
|
---|
20 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
21 | 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
|
---|
22 | 27 Sep 07 SHL Correct ULONGLONG size formatting
|
---|
23 |
|
---|
24 | ***********************************************************************/
|
---|
25 |
|
---|
26 | #define INCL_DOS
|
---|
27 | #define INCL_WIN
|
---|
28 | #define INCL_GPI
|
---|
29 | #define INCL_LONGLONG
|
---|
30 | #include <os2.h>
|
---|
31 |
|
---|
32 | #include <stdlib.h>
|
---|
33 | #include <stdio.h>
|
---|
34 | #include <string.h>
|
---|
35 | #include <ctype.h>
|
---|
36 | #include <process.h> // _beginthread
|
---|
37 |
|
---|
38 | #include "fm3dll.h"
|
---|
39 | #include "fm3dlg.h"
|
---|
40 | #include "fm3str.h"
|
---|
41 | #include "mle.h"
|
---|
42 |
|
---|
43 | #pragma data_seg(DATA1)
|
---|
44 |
|
---|
45 | static PSZ pszSrcFile = __FILE__;
|
---|
46 |
|
---|
47 | static HWND hwndAutoObj;
|
---|
48 | static CHAR stopflag;
|
---|
49 | static CHAR currfile[CCHMAXPATH];
|
---|
50 |
|
---|
51 | BOOL WriteEA(HWND hwnd, CHAR * filename, CHAR * eaname, USHORT type,
|
---|
52 | CHAR * data)
|
---|
53 | {
|
---|
54 | /* save an ea to disk */
|
---|
55 |
|
---|
56 | FEA2LIST *pfealist = NULL;
|
---|
57 | EAOP2 eaop;
|
---|
58 | APIRET rc;
|
---|
59 | ULONG ealen;
|
---|
60 | USHORT len, *num, *plen, usCodepage;
|
---|
61 | CHAR *p, *eaval;
|
---|
62 | BOOL ret = FALSE;
|
---|
63 |
|
---|
64 | if (!filename || !eaname)
|
---|
65 | return ret;
|
---|
66 | usCodepage = (USHORT) WinQueryCp(WinQueryWindowULong(hwnd, QWL_HMQ));
|
---|
67 | len = (data) ? strlen(data) : 0;
|
---|
68 | ealen = sizeof(FEA2LIST) + 24L + strlen(eaname) + 1L + (ULONG) len + 4L;
|
---|
69 | switch (type) {
|
---|
70 | case EAT_EA:
|
---|
71 | case EAT_ASCII:
|
---|
72 | break;
|
---|
73 | case EAT_MVST:
|
---|
74 | if (data) {
|
---|
75 | ealen += sizeof(USHORT) * 5;
|
---|
76 | p = data;
|
---|
77 | while (*p) {
|
---|
78 | if (*p == '\n' && *(p + 1))
|
---|
79 | ealen += sizeof(USHORT);
|
---|
80 | p++;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | break;
|
---|
84 | case EAT_MVMT:
|
---|
85 | if (data) {
|
---|
86 | ealen += sizeof(USHORT) * 5;
|
---|
87 | p = data;
|
---|
88 | while (*p) {
|
---|
89 | if (*p == '\n' && *(p + 1))
|
---|
90 | ealen += (sizeof(USHORT) * 2);
|
---|
91 | p++;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | break;
|
---|
95 | default:
|
---|
96 | return ret;
|
---|
97 | }
|
---|
98 |
|
---|
99 | rc = DosAllocMem((PPVOID) & pfealist, ealen, PAG_COMMIT | PAG_READ |
|
---|
100 | PAG_WRITE | OBJ_TILE);
|
---|
101 | if (rc || !pfealist)
|
---|
102 | Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
|
---|
103 | GetPString(IDS_OUTOFMEMORY));
|
---|
104 | else {
|
---|
105 | memset(pfealist, 0, ealen);
|
---|
106 | pfealist->list[0].cbName = strlen(eaname);
|
---|
107 | memcpy(pfealist->list[0].szName, eaname, pfealist->list[0].cbName + 1);
|
---|
108 | eaval = pfealist->list[0].szName + pfealist->list[0].cbName + 1;
|
---|
109 | switch (type) {
|
---|
110 | case EAT_EA:
|
---|
111 | case EAT_ASCII:
|
---|
112 | if (data) {
|
---|
113 | *(USHORT *) eaval = (USHORT) type;
|
---|
114 | eaval += sizeof(USHORT);
|
---|
115 | *(USHORT *) eaval = (USHORT) len;
|
---|
116 | eaval += sizeof(USHORT);
|
---|
117 | memcpy(eaval, data, len);
|
---|
118 | eaval += len;
|
---|
119 | }
|
---|
120 | break;
|
---|
121 | case EAT_MVST:
|
---|
122 | if (data) {
|
---|
123 | *(USHORT *) eaval = (USHORT) EAT_MVST;
|
---|
124 | eaval += sizeof(USHORT);
|
---|
125 | *(USHORT *) eaval = usCodepage;
|
---|
126 | eaval += sizeof(USHORT);
|
---|
127 | num = (USHORT *) eaval;
|
---|
128 | *num = 0;
|
---|
129 | eaval += sizeof(USHORT);
|
---|
130 | *(USHORT *) eaval = (USHORT) EAT_ASCII;
|
---|
131 | eaval += sizeof(USHORT);
|
---|
132 | plen = (USHORT *) eaval;
|
---|
133 | *plen = 0;
|
---|
134 | eaval += sizeof(USHORT);
|
---|
135 | p = data;
|
---|
136 | while (*p) {
|
---|
137 | while (*p) {
|
---|
138 | if (*p == '\n') {
|
---|
139 | p++;
|
---|
140 | break;
|
---|
141 | }
|
---|
142 | *eaval++ = *p++;
|
---|
143 | (*plen)++;
|
---|
144 | }
|
---|
145 | if (*p || *plen)
|
---|
146 | (*num)++;
|
---|
147 | if (*p) {
|
---|
148 | plen = (USHORT *) eaval;
|
---|
149 | *plen = 0;
|
---|
150 | eaval += sizeof(USHORT);
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 | break;
|
---|
155 | case EAT_MVMT:
|
---|
156 | if (data) {
|
---|
157 | *(USHORT *) eaval = (USHORT) EAT_MVMT;
|
---|
158 | eaval += sizeof(USHORT);
|
---|
159 | *(USHORT *) eaval = usCodepage;
|
---|
160 | eaval += sizeof(USHORT);
|
---|
161 | num = (USHORT *) eaval;
|
---|
162 | *num = 0;
|
---|
163 | eaval += sizeof(USHORT);
|
---|
164 | *(USHORT *) eaval = (USHORT) EAT_ASCII;
|
---|
165 | eaval += sizeof(USHORT);
|
---|
166 | plen = (USHORT *) eaval;
|
---|
167 | *plen = 0;
|
---|
168 | eaval += sizeof(USHORT);
|
---|
169 | p = data;
|
---|
170 | while (*p) {
|
---|
171 | while (*p) {
|
---|
172 | if (*p == '\n') {
|
---|
173 | p++;
|
---|
174 | break;
|
---|
175 | }
|
---|
176 | *eaval++ = *p++;
|
---|
177 | (*plen)++;
|
---|
178 | }
|
---|
179 | if (*p || *plen)
|
---|
180 | (*num)++;
|
---|
181 | if (*p) {
|
---|
182 | *(USHORT *) eaval = (USHORT) EAT_ASCII;
|
---|
183 | eaval += sizeof(USHORT);
|
---|
184 | plen = (USHORT *) eaval;
|
---|
185 | *plen = 0;
|
---|
186 | eaval += sizeof(USHORT);
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | break;
|
---|
191 | }
|
---|
192 | pfealist->list[0].cbValue = (ULONG) (eaval -
|
---|
193 | (pfealist->list[0].szName +
|
---|
194 | pfealist->list[0].cbName + 1));
|
---|
195 | memset(&eaop, 0, sizeof(eaop));
|
---|
196 | eaop.fpFEA2List = pfealist;
|
---|
197 | pfealist->cbList = 13 + (ULONG) pfealist->list[0].cbName +
|
---|
198 | (ULONG) pfealist->list[0].cbValue;
|
---|
199 | rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
|
---|
200 | &eaop, sizeof(eaop), DSPI_WRTTHRU);
|
---|
201 | DosFreeMem(pfealist);
|
---|
202 | if (!rc)
|
---|
203 | ret = TRUE;
|
---|
204 | }
|
---|
205 | return ret;
|
---|
206 | }
|
---|
207 |
|
---|
208 | BOOL PutComments(HWND hwnd, CHAR * filename, CHAR * comments)
|
---|
209 | {
|
---|
210 | register CHAR *p;
|
---|
211 |
|
---|
212 | if (comments) { /* check -- is it empty? */
|
---|
213 | p = comments;
|
---|
214 | while (*p && isspace(*p))
|
---|
215 | p++;
|
---|
216 | if (!*p)
|
---|
217 | comments = NULL;
|
---|
218 | }
|
---|
219 | return WriteEA(hwnd, filename, ".COMMENTS", EAT_MVMT, comments);
|
---|
220 | }
|
---|
221 |
|
---|
222 | static PSZ pszBufOvfMsg = "Buffer overflow";
|
---|
223 |
|
---|
224 | ULONG CreateHexDump(CHAR * pchInBuf, ULONG cbInBuf,
|
---|
225 | CHAR * pchOutBuf, ULONG cbOutBuf,
|
---|
226 | ULONG cOffset, BOOL fLongAddr)
|
---|
227 | {
|
---|
228 | register CHAR *pchIn, *pchReset, *pchOut;
|
---|
229 | register ULONG ibIn = 0, ibIn2, ibInFill;
|
---|
230 | ULONG cbOutLine = 6 + (fLongAddr ? 4 : 0) + 16 * 3 + 1 + 16 + 1;
|
---|
231 |
|
---|
232 | if (pchInBuf && cbInBuf && pchOutBuf && cbOutBuf) {
|
---|
233 | pchIn = pchInBuf;
|
---|
234 | pchOut = pchOutBuf;
|
---|
235 | if (cOffset)
|
---|
236 | *pchOut++ = '\n';
|
---|
237 | while (ibIn < cbInBuf) {
|
---|
238 | if (pchOut - pchOutBuf + cbOutLine >= cbOutBuf) {
|
---|
239 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
|
---|
240 | break;
|
---|
241 | }
|
---|
242 | pchReset = pchIn;
|
---|
243 | ibIn2 = ibIn;
|
---|
244 | if (fLongAddr)
|
---|
245 | sprintf(pchOut, "%08lx ", ibIn + cOffset);
|
---|
246 | else
|
---|
247 | sprintf(pchOut, "%04lx ", ibIn + cOffset);
|
---|
248 | pchOut += 6 + (fLongAddr ? 4 : 0);
|
---|
249 | do {
|
---|
250 | sprintf(pchOut, "%02hx ", *pchIn);
|
---|
251 | pchOut += 3;
|
---|
252 | pchIn++;
|
---|
253 | ibIn++;
|
---|
254 | } while (ibIn < cbInBuf && (ibIn % 16));
|
---|
255 | if (ibIn % 16) {
|
---|
256 | ibInFill = ibIn;
|
---|
257 | while (ibInFill % 16) {
|
---|
258 | *pchOut++ = ' ';
|
---|
259 | *pchOut++ = ' ';
|
---|
260 | *pchOut++ = ' ';
|
---|
261 | ibInFill++;
|
---|
262 | }
|
---|
263 | }
|
---|
264 | *pchOut++ = ' ';
|
---|
265 | pchIn = pchReset;
|
---|
266 | do {
|
---|
267 | if (*pchIn && *pchIn != '\n' && *pchIn != '\r' && *pchIn != '\t'
|
---|
268 | && *pchIn != '\x1a')
|
---|
269 | *pchOut++ = *pchIn++;
|
---|
270 | else {
|
---|
271 | *pchOut++ = '.';
|
---|
272 | pchIn++;
|
---|
273 | }
|
---|
274 | ibIn2++;
|
---|
275 | } while (ibIn2 < ibIn);
|
---|
276 | if (ibIn < cbInBuf)
|
---|
277 | *pchOut++ = '\n';
|
---|
278 | } // while ibIn
|
---|
279 | *pchOut = 0;
|
---|
280 | return (ULONG) (pchOut - pchOutBuf);
|
---|
281 | }
|
---|
282 | return 0L;
|
---|
283 | }
|
---|
284 |
|
---|
285 | MRESULT EXPENTRY AutoObjProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
286 | {
|
---|
287 | switch (msg) {
|
---|
288 | case UM_LOADFILE:
|
---|
289 | *currfile = 0;
|
---|
290 | stopflag--;
|
---|
291 | if (fAutoView) {
|
---|
292 | WinSetWindowText((fComments) ? hwndAutoMLE : hwndAutoview, "");
|
---|
293 | MLEsetreadonly(hwndAutoMLE, TRUE);
|
---|
294 | MLEsetchanged(hwndAutoMLE, FALSE);
|
---|
295 | }
|
---|
296 | if (mp1) {
|
---|
297 | if (fAutoView) {
|
---|
298 | strcpy(currfile, (CHAR *) mp1);
|
---|
299 | if (!fComments) {
|
---|
300 | if (IsFile((CHAR *) mp1) == 1) {
|
---|
301 |
|
---|
302 | HFILE handle;
|
---|
303 | ULONG olen, ibufflen, action, obufflen, l;
|
---|
304 | CHAR *ibuff, *obuff, *p, buffer[80];
|
---|
305 | ARC_TYPE *info;
|
---|
306 |
|
---|
307 | if (!DosOpen((CHAR *) mp1,
|
---|
308 | &handle,
|
---|
309 | &action,
|
---|
310 | 0,
|
---|
311 | 0,
|
---|
312 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
313 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
|
---|
314 | OPEN_FLAGS_RANDOMSEQUENTIAL | OPEN_SHARE_DENYNONE |
|
---|
315 | OPEN_ACCESS_READONLY, 0)) {
|
---|
316 | ibufflen = (AutoviewHeight < 96) ? 512 : 3072;
|
---|
317 | ibuff = xmalloc(ibufflen + 2, pszSrcFile, __LINE__);
|
---|
318 | if (ibuff) {
|
---|
319 | // Depends on CreateHexDump line width
|
---|
320 | obufflen = (ibufflen / 16) * (6 + 3 * 16 + 1 + 16 + 1) + 80;
|
---|
321 | obuff = xmalloc(obufflen + 1, pszSrcFile, __LINE__);
|
---|
322 | if (obuff) {
|
---|
323 | *obuff = 0;
|
---|
324 | if (!DosRead(handle,
|
---|
325 | ibuff, ibufflen, &ibufflen) && ibufflen) {
|
---|
326 | ibuff[ibufflen] = 0;
|
---|
327 | p = obuff;
|
---|
328 | if (IsBinary(ibuff, ibufflen)) {
|
---|
329 | olen = ibufflen;
|
---|
330 | // Check archive
|
---|
331 | if (!arcsigsloaded)
|
---|
332 | load_archivers();
|
---|
333 | info = arcsighead;
|
---|
334 | while (info) {
|
---|
335 | if (info->signature && *info->signature) {
|
---|
336 | l = strlen(info->signature);
|
---|
337 | l = min(l, 79);
|
---|
338 | if (!DosChgFilePtr(handle, abs(info->file_offset),
|
---|
339 | (info->file_offset >= 0L) ?
|
---|
340 | FILE_BEGIN :
|
---|
341 | FILE_END, &ibufflen)) {
|
---|
342 | if (!DosRead(handle,
|
---|
343 | buffer,
|
---|
344 | l, &ibufflen) && ibufflen == l) {
|
---|
345 | if (!memcmp(info->signature, buffer, l))
|
---|
346 | break;
|
---|
347 | }
|
---|
348 | }
|
---|
349 | }
|
---|
350 | info = info->next;
|
---|
351 | }
|
---|
352 | if (info) {
|
---|
353 | sprintf(p, "**%s%s%s\n",
|
---|
354 | info->id ? info->id : "",
|
---|
355 | info->id ? " " : "",
|
---|
356 | GetPString(IDS_ARCHIVETEXT));
|
---|
357 | p += strlen(p);
|
---|
358 | }
|
---|
359 | CreateHexDump(ibuff, // Input buffer
|
---|
360 | olen, // Input buffer size
|
---|
361 | p, // Output buffer
|
---|
362 | obufflen - (p - obuff), // Output buffer size
|
---|
363 | 0, // Address offest
|
---|
364 | FALSE); // Short addresses
|
---|
365 | }
|
---|
366 | else {
|
---|
367 | // Text file
|
---|
368 | register CHAR *src, *dest;
|
---|
369 | CHAR *endsrc;
|
---|
370 |
|
---|
371 | src = ibuff;
|
---|
372 | dest = obuff;
|
---|
373 | endsrc = ibuff + ibufflen;
|
---|
374 | while (src < endsrc) {
|
---|
375 | if (dest == obuff && (*src == '\t' || *src == ' ' ||
|
---|
376 | *src == '\r' || *src == '\n')) {
|
---|
377 | src++;
|
---|
378 | }
|
---|
379 | else if (*src == '\t' || !*src) {
|
---|
380 | *dest = ' ';
|
---|
381 | dest++;
|
---|
382 | src++;
|
---|
383 | }
|
---|
384 | else if (*src == '\r' || *src == '\n') {
|
---|
385 | *dest = *src;
|
---|
386 | while (*(src + 1) == '\r' || *(src + 1) == '\n' ||
|
---|
387 | *(src + 1) == ' ' || *(src + 1) == '\t')
|
---|
388 | src++;
|
---|
389 | dest++;
|
---|
390 | src++;
|
---|
391 | }
|
---|
392 | else {
|
---|
393 | *dest = *src;
|
---|
394 | src++;
|
---|
395 | dest++;
|
---|
396 | }
|
---|
397 | } // while
|
---|
398 | *dest = 0;
|
---|
399 | if (dest - obuff >= obufflen)
|
---|
400 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
|
---|
401 | }
|
---|
402 | if (*obuff)
|
---|
403 | WinSetWindowText(hwndAutoview, obuff);
|
---|
404 | }
|
---|
405 | free(obuff);
|
---|
406 | }
|
---|
407 | free(ibuff);
|
---|
408 | }
|
---|
409 | DosClose(handle);
|
---|
410 | }
|
---|
411 | }
|
---|
412 | else if (!IsFile(currfile)) {
|
---|
413 |
|
---|
414 | static FILEFINDBUF4L ffb[130];
|
---|
415 | CHAR fullname[CCHMAXPATH + 4];
|
---|
416 | HDIR hdir = HDIR_CREATE;
|
---|
417 | ULONG x, nm, ml, mc, bufflen;
|
---|
418 | PBYTE fb;
|
---|
419 | PFILEFINDBUF4L pffbFile;
|
---|
420 | PSZ pszBuf;
|
---|
421 | PSZ p;
|
---|
422 | APIRET rc;
|
---|
423 |
|
---|
424 | BldFullPathName(fullname, currfile, "*");
|
---|
425 | //sprintf(fullname,
|
---|
426 | // "%s%s*",
|
---|
427 | // currfile,
|
---|
428 | // (currfile[strlen(currfile) - 1] == '\\') ? "" : "\\");
|
---|
429 | DosError(FERR_DISABLEHARDERR);
|
---|
430 | nm = sizeof(ffb) / sizeof(FILEFINDBUF4L);
|
---|
431 | if (AutoviewHeight < 96)
|
---|
432 | nm /= 2;
|
---|
433 | rc = xDosFindFirst(fullname,
|
---|
434 | &hdir,
|
---|
435 | FILE_NORMAL | FILE_DIRECTORY |
|
---|
436 | FILE_READONLY | FILE_ARCHIVED |
|
---|
437 | FILE_SYSTEM | FILE_HIDDEN,
|
---|
438 | &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL);
|
---|
439 | if (!rc && nm) {
|
---|
440 | fb = (PBYTE) & ffb;
|
---|
441 | x = ml = 0;
|
---|
442 | while (x < nm) {
|
---|
443 | pffbFile = (PFILEFINDBUF4L) fb;
|
---|
444 | mc = (ULONG) pffbFile->cchName +
|
---|
445 | ((pffbFile->attrFile & FILE_DIRECTORY) != 0);
|
---|
446 | ml = max(ml, mc);
|
---|
447 | if (!pffbFile->oNextEntryOffset)
|
---|
448 | break;
|
---|
449 | fb += pffbFile->oNextEntryOffset;
|
---|
450 | x++;
|
---|
451 | }
|
---|
452 | bufflen = (CCHMAXPATHCOMP + 42) * nm;
|
---|
453 | pszBuf = xmalloc(bufflen, pszSrcFile, __LINE__);
|
---|
454 | if (pszBuf) {
|
---|
455 | p = pszBuf;
|
---|
456 | *p = 0;
|
---|
457 | fb = (PBYTE) & ffb;
|
---|
458 | x = 0;
|
---|
459 | while (x < nm) {
|
---|
460 | pffbFile = (PFILEFINDBUF4L) fb;
|
---|
461 | if (!(!*pffbFile->achName ||
|
---|
462 | (((pffbFile->attrFile & FILE_DIRECTORY) &&
|
---|
463 | pffbFile->achName[0] == '.') &&
|
---|
464 | (!pffbFile->achName[1] ||
|
---|
465 | (pffbFile->achName[1] == '.' &&
|
---|
466 | !pffbFile->achName[2]))))) {
|
---|
467 | // 27 Sep 07 SHL fixme to use CommaFmtULL
|
---|
468 | sprintf(p,
|
---|
469 | "%s%-*.*s %-8llu [%s%s%s%s] %04lu/%02lu/%02lu "
|
---|
470 | "%02lu:%02lu:%02lu\r",
|
---|
471 | pffbFile->attrFile & FILE_DIRECTORY ? "\\" : " ",
|
---|
472 | ml,
|
---|
473 | ml,
|
---|
474 | pffbFile->achName,
|
---|
475 | pffbFile->cbFile +
|
---|
476 | CBLIST_TO_EASIZE(pffbFile->cbList),
|
---|
477 | pffbFile->attrFile & FILE_READONLY ? "R" : "-",
|
---|
478 | pffbFile->attrFile & FILE_ARCHIVED ? "A" : "-",
|
---|
479 | pffbFile->attrFile & FILE_HIDDEN ? "H" : "-",
|
---|
480 | pffbFile->attrFile & FILE_SYSTEM ? "S" : "-",
|
---|
481 | pffbFile->fdateLastWrite.year + 1980,
|
---|
482 | pffbFile->fdateLastWrite.month,
|
---|
483 | pffbFile->fdateLastWrite.day,
|
---|
484 | pffbFile->ftimeLastWrite.hours,
|
---|
485 | pffbFile->ftimeLastWrite.minutes,
|
---|
486 | pffbFile->ftimeLastWrite.twosecs * 2);
|
---|
487 | p += strlen(p);
|
---|
488 | }
|
---|
489 | if (!pffbFile->oNextEntryOffset)
|
---|
490 | break;
|
---|
491 | fb += pffbFile->oNextEntryOffset;
|
---|
492 | x++;
|
---|
493 | } // while
|
---|
494 | if (p - pszBuf >= bufflen)
|
---|
495 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
|
---|
496 | if (*pszBuf)
|
---|
497 | WinSetWindowText(hwndAutoview, pszBuf);
|
---|
498 | free(pszBuf);
|
---|
499 | }
|
---|
500 | }
|
---|
501 | if (!rc)
|
---|
502 | DosFindClose(hdir);
|
---|
503 | }
|
---|
504 | }
|
---|
505 | else {
|
---|
506 |
|
---|
507 | APIRET rc;
|
---|
508 | EAOP2 eaop;
|
---|
509 | PGEA2LIST pgealist;
|
---|
510 | PFEA2LIST pfealist;
|
---|
511 | PGEA2 pgea;
|
---|
512 | PFEA2 pfea;
|
---|
513 | CHAR *value, *pszBuf, *p, *data;
|
---|
514 | USHORT len, type, plen, dlen;
|
---|
515 | BOOL readonly = FALSE;
|
---|
516 |
|
---|
517 | pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
|
---|
518 | if (pgealist) {
|
---|
519 | pgea = &pgealist->list[0];
|
---|
520 | strcpy(pgea->szName, ".COMMENTS");
|
---|
521 | pgea->cbName = strlen(pgea->szName);
|
---|
522 | pgea->oNextEntryOffset = 0L;
|
---|
523 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
---|
524 | pfealist = xmallocz(65536, pszSrcFile, __LINE__);
|
---|
525 | if (pfealist) {
|
---|
526 | pfealist->cbList = 65536;
|
---|
527 | eaop.fpGEA2List = pgealist;
|
---|
528 | eaop.fpFEA2List = pfealist;
|
---|
529 | eaop.oError = 0L;
|
---|
530 | rc = DosQueryPathInfo((CHAR *) mp1, FIL_QUERYEASFROMLIST,
|
---|
531 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
---|
532 | free(pgealist);
|
---|
533 | if (!rc) {
|
---|
534 | pfea = &eaop.fpFEA2List->list[0];
|
---|
535 | if (pfea->cbName && pfea->cbValue) {
|
---|
536 | value = pfea->szName + pfea->cbName + 1;
|
---|
537 | value[pfea->cbValue] = 0;
|
---|
538 | if (*(USHORT *) value == EAT_MVMT) {
|
---|
539 | pszBuf = xmalloc(65536, pszSrcFile, __LINE__);
|
---|
540 | if (pszBuf) {
|
---|
541 | p = pszBuf;
|
---|
542 | *pszBuf = 0;
|
---|
543 | data = value + (sizeof(USHORT) * 3);
|
---|
544 | type = *(USHORT *) data;
|
---|
545 | data += sizeof(USHORT);
|
---|
546 | len = *(USHORT *) data;
|
---|
547 | data += sizeof(USHORT);
|
---|
548 | while ((data - value) - len < pfea->cbValue) {
|
---|
549 | if (type == EAT_ASCII) {
|
---|
550 | dlen = plen = 0;
|
---|
551 | while (dlen < len) {
|
---|
552 | if (data[dlen] == '\r') {
|
---|
553 | dlen++;
|
---|
554 | if (dlen < len && data[dlen] != '\n')
|
---|
555 | p[plen++] = '\n';
|
---|
556 | }
|
---|
557 | else
|
---|
558 | p[plen++] = data[dlen++];
|
---|
559 | }
|
---|
560 | if ((!len || !plen || p[plen - 1] != '\n') &&
|
---|
561 | (data - value) + len < pfea->cbValue)
|
---|
562 | p[plen++] = '\n';
|
---|
563 | p += plen;
|
---|
564 | *p = 0;
|
---|
565 | }
|
---|
566 | else
|
---|
567 | readonly = TRUE;
|
---|
568 | data += len;
|
---|
569 | if (data - value >= pfea->cbValue)
|
---|
570 | break;
|
---|
571 | type = *(USHORT *) data;
|
---|
572 | data += sizeof(USHORT);
|
---|
573 | len = *(USHORT *) data;
|
---|
574 | data += sizeof(USHORT);
|
---|
575 | } // while
|
---|
576 | if (p - pszBuf >= 65536) {
|
---|
577 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
|
---|
578 | pszBuf[65535] = 0; // Try to stay alive
|
---|
579 | break;
|
---|
580 | }
|
---|
581 | WinSetWindowText(hwndAutoMLE, pszBuf);
|
---|
582 | free(pszBuf);
|
---|
583 | }
|
---|
584 | }
|
---|
585 | else
|
---|
586 | readonly = TRUE;
|
---|
587 | }
|
---|
588 | /* else EA not present */
|
---|
589 | MLEsetchanged(hwndAutoMLE, FALSE);
|
---|
590 | MLEsetreadonly(hwndAutoMLE, readonly);
|
---|
591 | }
|
---|
592 | else {
|
---|
593 | MLEsetchanged(hwndAutoMLE, FALSE);
|
---|
594 | MLEsetreadonly(hwndAutoMLE, FALSE);
|
---|
595 | }
|
---|
596 | free(pfealist);
|
---|
597 | }
|
---|
598 | }
|
---|
599 | }
|
---|
600 | }
|
---|
601 | free((CHAR *) mp1);
|
---|
602 | }
|
---|
603 | return 0;
|
---|
604 |
|
---|
605 | case UM_CLOSE:
|
---|
606 | if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
|
---|
607 | WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
|
---|
608 | WinDestroyWindow(hwnd);
|
---|
609 | return 0;
|
---|
610 | }
|
---|
611 | return WinDefWindowProc(hwnd, msg, mp1, mp2);
|
---|
612 | }
|
---|
613 |
|
---|
614 | static VOID MakeAutoWinThread(VOID * args)
|
---|
615 | {
|
---|
616 | HAB hab2;
|
---|
617 | HMQ hmq2;
|
---|
618 | HWND hwndParent = (HWND) args;
|
---|
619 | QMSG qmsg2;
|
---|
620 |
|
---|
621 | hab2 = WinInitialize(0);
|
---|
622 | if (hab2) {
|
---|
623 | hmq2 = WinCreateMsgQueue(hab2, 128);
|
---|
624 | if (hmq2) {
|
---|
625 | DosError(FERR_DISABLEHARDERR);
|
---|
626 | WinRegisterClass(hab2,
|
---|
627 | WC_OBJECTWINDOW,
|
---|
628 | AutoObjProc, 0, sizeof(PVOID));
|
---|
629 | hwndAutoObj = WinCreateWindow(HWND_OBJECT,
|
---|
630 | WC_OBJECTWINDOW,
|
---|
631 | (PSZ) NULL,
|
---|
632 | 0,
|
---|
633 | 0L,
|
---|
634 | 0L,
|
---|
635 | 0L,
|
---|
636 | 0L, 0L, HWND_TOP, OBJ_FRAME, NULL, NULL);
|
---|
637 | if (!hwndAutoObj) {
|
---|
638 | Win_Error2(HWND_OBJECT, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
639 | IDS_WINCREATEWINDOW);
|
---|
640 | if (!PostMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID))
|
---|
641 | WinSendMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID);
|
---|
642 | }
|
---|
643 | else {
|
---|
644 | WinSetWindowULong(hwndAutoObj, QWL_USER, hwndParent);
|
---|
645 | priority_normal();
|
---|
646 | while (WinGetMsg(hab2, &qmsg2, (HWND) 0, 0, 0))
|
---|
647 | WinDispatchMsg(hab2, &qmsg2);
|
---|
648 | WinDestroyWindow(hwndAutoObj);
|
---|
649 | hwndAutoObj = (HWND) 0;
|
---|
650 | }
|
---|
651 | WinDestroyMsgQueue(hmq2);
|
---|
652 | }
|
---|
653 | else
|
---|
654 | WinTerminate(hab2);
|
---|
655 | }
|
---|
656 | }
|
---|
657 |
|
---|
658 | MRESULT EXPENTRY AutoViewProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
659 | {
|
---|
660 | USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
|
---|
661 |
|
---|
662 | switch (msg) {
|
---|
663 | case WM_CREATE:
|
---|
664 | {
|
---|
665 | MRESULT mr;
|
---|
666 |
|
---|
667 | if (!hwndAutoObj) {
|
---|
668 | if (_beginthread(MakeAutoWinThread, NULL, 65536, (PVOID) hwnd) == -1) {
|
---|
669 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
670 | GetPString(IDS_COULDNTSTARTTHREADTEXT));
|
---|
671 | PostMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
|
---|
672 | }
|
---|
673 | }
|
---|
674 | mr = PFNWPStatic(hwnd, msg, mp1, mp2);
|
---|
675 | SetPresParams(hwnd,
|
---|
676 | &RGBGREY,
|
---|
677 | &RGBBLACK, &RGBGREY, GetPString(IDS_4SYSTEMVIOTEXT));
|
---|
678 | stopflag = 0;
|
---|
679 | return mr;
|
---|
680 | }
|
---|
681 |
|
---|
682 | case UM_SETUP:
|
---|
683 | MLEsetlimit(hwnd, 32768);
|
---|
684 | MLEsetformat(hwnd, MLFIE_NOTRANS);
|
---|
685 | MLEsetchanged(hwnd, FALSE);
|
---|
686 | return 0;
|
---|
687 |
|
---|
688 | case WM_BUTTON1DOWN:
|
---|
689 | {
|
---|
690 | SWP swp;
|
---|
691 |
|
---|
692 | WinQueryWindowPos(hwnd, &swp);
|
---|
693 | if (SHORT2FROMMP(mp1) > swp.cy - 4) {
|
---|
694 |
|
---|
695 | HPS hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
|
---|
696 | SWP swpC;
|
---|
697 | TRACKINFO track;
|
---|
698 |
|
---|
699 | if (hps) {
|
---|
700 | WinQueryWindowPos(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
|
---|
701 | FID_CLIENT), &swpC);
|
---|
702 | track.cxBorder = 4;
|
---|
703 | track.cyBorder = 4;
|
---|
704 | track.cxGrid = 1;
|
---|
705 | track.cyGrid = 8;
|
---|
706 | track.cxKeyboard = 8;
|
---|
707 | track.rclTrack.yBottom = swp.y;
|
---|
708 | track.rclTrack.yTop = swp.y + swp.cy;
|
---|
709 | track.rclTrack.xLeft = swp.x;
|
---|
710 | track.rclTrack.xRight = swp.x + swp.cx;
|
---|
711 | track.rclBoundary = track.rclTrack;
|
---|
712 | track.rclBoundary.yTop = (swpC.cy + swp.y + swp.cy) - 116;
|
---|
713 | track.ptlMinTrackSize.x = swp.x + swp.cx;
|
---|
714 | track.ptlMinTrackSize.y = 36;
|
---|
715 | track.ptlMaxTrackSize.x = swp.x + swp.cx;
|
---|
716 | track.ptlMaxTrackSize.y = (swpC.cy + swp.cy) - 116;
|
---|
717 | track.fs = TF_TOP;
|
---|
718 | if (WinTrackRect(hwnd, hps, &track)) {
|
---|
719 | AutoviewHeight = track.rclTrack.yTop - track.rclTrack.yBottom;
|
---|
720 | PrfWriteProfileData(fmprof,
|
---|
721 | FM3Str,
|
---|
722 | "AutoviewHeight",
|
---|
723 | &AutoviewHeight, sizeof(ULONG));
|
---|
724 | WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
|
---|
725 | WM_UPDATEFRAME, MPFROMLONG(FCF_SIZEBORDER), MPVOID);
|
---|
726 | }
|
---|
727 | WinReleasePS(hps);
|
---|
728 | }
|
---|
729 | return (MRESULT) TRUE;
|
---|
730 | }
|
---|
731 | else if (id != MAIN_AUTOVIEWMLE)
|
---|
732 | return CommonTextButton(hwnd, msg, mp1, mp2);
|
---|
733 | }
|
---|
734 | break;
|
---|
735 |
|
---|
736 | case WM_BUTTON3DOWN:
|
---|
737 | case WM_BUTTON1UP:
|
---|
738 | case WM_BUTTON3UP:
|
---|
739 | if (id != MAIN_AUTOVIEWMLE)
|
---|
740 | return CommonTextButton(hwnd, msg, mp1, mp2);
|
---|
741 | break;
|
---|
742 |
|
---|
743 | case WM_MOUSEMOVE:
|
---|
744 | shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
|
---|
745 | {
|
---|
746 | SWP swp;
|
---|
747 |
|
---|
748 | WinQueryWindowPos(hwnd, &swp);
|
---|
749 | if (SHORT2FROMMP(mp1) > swp.cy - 4) {
|
---|
750 | WinSetPointer(HWND_DESKTOP, hptrNS);
|
---|
751 | return (MRESULT) TRUE;
|
---|
752 | }
|
---|
753 | }
|
---|
754 | break;
|
---|
755 |
|
---|
756 | case WM_PAINT:
|
---|
757 | PostMsg(hwnd, UM_PAINT, MPVOID, MPVOID);
|
---|
758 | break;
|
---|
759 |
|
---|
760 | case UM_PAINT:
|
---|
761 | PaintRecessedWindow(hwnd, (HPS) 0, TRUE, TRUE);
|
---|
762 | return 0;
|
---|
763 |
|
---|
764 | case WM_SETFOCUS:
|
---|
765 | switch (id) {
|
---|
766 | case MAIN_AUTOVIEWMLE:
|
---|
767 | if (!mp2 && !AutoMenu) {
|
---|
768 | if (*currfile) {
|
---|
769 | if (MLEgetchanged(hwnd)) {
|
---|
770 | CHAR *ea = xmalloc(32768, pszSrcFile, __LINE__);
|
---|
771 |
|
---|
772 | if (ea) {
|
---|
773 | *ea = 0;
|
---|
774 | WinQueryWindowText(hwnd, 32767, ea);
|
---|
775 | PutComments(hwnd, currfile, ea);
|
---|
776 | PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
|
---|
777 | free(ea);
|
---|
778 | }
|
---|
779 | }
|
---|
780 | }
|
---|
781 | }
|
---|
782 | break;
|
---|
783 | default:
|
---|
784 | if (mp2)
|
---|
785 | PostMsg(hwnd, UM_FOCUSME, mp1, mp2);
|
---|
786 | break;
|
---|
787 | }
|
---|
788 | break;
|
---|
789 |
|
---|
790 | case UM_FOCUSME:
|
---|
791 | if (mp2) {
|
---|
792 |
|
---|
793 | PID pid;
|
---|
794 | TID tid;
|
---|
795 |
|
---|
796 | if (WinQueryWindowProcess((HWND) mp1, &pid, &tid) && pid == mypid)
|
---|
797 | WinSetFocus(HWND_DESKTOP, (HWND) mp1);
|
---|
798 | else
|
---|
799 | WinSetFocus(HWND_DESKTOP, hwndTree);
|
---|
800 | }
|
---|
801 | return 0;
|
---|
802 |
|
---|
803 | case UM_CLICKED:
|
---|
804 | case UM_CLICKED3:
|
---|
805 | if (id != MAIN_AUTOVIEWMLE) {
|
---|
806 | PostMsg(hwnd,
|
---|
807 | WM_COMMAND,
|
---|
808 | MPFROM2SHORT(((msg == UM_CLICKED3) ?
|
---|
809 | IDM_EAS : IDM_VIEWORARC), 0), MPVOID);
|
---|
810 | }
|
---|
811 | return 0;
|
---|
812 |
|
---|
813 | case WM_COMMAND:
|
---|
814 | PostMsg(hwnd, UM_COMMAND, mp1, mp2);
|
---|
815 | return 0;
|
---|
816 |
|
---|
817 | case UM_COMMAND:
|
---|
818 | switch (SHORT1FROMMP(mp1)) {
|
---|
819 | case IDM_RESCAN:
|
---|
820 | if (*currfile) {
|
---|
821 |
|
---|
822 | CHAR *cf = xstrdup(currfile, pszSrcFile, __LINE__);
|
---|
823 |
|
---|
824 | if (cf) {
|
---|
825 | stopflag++;
|
---|
826 | if (!PostMsg(hwndAutoObj, UM_LOADFILE, MPFROMP(cf), MPVOID))
|
---|
827 | free(cf);
|
---|
828 | }
|
---|
829 | }
|
---|
830 | break;
|
---|
831 |
|
---|
832 | case IDM_INFO:
|
---|
833 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 16, currfile);
|
---|
834 | break;
|
---|
835 |
|
---|
836 | case IDM_VIEW:
|
---|
837 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 0, currfile);
|
---|
838 | break;
|
---|
839 |
|
---|
840 | case IDM_EDIT:
|
---|
841 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 8, currfile);
|
---|
842 | break;
|
---|
843 |
|
---|
844 | case IDM_EAS:
|
---|
845 | {
|
---|
846 | char *list[2];
|
---|
847 |
|
---|
848 | list[0] = currfile;
|
---|
849 | list[1] = NULL;
|
---|
850 |
|
---|
851 | WinDlgBox(HWND_DESKTOP,
|
---|
852 | hwndMain,
|
---|
853 | DisplayEAsProc, FM3ModHandle, EA_FRAME, (PVOID) list);
|
---|
854 | }
|
---|
855 | break;
|
---|
856 |
|
---|
857 | default:
|
---|
858 | PostMsg(hwndMain, msg, mp1, mp2);
|
---|
859 | }
|
---|
860 | return 0;
|
---|
861 |
|
---|
862 | case WM_MENUEND:
|
---|
863 | if ((HWND) mp2 == AutoMenu) {
|
---|
864 | WinDestroyWindow(AutoMenu);
|
---|
865 | AutoMenu = (HWND) 0;
|
---|
866 | }
|
---|
867 | break;
|
---|
868 |
|
---|
869 | case WM_CONTEXTMENU:
|
---|
870 | CheckMenu(&AutoMenu, (id == MAIN_AUTOVIEWMLE) ?
|
---|
871 | IDM_AUTOVIEWMLE : IDM_AUTOVIEW);
|
---|
872 | WinCheckMenuItem(AutoMenu, IDM_AUTOVIEWFILE, !fComments);
|
---|
873 | WinCheckMenuItem(AutoMenu, IDM_AUTOVIEWCOMMENTS, fComments);
|
---|
874 | WinEnableMenuItem(AutoMenu, IDM_VIEW, (IsFile(currfile) == 1));
|
---|
875 | WinEnableMenuItem(AutoMenu, IDM_EDIT, (IsFile(currfile) == 1));
|
---|
876 | WinEnableMenuItem(AutoMenu, IDM_INFO, (*currfile != 0));
|
---|
877 | PopupMenu(hwnd, hwnd, AutoMenu);
|
---|
878 | break;
|
---|
879 |
|
---|
880 | case UM_LOADFILE:
|
---|
881 | stopflag++;
|
---|
882 | if (!PostMsg(hwndAutoObj, msg, mp1, mp2)) {
|
---|
883 | if (mp1)
|
---|
884 | free((CHAR *) mp1);
|
---|
885 | }
|
---|
886 | return 0;
|
---|
887 |
|
---|
888 | case UM_CLOSE:
|
---|
889 | if (AutoMenu) {
|
---|
890 | WinDestroyWindow(AutoMenu);
|
---|
891 | AutoMenu = (HWND) 0;
|
---|
892 | }
|
---|
893 | WinDestroyWindow(hwnd);
|
---|
894 | return 0;
|
---|
895 |
|
---|
896 | case WM_CLOSE:
|
---|
897 | WinSendMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
|
---|
898 | return 0;
|
---|
899 |
|
---|
900 | case WM_DESTROY:
|
---|
901 | if (id != MAIN_AUTOVIEWMLE) {
|
---|
902 | if (hwndAutoObj)
|
---|
903 | if (!PostMsg(hwndAutoObj, WM_CLOSE, MPVOID, MPVOID))
|
---|
904 | WinSendMsg(hwndAutoObj, WM_CLOSE, MPVOID, MPVOID);
|
---|
905 | break;
|
---|
906 | }
|
---|
907 | break;
|
---|
908 | }
|
---|
909 |
|
---|
910 | if (id == MAIN_AUTOVIEWMLE)
|
---|
911 | return PFNWPMLE(hwnd, msg, mp1, mp2);
|
---|
912 | return PFNWPStatic(hwnd, msg, mp1, mp2);
|
---|
913 | }
|
---|
914 |
|
---|
915 | #pragma alloc_text(AUTOVIEW,AutoViewProc,CreateHexDump,AutoObjProc)
|
---|
916 | #pragma alloc_text(AUTOVIEW2,MakeAutoWinThread,WriteEA,PutComments)
|
---|