source: trunk/dll/autoview.c@ 1439

Last change on this file since 1439 was 1439, checked in by Gregg Young, 16 years ago

Changes to allow high mem loading of dll; Refactor .LONGNAME and .SUBJECT EA fetch to FetchCommonEAs. Add szFSType to FillInRecordFromFSA use to bypass EA scan and size formatting for tree container; Fix labels/FS type to work on scan on NOPRESCAN Drives; Fixed dbl directory names on restore of dir cnrs; (Tickets 47, 339, 363, 368, 369, 370)

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