[2] | 1 |
|
---|
[123] | 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: mle.c 1498 2010-01-18 00:57:01Z gyoung $
|
---|
| 5 |
|
---|
| 6 | MLE text editor/viewer
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-97 M. Kimes
|
---|
[1498] | 9 | Copyright (c) 2004, 2010 Steven H.Levine
|
---|
[123] | 10 |
|
---|
[301] | 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
| 12 | 16 Apr 06 SHL MLEexportfile: rework to avoid wrap problems
|
---|
[350] | 13 | 14 Jul 06 SHL Use Runtime_Error
|
---|
[528] | 14 | 03 Nov 06 SHL Count thread usage
|
---|
[574] | 15 | 22 Mar 07 GKY Use QWL_USER
|
---|
[775] | 16 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
---|
[793] | 17 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[814] | 18 | 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
|
---|
[888] | 19 | 17 Dec 07 GKY Make WPURLDEFAULTSETTINGS the fall back for ftp/httprun
|
---|
[985] | 20 | 29 Feb 08 GKY Refactor global command line variables to notebook.h
|
---|
[1029] | 21 | 22 Jun 08 GKY Fixed memory buffer access after it had been freed
|
---|
[1042] | 22 | 06 Jul 08 GKY Rework LoadThread logic with Steven's help
|
---|
[1335] | 23 | 10 Dec 08 SHL Integrate exception handler support
|
---|
[1400] | 24 | 08 Mar 09 GKY Additional strings move to PCSZs in init.c
|
---|
[1480] | 25 | 12 Jul 09 GKY Add xDosQueryAppType and xDosAlloc... to allow FM/2 to load in high memory
|
---|
[1498] | 26 | 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
|
---|
[123] | 27 |
|
---|
| 28 | ***********************************************************************/
|
---|
| 29 |
|
---|
[2] | 30 | #include <stdlib.h>
|
---|
| 31 | #include <string.h>
|
---|
| 32 | #include <ctype.h>
|
---|
| 33 | #include <share.h>
|
---|
[1335] | 34 | // #include <process.h> // _beginthread
|
---|
[350] | 35 |
|
---|
[907] | 36 | #define INCL_DOS
|
---|
| 37 | #define INCL_WIN
|
---|
| 38 | #define INCL_LONGLONG
|
---|
| 39 |
|
---|
[1185] | 40 | #include "fm3dll.h"
|
---|
[1225] | 41 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
| 42 | #include "mle.h"
|
---|
[1210] | 43 | #include "init.h" // Data declaration(s)
|
---|
| 44 | #include "mainwnd.h" // Data declaration(s)
|
---|
| 45 | #include "newview.h" // Data declarations
|
---|
[2] | 46 | #include "fm3dlg.h"
|
---|
| 47 | #include "fm3str.h"
|
---|
[907] | 48 | #include "errutil.h" // Dos_Error...
|
---|
| 49 | #include "strutil.h" // GetPString
|
---|
[985] | 50 | #include "notebook.h" // httprun etc
|
---|
[1161] | 51 | #include "autoview.h" // CreateHexDump
|
---|
| 52 | #include "saveclip.h" // SaveToClip
|
---|
[1185] | 53 | #include "common.h" // DecrThreadUsage, IncrThreadUsage
|
---|
| 54 | #include "chklist.h" // PosOverOkay
|
---|
| 55 | #include "valid.h" // TestBinary
|
---|
| 56 | #include "strips.h" // bstrip
|
---|
| 57 | #include "systemf.h" // runemf2
|
---|
| 58 | #include "wrappers.h" // xfopen
|
---|
| 59 | #include "misc.h" // PostMsg
|
---|
[1029] | 60 | #include "fortify.h"
|
---|
[1335] | 61 | #include "excputil.h" // xbeginthread
|
---|
[2] | 62 |
|
---|
[350] | 63 | static PSZ pszSrcFile = __FILE__;
|
---|
| 64 |
|
---|
[2] | 65 | #define FAKEROT 1
|
---|
[578] | 66 | #define DOROT13(c) (!isalpha((c)))?(c):((((c) >= (char) 'A') && \
|
---|
[1335] | 67 | ((c) <= (char) 'M')) || (((c) >= (char) 'a') && ((c) <= (char) 'm')))?((c) + (char) 0xd)\
|
---|
| 68 | :((((c) >= (char) 'N') && ((c) <= (char) 'Z')) || (((c) >= (char) 'n') && ((c) <= (char) 'z')))?\
|
---|
| 69 | ((c) - (char) 0xd):(c)
|
---|
[578] | 70 |
|
---|
| 71 | /*((FAKEROT==0)?(c):(FAKEROT==1)?(!isalpha((c)))?(c):((((c) >= (char) 'A') && \
|
---|
[1335] | 72 | ((c) <= (char) 'M')) || (((c) >= (char) 'a') && ((c) <= (char) 'm')))?((c) + (char) 0xd)\
|
---|
| 73 | :((((c) >= (char) 'N') && ((c) <= (char) 'Z')) || (((c) >= (char) 'n') && ((c) <= (char) 'z')))?\
|
---|
| 74 | ((c) - (char) 0xd):(c):((c) >= (char) '!') ? ((((c) + (char) 47) > (char) '~') ? ((c) - (char) 47) :\
|
---|
| 75 | ((c) + (char) 47)) : (c))*/
|
---|
[2] | 76 |
|
---|
[551] | 77 | LONG MLEgetlinetext(HWND h, LONG l, CHAR * buf, INT maxlen)
|
---|
[301] | 78 | {
|
---|
[2] | 79 | /* get text of line l from MLE */
|
---|
| 80 |
|
---|
[551] | 81 | IPT s, e;
|
---|
[2] | 82 |
|
---|
[551] | 83 | s = MLEstartofline(h, l);
|
---|
| 84 | e = MLElinelenleft(h, s);
|
---|
| 85 | return MLEtextatpos(h, s, buf, min((INT) e, maxlen));
|
---|
[2] | 86 | }
|
---|
| 87 |
|
---|
[551] | 88 | LONG MLEdeleteline(HWND h, LONG l)
|
---|
[301] | 89 | {
|
---|
[2] | 90 | /* delete line l from MLE */
|
---|
| 91 |
|
---|
[551] | 92 | IPT s, e;
|
---|
[2] | 93 |
|
---|
[551] | 94 | s = MLEstartofline(h, l);
|
---|
| 95 | e = MLElinelenleft(h, s);
|
---|
| 96 | return MLEdelete(h, s, e);
|
---|
[2] | 97 | }
|
---|
| 98 |
|
---|
[551] | 99 | LONG MLEdeletecurline(HWND h)
|
---|
[301] | 100 | {
|
---|
[2] | 101 | /* delete current line from MLE */
|
---|
| 102 |
|
---|
| 103 | LONG l;
|
---|
| 104 |
|
---|
| 105 | l = MLEcurline(h);
|
---|
[551] | 106 | return MLEdeleteline(h, l);
|
---|
[2] | 107 | }
|
---|
| 108 |
|
---|
[551] | 109 | LONG MLEdeletetoeol(HWND h)
|
---|
[301] | 110 | {
|
---|
[2] | 111 | /* delete from cursor pos to end of line */
|
---|
| 112 |
|
---|
[551] | 113 | IPT s, e;
|
---|
[2] | 114 |
|
---|
| 115 | s = MLEcurpos(h);
|
---|
| 116 | e = MLEcurlenleft(h);
|
---|
[551] | 117 | return MLEdelete(h, s, e);
|
---|
[2] | 118 | }
|
---|
| 119 |
|
---|
[551] | 120 | VOID MLEclearall(HWND h)
|
---|
[301] | 121 | {
|
---|
[2] | 122 | /* remove all text from MLE */
|
---|
| 123 | LONG len;
|
---|
| 124 |
|
---|
| 125 | len = MLEgetlen(h);
|
---|
[551] | 126 | if (len)
|
---|
| 127 | MLEdelete(h, 0, len);
|
---|
[2] | 128 | }
|
---|
| 129 |
|
---|
[551] | 130 | LONG MLEtextatcursor(HWND h, CHAR * buffer, INT buflen)
|
---|
[301] | 131 | {
|
---|
[2] | 132 | /* place up to buflen chars of text from cursor pos into buffer
|
---|
| 133 | * return # of chars imported
|
---|
| 134 | */
|
---|
| 135 |
|
---|
[551] | 136 | IPT i;
|
---|
[2] | 137 |
|
---|
| 138 | i = MLEcurpos(h);
|
---|
[551] | 139 | return MLEtextatpos(h, i, buffer, buflen);
|
---|
[2] | 140 | }
|
---|
| 141 |
|
---|
[551] | 142 | LONG MLEtextatpos(HWND h, IPT i, CHAR * buffer, INT buflen)
|
---|
[301] | 143 | {
|
---|
[2] | 144 | /* place up to buflen chars of text from pos i in buffer
|
---|
| 145 | * return # of chars imported
|
---|
| 146 | */
|
---|
| 147 |
|
---|
[551] | 148 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(buffer),
|
---|
| 149 | MPFROMLONG((LONG) buflen));
|
---|
| 150 | return (LONG) WinSendMsg(h, MLM_EXPORT,
|
---|
| 151 | MPFROMP(&i), MPFROMLONG((PLONG) & buflen));
|
---|
[2] | 152 | }
|
---|
| 153 |
|
---|
[551] | 154 | LONG MLEsizeofsel(HWND h)
|
---|
[301] | 155 | {
|
---|
[2] | 156 | /* return length of selected text */
|
---|
| 157 |
|
---|
[551] | 158 | IPT cursor, anchor, test;
|
---|
[2] | 159 |
|
---|
| 160 | cursor = MLEcurpos(h);
|
---|
| 161 | anchor = MLEancpos(h);
|
---|
[551] | 162 | test = min(cursor, anchor);
|
---|
[2] | 163 | /* MLE fakes us out; get real length in bytes */
|
---|
[551] | 164 | return (LONG) WinSendMsg(h, MLM_QUERYFORMATTEXTLENGTH,
|
---|
| 165 | MPFROMLONG(test),
|
---|
| 166 | MPFROMLONG((LONG) ((cursor < anchor) ?
|
---|
| 167 | (anchor - cursor) :
|
---|
| 168 | (cursor - anchor))));
|
---|
[2] | 169 | }
|
---|
| 170 |
|
---|
[551] | 171 | VOID MLEinternet(HWND h, BOOL ftp)
|
---|
[301] | 172 | {
|
---|
[2] | 173 | CHAR *temp = NULL;
|
---|
[551] | 174 | IPT ancpos, curpos, here;
|
---|
| 175 | LONG len, oldlen;
|
---|
[350] | 176 | APIRET rc;
|
---|
[892] | 177 | ULONG size;
|
---|
[2] | 178 |
|
---|
| 179 | len = MLEsizeofsel(h);
|
---|
[551] | 180 | len = min(2048, len);
|
---|
[2] | 181 | oldlen = len;
|
---|
[350] | 182 | if (len) {
|
---|
[2] | 183 | len++;
|
---|
[1438] | 184 | rc = xDosAllocMem((PVOID) & temp, 4096,
|
---|
[1439] | 185 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__);
|
---|
[350] | 186 | if (rc || !temp)
|
---|
[551] | 187 | Dos_Error(MB_CANCEL, rc, h, pszSrcFile, __LINE__,
|
---|
| 188 | GetPString(IDS_OUTOFMEMORY));
|
---|
[350] | 189 | else {
|
---|
[2] | 190 | ancpos = MLEancpos(h);
|
---|
| 191 | curpos = MLEcurpos(h);
|
---|
[551] | 192 | here = min(curpos, ancpos);
|
---|
| 193 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(temp), MPFROMLONG(len));
|
---|
| 194 | len = (LONG) WinSendMsg(h, MLM_EXPORT, MPFROMP(&here), MPFROMP(&len));
|
---|
[350] | 195 | if (len <= 1)
|
---|
[551] | 196 | Runtime_Error(pszSrcFile, __LINE__, "len <= 1");
|
---|
[350] | 197 | else {
|
---|
[551] | 198 | if (len > oldlen)
|
---|
| 199 | len--;
|
---|
| 200 | temp[len] = 0;
|
---|
| 201 | bstripcr(temp);
|
---|
| 202 | if (*temp) {
|
---|
[1335] | 203 | if (ftp) {
|
---|
| 204 | if (fFtpRunWPSDefault) {
|
---|
| 205 | CHAR WPSDefaultFtpRun[CCHMAXPATH], WPSDefaultFtpRunDir[CCHMAXPATH];
|
---|
[892] | 206 |
|
---|
[1335] | 207 | size = sizeof(WPSDefaultFtpRun);
|
---|
[1498] | 208 | PrfQueryProfileData(HINI_USERPROFILE, (CHAR *) PCSZ_WPURLDEFAULTSETTINGS,
|
---|
[1335] | 209 | "DefaultBrowserExe", WPSDefaultFtpRun, &size);
|
---|
| 210 | size = sizeof(WPSDefaultFtpRunDir);
|
---|
[1498] | 211 | PrfQueryProfileData(HINI_USERPROFILE, (CHAR *) PCSZ_WPURLDEFAULTSETTINGS,
|
---|
[1335] | 212 | "DefaultWorkingDir", WPSDefaultFtpRunDir, &size);
|
---|
| 213 | runemf2(SEPARATE | WINDOWED,
|
---|
| 214 | h, pszSrcFile, __LINE__,
|
---|
| 215 | WPSDefaultFtpRunDir,
|
---|
[1400] | 216 | fLibPathStrictFtpRun ? pLibPathStrict : NULL,
|
---|
[1335] | 217 | "%s %s", WPSDefaultFtpRun, temp);
|
---|
| 218 | }
|
---|
| 219 | else
|
---|
| 220 | runemf2(SEPARATE | WINDOWED,
|
---|
| 221 | h, pszSrcFile, __LINE__,
|
---|
| 222 | ftprundir, NULL, "%s %s", ftprun, temp);
|
---|
| 223 | }
|
---|
| 224 | else
|
---|
| 225 | if (fHttpRunWPSDefault) {
|
---|
| 226 | CHAR WPSDefaultHttpRun[CCHMAXPATH], WPSDefaultHttpRunDir[CCHMAXPATH];
|
---|
[892] | 227 |
|
---|
[1335] | 228 | size = sizeof(WPSDefaultHttpRun);
|
---|
[1498] | 229 | PrfQueryProfileData(HINI_USERPROFILE, (CHAR *) PCSZ_WPURLDEFAULTSETTINGS,
|
---|
[1335] | 230 | "DefaultBrowserExe", WPSDefaultHttpRun, &size);
|
---|
| 231 | size = sizeof(WPSDefaultHttpRunDir);
|
---|
[1498] | 232 | PrfQueryProfileData(HINI_USERPROFILE, (CHAR *) PCSZ_WPURLDEFAULTSETTINGS,
|
---|
[1335] | 233 | "DefaultWorkingDir", WPSDefaultHttpRunDir, &size);
|
---|
| 234 | runemf2(SEPARATE | WINDOWED,
|
---|
| 235 | h, pszSrcFile, __LINE__,
|
---|
| 236 | WPSDefaultHttpRunDir,
|
---|
[1400] | 237 | fLibPathStrictHttpRun ? pLibPathStrict : NULL,
|
---|
[1335] | 238 | "%s %s", WPSDefaultHttpRun, temp);
|
---|
| 239 | }
|
---|
| 240 | else
|
---|
| 241 | runemf2(SEPARATE | WINDOWED,
|
---|
| 242 | h, pszSrcFile, __LINE__,
|
---|
| 243 | httprundir, NULL, "%s %s", httprun, temp);
|
---|
[551] | 244 | }
|
---|
[2] | 245 | }
|
---|
| 246 | DosFreeMem(temp);
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[551] | 251 | BOOL MLEdoblock(HWND h, INT action, CHAR * filename)
|
---|
[301] | 252 | {
|
---|
[2] | 253 | /* perform action on text in selection */
|
---|
| 254 |
|
---|
| 255 | register CHAR *p;
|
---|
[551] | 256 | CHAR *sel, *temp = NULL;
|
---|
| 257 | IPT ancpos, curpos, here;
|
---|
| 258 | LONG sellen, oldlen;
|
---|
[350] | 259 | APIRET rc;
|
---|
[2] | 260 |
|
---|
| 261 | oldlen = MLEsizeofsel(h);
|
---|
[551] | 262 | if (!oldlen)
|
---|
[2] | 263 | return TRUE;
|
---|
[551] | 264 | sel = xmallocz((size_t) (oldlen + 2), pszSrcFile, __LINE__);
|
---|
[350] | 265 | if (!sel)
|
---|
[2] | 266 | return FALSE;
|
---|
[1438] | 267 | rc = xDosAllocMem((PVOID) & temp, 32768L,
|
---|
[1439] | 268 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__);
|
---|
[350] | 269 | if (rc || !temp) {
|
---|
[551] | 270 | Dos_Error(MB_CANCEL, rc, h, pszSrcFile, __LINE__,
|
---|
| 271 | GetPString(IDS_OUTOFMEMORY));
|
---|
[1039] | 272 | free(sel);
|
---|
[1063] | 273 | # ifdef FORTIFY
|
---|
| 274 | Fortify_LeaveScope();
|
---|
| 275 | # endif
|
---|
[2] | 276 | DosPostEventSem(CompactSem);
|
---|
| 277 | return FALSE;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 | ancpos = MLEancpos(h);
|
---|
| 281 | curpos = MLEcurpos(h);
|
---|
[551] | 282 | here = min(curpos, ancpos);
|
---|
[2] | 283 | p = sel;
|
---|
| 284 | MLEdisable(h);
|
---|
[551] | 285 | while (oldlen > 0) {
|
---|
| 286 | sellen = min(oldlen + 1, 32701);
|
---|
| 287 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(temp), MPFROMLONG(sellen));
|
---|
| 288 | sellen =
|
---|
| 289 | (LONG) WinSendMsg(h, MLM_EXPORT, MPFROMP(&here), MPFROMP(&sellen));
|
---|
[350] | 290 | if (sellen < 1) {
|
---|
| 291 | Runtime_Error(pszSrcFile, __LINE__, "len < 1");
|
---|
[1039] | 292 | free(sel);
|
---|
[1063] | 293 | # ifdef FORTIFY
|
---|
| 294 | Fortify_LeaveScope();
|
---|
| 295 | # endif
|
---|
[2] | 296 | DosPostEventSem(CompactSem);
|
---|
| 297 | return FALSE;
|
---|
| 298 | }
|
---|
[551] | 299 | if (sellen > min(oldlen, 32700))
|
---|
[2] | 300 | sellen--;
|
---|
[551] | 301 | memcpy(p, temp, sellen);
|
---|
[2] | 302 | p += sellen;
|
---|
| 303 | oldlen -= sellen;
|
---|
| 304 | }
|
---|
[551] | 305 | switch (action) {
|
---|
| 306 | case APPENDCLIP:
|
---|
| 307 | SaveToClip(h, sel, TRUE);
|
---|
| 308 | DosFreeMem(temp);
|
---|
[1039] | 309 | free(sel);
|
---|
[1063] | 310 | # ifdef FORTIFY
|
---|
| 311 | Fortify_LeaveScope();
|
---|
| 312 | # endif
|
---|
[551] | 313 | MLEenable(h);
|
---|
| 314 | DosPostEventSem(CompactSem);
|
---|
| 315 | return TRUE;
|
---|
| 316 |
|
---|
| 317 | case WRITE:
|
---|
| 318 | {
|
---|
| 319 | FILE *fp;
|
---|
| 320 |
|
---|
| 321 | fp = fopen(filename, "a+");
|
---|
| 322 | if (!fp)
|
---|
| 323 | fp = xfopen(filename, "w", pszSrcFile, __LINE__);
|
---|
| 324 | if (fp) {
|
---|
| 325 | fseek(fp, 0L, SEEK_END);
|
---|
| 326 | fwrite(sel, 1, strlen(sel), fp);
|
---|
| 327 | fclose(fp);
|
---|
| 328 | }
|
---|
| 329 | #ifdef __DEBUG_ALLOC__
|
---|
| 330 | _heap_check();
|
---|
| 331 | #endif
|
---|
[2] | 332 | DosFreeMem(temp);
|
---|
[1039] | 333 | free(sel);
|
---|
[1063] | 334 | # ifdef FORTIFY
|
---|
| 335 | Fortify_LeaveScope();
|
---|
| 336 | # endif
|
---|
[2] | 337 | MLEenable(h);
|
---|
| 338 | DosPostEventSem(CompactSem);
|
---|
| 339 | return TRUE;
|
---|
[551] | 340 | }
|
---|
[2] | 341 |
|
---|
[551] | 342 | case UPPERCASE:
|
---|
| 343 | p = sel;
|
---|
| 344 | while (*p) {
|
---|
| 345 | if (isalpha(*p))
|
---|
| 346 | *p = toupper(*p);
|
---|
| 347 | p++;
|
---|
| 348 | }
|
---|
| 349 | break;
|
---|
[2] | 350 |
|
---|
[551] | 351 | case LOWERCASE:
|
---|
| 352 | p = sel;
|
---|
| 353 | while (*p) {
|
---|
| 354 | if (isalpha(*p))
|
---|
| 355 | *p = tolower(*p);
|
---|
| 356 | p++;
|
---|
| 357 | }
|
---|
| 358 | break;
|
---|
[2] | 359 |
|
---|
[551] | 360 | case TOGGLECASE:
|
---|
| 361 | p = sel;
|
---|
| 362 | while (*p) {
|
---|
| 363 | if (isalpha(*p)) {
|
---|
| 364 | if (islower(*p))
|
---|
| 365 | *p = toupper(*p);
|
---|
| 366 | else
|
---|
| 367 | *p = tolower(*p);
|
---|
[2] | 368 | }
|
---|
[551] | 369 | p++;
|
---|
| 370 | }
|
---|
| 371 | break;
|
---|
[2] | 372 |
|
---|
[551] | 373 | case ROT13:
|
---|
| 374 | p = sel;
|
---|
| 375 | while (*p) {
|
---|
| 376 | *p = DOROT13(*p); // fixme condition both true and false?
|
---|
| 377 | p++;
|
---|
| 378 | }
|
---|
| 379 | break;
|
---|
[2] | 380 |
|
---|
[551] | 381 | case XOR:
|
---|
| 382 | p = sel;
|
---|
| 383 | while (*p) {
|
---|
| 384 | *p = (~*p);
|
---|
| 385 | p++;
|
---|
| 386 | }
|
---|
| 387 | break;
|
---|
[2] | 388 |
|
---|
[551] | 389 | case FORMAT:
|
---|
| 390 | p = sel;
|
---|
| 391 | while (*p) {
|
---|
| 392 | if (*p == '\r') {
|
---|
| 393 | memmove(p, p + 1, strlen(p));
|
---|
| 394 | continue;
|
---|
[2] | 395 | }
|
---|
[551] | 396 | if (*p == '\n') {
|
---|
| 397 | *p = ' ';
|
---|
| 398 | continue;
|
---|
[2] | 399 | }
|
---|
[551] | 400 | p++;
|
---|
| 401 | }
|
---|
| 402 | break;
|
---|
[2] | 403 |
|
---|
[551] | 404 | default: /* unknown action */
|
---|
[2] | 405 | #ifdef __DEBUG_ALLOC__
|
---|
| 406 | _heap_check();
|
---|
| 407 | #endif
|
---|
[551] | 408 | DosFreeMem(temp);
|
---|
[1039] | 409 | free(sel);
|
---|
[1063] | 410 | # ifdef FORTIFY
|
---|
| 411 | Fortify_LeaveScope();
|
---|
| 412 | # endif
|
---|
[551] | 413 | DosPostEventSem(CompactSem);
|
---|
| 414 | MLEenable(h);
|
---|
| 415 | return FALSE;
|
---|
[2] | 416 | }
|
---|
| 417 |
|
---|
| 418 | /* replace selection with altered text */
|
---|
| 419 | p = sel;
|
---|
[551] | 420 | here = min(curpos, ancpos);
|
---|
| 421 | MLEclear(h); /* delete current selection */
|
---|
| 422 | sellen = oldlen = strlen(sel); /* actual number of bytes */
|
---|
| 423 | while (oldlen > 0) {
|
---|
| 424 | sellen = min(oldlen, 32700);
|
---|
| 425 | memcpy(temp, p, sellen);
|
---|
| 426 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(temp), MPFROMLONG(sellen));
|
---|
| 427 | sellen = (LONG) WinSendMsg(h,
|
---|
| 428 | MLM_IMPORT,
|
---|
| 429 | MPFROMP(&here), MPFROMLONG(sellen));
|
---|
[350] | 430 | if (!sellen) {
|
---|
| 431 | Runtime_Error(pszSrcFile, __LINE__, "sellen 0");
|
---|
[2] | 432 | break;
|
---|
| 433 | }
|
---|
| 434 | p += sellen;
|
---|
| 435 | oldlen -= sellen;
|
---|
[551] | 436 | if (oldlen && *p == '\n' /* && *(p - 1) == '\r' */ )
|
---|
[2] | 437 | p--;
|
---|
[551] | 438 | } // while
|
---|
| 439 | WinSendMsg(h, MLM_SETSEL, MPFROMLONG(ancpos), MPFROMLONG(curpos));
|
---|
[2] | 440 | MLEenable(h);
|
---|
| 441 | #ifdef __DEBUG_ALLOC__
|
---|
[551] | 442 | _heap_check();
|
---|
[2] | 443 | #endif
|
---|
| 444 | DosFreeMem(temp);
|
---|
[1039] | 445 | free(sel);
|
---|
[1029] | 446 | # ifdef FORTIFY
|
---|
| 447 | Fortify_LeaveScope();
|
---|
[1063] | 448 | # endif
|
---|
[2] | 449 | DosPostEventSem(CompactSem);
|
---|
| 450 | return TRUE;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
[551] | 453 | BOOL MLEquotepara(HWND h, CHAR * initials, BOOL fQuoteOld)
|
---|
[301] | 454 | {
|
---|
[2] | 455 | LONG num;
|
---|
[551] | 456 | CHAR lineend[2], line[8], *p;
|
---|
[2] | 457 |
|
---|
[551] | 458 | if (!initials || !*initials)
|
---|
[2] | 459 | initials = " > ";
|
---|
| 460 | num = MLEcurline(h);
|
---|
[551] | 461 | while (MLElinelen(h, num) < 3L && MLEnumlines(h) >= num)
|
---|
[2] | 462 | num++;
|
---|
[551] | 463 | while (MLElinelen(h, num) > 2L && MLEnumlines(h) >= num) {
|
---|
| 464 | memset(line, 0, 8);
|
---|
| 465 | MLEgetlinetext(h, num, line, 7L);
|
---|
[2] | 466 | line[7] = 0;
|
---|
[551] | 467 | if ((p = strchr(line, '>')) == NULL) {
|
---|
| 468 | MLEsetcurpos(h, MLEstartofline(h, num));
|
---|
| 469 | MLEinsert(h, initials);
|
---|
| 470 | MLEsetcurpos(h, (MLEstartofline(h, num) + MLElinelen(h, num)) - 1L);
|
---|
| 471 | MLEtextatcursor(h, lineend, 2L);
|
---|
| 472 | if (*lineend != '\r' && *lineend != '\n')
|
---|
| 473 | MLEinsert(h, "\n");
|
---|
[2] | 474 | }
|
---|
[551] | 475 | else if (fQuoteOld) {
|
---|
| 476 | while (isspace(line[strlen(line) - 1]))
|
---|
| 477 | line[strlen(line) - 1] = 0;
|
---|
| 478 | MLEsetcurpos(h, MLEstartofline(h, num) + (p - line));
|
---|
| 479 | MLEinsert(h, ">");
|
---|
[2] | 480 | }
|
---|
| 481 | num++;
|
---|
| 482 | }
|
---|
[551] | 483 | MLEsetcurpos(h, MLEstartofline(h, num));
|
---|
[2] | 484 | return TRUE;
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[551] | 487 | BOOL MLEAutoLoad(HWND h, CHAR * filename)
|
---|
[301] | 488 | {
|
---|
[2] | 489 | XMLEWNDPTR *vw;
|
---|
| 490 |
|
---|
[574] | 491 | vw = (XMLEWNDPTR *) WinQueryWindowPtr(WinQueryWindow(h, QW_PARENT), QWL_USER);
|
---|
[551] | 492 | if (vw && vw->size != sizeof(XMLEWNDPTR))
|
---|
[2] | 493 | vw = NULL;
|
---|
[551] | 494 | if (TestBinary(filename)) {
|
---|
| 495 | if (vw)
|
---|
[2] | 496 | vw->hex = 1;
|
---|
[551] | 497 | return MLEHexLoad(h, filename);
|
---|
[2] | 498 | }
|
---|
[551] | 499 | if (vw)
|
---|
[2] | 500 | vw->hex = 2;
|
---|
[551] | 501 | return MLEloadfile(h, filename);
|
---|
[2] | 502 | }
|
---|
| 503 |
|
---|
[551] | 504 | BOOL MLEHexLoad(HWND h, CHAR * filename)
|
---|
[301] | 505 | {
|
---|
[2] | 506 | /* insert a file into the current position in the MLE */
|
---|
| 507 |
|
---|
[551] | 508 | HAB hab;
|
---|
| 509 | CHAR *buffer = NULL, *hexbuff = NULL;
|
---|
[841] | 510 | IPT iptOffset = -1;
|
---|
| 511 | ULONG numread, howmuch, numimport, action, len, left = 0;
|
---|
[551] | 512 | BOOL ret = TRUE, first = TRUE;
|
---|
| 513 | CHAR titletext[512];
|
---|
| 514 | HWND grandpa;
|
---|
[2] | 515 | XMLEWNDPTR *vw;
|
---|
[551] | 516 | HFILE handle;
|
---|
| 517 | APIRET rc;
|
---|
[2] | 518 |
|
---|
| 519 | *titletext = 0;
|
---|
| 520 | hab = WinQueryAnchorBlock(h);
|
---|
[574] | 521 | vw = (XMLEWNDPTR *) WinQueryWindowPtr(WinQueryWindow(h, QW_PARENT), QWL_USER);
|
---|
[551] | 522 | if (vw && vw->size != sizeof(XMLEWNDPTR))
|
---|
[2] | 523 | vw = NULL;
|
---|
| 524 | grandpa = GrandparentOf(h);
|
---|
| 525 | *titletext = 0;
|
---|
[551] | 526 | WinQueryWindowText(grandpa, 512, titletext);
|
---|
[844] | 527 | rc = DosOpen(filename, &handle, &action, 0, 0,
|
---|
| 528 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
| 529 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
|
---|
| 530 | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
|
---|
| 531 | OPEN_ACCESS_READONLY, 0);
|
---|
[350] | 532 | if (rc) {
|
---|
| 533 | ret = FALSE;
|
---|
| 534 | }
|
---|
| 535 | else {
|
---|
[841] | 536 | DosChgFilePtr(handle, 0, FILE_END, &len);
|
---|
| 537 | DosChgFilePtr(handle, 0, FILE_BEGIN, &action);
|
---|
[350] | 538 | if (len) {
|
---|
[1438] | 539 | rc = xDosAllocMem((PVOID) & hexbuff, 50001,
|
---|
[1439] | 540 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__);
|
---|
[350] | 541 | if (rc || !hexbuff) {
|
---|
[551] | 542 | Dos_Error(MB_CANCEL, rc, h, pszSrcFile, __LINE__,
|
---|
| 543 | GetPString(IDS_OUTOFMEMORY));
|
---|
| 544 | ret = FALSE;
|
---|
[350] | 545 | }
|
---|
| 546 | else {
|
---|
[551] | 547 | buffer = xmalloc(10000, pszSrcFile, __LINE__);
|
---|
| 548 | if (!buffer)
|
---|
| 549 | ret = FALSE;
|
---|
[350] | 550 | else {
|
---|
[551] | 551 | MLEclearall(h);
|
---|
| 552 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(hexbuff),
|
---|
| 553 | MPFROMLONG(50000L));
|
---|
| 554 | if (!DosRead(handle, buffer, min(10000, len), &numread) && numread) {
|
---|
[2] | 555 |
|
---|
[551] | 556 | CHAR s[81];
|
---|
[2] | 557 |
|
---|
[551] | 558 | MLEsetwrap(h, FALSE);
|
---|
| 559 | WinSetSysValue(HWND_DESKTOP, SV_INSERTMODE, FALSE);
|
---|
| 560 | *hexbuff = 0;
|
---|
| 561 | numimport = CreateHexDump(buffer,
|
---|
| 562 | numread, hexbuff, 50000, left, TRUE);
|
---|
| 563 | while (len && numimport) { /* import entire file */
|
---|
| 564 | left += numread;
|
---|
| 565 | len -= numread;
|
---|
| 566 | if (!WinIsWindow(hab, h) || (vw && vw->killme))
|
---|
| 567 | break;
|
---|
| 568 | howmuch = (INT) WinSendMsg(h,
|
---|
| 569 | MLM_IMPORT,
|
---|
| 570 | MPFROMP(&iptOffset),
|
---|
| 571 | MPFROMLONG(numimport));
|
---|
| 572 | if (first && len) {
|
---|
| 573 | MLEdisable(h);
|
---|
| 574 | WinEnableWindowUpdate(h, FALSE);
|
---|
| 575 | first = FALSE;
|
---|
| 576 | }
|
---|
[2] | 577 | // fprintf(stderr,"%d bytes of %d imported\n",howmuch,numimport);
|
---|
[551] | 578 | if (howmuch < 1) {
|
---|
| 579 | numimport = 0;
|
---|
| 580 | break;
|
---|
| 581 | }
|
---|
| 582 | while (howmuch < numimport) {
|
---|
| 583 | numimport -= howmuch;
|
---|
| 584 | memmove(hexbuff, hexbuff + howmuch, numimport);
|
---|
[814] | 585 | DosSleep(0); //26 Aug 07 GKY 1
|
---|
[551] | 586 | if (!WinIsWindow(hab, h) || (vw && vw->killme))
|
---|
| 587 | break;
|
---|
| 588 | howmuch = (INT) WinSendMsg(h,
|
---|
| 589 | MLM_IMPORT,
|
---|
| 590 | MPFROMP(&iptOffset),
|
---|
| 591 | MPFROMLONG((LONG) numimport));
|
---|
| 592 | if (howmuch < 1)
|
---|
| 593 | break;
|
---|
| 594 | }
|
---|
| 595 | if (DosRead(handle, buffer, min(10000, len), &numread)
|
---|
| 596 | || !numread) {
|
---|
| 597 | numimport = 0;
|
---|
| 598 | break;
|
---|
| 599 | }
|
---|
| 600 | *hexbuff = 0;
|
---|
| 601 | numimport =
|
---|
| 602 | CreateHexDump(buffer, numread, hexbuff, 50000, left, TRUE);
|
---|
| 603 | if (numimport < 1 || !WinIsWindow(hab, h) || (vw && vw->killme)) {
|
---|
| 604 | numimport = 0;
|
---|
| 605 | break;
|
---|
| 606 | }
|
---|
| 607 | sprintf(s, GetPString(IDS_LOADINGMLETEXT), len);
|
---|
| 608 | WinSetWindowText(grandpa, s);
|
---|
| 609 | }
|
---|
[771] | 610 | DosSleep(1);
|
---|
[551] | 611 | }
|
---|
| 612 | else
|
---|
| 613 | ret = FALSE;
|
---|
[1039] | 614 | free(buffer);
|
---|
[1063] | 615 | # ifdef FORTIFY
|
---|
[1335] | 616 | Fortify_LeaveScope();
|
---|
[1063] | 617 | # endif
|
---|
[551] | 618 | }
|
---|
| 619 | DosFreeMem(hexbuff);
|
---|
[2] | 620 | }
|
---|
| 621 | }
|
---|
[551] | 622 | if (WinIsWindow(hab, h))
|
---|
| 623 | WinSetWindowText(grandpa, titletext);
|
---|
[2] | 624 | DosClose(handle);
|
---|
| 625 | }
|
---|
[551] | 626 | if (!first) {
|
---|
| 627 | WinEnableWindowUpdate(h, TRUE);
|
---|
[2] | 628 | MLEenable(h);
|
---|
| 629 | }
|
---|
[551] | 630 | MLEsetchanged(h, FALSE);
|
---|
[2] | 631 | return ret;
|
---|
| 632 | }
|
---|
| 633 |
|
---|
[350] | 634 | //== MLEinsertfile() insert a file into the current position in the MLE ==
|
---|
| 635 |
|
---|
[551] | 636 | BOOL MLEinsertfile(HWND h, CHAR * filename)
|
---|
[301] | 637 | {
|
---|
[2] | 638 |
|
---|
[551] | 639 | HAB hab;
|
---|
[2] | 640 | FILE *fp;
|
---|
[551] | 641 | CHAR *buffer = NULL;
|
---|
| 642 | INT len;
|
---|
| 643 | IPT iptOffset = -1L;
|
---|
| 644 | INT numread, howmuch, tempnum, x;
|
---|
| 645 | BOOL ret = TRUE, first = TRUE, once = FALSE, dont = FALSE;
|
---|
| 646 | CHAR titletext[512];
|
---|
| 647 | HWND grandpa;
|
---|
[2] | 648 | XMLEWNDPTR *vw;
|
---|
| 649 | APIRET rc;
|
---|
| 650 |
|
---|
| 651 | *titletext = 0;
|
---|
| 652 | hab = WinQueryAnchorBlock(h);
|
---|
[574] | 653 | vw = (XMLEWNDPTR *) WinQueryWindowPtr(WinQueryWindow(h, QW_PARENT), QWL_USER);
|
---|
[551] | 654 | if (vw && vw->size != sizeof(XMLEWNDPTR))
|
---|
[2] | 655 | vw = NULL;
|
---|
| 656 | grandpa = GrandparentOf(h);
|
---|
| 657 | *titletext = 0;
|
---|
[551] | 658 | WinQueryWindowText(grandpa, 512, titletext);
|
---|
| 659 | fp = _fsopen(filename, "r", SH_DENYNO);
|
---|
[350] | 660 | if (!fp)
|
---|
| 661 | ret = FALSE;
|
---|
| 662 | else {
|
---|
[551] | 663 | setvbuf(fp, NULL, _IONBF, 0);
|
---|
| 664 | fseek(fp, 0L, SEEK_END);
|
---|
| 665 | len = (INT) ftell(fp);
|
---|
| 666 | fseek(fp, 0L, SEEK_SET);
|
---|
| 667 | if (len && len != -1) {
|
---|
[1438] | 668 | rc = xDosAllocMem((PVOID) & buffer,
|
---|
[1439] | 669 | 50000L, PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__);
|
---|
[350] | 670 | if (rc || !buffer) {
|
---|
[551] | 671 | Dos_Error(MB_CANCEL, rc, h, pszSrcFile, __LINE__,
|
---|
| 672 | GetPString(IDS_OUTOFMEMORY));
|
---|
| 673 | ret = FALSE;
|
---|
[350] | 674 | }
|
---|
| 675 | else {
|
---|
[551] | 676 | WinSendMsg(h,
|
---|
| 677 | MLM_SETIMPORTEXPORT, MPFROMP(buffer), MPFROMLONG(50000L));
|
---|
| 678 | numread = fread(buffer, 1, min(50000, len), fp);
|
---|
| 679 | if (numread < 1)
|
---|
| 680 | ret = FALSE;
|
---|
| 681 | while (len && numread > 0) { /* here we go... */
|
---|
[2] | 682 |
|
---|
[551] | 683 | CHAR s[81];
|
---|
[2] | 684 |
|
---|
[551] | 685 | while (numread > 0) { /* import entire file */
|
---|
| 686 | if (!WinIsWindow(hab, h) || (vw && vw->killme))
|
---|
| 687 | break;
|
---|
| 688 | if (strlen(buffer) < numread) {
|
---|
| 689 | if (!once && !dont)
|
---|
| 690 | rc = saymsg(MB_YESNOCANCEL,
|
---|
| 691 | HWND_DESKTOP,
|
---|
| 692 | GetPString(IDS_WARNINGTEXT),
|
---|
| 693 | GetPString(IDS_TEXTNULSTEXT));
|
---|
| 694 | else if (once)
|
---|
| 695 | rc = MBID_YES;
|
---|
| 696 | else if (dont)
|
---|
| 697 | rc = MBID_NO;
|
---|
| 698 | if (rc == MBID_YES) {
|
---|
| 699 | once = FALSE;
|
---|
| 700 | for (x = 0; x < numread; x++) {
|
---|
| 701 | if (!buffer[x])
|
---|
| 702 | buffer[x] = ' ';
|
---|
| 703 | }
|
---|
| 704 | }
|
---|
| 705 | else if (rc == MBID_CANCEL) {
|
---|
| 706 | len = 0;
|
---|
| 707 | numread = 0;
|
---|
| 708 | saymsg(MB_ENTER,
|
---|
| 709 | HWND_DESKTOP,
|
---|
| 710 | GetPString(IDS_OBEYTEXT),
|
---|
| 711 | GetPString(IDS_LOADCANCELLEDTEXT));
|
---|
| 712 | break;
|
---|
| 713 | }
|
---|
| 714 | else if (rc == MBID_NO)
|
---|
| 715 | dont = TRUE;
|
---|
| 716 | }
|
---|
| 717 | howmuch = (INT) WinSendMsg(h,
|
---|
| 718 | MLM_IMPORT,
|
---|
| 719 | MPFROMP(&iptOffset),
|
---|
| 720 | MPFROMLONG((LONG) numread));
|
---|
| 721 | if (first && !feof(fp)) {
|
---|
| 722 | MLEdisable(h);
|
---|
| 723 | WinEnableWindowUpdate(h, FALSE);
|
---|
| 724 | first = FALSE;
|
---|
| 725 | }
|
---|
[2] | 726 | // fprintf(stderr,"%d bytes of %d imported\n",howmuch,numread);
|
---|
[551] | 727 | if (howmuch < 1) {
|
---|
| 728 | numread = 0;
|
---|
| 729 | break;
|
---|
| 730 | }
|
---|
| 731 | len -= howmuch;
|
---|
| 732 | if (howmuch < numread) {
|
---|
| 733 | numread -= howmuch;
|
---|
| 734 | memmove(buffer, buffer + howmuch, numread);
|
---|
| 735 | if (numread && len) {
|
---|
| 736 | tempnum = numread;
|
---|
| 737 | numread = fread(buffer + tempnum,
|
---|
| 738 | 1, min(50000 - tempnum, len), fp);
|
---|
| 739 | if (numread > 1)
|
---|
| 740 | numread += tempnum;
|
---|
| 741 | else
|
---|
| 742 | numread = tempnum;
|
---|
| 743 | }
|
---|
[814] | 744 | DosSleep(0); //26 Aug 07 GKY 1
|
---|
[551] | 745 | }
|
---|
| 746 | else
|
---|
| 747 | numread = fread(buffer, 1, min(50000, len), fp);
|
---|
| 748 | if (numread < 1 || !WinIsWindow(hab, h) || (vw && vw->killme)) {
|
---|
| 749 | numread = 0;
|
---|
| 750 | break;
|
---|
| 751 | }
|
---|
| 752 | sprintf(s, GetPString(IDS_LOADINGMLETEXT), len);
|
---|
| 753 | WinSetWindowText(grandpa, s);
|
---|
| 754 | }
|
---|
[814] | 755 | DosSleep(0); //26 Aug 07 GKY 1
|
---|
[551] | 756 | }
|
---|
| 757 | DosFreeMem(buffer);
|
---|
[2] | 758 | }
|
---|
| 759 | }
|
---|
[551] | 760 | if (WinIsWindow(hab, h))
|
---|
| 761 | WinSetWindowText(grandpa, titletext);
|
---|
[2] | 762 | fclose(fp);
|
---|
| 763 | }
|
---|
[551] | 764 | if (!first) {
|
---|
| 765 | WinEnableWindowUpdate(h, TRUE);
|
---|
[2] | 766 | MLEenable(h);
|
---|
| 767 | }
|
---|
| 768 | return ret;
|
---|
| 769 | }
|
---|
| 770 |
|
---|
[551] | 771 | typedef struct
|
---|
| 772 | {
|
---|
[2] | 773 | USHORT size;
|
---|
| 774 | USHORT hex;
|
---|
[551] | 775 | HWND h;
|
---|
| 776 | CHAR filename[CCHMAXPATH];
|
---|
| 777 | HWND hwndReport;
|
---|
| 778 | HWND msg;
|
---|
| 779 | }
|
---|
| 780 | BKGLOAD;
|
---|
[2] | 781 |
|
---|
[551] | 782 | VOID LoadThread(VOID * arg)
|
---|
[301] | 783 | {
|
---|
[2] | 784 | BKGLOAD *bkg;
|
---|
[551] | 785 | BOOL fSuccess;
|
---|
| 786 | HAB thab;
|
---|
| 787 | HMQ thmq;
|
---|
[2] | 788 |
|
---|
| 789 | DosError(FERR_DISABLEHARDERR);
|
---|
| 790 |
|
---|
[1042] | 791 | # ifdef FORTIFY
|
---|
| 792 | Fortify_EnterScope();
|
---|
[1063] | 793 | # endif
|
---|
[1042] | 794 |
|
---|
[551] | 795 | bkg = (BKGLOAD *) arg;
|
---|
| 796 | if (bkg) {
|
---|
[2] | 797 | thab = WinInitialize(0);
|
---|
[551] | 798 | if (thab) {
|
---|
| 799 | thmq = WinCreateMsgQueue(thab, 0);
|
---|
| 800 | if (thmq) {
|
---|
| 801 | WinCancelShutdown(thmq, TRUE);
|
---|
| 802 | IncrThreadUsage();
|
---|
| 803 | priority_normal();
|
---|
| 804 | if (bkg->hex == 1)
|
---|
| 805 | fSuccess = MLEHexLoad(bkg->h, bkg->filename);
|
---|
| 806 | else if (bkg->hex == 2)
|
---|
| 807 | fSuccess = MLEloadfile(bkg->h, bkg->filename);
|
---|
| 808 | else
|
---|
| 809 | fSuccess = MLEAutoLoad(bkg->h, bkg->filename);
|
---|
| 810 | priority_bumped();
|
---|
| 811 | if (bkg->hwndReport && WinIsWindow(thab, bkg->hwndReport))
|
---|
| 812 | PostMsg(bkg->hwndReport, bkg->msg, MPFROMLONG(fSuccess),
|
---|
| 813 | MPFROMP(bkg->filename));
|
---|
[2] | 814 | #ifdef __DEBUG_ALLOC__
|
---|
[551] | 815 | _heap_check();
|
---|
[2] | 816 | #endif
|
---|
[551] | 817 | WinDestroyMsgQueue(thmq);
|
---|
[2] | 818 | }
|
---|
[1039] | 819 | else
|
---|
[1335] | 820 | PostMsg(bkg->hwndReport, bkg->msg, MPVOID, MPVOID);
|
---|
[528] | 821 | DecrThreadUsage();
|
---|
[2] | 822 | WinTerminate(thab);
|
---|
| 823 | }
|
---|
[1039] | 824 | else {
|
---|
[1042] | 825 | // fixme to be gone? - can not PostMsg without HAB
|
---|
[1029] | 826 | PostMsg(bkg->hwndReport, bkg->msg, MPVOID, MPVOID);
|
---|
[1042] | 827 | }
|
---|
| 828 | free(bkg);
|
---|
| 829 | } // if bkg
|
---|
[1029] | 830 | # ifdef FORTIFY
|
---|
| 831 | Fortify_LeaveScope();
|
---|
[1063] | 832 | # endif
|
---|
[1335] | 833 | // _endthread(); // 10 Dec 08 SHL
|
---|
[2] | 834 | }
|
---|
| 835 |
|
---|
[551] | 836 | INT MLEbackgroundload(HWND hwndReport, ULONG msg, HWND h, CHAR * filename,
|
---|
| 837 | INT hex)
|
---|
[350] | 838 | {
|
---|
| 839 | /* load a file into the MLE in the background (via a separate thread)
|
---|
| 840 | * return _beginthread status
|
---|
| 841 | */
|
---|
[2] | 842 |
|
---|
| 843 | BKGLOAD *bkg;
|
---|
| 844 |
|
---|
[551] | 845 | bkg = xmallocz(sizeof(BKGLOAD), pszSrcFile, __LINE__);
|
---|
[350] | 846 | if (!bkg)
|
---|
| 847 | return -1;
|
---|
| 848 | bkg->size = sizeof(BKGLOAD);
|
---|
[551] | 849 | bkg->hex = (USHORT) hex;
|
---|
[350] | 850 | bkg->hwndReport = hwndReport;
|
---|
| 851 | bkg->msg = msg;
|
---|
| 852 | bkg->h = h;
|
---|
[551] | 853 | strcpy(bkg->filename, filename);
|
---|
[1335] | 854 | return xbeginthread(LoadThread,
|
---|
| 855 | 65536,
|
---|
| 856 | bkg,
|
---|
| 857 | pszSrcFile,
|
---|
| 858 | __LINE__);
|
---|
[2] | 859 | }
|
---|
| 860 |
|
---|
[551] | 861 | BOOL MLEloadfile(HWND h, CHAR * filename)
|
---|
[301] | 862 | {
|
---|
[2] | 863 | /* load a file into the MLE, getting rid of whatever was already
|
---|
| 864 | * there. Note this returns without erasing existing text if the
|
---|
| 865 | * file to load does not exist
|
---|
| 866 | */
|
---|
| 867 |
|
---|
[843] | 868 | FILESTATUS3 fsa;
|
---|
[551] | 869 | BOOL ret;
|
---|
[2] | 870 |
|
---|
[843] | 871 | if (!DosQueryPathInfo(filename, FIL_STANDARD, &fsa, sizeof(fsa)) &&
|
---|
| 872 | ~fsa.attrFile & FILE_DIRECTORY) {
|
---|
[2] | 873 | MLEclearall(h);
|
---|
[551] | 874 | ret = MLEinsertfile(h, filename);
|
---|
| 875 | MLEsetchanged(h, FALSE);
|
---|
[2] | 876 | return ret;
|
---|
| 877 | }
|
---|
| 878 | return FALSE;
|
---|
| 879 | }
|
---|
| 880 |
|
---|
[551] | 881 | BOOL MLEexportfile(HWND h, CHAR * filename, INT tabspaces,
|
---|
| 882 | BOOL striptraillines, BOOL striptrailspaces)
|
---|
[301] | 883 | {
|
---|
[2] | 884 | /* save the MLE contents as a file. Format the output so that
|
---|
| 885 | * the file is CR/LF terminated as presented in the MLE.
|
---|
| 886 | */
|
---|
| 887 |
|
---|
[301] | 888 | FILE *fp = NULL;
|
---|
| 889 | CHAR *buffer = NULL;
|
---|
| 890 | CHAR *p;
|
---|
| 891 | BOOL ok = TRUE;
|
---|
[551] | 892 | INT blanklines = 0;
|
---|
[301] | 893 | BOOL fWrap = MLEgetwrap(h);
|
---|
[350] | 894 | APIRET rc;
|
---|
[2] | 895 |
|
---|
[551] | 896 | if (!MLEgetlen(h)) /* nothing to save; forget it */
|
---|
[2] | 897 | return TRUE;
|
---|
| 898 |
|
---|
[551] | 899 | MLEsetwrap(h, FALSE); // Need wrap off to export MLFIE_NOTRANS
|
---|
[301] | 900 |
|
---|
[551] | 901 | if (striptraillines) {
|
---|
[2] | 902 |
|
---|
| 903 | register LONG x;
|
---|
[551] | 904 | LONG numlines;
|
---|
[2] | 905 |
|
---|
| 906 | numlines = MLEnumlines(h);
|
---|
[551] | 907 | for (x = numlines; x; x--) {
|
---|
| 908 | if (MLElinelen(h, x - 1L) < 2)
|
---|
| 909 | MLEdeleteline(h, x - 1L);
|
---|
[2] | 910 | else
|
---|
[551] | 911 | break;
|
---|
[2] | 912 | }
|
---|
[551] | 913 | if (!MLEgetlen(h)) {
|
---|
[301] | 914 | /* nothing to save; forget it */
|
---|
| 915 | MLEsetwrap(h, fWrap); // Restore
|
---|
[2] | 916 | return TRUE;
|
---|
[301] | 917 | }
|
---|
[2] | 918 | }
|
---|
| 919 |
|
---|
[1438] | 920 | rc = xDosAllocMem((PVOID) & buffer, 4096L,
|
---|
[1439] | 921 | PAG_COMMIT | PAG_READ | PAG_WRITE, pszSrcFile, __LINE__);
|
---|
[350] | 922 | if (rc || !buffer) {
|
---|
[551] | 923 | Dos_Error(MB_CANCEL, rc, h, pszSrcFile, __LINE__,
|
---|
| 924 | GetPString(IDS_OUTOFMEMORY));
|
---|
[350] | 925 | ok = FALSE;
|
---|
| 926 | }
|
---|
[551] | 927 | else {
|
---|
| 928 | fp = fopen(filename, "a+");
|
---|
[350] | 929 | if (!fp)
|
---|
[551] | 930 | fp = xfopen(filename, "w", pszSrcFile, __LINE__);
|
---|
[350] | 931 | if (!fp)
|
---|
| 932 | ok = FALSE;
|
---|
| 933 | else {
|
---|
[551] | 934 | LONG numlines, ret, len, wl, temp;
|
---|
| 935 | IPT s;
|
---|
[2] | 936 |
|
---|
[551] | 937 | fseek(fp, 0L, SEEK_END);
|
---|
[2] | 938 | numlines = MLEnumlines(h);
|
---|
| 939 |
|
---|
[551] | 940 | WinSendMsg(h, MLM_SETIMPORTEXPORT, MPFROMP(buffer), MPFROMLONG(4095L));
|
---|
| 941 | for (temp = 0; temp < numlines; temp++) {
|
---|
| 942 | s = MLEstartofline(h, temp);
|
---|
| 943 | wl = len = (LONG) MLElinelenleft(h, s);
|
---|
| 944 | ret = (LONG) WinSendMsg(h, MLM_EXPORT, MPFROMP(&s), MPFROMP(&len));
|
---|
| 945 | if (ret < 0)
|
---|
| 946 | break;
|
---|
| 947 | wl = min(wl, ret);
|
---|
| 948 | buffer[wl] = 0;
|
---|
| 949 | if (*buffer) {
|
---|
| 950 | p = buffer + strlen(buffer) - 1;
|
---|
| 951 | while (p >= buffer && (*p == '\n' || *p == '\r')) {
|
---|
| 952 | *p = 0;
|
---|
| 953 | p--;
|
---|
| 954 | }
|
---|
| 955 | }
|
---|
| 956 | if (tabspaces) {
|
---|
| 957 | p = buffer;
|
---|
| 958 | while (*p) {
|
---|
| 959 | if (*p == '\t') {
|
---|
| 960 | *p = ' ';
|
---|
| 961 | memmove((p + tabspaces) - 1, p, strlen(p) + 1);
|
---|
| 962 | memset(p, ' ', tabspaces);
|
---|
| 963 | }
|
---|
| 964 | p++;
|
---|
| 965 | }
|
---|
| 966 | }
|
---|
| 967 | if (striptrailspaces && *buffer) {
|
---|
| 968 | p = buffer + strlen(buffer) - 1;
|
---|
| 969 | while (p >= buffer && (*p == ' ' || *p == '\t')) {
|
---|
| 970 | *p = 0;
|
---|
| 971 | p--;
|
---|
| 972 | }
|
---|
| 973 | }
|
---|
| 974 | if (striptraillines) {
|
---|
| 975 | if (!*buffer) {
|
---|
| 976 | blanklines++;
|
---|
| 977 | continue;
|
---|
| 978 | }
|
---|
| 979 | else {
|
---|
| 980 | while (blanklines) {
|
---|
| 981 | fwrite("\n", 1, 1, fp);
|
---|
| 982 | blanklines--;
|
---|
| 983 | }
|
---|
| 984 | }
|
---|
| 985 | }
|
---|
| 986 | strcat(buffer, "\n");
|
---|
| 987 | if (fwrite(buffer, 1, strlen(buffer), fp) < 1) {
|
---|
| 988 | saymsg(MB_ENTER,
|
---|
| 989 | h, GetPString(IDS_ARGHTEXT), GetPString(IDS_WRITEERRORTEXT));
|
---|
| 990 | break;
|
---|
| 991 | }
|
---|
| 992 | } // for lines
|
---|
[2] | 993 | }
|
---|
| 994 | }
|
---|
[301] | 995 |
|
---|
[551] | 996 | MLEsetwrap(h, fWrap); // Restore
|
---|
[301] | 997 |
|
---|
| 998 | if (fp)
|
---|
| 999 | fclose(fp);
|
---|
| 1000 | if (buffer)
|
---|
| 1001 | DosFreeMem(buffer);
|
---|
| 1002 |
|
---|
| 1003 | return ok;
|
---|
[2] | 1004 | }
|
---|
| 1005 |
|
---|
[551] | 1006 | MRESULT EXPENTRY SandRDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
[301] | 1007 | {
|
---|
[2] | 1008 | /* initiate search(/replace)s in edit mode */
|
---|
| 1009 |
|
---|
| 1010 | SRCHPTR *vw;
|
---|
| 1011 |
|
---|
[551] | 1012 | if (msg != WM_INITDLG)
|
---|
[574] | 1013 | vw = (SRCHPTR *) WinQueryWindowPtr(hwnd, QWL_USER);
|
---|
[2] | 1014 | else
|
---|
| 1015 | vw = NULL;
|
---|
| 1016 |
|
---|
[551] | 1017 | switch (msg) {
|
---|
| 1018 | case WM_INITDLG:
|
---|
| 1019 | vw = (SRCHPTR *) mp2;
|
---|
| 1020 | if (!vw) {
|
---|
| 1021 | WinDismissDlg(hwnd, 0);
|
---|
[2] | 1022 | break;
|
---|
[551] | 1023 | }
|
---|
[574] | 1024 | WinSetWindowPtr(hwnd, QWL_USER, (PVOID) mp2);
|
---|
[551] | 1025 | WinSendDlgItemMsg(hwnd, SRCH_SEARCH, EM_SETTEXTLIMIT,
|
---|
| 1026 | MPFROM2SHORT(256, 0), MPVOID);
|
---|
| 1027 | WinSendDlgItemMsg(hwnd, SRCH_REPLACE, EM_SETTEXTLIMIT,
|
---|
| 1028 | MPFROM2SHORT(256, 0), MPVOID);
|
---|
| 1029 | if (*vw->search)
|
---|
| 1030 | WinSetDlgItemText(hwnd, SRCH_SEARCH, vw->search);
|
---|
| 1031 | if (!MLEgetreadonly(vw->hwndmle)) {
|
---|
| 1032 | if (*vw->replace)
|
---|
| 1033 | WinSetDlgItemText(hwnd, SRCH_REPLACE, vw->replace);
|
---|
| 1034 | WinSendDlgItemMsg(hwnd, SRCH_SANDR, BM_SETCHECK,
|
---|
| 1035 | MPFROM2SHORT(vw->sandr, 0), MPVOID);
|
---|
| 1036 | WinSendDlgItemMsg(hwnd, SRCH_RALL, BM_SETCHECK,
|
---|
| 1037 | MPFROM2SHORT(vw->rall, 0), MPVOID);
|
---|
| 1038 | }
|
---|
| 1039 | else {
|
---|
| 1040 | WinEnableWindow(WinWindowFromID(hwnd, SRCH_SANDR), FALSE);
|
---|
| 1041 | WinEnableWindow(WinWindowFromID(hwnd, SRCH_RALL), FALSE);
|
---|
| 1042 | WinEnableWindow(WinWindowFromID(hwnd, SRCH_REPLACE), FALSE);
|
---|
| 1043 | WinShowWindow(WinWindowFromID(hwnd, SRCH_REPLACE), FALSE);
|
---|
| 1044 | *vw->replace = 0;
|
---|
| 1045 | vw->sandr = FALSE;
|
---|
| 1046 | vw->rall = FALSE;
|
---|
| 1047 | }
|
---|
| 1048 | memset(&vw->se, 0, sizeof(MLE_SEARCHDATA));
|
---|
| 1049 | vw->se.cb = sizeof(MLE_SEARCHDATA);
|
---|
| 1050 | vw->se.pchFind = (PCHAR) vw->search;
|
---|
| 1051 | vw->se.cchFind = (SHORT) strlen(vw->search);
|
---|
| 1052 | vw->se.pchReplace = (PCHAR) vw->replace;
|
---|
| 1053 | vw->se.cchReplace = (SHORT) strlen(vw->replace);
|
---|
| 1054 | vw->se.iptStart = MLEcurpos(vw->hwndmle);
|
---|
| 1055 | vw->se.iptStop = -1L;
|
---|
| 1056 | vw->se.cchFound = 0;
|
---|
| 1057 | PosOverOkay(hwnd);
|
---|
| 1058 | break;
|
---|
[2] | 1059 |
|
---|
[551] | 1060 | case WM_CONTROL:
|
---|
| 1061 | return 0;
|
---|
[2] | 1062 |
|
---|
[551] | 1063 | case WM_COMMAND:
|
---|
| 1064 | switch (SHORT1FROMMP(mp1)) {
|
---|
| 1065 | case IDM_HELP:
|
---|
| 1066 | saymsg(MB_ENTER | MB_ICONASTERISK,
|
---|
| 1067 | hwnd,
|
---|
| 1068 | NullStr,
|
---|
| 1069 | GetPString(IDS_ENTERSEARCHSTRINGTEXT),
|
---|
| 1070 | (MLEgetreadonly(vw->hwndmle)) ?
|
---|
| 1071 | "." : GetPString(IDS_REPLACESTRINGTEXT));
|
---|
| 1072 | break;
|
---|
[2] | 1073 |
|
---|
[551] | 1074 | case DID_CANCEL:
|
---|
| 1075 | WinDismissDlg(hwnd, 0);
|
---|
| 1076 | break;
|
---|
[2] | 1077 |
|
---|
[551] | 1078 | case DID_OK:
|
---|
| 1079 | WinShowWindow(hwnd, FALSE);
|
---|
| 1080 | {
|
---|
| 1081 | CHAR temp[257];
|
---|
| 1082 | APIRET ret;
|
---|
[2] | 1083 |
|
---|
[551] | 1084 | if ((USHORT) WinSendDlgItemMsg(hwnd, SRCH_SANDR, BM_QUERYCHECK,
|
---|
| 1085 | MPVOID, MPVOID))
|
---|
| 1086 | vw->sandr = TRUE;
|
---|
| 1087 | else
|
---|
| 1088 | vw->sandr = FALSE;
|
---|
| 1089 | if ((USHORT) WinSendDlgItemMsg(hwnd, SRCH_RALL, BM_QUERYCHECK,
|
---|
| 1090 | MPVOID, MPVOID))
|
---|
| 1091 | vw->rall = TRUE;
|
---|
| 1092 | else
|
---|
| 1093 | vw->rall = FALSE;
|
---|
| 1094 | *vw->replace = 0;
|
---|
| 1095 | WinQueryDlgItemText(hwnd, SRCH_REPLACE, 256, vw->replace);
|
---|
| 1096 | vw->se.cchReplace = (SHORT) strlen(vw->replace);
|
---|
| 1097 | WinQueryDlgItemText(hwnd, SRCH_SEARCH, 256, temp);
|
---|
| 1098 | if (*temp) {
|
---|
| 1099 | strcpy(vw->search, temp);
|
---|
| 1100 | vw->se.cchFind = (SHORT) strlen(vw->search);
|
---|
| 1101 | if (!WinSendMsg(vw->hwndmle, MLM_SEARCH,
|
---|
| 1102 | MPFROMLONG(MLFSEARCH_SELECTMATCH |
|
---|
| 1103 | (MLFSEARCH_CASESENSITIVE *
|
---|
| 1104 | (vw->fInsensitive ==
|
---|
| 1105 | FALSE)) | (MLFSEARCH_CHANGEALL *
|
---|
| 1106 | (vw->rall != 0))),
|
---|
| 1107 | MPFROMP(&vw->se))) {
|
---|
| 1108 | saymsg(MB_ENTER | MB_ICONASTERISK, hwnd, NullStr,
|
---|
| 1109 | GetPString(IDS_STRINGNOTFOUNDTEXT), vw->search);
|
---|
| 1110 | WinDismissDlg(hwnd, 0);
|
---|
| 1111 | break;
|
---|
| 1112 | }
|
---|
| 1113 | else if (vw->sandr && !vw->rall) {
|
---|
| 1114 | ret = saymsg(MB_YESNOCANCEL,
|
---|
| 1115 | hwnd,
|
---|
| 1116 | NullStr,
|
---|
| 1117 | GetPString(IDS_CONFIRMREPLACETEXT), vw->replace);
|
---|
| 1118 | if (ret == MBID_YES)
|
---|
| 1119 | MLEinsert(vw->hwndmle, vw->replace);
|
---|
| 1120 | else if (ret == MBID_CANCEL) {
|
---|
| 1121 | WinDismissDlg(hwnd, 0);
|
---|
| 1122 | break;
|
---|
| 1123 | }
|
---|
| 1124 | WinDismissDlg(hwnd, 1);
|
---|
| 1125 | break;
|
---|
| 1126 | }
|
---|
| 1127 | }
|
---|
| 1128 | WinDismissDlg(hwnd, 0);
|
---|
[2] | 1129 | }
|
---|
[551] | 1130 | break;
|
---|
| 1131 | }
|
---|
| 1132 | return 0;
|
---|
[2] | 1133 |
|
---|
[551] | 1134 | case WM_CLOSE:
|
---|
| 1135 | break;
|
---|
[2] | 1136 | }
|
---|
| 1137 |
|
---|
[551] | 1138 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
---|
[2] | 1139 | }
|
---|
| 1140 |
|
---|
[551] | 1141 | BOOL MLEfindfirst(HWND hwnd, SRCHPTR * vw)
|
---|
[301] | 1142 | {
|
---|
[551] | 1143 | if (MLEsizeofsel(vw->hwndmle) < 256L) {
|
---|
| 1144 | MLEgetseltext(vw->hwndmle, vw->search);
|
---|
[2] | 1145 | vw->search[255] = 0;
|
---|
| 1146 | }
|
---|
[551] | 1147 | if (WinDlgBox(HWND_DESKTOP, hwnd, SandRDlgProc, FM3ModHandle,
|
---|
| 1148 | SRCH_FRAME, MPFROMP(vw)) && *vw->search)
|
---|
[2] | 1149 | return TRUE;
|
---|
| 1150 | return FALSE;
|
---|
| 1151 | }
|
---|
| 1152 |
|
---|
[551] | 1153 | INT MLEfindnext(HWND hwnd, SRCHPTR * vw)
|
---|
[301] | 1154 | {
|
---|
[551] | 1155 | if (!*vw->search)
|
---|
[2] | 1156 | return -1;
|
---|
| 1157 | else {
|
---|
| 1158 | vw->se.iptStart++;
|
---|
[551] | 1159 | if (!WinSendMsg(vw->hwndmle, MLM_SEARCH,
|
---|
| 1160 | MPFROMLONG(MLFSEARCH_SELECTMATCH |
|
---|
| 1161 | (MLFSEARCH_CASESENSITIVE *
|
---|
| 1162 | (vw->fInsensitive ==
|
---|
| 1163 | FALSE)) | (MLFSEARCH_CHANGEALL *
|
---|
| 1164 | (vw->rall))), MPFROMP(&vw->se)))
|
---|
| 1165 | saymsg(MB_ENTER | MB_ICONASTERISK, hwnd, NullStr,
|
---|
| 1166 | GetPString(IDS_STRINGNOTFOUNDTEXT), vw->search);
|
---|
| 1167 | else if (vw->sandr && !vw->rall) {
|
---|
[2] | 1168 |
|
---|
| 1169 | APIRET ret;
|
---|
| 1170 |
|
---|
| 1171 | ret = saymsg(MB_YESNOCANCEL,
|
---|
[551] | 1172 | hwnd,
|
---|
| 1173 | NullStr, GetPString(IDS_CONFIRMREPLACETEXT), vw->replace);
|
---|
| 1174 | if (ret == MBID_YES)
|
---|
| 1175 | MLEinsert(vw->hwndmle, vw->replace);
|
---|
| 1176 | if (ret != MBID_CANCEL)
|
---|
| 1177 | return 1;
|
---|
[2] | 1178 | }
|
---|
| 1179 | }
|
---|
| 1180 | return 0;
|
---|
| 1181 | }
|
---|
[793] | 1182 |
|
---|
| 1183 | #pragma alloc_text(FMMLE,MLEgetlinetext,MLEdeleteline,MLEdeletecurline,MLEdeletetoeol)
|
---|
| 1184 | #pragma alloc_text(FMMLE,MLEclearall,MLEtextatcursor,MLEtextatpos,MLEsizeofsel)
|
---|
| 1185 | #pragma alloc_text(FMMLE3,MLEdoblock,MLEquotepara,MLEinternet)
|
---|
| 1186 | #pragma alloc_text(FMMLE4,MLEAutoLoad,MLEHexLoad,MLEinsertfile,LoadThread,MLEbackgroundload)
|
---|
| 1187 | #pragma alloc_text(FMMLE5,MLEloadfile,MLEexportfile)
|
---|
| 1188 | #pragma alloc_text(FMMLE3,MLEfindfirst,MLEfindnext,SandRDlgProc)
|
---|