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