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