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