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