source: trunk/dll/autoview.c@ 1032

Last change on this file since 1032 was 1032, checked in by Gregg Young, 17 years ago

Fortify updates including a leave scope wrapper which frees and in some cases reloads commands, archivers, association, etc.

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