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