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