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