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
RevLine 
[41]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
[907]9 Copyright (c) 2001, 2008 Steven H.Levine
[41]10
[130]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
[291]15 29 May 06 SHL Sync with archiver.bb2 mods
[341]16 22 Jul 06 SHL Check more run time errors
[439]17 15 Aug 06 SHL Use Runtime_Error more
[531]18 03 Nov 06 SHL Renames
[689]19 30 Mar 07 GKY Remove GetPString for window class names
[793]20 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[827]21 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry
[846]22 27 Sep 07 SHL Correct ULONGLONG size formatting
[872]23 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
[897]24 30 Dec 07 GKY Use CommaFmtULL
[985]25 29 Feb 08 GKY Use xfree where appropriate
[1335]26 10 Dec 08 SHL Integrate exception handler support
[1391]27 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
[1395]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
[41]30
31***********************************************************************/
32
[907]33#include <stdlib.h>
34#include <string.h>
35#include <ctype.h>
[1335]36// #include <process.h> // _beginthread
[907]37
[2]38#define INCL_DOS
39#define INCL_WIN
40#define INCL_GPI
[841]41#define INCL_LONGLONG
[2]42
[1182]43#include "fm3dll.h"
[1220]44#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1204]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)
[2]51#include "fm3dlg.h"
52#include "fm3str.h"
53#include "mle.h"
[907]54#include "pathutil.h" // BldFullPathName
55#include "errutil.h" // Dos_Error...
56#include "strutil.h" // GetPString
[1159]57#include "autoview.h"
58#include "defview.h" // DefaultView
59#include "valid.h" // IsBinary
[1182]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
[1029]67#include "fortify.h"
[1335]68#include "excputil.h" // 06 May 08 SHL added
[1029]69
[1204]70static BOOL PutComments(HWND hwnd, CHAR * filename, CHAR * comments);
[1398]71static BOOL WriteEA(HWND hwnd, CHAR * filename, PCSZ eaname, USHORT type,
[1204]72 CHAR * data);
73
74// Data definitions
75#pragma data_seg(GLOBAL1)
76HWND hwndAutoMLE;
77
78#pragma data_seg(GLOBAL2)
79ULONG AutoviewHeight;
80
[2]81#pragma data_seg(DATA1)
[341]82static PSZ pszSrcFile = __FILE__;
83
[1204]84static HWND AutoMenu;
[341]85static HWND hwndAutoObj;
[2]86static CHAR stopflag;
87static CHAR currfile[CCHMAXPATH];
88
[1398]89BOOL WriteEA(HWND hwnd, CHAR * filename, PCSZ eaname, USHORT type,
[551]90 CHAR * data)
[341]91{
[2]92 /* save an ea to disk */
93
94 FEA2LIST *pfealist = NULL;
[551]95 EAOP2 eaop;
96 APIRET rc;
97 ULONG ealen;
98 USHORT len, *num, *plen, usCodepage;
99 CHAR *p, *eaval;
100 BOOL ret = FALSE;
[2]101
[551]102 if (!filename || !eaname)
[2]103 return ret;
[551]104 usCodepage = (USHORT) WinQueryCp(WinQueryWindowULong(hwnd, QWL_HMQ));
[2]105 len = (data) ? strlen(data) : 0;
[551]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) {
[2]148 case EAT_EA:
149 case EAT_ASCII:
[551]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 }
[2]158 break;
159 case EAT_MVST:
[551]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 }
[2]191 }
192 break;
193 case EAT_MVMT:
[551]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 }
[2]227 }
228 break;
229 }
[1029]230 pfealist->list[0].cbValue = /*(ULONG)*/ (eaval -
[551]231 (pfealist->list[0].szName +
232 pfealist->list[0].cbName + 1));
233 memset(&eaop, 0, sizeof(eaop));
[2]234 eaop.fpFEA2List = pfealist;
[841]235 pfealist->cbList = 13 + (ULONG) pfealist->list[0].cbName +
[551]236 (ULONG) pfealist->list[0].cbValue;
[827]237 rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE,
238 &eaop, sizeof(eaop), DSPI_WRTTHRU);
[2]239 DosFreeMem(pfealist);
[551]240 if (!rc)
[2]241 ret = TRUE;
242 }
243 return ret;
244}
245
[551]246BOOL PutComments(HWND hwnd, CHAR * filename, CHAR * comments)
[341]247{
[2]248 register CHAR *p;
249
[551]250 if (comments) { /* check -- is it empty? */
[2]251 p = comments;
[551]252 while (*p && isspace(*p))
[2]253 p++;
[551]254 if (!*p)
[2]255 comments = NULL;
256 }
[1398]257 return WriteEA(hwnd, filename, PCSZ_DOTCOMMENTS, EAT_MVMT, comments);
[2]258}
259
[439]260static PSZ pszBufOvfMsg = "Buffer overflow";
[2]261
[551]262ULONG CreateHexDump(CHAR * pchInBuf, ULONG cbInBuf,
263 CHAR * pchOutBuf, ULONG cbOutBuf,
264 ULONG cOffset, BOOL fLongAddr)
[41]265{
[551]266 register CHAR *pchIn, *pchReset, *pchOut;
267 register ULONG ibIn = 0, ibIn2, ibInFill;
[41]268 ULONG cbOutLine = 6 + (fLongAddr ? 4 : 0) + 16 * 3 + 1 + 16 + 1;
[2]269
[551]270 if (pchInBuf && cbInBuf && pchOutBuf && cbOutBuf) {
[41]271 pchIn = pchInBuf;
272 pchOut = pchOutBuf;
[551]273 if (cOffset)
[41]274 *pchOut++ = '\n';
275 while (ibIn < cbInBuf) {
276 if (pchOut - pchOutBuf + cbOutLine >= cbOutBuf) {
[551]277 Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
[41]278 break;
279 }
280 pchReset = pchIn;
281 ibIn2 = ibIn;
[551]282 if (fLongAddr)
283 sprintf(pchOut, "%08lx ", ibIn + cOffset);
[2]284 else
[551]285 sprintf(pchOut, "%04lx ", ibIn + cOffset);
[41]286 pchOut += 6 + (fLongAddr ? 4 : 0);
[2]287 do {
[870]288 sprintf(pchOut, "%02x ", (UCHAR)*pchIn);
[551]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 }
[2]301 }
[41]302 *pchOut++ = ' ';
303 pchIn = pchReset;
[2]304 do {
[551]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
[41]317 *pchOut = 0;
[551]318 return (ULONG) (pchOut - pchOutBuf);
[2]319 }
320 return 0L;
321}
322
[551]323MRESULT EXPENTRY AutoObjProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[51]324{
[551]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) {
[1009]336 strcpy(currfile, (CHAR *)mp1);
[551]337 if (!fComments) {
[1009]338 if (IsFile((CHAR *)mp1) == 1) {
[2]339
[551]340 HFILE handle;
[858]341 ULONG olen, ibufflen, action, obufflen, l;
[850]342 CHAR *ibuff, *obuff, *p;
343 CHAR buffer[4096];
[551]344 ARC_TYPE *info;
[2]345
[1009]346 if (!DosOpen((CHAR *)mp1,
[844]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)) {
[850]355 ibufflen = AutoviewHeight < 96 ? 512 : 3072;
356 // 06 Oct 07 SHL protect against NTFS driver small buffer defect
[858]357 ibuff = xmalloc(max(ibufflen + 2, 4096), pszSrcFile, __LINE__);
[551]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;
[850]364 if (!DosRead(handle, ibuff, ibufflen, &ibufflen) &&
365 ibufflen)
366 {
[551]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",
[773]395 info->id ? info->id : "",
396 info->id ? " " : "",
[551]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;
[2]411
[551]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 }
[1039]446 free(obuff);
[551]447 }
[1039]448 free(ibuff);
[551]449 }
450 DosClose(handle);
451 }
452 }
453 else if (!IsFile(currfile)) {
[2]454
[841]455 static FILEFINDBUF4L ffb[130];
[1397]456 CHAR fullname[CCHMAXPATH + 4], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES];
[551]457 HDIR hdir = HDIR_CREATE;
458 ULONG x, nm, ml, mc, bufflen;
459 PBYTE fb;
[841]460 PFILEFINDBUF4L pffbFile;
[773]461 PSZ pszBuf;
462 PSZ p;
463 APIRET rc;
[2]464
[773]465 BldFullPathName(fullname, currfile, "*");
[551]466 DosError(FERR_DISABLEHARDERR);
[841]467 nm = sizeof(ffb) / sizeof(FILEFINDBUF4L);
[551]468 if (AutoviewHeight < 96)
469 nm /= 2;
[838]470 rc = xDosFindFirst(fullname,
[858]471 &hdir,
472 FILE_NORMAL | FILE_DIRECTORY |
473 FILE_READONLY | FILE_ARCHIVED |
474 FILE_SYSTEM | FILE_HIDDEN,
475 &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL);
[551]476 if (!rc && nm) {
477 fb = (PBYTE) & ffb;
478 x = ml = 0;
479 while (x < nm) {
[841]480 pffbFile = (PFILEFINDBUF4L) fb;
[551]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;
[773]490 pszBuf = xmalloc(bufflen, pszSrcFile, __LINE__);
491 if (pszBuf) {
492 p = pszBuf;
[551]493 *p = 0;
494 fb = (PBYTE) & ffb;
495 x = 0;
496 while (x < nm) {
[841]497 pffbFile = (PFILEFINDBUF4L) fb;
[551]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]))))) {
[1078]504 CommaFmtULL(szCmmaFmtFileSize,
505 sizeof(szCmmaFmtFileSize),
506 pffbFile->cbFile + CBLIST_TO_EASIZE(pffbFile->cbList),
[1395]507 ' ');
508 FDateFormat(szDate, pffbFile->fdateLastWrite);
[551]509 sprintf(p,
[1395]510 "%s%-*.*s %-8s [%s%s%s%s] %s "
511 "%02lu%s%02lu%s%02lu\r",
[846]512 pffbFile->attrFile & FILE_DIRECTORY ? "\\" : " ",
[551]513 ml,
514 ml,
[1078]515 pffbFile->achName,
516 szCmmaFmtFileSize,
[846]517 pffbFile->attrFile & FILE_READONLY ? "R" : "-",
518 pffbFile->attrFile & FILE_ARCHIVED ? "A" : "-",
519 pffbFile->attrFile & FILE_HIDDEN ? "H" : "-",
520 pffbFile->attrFile & FILE_SYSTEM ? "S" : "-",
[1395]521 szDate,
522 pffbFile->ftimeLastWrite.hours, TimeSeparator,
523 pffbFile->ftimeLastWrite.minutes, TimeSeparator,
[551]524 pffbFile->ftimeLastWrite.twosecs * 2);
525 p += strlen(p);
526 }
527 if (!pffbFile->oNextEntryOffset)
528 break;
529 fb += pffbFile->oNextEntryOffset;
530 x++;
531 } // while
[773]532 if (p - pszBuf >= bufflen)
[551]533 Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
[773]534 if (*pszBuf)
535 WinSetWindowText(hwndAutoview, pszBuf);
[1039]536 free(pszBuf);
[551]537 }
538 }
539 if (!rc)
540 DosFindClose(hdir);
541 }
542 }
543 else {
[2]544
[551]545 APIRET rc;
546 EAOP2 eaop;
547 PGEA2LIST pgealist;
548 PFEA2LIST pfealist;
549 PGEA2 pgea;
550 PFEA2 pfea;
[773]551 CHAR *value, *pszBuf, *p, *data;
[551]552 USHORT len, type, plen, dlen;
553 BOOL readonly = FALSE;
[2]554
[551]555 pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__);
556 if (pgealist) {
557 pgea = &pgealist->list[0];
[1398]558 strcpy(pgea->szName, PCSZ_DOTCOMMENTS);
[551]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;
[1009]568 rc = DosQueryPathInfo((CHAR *)mp1, FIL_QUERYEASFROMLIST,
[551]569 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
[1039]570 free(pgealist);
[551]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) {
[773]577 pszBuf = xmalloc(65536, pszSrcFile, __LINE__);
578 if (pszBuf) {
579 p = pszBuf;
580 *pszBuf = 0;
[551]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)
[41]608 break;
[551]609 type = *(USHORT *) data;
610 data += sizeof(USHORT);
611 len = *(USHORT *) data;
612 data += sizeof(USHORT);
613 } // while
[773]614 if (p - pszBuf >= 65536) {
[551]615 Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg);
[773]616 pszBuf[65535] = 0; // Try to stay alive
[551]617 break;
618 }
[773]619 WinSetWindowText(hwndAutoMLE, pszBuf);
[1039]620 free(pszBuf);
[551]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 }
[1039]634 free(pfealist);
[551]635 }
636 }
637 }
[2]638 }
[1039]639 free((CHAR *)mp1);
[1063]640# ifdef FORTIFY
641 Fortify_LeaveScope();
642# endif
[551]643 }
644 return 0;
[2]645
[551]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;
[2]651 }
[551]652 return WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]653}
654
[551]655static VOID MakeAutoWinThread(VOID * args)
[341]656{
[551]657 HAB hab2;
658 HMQ hmq2;
659 HWND hwndParent = (HWND) args;
660 QMSG qmsg2;
[2]661
662 hab2 = WinInitialize(0);
[551]663 if (hab2) {
[1063]664# ifdef FORTIFY
665 Fortify_EnterScope();
[1078]666# endif
[551]667 hmq2 = WinCreateMsgQueue(hab2, 128);
668 if (hmq2) {
[2]669 DosError(FERR_DISABLEHARDERR);
670 WinRegisterClass(hab2,
[593]671 WC_OBJECTWINDOW,
[551]672 AutoObjProc, 0, sizeof(PVOID));
[2]673 hwndAutoObj = WinCreateWindow(HWND_OBJECT,
[593]674 WC_OBJECTWINDOW,
[551]675 (PSZ) NULL,
676 0,
677 0L,
678 0L,
679 0L,
680 0L, 0L, HWND_TOP, OBJ_FRAME, NULL, NULL);
[377]681 if (!hwndAutoObj) {
[1395]682 Win_Error(HWND_OBJECT, HWND_DESKTOP, pszSrcFile, __LINE__,
683 PCSZ_WINCREATEWINDOW);
[551]684 if (!PostMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID))
685 WinSendMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID);
[377]686 }
687 else {
[551]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;
[2]694 }
695 WinDestroyMsgQueue(hmq2);
696 }
[1032]697 // else
698 WinTerminate(hab2);
[1063]699# ifdef FORTIFY
[1038]700 Fortify_LeaveScope();
[1078]701# endif
[2]702 }
703}
704
[551]705MRESULT EXPENTRY AutoViewProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[341]706{
[551]707 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
[2]708
[551]709 switch (msg) {
710 case WM_CREATE:
711 {
712 MRESULT mr;
[2]713
[551]714 if (!hwndAutoObj) {
[1335]715 if (xbeginthread(MakeAutoWinThread,
716 65536,
717 (PVOID)hwnd,
718 pszSrcFile,
719 __LINE__) == -1) {
[551]720 PostMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
[341]721 }
[2]722 }
[551]723 mr = PFNWPStatic(hwnd, msg, mp1, mp2);
[1391]724 //fixme to allow user to change presparams 1-10-09 GKY
[551]725 SetPresParams(hwnd,
726 &RGBGREY,
[1391]727 &RGBBLACK, &RGBGREY, FNT_4SYSTEMVIO);
[551]728 stopflag = 0;
729 return mr;
730 }
[2]731
[551]732 case UM_SETUP:
733 MLEsetlimit(hwnd, 32768);
734 MLEsetformat(hwnd, MLFIE_NOTRANS);
735 MLEsetchanged(hwnd, FALSE);
736 return 0;
[2]737
[551]738 case WM_BUTTON1DOWN:
739 {
740 SWP swp;
[2]741
[551]742 WinQueryWindowPos(hwnd, &swp);
743 if (SHORT2FROMMP(mp1) > swp.cy - 4) {
[2]744
[551]745 HPS hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT));
746 SWP swpC;
747 TRACKINFO track;
[2]748
[551]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;
[2]780 }
[551]781 else if (id != MAIN_AUTOVIEWMLE)
782 return CommonTextButton(hwnd, msg, mp1, mp2);
783 }
784 break;
[2]785
[551]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;
[2]792
[551]793 case WM_MOUSEMOVE:
794 shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL));
795 {
796 SWP swp;
[2]797
[551]798 WinQueryWindowPos(hwnd, &swp);
799 if (SHORT2FROMMP(mp1) > swp.cy - 4) {
800 WinSetPointer(HWND_DESKTOP, hptrNS);
801 return (MRESULT) TRUE;
[2]802 }
[551]803 }
804 break;
[2]805
[551]806 case WM_PAINT:
807 PostMsg(hwnd, UM_PAINT, MPVOID, MPVOID);
808 break;
[2]809
[551]810 case UM_PAINT:
811 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, TRUE);
812 return 0;
[2]813
[551]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);
[1039]827 free(ea);
[1063]828# ifdef FORTIFY
[1078]829 Fortify_LeaveScope();
[1063]830# endif
[551]831 }
832 }
833 }
[2]834 }
835 break;
[551]836 default:
837 if (mp2)
838 PostMsg(hwnd, UM_FOCUSME, mp1, mp2);
839 break;
840 }
841 break;
[2]842
[551]843 case UM_FOCUSME:
844 if (mp2) {
[2]845
[551]846 PID pid;
847 TID tid;
[2]848
[551]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;
[2]855
[551]856 case UM_CLICKED:
857 case UM_CLICKED3:
858 if (id != MAIN_AUTOVIEWMLE) {
[2]859 PostMsg(hwnd,
[551]860 WM_COMMAND,
861 MPFROM2SHORT(((msg == UM_CLICKED3) ?
862 IDM_EAS : IDM_VIEWORARC), 0), MPVOID);
863 }
864 return 0;
[2]865
[551]866 case WM_COMMAND:
867 PostMsg(hwnd, UM_COMMAND, mp1, mp2);
868 return 0;
[2]869
[551]870 case UM_COMMAND:
871 switch (SHORT1FROMMP(mp1)) {
872 case IDM_RESCAN:
873 if (*currfile) {
[2]874
[551]875 CHAR *cf = xstrdup(currfile, pszSrcFile, __LINE__);
[2]876
[551]877 if (cf) {
878 stopflag++;
879 if (!PostMsg(hwndAutoObj, UM_LOADFILE, MPFROMP(cf), MPVOID))
[1039]880 free(cf);
[1063]881# ifdef FORTIFY
[1078]882 Fortify_LeaveScope();
[1063]883# endif
[551]884 }
885 }
886 break;
[2]887
[551]888 case IDM_INFO:
889 DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 16, currfile);
890 break;
[2]891
[551]892 case IDM_VIEW:
893 DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 0, currfile);
894 break;
[2]895
[551]896 case IDM_EDIT:
897 DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 8, currfile);
898 break;
[2]899
[551]900 case IDM_EAS:
901 {
902 char *list[2];
[2]903
[551]904 list[0] = currfile;
905 list[1] = NULL;
[2]906
[551]907 WinDlgBox(HWND_DESKTOP,
908 hwndMain,
909 DisplayEAsProc, FM3ModHandle, EA_FRAME, (PVOID) list);
[2]910 }
911 break;
912
[551]913 default:
914 PostMsg(hwndMain, msg, mp1, mp2);
915 }
916 return 0;
[2]917
[551]918 case WM_MENUEND:
919 if ((HWND) mp2 == AutoMenu) {
920 WinDestroyWindow(AutoMenu);
921 AutoMenu = (HWND) 0;
922 }
923 break;
[2]924
[551]925 case WM_CONTEXTMENU:
[872]926 CheckMenu(hwnd, &AutoMenu, (id == MAIN_AUTOVIEWMLE) ?
[551]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;
[2]935
[551]936 case UM_LOADFILE:
937 stopflag++;
938 if (!PostMsg(hwndAutoObj, msg, mp1, mp2)) {
[1009]939 xfree((CHAR *)mp1, pszSrcFile, __LINE__);
[1063]940# ifdef FORTIFY
941 Fortify_LeaveScope();
942# endif
[551]943 }
944 return 0;
[2]945
[551]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);
[2]963 break;
[551]964 }
965 break;
[2]966 }
967
[551]968 if (id == MAIN_AUTOVIEWMLE)
969 return PFNWPMLE(hwnd, msg, mp1, mp2);
970 return PFNWPStatic(hwnd, msg, mp1, mp2);
[2]971}
[793]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.