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