| [41] | 1 |  | 
|---|
|  | 2 | /*********************************************************************** | 
|---|
|  | 3 |  | 
|---|
|  | 4 | $Id: autoview.c 1628 2011-08-27 19:35:39Z gyoung $ | 
|---|
|  | 5 |  | 
|---|
|  | 6 | Auto view | 
|---|
|  | 7 |  | 
|---|
|  | 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| [1498] | 9 | Copyright (c) 2001, 2010 Steven H.Levine | 
|---|
| [41] | 10 |  | 
|---|
| [130] | 11 | 12 Sep 02 SHL AutoObjProc: catch buff2 overflows | 
|---|
|  | 12 | 25 Oct 02 SHL CreateHexDump: catch buffer overflow | 
|---|
|  | 13 | 12 Feb 03 SHL AutoObjProc: standardize EA math | 
|---|
|  | 14 | 23 May 05 SHL Use QWL_USER | 
|---|
| [291] | 15 | 29 May 06 SHL Sync with archiver.bb2 mods | 
|---|
| [341] | 16 | 22 Jul 06 SHL Check more run time errors | 
|---|
| [439] | 17 | 15 Aug 06 SHL Use Runtime_Error more | 
|---|
| [531] | 18 | 03 Nov 06 SHL Renames | 
|---|
| [689] | 19 | 30 Mar 07 GKY Remove GetPString for window class names | 
|---|
| [793] | 20 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat | 
|---|
| [827] | 21 | 01 Sep 07 GKY Use xDosSetPathInfo to fix case where FS3 buffer crosses 64k boundry | 
|---|
| [846] | 22 | 27 Sep 07 SHL Correct ULONGLONG size formatting | 
|---|
| [872] | 23 | 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus | 
|---|
| [897] | 24 | 30 Dec 07 GKY Use CommaFmtULL | 
|---|
| [985] | 25 | 29 Feb 08 GKY Use xfree where appropriate | 
|---|
| [1335] | 26 | 10 Dec 08 SHL Integrate exception handler support | 
|---|
| [1391] | 27 | 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c | 
|---|
| [1395] | 28 | 07 Feb 09 GKY Add *DateFormat functions to format dates bassed on locale | 
|---|
|  | 29 | 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error | 
|---|
| [1400] | 30 | 08 Mar 09 GKY Renamed commafmt.h i18nutil.h | 
|---|
| [1480] | 31 | 12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory | 
|---|
| [1482] | 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 | 
|---|
| [1498] | 37 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *. | 
|---|
| [1616] | 38 | 13 Aug 11 GKY Change to Doxygen comment format | 
|---|
| [1627] | 39 | 26 Aug 11 GKY Add a low mem version of xDosAlloc* wrappers; move error checking into all the | 
|---|
|  | 40 | xDosAlloc* wrappers. | 
|---|
| [41] | 41 |  | 
|---|
|  | 42 | ***********************************************************************/ | 
|---|
|  | 43 |  | 
|---|
| [907] | 44 | #include <stdlib.h> | 
|---|
|  | 45 | #include <string.h> | 
|---|
|  | 46 | #include <ctype.h> | 
|---|
| [1335] | 47 | // #include <process.h>                 // _beginthread | 
|---|
| [907] | 48 |  | 
|---|
| [2] | 49 | #define INCL_DOS | 
|---|
|  | 50 | #define INCL_WIN | 
|---|
|  | 51 | #define INCL_GPI | 
|---|
| [841] | 52 | #define INCL_LONGLONG | 
|---|
| [2] | 53 |  | 
|---|
| [1182] | 54 | #include "fm3dll.h" | 
|---|
| [1220] | 55 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc. | 
|---|
| [1204] | 56 | #include "killproc.h"                   // Data declaration(s) | 
|---|
|  | 57 | #include "notebook.h"                   // Data declaration(s) | 
|---|
|  | 58 | #include "avl.h"                        // Data declaration(s) | 
|---|
|  | 59 | #include "inis.h"                       // Data declaration(s) | 
|---|
|  | 60 | #include "init.h"                       // Data declaration(s) | 
|---|
|  | 61 | #include "mainwnd.h"                    // Data declaration(s) | 
|---|
| [2] | 62 | #include "fm3dlg.h" | 
|---|
|  | 63 | #include "fm3str.h" | 
|---|
|  | 64 | #include "mle.h" | 
|---|
| [907] | 65 | #include "pathutil.h"                   // BldFullPathName | 
|---|
|  | 66 | #include "errutil.h"                    // Dos_Error... | 
|---|
|  | 67 | #include "strutil.h"                    // GetPString | 
|---|
| [1159] | 68 | #include "autoview.h" | 
|---|
|  | 69 | #include "defview.h"                    // DefaultView | 
|---|
|  | 70 | #include "valid.h"                      // IsBinary | 
|---|
| [1182] | 71 | #include "misc.h"                       // CheckMenu | 
|---|
|  | 72 | #include "common.h"                     // CommonTextButton | 
|---|
|  | 73 | #include "presparm.h"                   // CopyPresParams | 
|---|
|  | 74 | #include "eas.h"                        // DisplayEAsProc | 
|---|
|  | 75 | #include "chklist.h"                    // PopupMenu | 
|---|
|  | 76 | #include "wrappers.h"                   // xDosSetPathInfo | 
|---|
| [1400] | 77 | #include "i18nutil.h"                   // CommaFmtULL | 
|---|
| [1029] | 78 | #include "fortify.h" | 
|---|
| [1335] | 79 | #include "excputil.h"                   // 06 May 08 SHL added | 
|---|
| [1029] | 80 |  | 
|---|
| [1204] | 81 | static BOOL PutComments(HWND hwnd, CHAR * filename, CHAR * comments); | 
|---|
| [1398] | 82 | static BOOL WriteEA(HWND hwnd, CHAR * filename, PCSZ eaname, USHORT type, | 
|---|
| [1204] | 83 | CHAR * data); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | // Data definitions | 
|---|
|  | 86 | #pragma data_seg(GLOBAL1) | 
|---|
|  | 87 | HWND hwndAutoMLE; | 
|---|
|  | 88 |  | 
|---|
|  | 89 | #pragma data_seg(GLOBAL2) | 
|---|
|  | 90 | ULONG AutoviewHeight; | 
|---|
|  | 91 |  | 
|---|
| [2] | 92 | #pragma data_seg(DATA1) | 
|---|
| [341] | 93 | static PSZ pszSrcFile = __FILE__; | 
|---|
|  | 94 |  | 
|---|
| [1204] | 95 | static HWND AutoMenu; | 
|---|
| [341] | 96 | static HWND hwndAutoObj; | 
|---|
| [2] | 97 | static CHAR stopflag; | 
|---|
|  | 98 | static CHAR currfile[CCHMAXPATH]; | 
|---|
|  | 99 |  | 
|---|
| [1398] | 100 | BOOL WriteEA(HWND hwnd, CHAR * filename, PCSZ eaname, USHORT type, | 
|---|
| [551] | 101 | CHAR * data) | 
|---|
| [341] | 102 | { | 
|---|
| [1616] | 103 | // save an ea to disk | 
|---|
| [2] | 104 |  | 
|---|
|  | 105 | FEA2LIST *pfealist = NULL; | 
|---|
| [551] | 106 | EAOP2 eaop; | 
|---|
|  | 107 | APIRET rc; | 
|---|
|  | 108 | ULONG ealen; | 
|---|
|  | 109 | USHORT len, *num, *plen, usCodepage; | 
|---|
|  | 110 | CHAR *p, *eaval; | 
|---|
|  | 111 | BOOL ret = FALSE; | 
|---|
| [2] | 112 |  | 
|---|
| [551] | 113 | if (!filename || !eaname) | 
|---|
| [2] | 114 | return ret; | 
|---|
| [551] | 115 | usCodepage = (USHORT) WinQueryCp(WinQueryWindowULong(hwnd, QWL_HMQ)); | 
|---|
| [2] | 116 | len = (data) ? strlen(data) : 0; | 
|---|
| [551] | 117 | ealen = sizeof(FEA2LIST) + 24L + strlen(eaname) + 1L + (ULONG) len + 4L; | 
|---|
|  | 118 | switch (type) { | 
|---|
|  | 119 | case EAT_EA: | 
|---|
|  | 120 | case EAT_ASCII: | 
|---|
|  | 121 | break; | 
|---|
|  | 122 | case EAT_MVST: | 
|---|
|  | 123 | if (data) { | 
|---|
|  | 124 | ealen += sizeof(USHORT) * 5; | 
|---|
|  | 125 | p = data; | 
|---|
|  | 126 | while (*p) { | 
|---|
|  | 127 | if (*p == '\n' && *(p + 1)) | 
|---|
|  | 128 | ealen += sizeof(USHORT); | 
|---|
|  | 129 | p++; | 
|---|
|  | 130 | } | 
|---|
|  | 131 | } | 
|---|
|  | 132 | break; | 
|---|
|  | 133 | case EAT_MVMT: | 
|---|
|  | 134 | if (data) { | 
|---|
|  | 135 | ealen += sizeof(USHORT) * 5; | 
|---|
|  | 136 | p = data; | 
|---|
|  | 137 | while (*p) { | 
|---|
|  | 138 | if (*p == '\n' && *(p + 1)) | 
|---|
|  | 139 | ealen += (sizeof(USHORT) * 2); | 
|---|
|  | 140 | p++; | 
|---|
|  | 141 | } | 
|---|
|  | 142 | } | 
|---|
|  | 143 | break; | 
|---|
|  | 144 | default: | 
|---|
|  | 145 | return ret; | 
|---|
|  | 146 | } | 
|---|
|  | 147 |  | 
|---|
| [1628] | 148 | if (xDosAllocMem((PPVOID) &pfealist, ealen, pszSrcFile, __LINE__)) | 
|---|
| [1627] | 149 | ret = FALSE; | 
|---|
| [551] | 150 | else { | 
|---|
|  | 151 | memset(pfealist, 0, ealen); | 
|---|
|  | 152 | pfealist->list[0].cbName = strlen(eaname); | 
|---|
|  | 153 | memcpy(pfealist->list[0].szName, eaname, pfealist->list[0].cbName + 1); | 
|---|
|  | 154 | eaval = pfealist->list[0].szName + pfealist->list[0].cbName + 1; | 
|---|
|  | 155 | switch (type) { | 
|---|
| [2] | 156 | case EAT_EA: | 
|---|
|  | 157 | case EAT_ASCII: | 
|---|
| [551] | 158 | if (data) { | 
|---|
|  | 159 | *(USHORT *) eaval = (USHORT) type; | 
|---|
|  | 160 | eaval += sizeof(USHORT); | 
|---|
|  | 161 | *(USHORT *) eaval = (USHORT) len; | 
|---|
|  | 162 | eaval += sizeof(USHORT); | 
|---|
|  | 163 | memcpy(eaval, data, len); | 
|---|
|  | 164 | eaval += len; | 
|---|
|  | 165 | } | 
|---|
| [2] | 166 | break; | 
|---|
|  | 167 | case EAT_MVST: | 
|---|
| [551] | 168 | if (data) { | 
|---|
|  | 169 | *(USHORT *) eaval = (USHORT) EAT_MVST; | 
|---|
|  | 170 | eaval += sizeof(USHORT); | 
|---|
|  | 171 | *(USHORT *) eaval = usCodepage; | 
|---|
|  | 172 | eaval += sizeof(USHORT); | 
|---|
|  | 173 | num = (USHORT *) eaval; | 
|---|
|  | 174 | *num = 0; | 
|---|
|  | 175 | eaval += sizeof(USHORT); | 
|---|
|  | 176 | *(USHORT *) eaval = (USHORT) EAT_ASCII; | 
|---|
|  | 177 | eaval += sizeof(USHORT); | 
|---|
|  | 178 | plen = (USHORT *) eaval; | 
|---|
|  | 179 | *plen = 0; | 
|---|
|  | 180 | eaval += sizeof(USHORT); | 
|---|
|  | 181 | p = data; | 
|---|
|  | 182 | while (*p) { | 
|---|
|  | 183 | while (*p) { | 
|---|
|  | 184 | if (*p == '\n') { | 
|---|
|  | 185 | p++; | 
|---|
|  | 186 | break; | 
|---|
|  | 187 | } | 
|---|
|  | 188 | *eaval++ = *p++; | 
|---|
|  | 189 | (*plen)++; | 
|---|
|  | 190 | } | 
|---|
|  | 191 | if (*p || *plen) | 
|---|
|  | 192 | (*num)++; | 
|---|
|  | 193 | if (*p) { | 
|---|
|  | 194 | plen = (USHORT *) eaval; | 
|---|
|  | 195 | *plen = 0; | 
|---|
|  | 196 | eaval += sizeof(USHORT); | 
|---|
|  | 197 | } | 
|---|
|  | 198 | } | 
|---|
| [2] | 199 | } | 
|---|
|  | 200 | break; | 
|---|
|  | 201 | case EAT_MVMT: | 
|---|
| [551] | 202 | if (data) { | 
|---|
|  | 203 | *(USHORT *) eaval = (USHORT) EAT_MVMT; | 
|---|
|  | 204 | eaval += sizeof(USHORT); | 
|---|
|  | 205 | *(USHORT *) eaval = usCodepage; | 
|---|
|  | 206 | eaval += sizeof(USHORT); | 
|---|
|  | 207 | num = (USHORT *) eaval; | 
|---|
|  | 208 | *num = 0; | 
|---|
|  | 209 | eaval += sizeof(USHORT); | 
|---|
|  | 210 | *(USHORT *) eaval = (USHORT) EAT_ASCII; | 
|---|
|  | 211 | eaval += sizeof(USHORT); | 
|---|
|  | 212 | plen = (USHORT *) eaval; | 
|---|
|  | 213 | *plen = 0; | 
|---|
|  | 214 | eaval += sizeof(USHORT); | 
|---|
|  | 215 | p = data; | 
|---|
|  | 216 | while (*p) { | 
|---|
|  | 217 | while (*p) { | 
|---|
|  | 218 | if (*p == '\n') { | 
|---|
|  | 219 | p++; | 
|---|
|  | 220 | break; | 
|---|
|  | 221 | } | 
|---|
|  | 222 | *eaval++ = *p++; | 
|---|
|  | 223 | (*plen)++; | 
|---|
|  | 224 | } | 
|---|
|  | 225 | if (*p || *plen) | 
|---|
|  | 226 | (*num)++; | 
|---|
|  | 227 | if (*p) { | 
|---|
|  | 228 | *(USHORT *) eaval = (USHORT) EAT_ASCII; | 
|---|
|  | 229 | eaval += sizeof(USHORT); | 
|---|
|  | 230 | plen = (USHORT *) eaval; | 
|---|
|  | 231 | *plen = 0; | 
|---|
|  | 232 | eaval += sizeof(USHORT); | 
|---|
|  | 233 | } | 
|---|
|  | 234 | } | 
|---|
| [2] | 235 | } | 
|---|
|  | 236 | break; | 
|---|
|  | 237 | } | 
|---|
| [1616] | 238 | pfealist->list[0].cbValue = (eaval - (pfealist->list[0].szName + | 
|---|
| [551] | 239 | pfealist->list[0].cbName + 1)); | 
|---|
|  | 240 | memset(&eaop, 0, sizeof(eaop)); | 
|---|
| [2] | 241 | eaop.fpFEA2List = pfealist; | 
|---|
| [841] | 242 | pfealist->cbList = 13 + (ULONG) pfealist->list[0].cbName + | 
|---|
| [551] | 243 | (ULONG) pfealist->list[0].cbValue; | 
|---|
| [827] | 244 | rc = xDosSetPathInfo(filename, FIL_QUERYEASIZE, | 
|---|
|  | 245 | &eaop, sizeof(eaop), DSPI_WRTTHRU); | 
|---|
| [2] | 246 | DosFreeMem(pfealist); | 
|---|
| [551] | 247 | if (!rc) | 
|---|
| [2] | 248 | ret = TRUE; | 
|---|
|  | 249 | } | 
|---|
|  | 250 | return ret; | 
|---|
|  | 251 | } | 
|---|
|  | 252 |  | 
|---|
| [551] | 253 | BOOL PutComments(HWND hwnd, CHAR * filename, CHAR * comments) | 
|---|
| [341] | 254 | { | 
|---|
| [2] | 255 | register CHAR *p; | 
|---|
|  | 256 |  | 
|---|
| [1616] | 257 | if (comments) {                       // check -- is it empty? | 
|---|
| [2] | 258 | p = comments; | 
|---|
| [551] | 259 | while (*p && isspace(*p)) | 
|---|
| [2] | 260 | p++; | 
|---|
| [551] | 261 | if (!*p) | 
|---|
| [2] | 262 | comments = NULL; | 
|---|
|  | 263 | } | 
|---|
| [1398] | 264 | return WriteEA(hwnd, filename, PCSZ_DOTCOMMENTS, EAT_MVMT, comments); | 
|---|
| [2] | 265 | } | 
|---|
|  | 266 |  | 
|---|
| [439] | 267 | static PSZ pszBufOvfMsg = "Buffer overflow"; | 
|---|
| [2] | 268 |  | 
|---|
| [551] | 269 | ULONG CreateHexDump(CHAR * pchInBuf, ULONG cbInBuf, | 
|---|
|  | 270 | CHAR * pchOutBuf, ULONG cbOutBuf, | 
|---|
|  | 271 | ULONG cOffset, BOOL fLongAddr) | 
|---|
| [41] | 272 | { | 
|---|
| [551] | 273 | register CHAR *pchIn, *pchReset, *pchOut; | 
|---|
|  | 274 | register ULONG ibIn = 0, ibIn2, ibInFill; | 
|---|
| [41] | 275 | ULONG cbOutLine = 6 + (fLongAddr ? 4 : 0) + 16 * 3 + 1 + 16 + 1; | 
|---|
| [2] | 276 |  | 
|---|
| [551] | 277 | if (pchInBuf && cbInBuf && pchOutBuf && cbOutBuf) { | 
|---|
| [41] | 278 | pchIn = pchInBuf; | 
|---|
|  | 279 | pchOut = pchOutBuf; | 
|---|
| [551] | 280 | if (cOffset) | 
|---|
| [41] | 281 | *pchOut++ = '\n'; | 
|---|
|  | 282 | while (ibIn < cbInBuf) { | 
|---|
|  | 283 | if (pchOut - pchOutBuf + cbOutLine >= cbOutBuf) { | 
|---|
| [551] | 284 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg); | 
|---|
| [41] | 285 | break; | 
|---|
|  | 286 | } | 
|---|
|  | 287 | pchReset = pchIn; | 
|---|
|  | 288 | ibIn2 = ibIn; | 
|---|
| [551] | 289 | if (fLongAddr) | 
|---|
|  | 290 | sprintf(pchOut, "%08lx  ", ibIn + cOffset); | 
|---|
| [2] | 291 | else | 
|---|
| [551] | 292 | sprintf(pchOut, "%04lx  ", ibIn + cOffset); | 
|---|
| [41] | 293 | pchOut += 6 + (fLongAddr ? 4 : 0); | 
|---|
| [2] | 294 | do { | 
|---|
| [870] | 295 | sprintf(pchOut, "%02x ", (UCHAR)*pchIn); | 
|---|
| [551] | 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 | } | 
|---|
| [2] | 308 | } | 
|---|
| [41] | 309 | *pchOut++ = ' '; | 
|---|
|  | 310 | pchIn = pchReset; | 
|---|
| [2] | 311 | do { | 
|---|
| [551] | 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 | 
|---|
| [41] | 324 | *pchOut = 0; | 
|---|
| [551] | 325 | return (ULONG) (pchOut - pchOutBuf); | 
|---|
| [2] | 326 | } | 
|---|
|  | 327 | return 0L; | 
|---|
|  | 328 | } | 
|---|
|  | 329 |  | 
|---|
| [551] | 330 | MRESULT EXPENTRY AutoObjProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| [51] | 331 | { | 
|---|
| [551] | 332 | switch (msg) { | 
|---|
|  | 333 | case UM_LOADFILE: | 
|---|
|  | 334 | *currfile = 0; | 
|---|
|  | 335 | stopflag--; | 
|---|
|  | 336 | if (fAutoView) { | 
|---|
| [1438] | 337 | WinSetWindowText((fComments) ? hwndAutoMLE : hwndAutoview, NullStr); | 
|---|
| [551] | 338 | MLEsetreadonly(hwndAutoMLE, TRUE); | 
|---|
|  | 339 | MLEsetchanged(hwndAutoMLE, FALSE); | 
|---|
|  | 340 | } | 
|---|
|  | 341 | if (mp1) { | 
|---|
|  | 342 | if (fAutoView) { | 
|---|
| [1009] | 343 | strcpy(currfile, (CHAR *)mp1); | 
|---|
| [551] | 344 | if (!fComments) { | 
|---|
| [1009] | 345 | if (IsFile((CHAR *)mp1) == 1) { | 
|---|
| [2] | 346 |  | 
|---|
| [551] | 347 | HFILE handle; | 
|---|
| [858] | 348 | ULONG olen, ibufflen, action, obufflen, l; | 
|---|
| [850] | 349 | CHAR *ibuff, *obuff, *p; | 
|---|
|  | 350 | CHAR buffer[4096]; | 
|---|
| [551] | 351 | ARC_TYPE *info; | 
|---|
| [2] | 352 |  | 
|---|
| [1009] | 353 | if (!DosOpen((CHAR *)mp1, | 
|---|
| [844] | 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)) { | 
|---|
| [850] | 362 | ibufflen = AutoviewHeight < 96 ? 512 : 3072; | 
|---|
|  | 363 | // 06 Oct 07 SHL protect against NTFS driver small buffer defect | 
|---|
| [858] | 364 | ibuff = xmalloc(max(ibufflen + 2, 4096), pszSrcFile, __LINE__); | 
|---|
| [551] | 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; | 
|---|
| [850] | 371 | if (!DosRead(handle, ibuff, ibufflen, &ibufflen) && | 
|---|
|  | 372 | ibufflen) | 
|---|
|  | 373 | { | 
|---|
| [551] | 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", | 
|---|
| [1438] | 402 | info->id ? info->id : NullStr, | 
|---|
|  | 403 | info->id ? " " : NullStr, | 
|---|
| [551] | 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; | 
|---|
| [2] | 418 |  | 
|---|
| [551] | 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 | } | 
|---|
| [1039] | 453 | free(obuff); | 
|---|
| [551] | 454 | } | 
|---|
| [1039] | 455 | free(ibuff); | 
|---|
| [551] | 456 | } | 
|---|
|  | 457 | DosClose(handle); | 
|---|
|  | 458 | } | 
|---|
|  | 459 | } | 
|---|
|  | 460 | else if (!IsFile(currfile)) { | 
|---|
| [2] | 461 |  | 
|---|
| [841] | 462 | static FILEFINDBUF4L ffb[130]; | 
|---|
| [1397] | 463 | CHAR fullname[CCHMAXPATH + 4], szCmmaFmtFileSize[81], szDate[DATE_BUF_BYTES]; | 
|---|
| [551] | 464 | HDIR hdir = HDIR_CREATE; | 
|---|
|  | 465 | ULONG x, nm, ml, mc, bufflen; | 
|---|
|  | 466 | PBYTE fb; | 
|---|
| [841] | 467 | PFILEFINDBUF4L pffbFile; | 
|---|
| [773] | 468 | PSZ pszBuf; | 
|---|
|  | 469 | PSZ p; | 
|---|
|  | 470 | APIRET rc; | 
|---|
| [2] | 471 |  | 
|---|
| [773] | 472 | BldFullPathName(fullname, currfile, "*"); | 
|---|
| [551] | 473 | DosError(FERR_DISABLEHARDERR); | 
|---|
| [841] | 474 | nm = sizeof(ffb) / sizeof(FILEFINDBUF4L); | 
|---|
| [551] | 475 | if (AutoviewHeight < 96) | 
|---|
|  | 476 | nm /= 2; | 
|---|
| [838] | 477 | rc = xDosFindFirst(fullname, | 
|---|
| [858] | 478 | &hdir, | 
|---|
|  | 479 | FILE_NORMAL | FILE_DIRECTORY | | 
|---|
|  | 480 | FILE_READONLY | FILE_ARCHIVED | | 
|---|
|  | 481 | FILE_SYSTEM | FILE_HIDDEN, | 
|---|
|  | 482 | &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL); | 
|---|
| [551] | 483 | if (!rc && nm) { | 
|---|
|  | 484 | fb = (PBYTE) & ffb; | 
|---|
|  | 485 | x = ml = 0; | 
|---|
|  | 486 | while (x < nm) { | 
|---|
| [841] | 487 | pffbFile = (PFILEFINDBUF4L) fb; | 
|---|
| [551] | 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; | 
|---|
| [773] | 497 | pszBuf = xmalloc(bufflen, pszSrcFile, __LINE__); | 
|---|
|  | 498 | if (pszBuf) { | 
|---|
|  | 499 | p = pszBuf; | 
|---|
| [551] | 500 | *p = 0; | 
|---|
|  | 501 | fb = (PBYTE) & ffb; | 
|---|
|  | 502 | x = 0; | 
|---|
|  | 503 | while (x < nm) { | 
|---|
| [841] | 504 | pffbFile = (PFILEFINDBUF4L) fb; | 
|---|
| [551] | 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]))))) { | 
|---|
| [1078] | 511 | CommaFmtULL(szCmmaFmtFileSize, | 
|---|
|  | 512 | sizeof(szCmmaFmtFileSize), | 
|---|
|  | 513 | pffbFile->cbFile + CBLIST_TO_EASIZE(pffbFile->cbList), | 
|---|
| [1395] | 514 | ' '); | 
|---|
|  | 515 | FDateFormat(szDate, pffbFile->fdateLastWrite); | 
|---|
| [551] | 516 | sprintf(p, | 
|---|
| [1395] | 517 | "%s%-*.*s  %-8s  [%s%s%s%s]  %s " | 
|---|
|  | 518 | "%02lu%s%02lu%s%02lu\r", | 
|---|
| [1438] | 519 | pffbFile->attrFile & FILE_DIRECTORY ? PCSZ_BACKSLASH : " ", | 
|---|
| [551] | 520 | ml, | 
|---|
|  | 521 | ml, | 
|---|
| [1078] | 522 | pffbFile->achName, | 
|---|
|  | 523 | szCmmaFmtFileSize, | 
|---|
| [846] | 524 | pffbFile->attrFile & FILE_READONLY ? "R" : "-", | 
|---|
|  | 525 | pffbFile->attrFile & FILE_ARCHIVED ? "A" : "-", | 
|---|
|  | 526 | pffbFile->attrFile & FILE_HIDDEN ? "H" : "-", | 
|---|
|  | 527 | pffbFile->attrFile & FILE_SYSTEM ? "S" : "-", | 
|---|
| [1395] | 528 | szDate, | 
|---|
|  | 529 | pffbFile->ftimeLastWrite.hours, TimeSeparator, | 
|---|
|  | 530 | pffbFile->ftimeLastWrite.minutes, TimeSeparator, | 
|---|
| [551] | 531 | pffbFile->ftimeLastWrite.twosecs * 2); | 
|---|
|  | 532 | p += strlen(p); | 
|---|
|  | 533 | } | 
|---|
|  | 534 | if (!pffbFile->oNextEntryOffset) | 
|---|
|  | 535 | break; | 
|---|
|  | 536 | fb += pffbFile->oNextEntryOffset; | 
|---|
|  | 537 | x++; | 
|---|
|  | 538 | }                       // while | 
|---|
| [773] | 539 | if (p - pszBuf >= bufflen) | 
|---|
| [551] | 540 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg); | 
|---|
| [773] | 541 | if (*pszBuf) | 
|---|
|  | 542 | WinSetWindowText(hwndAutoview, pszBuf); | 
|---|
| [1039] | 543 | free(pszBuf); | 
|---|
| [551] | 544 | } | 
|---|
|  | 545 | } | 
|---|
|  | 546 | if (!rc) | 
|---|
|  | 547 | DosFindClose(hdir); | 
|---|
|  | 548 | } | 
|---|
|  | 549 | } | 
|---|
|  | 550 | else { | 
|---|
| [2] | 551 |  | 
|---|
| [551] | 552 | APIRET rc; | 
|---|
|  | 553 | EAOP2 eaop; | 
|---|
|  | 554 | PGEA2LIST pgealist; | 
|---|
|  | 555 | PFEA2LIST pfealist; | 
|---|
|  | 556 | PGEA2 pgea; | 
|---|
|  | 557 | PFEA2 pfea; | 
|---|
| [773] | 558 | CHAR *value, *pszBuf, *p, *data; | 
|---|
| [551] | 559 | USHORT len, type, plen, dlen; | 
|---|
|  | 560 | BOOL readonly = FALSE; | 
|---|
| [2] | 561 |  | 
|---|
| [551] | 562 | pgealist = xmallocz(sizeof(GEA2LIST) + 64, pszSrcFile, __LINE__); | 
|---|
|  | 563 | if (pgealist) { | 
|---|
|  | 564 | pgea = &pgealist->list[0]; | 
|---|
| [1398] | 565 | strcpy(pgea->szName, PCSZ_DOTCOMMENTS); | 
|---|
| [551] | 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; | 
|---|
| [1009] | 575 | rc = DosQueryPathInfo((CHAR *)mp1, FIL_QUERYEASFROMLIST, | 
|---|
| [551] | 576 | (PVOID) & eaop, (ULONG) sizeof(EAOP2)); | 
|---|
| [1039] | 577 | free(pgealist); | 
|---|
| [551] | 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) { | 
|---|
| [773] | 584 | pszBuf = xmalloc(65536, pszSrcFile, __LINE__); | 
|---|
|  | 585 | if (pszBuf) { | 
|---|
|  | 586 | p = pszBuf; | 
|---|
|  | 587 | *pszBuf = 0; | 
|---|
| [551] | 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) | 
|---|
| [41] | 615 | break; | 
|---|
| [551] | 616 | type = *(USHORT *) data; | 
|---|
|  | 617 | data += sizeof(USHORT); | 
|---|
|  | 618 | len = *(USHORT *) data; | 
|---|
|  | 619 | data += sizeof(USHORT); | 
|---|
|  | 620 | }                 // while | 
|---|
| [773] | 621 | if (p - pszBuf >= 65536) { | 
|---|
| [551] | 622 | Runtime_Error(pszSrcFile, __LINE__, pszBufOvfMsg); | 
|---|
| [773] | 623 | pszBuf[65535] = 0;      // Try to stay alive | 
|---|
| [551] | 624 | break; | 
|---|
|  | 625 | } | 
|---|
| [773] | 626 | WinSetWindowText(hwndAutoMLE, pszBuf); | 
|---|
| [1039] | 627 | free(pszBuf); | 
|---|
| [551] | 628 | } | 
|---|
|  | 629 | } | 
|---|
|  | 630 | else | 
|---|
|  | 631 | readonly = TRUE; | 
|---|
|  | 632 | } | 
|---|
| [1616] | 633 | // else EA not present | 
|---|
| [551] | 634 | MLEsetchanged(hwndAutoMLE, FALSE); | 
|---|
|  | 635 | MLEsetreadonly(hwndAutoMLE, readonly); | 
|---|
|  | 636 | } | 
|---|
|  | 637 | else { | 
|---|
|  | 638 | MLEsetchanged(hwndAutoMLE, FALSE); | 
|---|
|  | 639 | MLEsetreadonly(hwndAutoMLE, FALSE); | 
|---|
|  | 640 | } | 
|---|
| [1039] | 641 | free(pfealist); | 
|---|
| [551] | 642 | } | 
|---|
|  | 643 | } | 
|---|
|  | 644 | } | 
|---|
| [2] | 645 | } | 
|---|
| [1039] | 646 | free((CHAR *)mp1); | 
|---|
| [1063] | 647 | #     ifdef FORTIFY | 
|---|
|  | 648 | Fortify_LeaveScope(); | 
|---|
|  | 649 | #      endif | 
|---|
| [551] | 650 | } | 
|---|
|  | 651 | return 0; | 
|---|
| [2] | 652 |  | 
|---|
| [551] | 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; | 
|---|
| [2] | 658 | } | 
|---|
| [551] | 659 | return WinDefWindowProc(hwnd, msg, mp1, mp2); | 
|---|
| [2] | 660 | } | 
|---|
|  | 661 |  | 
|---|
| [551] | 662 | static VOID MakeAutoWinThread(VOID * args) | 
|---|
| [341] | 663 | { | 
|---|
| [551] | 664 | HAB hab2; | 
|---|
|  | 665 | HMQ hmq2; | 
|---|
|  | 666 | HWND hwndParent = (HWND) args; | 
|---|
|  | 667 | QMSG qmsg2; | 
|---|
| [2] | 668 |  | 
|---|
|  | 669 | hab2 = WinInitialize(0); | 
|---|
| [551] | 670 | if (hab2) { | 
|---|
| [1063] | 671 | #   ifdef FORTIFY | 
|---|
|  | 672 | Fortify_EnterScope(); | 
|---|
| [1078] | 673 | #   endif | 
|---|
| [551] | 674 | hmq2 = WinCreateMsgQueue(hab2, 128); | 
|---|
|  | 675 | if (hmq2) { | 
|---|
| [2] | 676 | DosError(FERR_DISABLEHARDERR); | 
|---|
|  | 677 | WinRegisterClass(hab2, | 
|---|
| [1498] | 678 | (CHAR *) WC_OBJECTWINDOW, | 
|---|
| [551] | 679 | AutoObjProc, 0, sizeof(PVOID)); | 
|---|
| [2] | 680 | hwndAutoObj = WinCreateWindow(HWND_OBJECT, | 
|---|
| [1498] | 681 | (CHAR *) WC_OBJECTWINDOW, | 
|---|
| [551] | 682 | (PSZ) NULL, | 
|---|
|  | 683 | 0, | 
|---|
|  | 684 | 0L, | 
|---|
|  | 685 | 0L, | 
|---|
|  | 686 | 0L, | 
|---|
|  | 687 | 0L, 0L, HWND_TOP, OBJ_FRAME, NULL, NULL); | 
|---|
| [377] | 688 | if (!hwndAutoObj) { | 
|---|
| [1395] | 689 | Win_Error(HWND_OBJECT, HWND_DESKTOP, pszSrcFile, __LINE__, | 
|---|
|  | 690 | PCSZ_WINCREATEWINDOW); | 
|---|
| [551] | 691 | if (!PostMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID)) | 
|---|
|  | 692 | WinSendMsg(hwndParent, UM_CLOSE, MPVOID, MPVOID); | 
|---|
| [377] | 693 | } | 
|---|
|  | 694 | else { | 
|---|
| [551] | 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; | 
|---|
| [2] | 701 | } | 
|---|
|  | 702 | WinDestroyMsgQueue(hmq2); | 
|---|
|  | 703 | } | 
|---|
| [1032] | 704 | // else | 
|---|
|  | 705 | WinTerminate(hab2); | 
|---|
| [1063] | 706 | #   ifdef FORTIFY | 
|---|
| [1038] | 707 | Fortify_LeaveScope(); | 
|---|
| [1078] | 708 | #   endif | 
|---|
| [2] | 709 | } | 
|---|
|  | 710 | } | 
|---|
|  | 711 |  | 
|---|
| [551] | 712 | MRESULT EXPENTRY AutoViewProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| [341] | 713 | { | 
|---|
| [551] | 714 | USHORT id = WinQueryWindowUShort(hwnd, QWS_ID); | 
|---|
| [2] | 715 |  | 
|---|
| [551] | 716 | switch (msg) { | 
|---|
|  | 717 | case WM_CREATE: | 
|---|
|  | 718 | { | 
|---|
|  | 719 | MRESULT mr; | 
|---|
| [2] | 720 |  | 
|---|
| [551] | 721 | if (!hwndAutoObj) { | 
|---|
| [1335] | 722 | if (xbeginthread(MakeAutoWinThread, | 
|---|
|  | 723 | 65536, | 
|---|
|  | 724 | (PVOID)hwnd, | 
|---|
|  | 725 | pszSrcFile, | 
|---|
|  | 726 | __LINE__) == -1) { | 
|---|
| [551] | 727 | PostMsg(hwnd, UM_CLOSE, MPVOID, MPVOID); | 
|---|
| [341] | 728 | } | 
|---|
| [2] | 729 | } | 
|---|
| [551] | 730 | mr = PFNWPStatic(hwnd, msg, mp1, mp2); | 
|---|
| [1391] | 731 | //fixme to allow user to change presparams 1-10-09 GKY | 
|---|
| [551] | 732 | SetPresParams(hwnd, | 
|---|
|  | 733 | &RGBGREY, | 
|---|
| [1391] | 734 | &RGBBLACK, &RGBGREY, FNT_4SYSTEMVIO); | 
|---|
| [551] | 735 | stopflag = 0; | 
|---|
|  | 736 | return mr; | 
|---|
|  | 737 | } | 
|---|
| [2] | 738 |  | 
|---|
| [551] | 739 | case UM_SETUP: | 
|---|
|  | 740 | MLEsetlimit(hwnd, 32768); | 
|---|
|  | 741 | MLEsetformat(hwnd, MLFIE_NOTRANS); | 
|---|
|  | 742 | MLEsetchanged(hwnd, FALSE); | 
|---|
|  | 743 | return 0; | 
|---|
| [2] | 744 |  | 
|---|
| [551] | 745 | case WM_BUTTON1DOWN: | 
|---|
|  | 746 | { | 
|---|
|  | 747 | SWP swp; | 
|---|
| [2] | 748 |  | 
|---|
| [551] | 749 | WinQueryWindowPos(hwnd, &swp); | 
|---|
|  | 750 | if (SHORT2FROMMP(mp1) > swp.cy - 4) { | 
|---|
| [2] | 751 |  | 
|---|
| [551] | 752 | HPS hps = WinGetPS(WinQueryWindow(hwnd, QW_PARENT)); | 
|---|
|  | 753 | SWP swpC; | 
|---|
|  | 754 | TRACKINFO track; | 
|---|
| [2] | 755 |  | 
|---|
| [551] | 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; | 
|---|
| [1482] | 777 | PrfWriteProfileData(fmprof, appname, "AutoviewHeight", | 
|---|
| [551] | 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; | 
|---|
| [2] | 785 | } | 
|---|
| [551] | 786 | else if (id != MAIN_AUTOVIEWMLE) | 
|---|
|  | 787 | return CommonTextButton(hwnd, msg, mp1, mp2); | 
|---|
|  | 788 | } | 
|---|
|  | 789 | break; | 
|---|
| [2] | 790 |  | 
|---|
| [551] | 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; | 
|---|
| [2] | 797 |  | 
|---|
| [551] | 798 | case WM_MOUSEMOVE: | 
|---|
|  | 799 | shiftstate = (SHORT2FROMMP(mp2) & (KC_ALT | KC_SHIFT | KC_CTRL)); | 
|---|
|  | 800 | { | 
|---|
|  | 801 | SWP swp; | 
|---|
| [2] | 802 |  | 
|---|
| [551] | 803 | WinQueryWindowPos(hwnd, &swp); | 
|---|
|  | 804 | if (SHORT2FROMMP(mp1) > swp.cy - 4) { | 
|---|
|  | 805 | WinSetPointer(HWND_DESKTOP, hptrNS); | 
|---|
|  | 806 | return (MRESULT) TRUE; | 
|---|
| [2] | 807 | } | 
|---|
| [551] | 808 | } | 
|---|
|  | 809 | break; | 
|---|
| [2] | 810 |  | 
|---|
| [551] | 811 | case WM_PAINT: | 
|---|
|  | 812 | PostMsg(hwnd, UM_PAINT, MPVOID, MPVOID); | 
|---|
|  | 813 | break; | 
|---|
| [2] | 814 |  | 
|---|
| [551] | 815 | case UM_PAINT: | 
|---|
|  | 816 | PaintRecessedWindow(hwnd, (HPS) 0, TRUE, TRUE); | 
|---|
|  | 817 | return 0; | 
|---|
| [2] | 818 |  | 
|---|
| [551] | 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); | 
|---|
| [1039] | 832 | free(ea); | 
|---|
| [1063] | 833 | #             ifdef FORTIFY | 
|---|
| [1078] | 834 | Fortify_LeaveScope(); | 
|---|
| [1063] | 835 | #              endif | 
|---|
| [551] | 836 | } | 
|---|
|  | 837 | } | 
|---|
|  | 838 | } | 
|---|
| [2] | 839 | } | 
|---|
|  | 840 | break; | 
|---|
| [551] | 841 | default: | 
|---|
|  | 842 | if (mp2) | 
|---|
|  | 843 | PostMsg(hwnd, UM_FOCUSME, mp1, mp2); | 
|---|
|  | 844 | break; | 
|---|
|  | 845 | } | 
|---|
|  | 846 | break; | 
|---|
| [2] | 847 |  | 
|---|
| [551] | 848 | case UM_FOCUSME: | 
|---|
|  | 849 | if (mp2) { | 
|---|
| [2] | 850 |  | 
|---|
| [551] | 851 | PID pid; | 
|---|
|  | 852 | TID tid; | 
|---|
| [2] | 853 |  | 
|---|
| [551] | 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; | 
|---|
| [2] | 860 |  | 
|---|
| [551] | 861 | case UM_CLICKED: | 
|---|
|  | 862 | case UM_CLICKED3: | 
|---|
|  | 863 | if (id != MAIN_AUTOVIEWMLE) { | 
|---|
| [2] | 864 | PostMsg(hwnd, | 
|---|
| [551] | 865 | WM_COMMAND, | 
|---|
|  | 866 | MPFROM2SHORT(((msg == UM_CLICKED3) ? | 
|---|
|  | 867 | IDM_EAS : IDM_VIEWORARC), 0), MPVOID); | 
|---|
|  | 868 | } | 
|---|
|  | 869 | return 0; | 
|---|
| [2] | 870 |  | 
|---|
| [551] | 871 | case WM_COMMAND: | 
|---|
|  | 872 | PostMsg(hwnd, UM_COMMAND, mp1, mp2); | 
|---|
|  | 873 | return 0; | 
|---|
| [2] | 874 |  | 
|---|
| [551] | 875 | case UM_COMMAND: | 
|---|
|  | 876 | switch (SHORT1FROMMP(mp1)) { | 
|---|
|  | 877 | case IDM_RESCAN: | 
|---|
|  | 878 | if (*currfile) { | 
|---|
| [2] | 879 |  | 
|---|
| [551] | 880 | CHAR *cf = xstrdup(currfile, pszSrcFile, __LINE__); | 
|---|
| [2] | 881 |  | 
|---|
| [551] | 882 | if (cf) { | 
|---|
|  | 883 | stopflag++; | 
|---|
|  | 884 | if (!PostMsg(hwndAutoObj, UM_LOADFILE, MPFROMP(cf), MPVOID)) | 
|---|
| [1039] | 885 | free(cf); | 
|---|
| [1063] | 886 | #           ifdef FORTIFY | 
|---|
| [1078] | 887 | Fortify_LeaveScope(); | 
|---|
| [1063] | 888 | #            endif | 
|---|
| [551] | 889 | } | 
|---|
|  | 890 | } | 
|---|
|  | 891 | break; | 
|---|
| [2] | 892 |  | 
|---|
| [551] | 893 | case IDM_INFO: | 
|---|
|  | 894 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 16, currfile); | 
|---|
|  | 895 | break; | 
|---|
| [2] | 896 |  | 
|---|
| [551] | 897 | case IDM_VIEW: | 
|---|
|  | 898 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 0, currfile); | 
|---|
|  | 899 | break; | 
|---|
| [2] | 900 |  | 
|---|
| [551] | 901 | case IDM_EDIT: | 
|---|
|  | 902 | DefaultView(hwnd, (HWND) 0, hwndMain, NULL, 8, currfile); | 
|---|
|  | 903 | break; | 
|---|
| [2] | 904 |  | 
|---|
| [551] | 905 | case IDM_EAS: | 
|---|
|  | 906 | { | 
|---|
|  | 907 | char *list[2]; | 
|---|
| [2] | 908 |  | 
|---|
| [551] | 909 | list[0] = currfile; | 
|---|
|  | 910 | list[1] = NULL; | 
|---|
| [2] | 911 |  | 
|---|
| [551] | 912 | WinDlgBox(HWND_DESKTOP, | 
|---|
|  | 913 | hwndMain, | 
|---|
|  | 914 | DisplayEAsProc, FM3ModHandle, EA_FRAME, (PVOID) list); | 
|---|
| [2] | 915 | } | 
|---|
|  | 916 | break; | 
|---|
|  | 917 |  | 
|---|
| [551] | 918 | default: | 
|---|
|  | 919 | PostMsg(hwndMain, msg, mp1, mp2); | 
|---|
|  | 920 | } | 
|---|
|  | 921 | return 0; | 
|---|
| [2] | 922 |  | 
|---|
| [551] | 923 | case WM_MENUEND: | 
|---|
|  | 924 | if ((HWND) mp2 == AutoMenu) { | 
|---|
|  | 925 | WinDestroyWindow(AutoMenu); | 
|---|
|  | 926 | AutoMenu = (HWND) 0; | 
|---|
|  | 927 | } | 
|---|
|  | 928 | break; | 
|---|
| [2] | 929 |  | 
|---|
| [551] | 930 | case WM_CONTEXTMENU: | 
|---|
| [872] | 931 | CheckMenu(hwnd, &AutoMenu, (id == MAIN_AUTOVIEWMLE) ? | 
|---|
| [551] | 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; | 
|---|
| [2] | 940 |  | 
|---|
| [551] | 941 | case UM_LOADFILE: | 
|---|
|  | 942 | stopflag++; | 
|---|
|  | 943 | if (!PostMsg(hwndAutoObj, msg, mp1, mp2)) { | 
|---|
| [1009] | 944 | xfree((CHAR *)mp1, pszSrcFile, __LINE__); | 
|---|
| [1063] | 945 | #     ifdef FORTIFY | 
|---|
|  | 946 | Fortify_LeaveScope(); | 
|---|
|  | 947 | #      endif | 
|---|
| [551] | 948 | } | 
|---|
|  | 949 | return 0; | 
|---|
| [2] | 950 |  | 
|---|
| [551] | 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); | 
|---|
| [2] | 968 | break; | 
|---|
| [551] | 969 | } | 
|---|
|  | 970 | break; | 
|---|
| [2] | 971 | } | 
|---|
|  | 972 |  | 
|---|
| [551] | 973 | if (id == MAIN_AUTOVIEWMLE) | 
|---|
|  | 974 | return PFNWPMLE(hwnd, msg, mp1, mp2); | 
|---|
|  | 975 | return PFNWPStatic(hwnd, msg, mp1, mp2); | 
|---|
| [2] | 976 | } | 
|---|
| [793] | 977 |  | 
|---|
|  | 978 | #pragma alloc_text(AUTOVIEW,AutoViewProc,CreateHexDump,AutoObjProc) | 
|---|
|  | 979 | #pragma alloc_text(AUTOVIEW2,MakeAutoWinThread,WriteEA,PutComments) | 
|---|