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