source: trunk/dll/autoview.c@ 1398

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

Move embeded strings to PCSZ variables or string table; Eliminate Error2 functions Runtime_Error with NULL format string returns "No data" error. Change declares from PSZ to PCSZ in functions where the variable isn't changed. Added btm as an executable file type in several additional places. Use fProtectOnly to prevent attempt to execute Dos and Win programs on "Protect only" installs in several additional places.

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