source: trunk/dll/autoview.c@ 1421

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

Remainder of changes to rename commafmt.h/c (Ticket 28, 82); Additional strings moved to PCSZs in init.c (Ticket 6); Added WriteDetailsSwitches used it and LoadDetailsSwitches to consolidate inline code (Ticket 343, 344)

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