txtedit 119 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
  Purpose: some general-purpose editing facilties for use with Texts
  Author: William Stoye
  History:
    4th August 87 -- started
    20th August 87 -- general overhaul in the light of demos
      this is still an experimental stab, and will undoubtedly
      be a mess. Objectives such as extensibility are dropped for the
      moment, this module is an editor rather than a component of
      an editor.
    02-Mar-88: WRS: changes to undo. Use of better trace.
    02-Mar-88: WRS: xfersend experiments.
    17-Mar-88: igj: new find, format, shell
    13-Dec-89: WRS: menu interactive help.
    14-Dec-89: WRS: msgs literal text put back in.
                    txtedit_menuevent will give menu interactive help
                      if the last wimp event was a help one. (to help help in c.message)
    05-Jan-90: WRS: donormalisepara, if at end of para then format THIS one not NEXT one.
    29-Jan-90: IDJ: changed to use new find technology
    31-Jan-90: IDJ: new dbox added for finding
    31-Jan-90: IDJ: got opening on find dbox small/large depending on 'magic'
     2-Feb-90: IDJ: added raw event handler for find dbox to cure opening problems
                    NB. must still pass things on to help_rawevents
     5-Feb-90: IDJ: changed find dialogue to call dbox_fillin_fixedcaret to stop
                    caret being moved to end of icon, when using magic buttons
     5-Feb-90: IDJ: caret now properly set to end of string after a 'previous' click
    15-Feb-90: IDJ: added up-call on creating new txtedit_state
    16-Feb-90: IDJ: added hex char stuff
    16-Feb-90: IDJ: added "Makefile" to set of default names in txtedit__dftname
    21-Feb-90: IDJ: added use of txtopt_get_name for setting options
    21-Feb-90: IDJ: folded in changes from WRS viz:
                    ctl-sh-left/right to move all windows together.
                    add a \n when sh-importing filename.
    05-Apr-90: IDJ: added optimisation when not using ? in replacement string
    31-May-90: NDR: removed bodge setting estsize=1 if was 0, as xfersend() now fixed
    31-May-90: NDR: deal with Message_DataSaved
     1-Jun-90: NDR: txtmisc routines moved into c.txtmisc
     7-Mar-91: PJC: support for BASIC files added
    29-Apr-91: IDJ: finish off printing support
    09-May-91: ECN: #ifndef out unused ROM functions
    16-May-91: IDJ: Quick hack to txtedit_saveas to get rid of 'data transfer failed'
    12-Jun-91: IDJ: increase buffer size for reading edit$options
    12-Jun-91: IDJ: made filename comparison case-insensitive
    12-Jun-91: IDJ: put window hand and icon no in dataload msg back to !printers
                    and report errors from !printers
    26-Jun-91: IDJ: fixed printing protocol to understand old and new printer mungers
    27-Jun-91: IDJ: experiments with not resetting filename on insert (abandoned)
    28-Jun-91: IDJ: experiments with edit$options and wordwrap,coltab,overwrite
    01-Jul-91: IDJ: close down menu after Sh-F3(Coltab), Sh-F1(Overwrite), Ctrl-F5(WordWrap)
    22-Jul-91: IDJ: stop pretending that all files are text when sending to !printers
    23-Jul-91: IDJ: some tracing inserted to chase interaction with email bug
    08-Aug-91: IDJ: put current type in set type menu, or null if untyped.
    09-Aug-91: IDJ: remove correct handler when error on print selection
    19-Aug-91: IDJ: set edit$options after Sh-F3(Coltab), Sh-F1(Overwrite), Ctrl-F5(WordWrap)
    22-Aug-91: IDJ: remove last string literals from code area
    30-Aug-91: IDJ: when printing send leafname <untitled> if untitled text
    04-Sep-91: IDJ: set correct options on Sh-F3,Sh-F1,Ctrl-F5
    :
    17-Jan-95: AMcC: updated txtedit_infoaboutprogram: Version/Date looked up in Messages file
*/

#define BOOL int
#define TRUE 1
#define FALSE 0

#define PRINT 1
/* 29-Apr-91: IDJ: support for printing */

#define BASIC 1
/* 7-Mar-91: PJC: support for BASIC files wanted */

#define OVERWRITE 1
/* 17-Nov-88: WRS: Overwrite feature - late spec extension. */
#define MOVERWRITE 1
/* 29-Nov-88: WRS: overwrite is on menu tree - no. */
#define FMTTEXT1 1
/* 17-Nov-88: WRS: late spec change - set width of format-text causes
an actual format operation. */
/* User Guide wording does not actually preclude this change: so, in it goes. */
#define TAB1 1
/* 17-Nov-88: WRS: late spec change - tab by columns-of-8, user-settable. */

/* WORDWRAP definition moved to h.EditIntern.txtmisc by NRaine */
#define EDIT2 1
/* 05-Jan-89 WRS: beyond 1.00: wordwrap, tab col, overwrite modes */
100 101
#define NEWDELETE 1
/* 30-Oct-02 KJB: Delete deletes right */
Neil Turton's avatar
Neil Turton committed
102 103 104 105 106 107 108

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <signal.h>
#include <ctype.h>
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
#include "akbd.h"
#include "werr.h"
#include "menu.h"
#include "os.h"
#include "wimp.h"
#include "wimpt.h"
#include "txt.h"
#include "win.h"
#include "txtwin.h"
#include "flex.h"
#include "txtscrap.h"
#include "event.h"
#include "txtedit.h"
#include "EditIntern/txtfind.h"
#include "EditIntern/txtmisc.h"
#include "EditIntern/txtundo.h"
#include "EditIntern/txtar.h"    /* >>>> because of TextOptMen, Options */
#include "dboxquery.h"
#include "dboxfile.h"
#include "trace.h"
#include "dbox.h"
#include "EditIntern/txtoptmenu.h"
#include "xfersend.h"
#include "xferrecv.h"
#include "saveas.h"
#include "typdat.h"
#include "fileicon.h"
#include "visdelay.h"
#include "EditIntern/txtfile.h"
#include "EditIntern/txtregexp.h"
#include "swis.h"
Neil Turton's avatar
Neil Turton committed
140
#ifdef SETOPTIONS
141
#include "txtopt.h"
Neil Turton's avatar
Neil Turton committed
142 143
#endif

144 145 146 147
#include "msgs.h"
#include "help.h"
#include "template.h"
#include "VerIntern/messages.h"
Neil Turton's avatar
Neil Turton committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329

txtedit_state *txtedit_newwithoptions(char *filename, int desired_filetype, txtar_options *o);
void txtedit_splitwindow(void *v);
void txtedit__undomajor(txtedit_state *s);


#define txtedit_AMax 20


/* Offsets within the main menu tree for an editor window. */

#define txtedit_MMisc 1
#define txtedit_MFile 2
#define txtedit_MSel 3
#define txtedit_MEdit 4
#define txtedit_MDisplay 5

#define txtedit_MAboutProgram 1
#define txtedit_MAboutFile 2
#define txtedit_MNewType 3
#define txtedit_MSplit 4
#if PRINT
#define txtedit_MPrint 5

#if EDIT2
/* new features beyond 1.00 */
#define txtedit_MColTab 6
#define txtedit_MOverwrite 7
#define txtedit_MWordwrap 8
#define txtedit_MTrace 9
#define txtedit_MNoTrace 10
#else
#define txtedit_MTrace 6
#define txtedit_MNoTrace 7
#endif

#else
/* no PRINT */

#if EDIT2
/* new features beyond 1.00 */
#define txtedit_MColTab 5
#define txtedit_MOverwrite 6
#define txtedit_MWordwrap 7
#define txtedit_MTrace 8
#define txtedit_MNoTrace 9
#else
#define txtedit_MTrace 5
#define txtedit_MNoTrace 6
#endif

#endif    /* PRINT */

#if PRINT
#define txtedit_MSelSave 1
#define txtedit_MSelPrint 2
#define txtedit_MSelCopy 3
#define txtedit_MSelMove 4
#define txtedit_MSelDelete 5
#define txtedit_MSelClear 6
#define txtedit_MSelIndent 7
#else
#define txtedit_MSelSave 1
#define txtedit_MSelCopy 2
#define txtedit_MSelMove 3
#define txtedit_MSelDelete 4
#define txtedit_MSelClear 5
#define txtedit_MSelIndent 6
#endif  /* PRINT */

#define txtedit_MFind 1
#define txtedit_MGoto 2
#define txtedit_MUndo 3
#define txtedit_MRedo 4
#define txtedit_MExchangeCRLF 5
#define txtedit_MExpandTabs 6
#define txtedit_MFormatText 7

/* field offsets for the Find and Found DBoxes. */

/* IDJ 31-Jan-90 Size of extension to find dbox */
#define txtedit_small_findbox  0
#define txtedit_large_findbox  1

#define txtedit_FiGo 0
#define txtedit_FiPrevious 1
#define txtedit_FiFind 2
#define txtedit_FiReplace 3
#define txtedit_FiMsg 4      /* output, for saying "not found". */
/* 5, 6 are text for prompt - we don't use them */
#define txtedit_FiCount 7
#define txtedit_FiCase 8
#define txtedit_FiMagic 9
#define txtedit_FiRegularExpressions 10
#define txtedit_FiAny   11
#define txtedit_FiNewline 12
#define txtedit_FiAlphanum 13
#define txtedit_FiDigit 14
#define txtedit_FiCtrl 15
#define txtedit_FiNormal 16
#define txtedit_FiSetBra 17
#define txtedit_FiSetKet 18
#define txtedit_FiNot 19
#define txtedit_Fi0OrMore 20
#define txtedit_Fi1OrMore 21
#define txtedit_FiMost 22
#define txtedit_FiTo 23
#define txtedit_FiFound 24
#define txtedit_FiField 25
#define txtedit_FiHex 26

#define txtedit_FiBackGnd 27
#define txtedit_FiFoundString 36


#define txtedit_FoStop 0
#define txtedit_FoCont 1
#define txtedit_FoRep 2
#define txtedit_FoLastRep 3
#define txtedit_FoEndRep 4
#define txtedit_FoMsg 5      /* output, for saying how many done */
#define txtedit_FoUndo 6
#define txtedit_FoRedo 7


/* fields of Indent DBox */

#define txtedit_IndOK 0
#define txtedit_IndCancel 1
#define txtedit_IndBy 2


/* fields for Goto DBox. */

#define txtedit_GoGo 0
#define txtedit_GoCancel 1
#define txtedit_GoCurrentLine 2
#define txtedit_GoCurrentChar 3
#define txtedit_GoLine 4


#if FALSE
/* fields in the undo template */

#define txtedit_UQuit 0
#define txtedit_UMore 1
#define txtedit_URedo 2

#endif

#define txtedit_IFOK 0
#define txtedit_IFName 1       /* text output */
#define txtedit_IFModified 2   /* YES or NO text */
#define txtedit_IFType 3       /* output */
#define txtedit_IFSize 4       /* numeric output */
#define txtedit_IFLastUpdate 5 /* text output */
#define txtedit_IFIcon 6       /* icon output */

/* Standard tool for editors? */
/* could toggle update flag, change type/name */

/* The rest is just decoration. */
/* Is this a standard useful template for editors? */

/* -------- statics. -------- */

#if FALSE
static BOOL lastopts_set = FALSE;
static txtar_options lastopts;
#endif

/* -------- -------- */

typedef enum

  {

   txtedit_SEL = 1, txtedit_EXT = 2, txtedit_CTLSEL = 4, txtedit_NONE = 8

  } txtedit_SELACTION;


330
static menu txtedit_menumaker(void *a);
Neil Turton's avatar
Neil Turton committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
/* Forward reference. */

void txtedit_copyselection(txtedit_state *s);

static txtedit_state *txtedits = 0; /* list of them all */

/* handlers and handles for update/close/save/shutdown */
static txtedit_update_handler txtedit__update_handler = 0;
static txtedit_save_handler txtedit__save_handler = 0;
static txtedit_close_handler txtedit__close_handler = 0;
static txtedit_shutdown_handler txtedit__shutdown_handler = 0;
static txtedit_undofail_handler txtedit__undofail_handler = 0;
static txtedit_open_handler txtedit__open_handler = 0;
static void *txtedit__update_handle = 0;
static void *txtedit__save_handle = 0;
static void *txtedit__close_handle = 0;
static void *txtedit__shutdown_handle = 0;
static void *txtedit__undofail_handle = 0;
static void *txtedit__open_handle = 0;

#if BASIC
static int txtedit__detokenise = -1;
static int txtedit__tokenise = -1;
static int txtedit__increment = 10;
static BOOL txtedit__strip = TRUE;
#endif

static int cistrcmp(const char *s1, const char *s2)
{
  int ch1, ch2;
  for (;;) {
    ch1 = *s1++;  ch2 = *s2++;
    /* care here for portability... don't rely on ANSI spec */
    if (isupper(ch1)) ch1 = tolower(ch1);
    if (isupper(ch2)) ch2 = tolower(ch2);
    if (ch1 != ch2) return ch1-ch2;
    if (ch1 == 0) return 0;
  }
}

Kevin Bracey's avatar
Kevin Bracey committed
371
static txtedit_state *txtedit__init(txt t)
Neil Turton's avatar
Neil Turton committed
372 373 374 375 376 377 378 379 380 381 382 383 384
{

txtedit_state  *s;
#ifdef SET_MISC_OPTIONS
txtar_options opts;
#endif

s = malloc(sizeof(txtedit_state));
if (s == 0) return 0;

s->t = t;
txt_newmarker(t, &s->selpivot);
s->seltype       = txtedit_CHARSEL;
385
s->selectrecent  = FALSE;
Neil Turton's avatar
Neil Turton committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
s->filename[0]   = 0;
s->ty.ex = -1;
s->ty.ld = -1;
txtfile_buildnewtimestamp(s->ty, &s->ty);
s->next          = txtedits;

#ifndef SET_MISC_OPTIONS

#if OVERWRITE
s->overwrite     = FALSE;
#endif

#if TAB1
s->wordtab       = TRUE;
#endif

#if WORDWRAP
s->wordwrap    = FALSE;
#endif

#else

txtar_getoptions(s->t, &opts);
s->overwrite = opts.overwrite;
s->wordtab = opts.wordtab;
s->wordwrap = opts.wordwrap;

#endif

txtedits         = s;

/* Force the creation of the menu tree early on.
This prevents embarassing cases of running out of memory. */
txtedit_menumaker(s);

return(s);

}

Kevin Bracey's avatar
Kevin Bracey committed
425
void txtedit_dispose(txtedit_state *s)
Neil Turton's avatar
Neil Turton committed
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
{

if (txtscrap_selectowner() == s->t)
   txtscrap_setselect(s->t, 0, 0);

txt_disposemarker(s->t, &(s->selpivot));
txt_dispose(&(s->t));

/* remove s from the list of all text editors. */
if (txtedits == s) {
  txtedits = s->next;
} else {
  txtedit_state *ptr = txtedits;
  while (ptr->next != s) {
#if FALSE
    if (ptr == 0) {
      /* >>> chasing apparent collapse in findnamedtxt... */
      werr(TRUE, "Unexpected internal error te-1-1.");
    };
#endif
    ptr = ptr->next;
  };
  ptr->next = s->next;
};

free(s);
}

static int txtedit__countupdated(void) {
  txtedit_state *ptr = txtedits;
  int count = 0;
  while (ptr != 0) {
    if ((txt_charoptions(ptr->t) & txt_UPDATED) != 0) count++;
    ptr = ptr->next;
  };
  return count;
}

BOOL txtedit_mayquit(void) {
  int count = txtedit__countupdated();
  if (count == 0) {
    return TRUE;
  } else {
    char a[80];
    if (count == 1) {
      sprintf(a, msgs_lookup(MSGS_txt6));
    } else {
      sprintf(a, msgs_lookup(MSGS_txt7), count);
    };
    return (dboxquery_quit(a) == dboxquery_quit_DISCARD);
  }
}

/* 14-Dec-88 WRS: can recurse in txtedit_mayquit! */

void txtedit_prequit(void) {
  int count = txtedit__countupdated();
  if (count != 0) {
    /* First, acknowledge the message. */
    wimp_eventstr *e = wimpt_last_event();
    if ((e->e == wimp_ESEND || e->e == wimp_ESENDWANTACK)
    && e->data.msg.hdr.action == wimp_MPREQUIT)
    {
      wimp_t taskmgr = e->data.msg.hdr.task;

      /* amg 8th August 1994 add awareness of flag word */
      int size_of_prequit = e->data.msg.hdr.size;
      int flags_of_prequit = e->data.msg.data.words[0];

      e->data.msg.hdr.your_ref = e->data.msg.hdr.my_ref;
      wimpt_noerr(wimp_sendmessage(wimp_EACK, &e->data.msg, e->data.msg.hdr.task));
      /* And then tell the user. */
      if (txtedit_mayquit()) {
        /* start up the closedown sequence again. */
        /* We assume that the sender is the Task Manager, and that sh-ctl-12
        is the closedown key sequence. */
        wimp_eventdata ee;
        if (txtedit__shutdown_handler != 0)
           txtedit__shutdown_handler(txtedit__shutdown_handle);

        if (size_of_prequit > sizeof(wimp_msghdr) && flags_of_prequit & 1)
        {
          /* we are being killed individually by the Task Manager */
          /* do NOT send back a C/S/F12 */
        }
        else
        {
          wimpt_noerr(wimp_get_caret_pos(&ee.key.c));
          ee.key.chcode = akbd_Sh + akbd_Ctl + akbd_Fn12;
          wimpt_noerr(wimp_sendmessage(wimp_EKEY, (wimp_msgstr*) &ee, taskmgr));
        }
        /* and stop. */
        while (txtedits != 0) txtedit_dispose(txtedits);
      };
    };
  };
}

static txtedit_state *txtedit_findnamedtxt(char *filename) {
#if TRUE
  txtedit_state *ptr = txtedits;
  tracef1("txtedit_findnamedtext of '%s'.\n", (int) filename);
  while (ptr != 0 && cistrcmp(ptr->filename, filename) != 0) {
    ptr = ptr->next;
    tracef1("txtedit_findnamedtext try %i.\n", (int) ptr);
  };
  tracef1("txtedit_findnamedtext returns %i.\n", (int) ptr);
  return ptr;
#else
/* 17-Nov-88: WRS: occasional mysterious crash here, major release
imminent, and the feature is out of line with the other editors
anyway: so, disabled for the moment. */
  return NULL;
#endif
}

static txtedit_state *txtedit__findtxt(txt t) {
  txtedit_state *ptr = txtedits;
  tracef0("txtedit_findtext'.\n");
  while (ptr != 0 && t != ptr->t) {
    ptr = ptr->next;
    tracef1("txtedit_findtext try %i.\n", (int) ptr);
  };
  tracef1("txtedit_findtext returns %i.\n", (int) ptr);
  return ptr;
}

/* PJC: I've had to made settexttitle public so that my code in txtfile
        can set the title
*/

void txtedit_settexttitle(txtedit_state *s)
{

#if EDIT2
char a[356];
char b[20];
#else
char a[256];
#endif

int updated;
unsigned n;
char *name;

if (s->filename[0] == 0) {
  name = msgs_lookup(MSGS_txt65);
} else {
  name = s->filename;
};

updated = (txt_UPDATED & txt_charoptions(s->t)) !=0;
n = txtwin_number(s->t);

#if EDIT2

a[0] = 0;
strcat(a, name);
if (updated)
{
   if (txtedit__update_handler != 0)
      if (txtedit__update_handler(s->filename, s, txtedit__update_handle) == FALSE)
      {
            int i = 20;
            BOOL undo_failed = FALSE;
            txtundo_result res;

            if(txtundo_undo(s->t) == txtundo_RANOUT)
               undo_failed = TRUE;
            while ((res = txtundo_undo(s->t)) == txtundo_MINOR) {
                   i--;
                   if (i == 0) txt_setcharoptions(s->t, txt_DISPLAY, 0);
            };
            if (res == txtundo_RANOUT) undo_failed = TRUE;
            if (i <= 0) txt_setcharoptions(s->t, txt_DISPLAY, txt_DISPLAY);
           /*txtedit__undomajor(s);*/
           if(undo_failed == TRUE)
           {
              if(txtedit__undofail_handler != 0)
                 txtedit__undofail_handler(s->filename, s, txtedit__undofail_handle);
           }
           else
           {
              txt_setcharoptions(s->t, txt_UPDATED, 0);
              return;  /* ie don't modify text !!!! */
           }
      }
   strcat(a, " *");
}
if (n > 1) {
  sprintf(b, " %d", n);
  strcat(a, b);
};
if (! s->wordtab) strcat(a, msgs_lookup(MSGS_txt23));
if (s->overwrite) strcat(a, msgs_lookup(MSGS_txt24));
if (s->wordwrap) strcat(a, msgs_lookup(MSGS_txt25));

#else

if (n > 1)
  if (updated)
    sprintf(a, "%s * %d", name, n);
  else
    sprintf(a, "%s %d", name, n);
else
  if (updated)
    sprintf(a, "%s *", name);
  else
    sprintf(a, "%s", name);

#endif

txt_settitle(s->t, a);

}



/* -------- The Menu. -------- */

static menu txtedit__menu = 0;
static menu m1;
/*static menu m2;*/
static menu m3;
static menu m4;
static menu m5;
static char fwidthbuf[10] = "76"; /* format width */
static char filetypebuff[10] = ""; /* new file type */

static void txtedit__menumaker(void *a)
{
  txtedit_state *s = (txtedit_state *) a;

  txtedit__menu = menu_new(
    msgs_lookup(MSGS_txt10),
    msgs_lookup(MSGS_txt11));

  m1 = menu_new(
   msgs_lookup(MSGS_txt12),
   msgs_lookup(MSGS_txt13));
    /* In the string above,
       \x8b is an up-arrow - provided by the Wimp, utterly non-standard.
       I then can't figure out how to stop C complaining about following hex digits!
       \x46 is 'F'
       \x33 is '3'
       \x31 is '1'
    */

#if TRACE
  menu_extend(m1, "|trace,no trace");
#endif

  { menu foo = menu_new(msgs_lookup(MSGS_txt13a), "foo");

    menu_make_writeable(foo, 1, filetypebuff, 9, "a~.");
    menu_submenu(m1, txtedit_MNewType, foo);
  }

  menu_submenu(txtedit__menu, txtedit_MMisc, m1);

  m3 = menu_new(
    msgs_lookup(MSGS_txt14),
    msgs_lookup(MSGS_txt15));
  menu_submenu(txtedit__menu, txtedit_MSel, m3);

  m4 = menu_new(
    msgs_lookup(MSGS_txt16),
    msgs_lookup(MSGS_txt17));
  m5 = menu_new(msgs_lookup(MSGS_txt18), msgs_lookup(MSGS_txt72));
  menu_make_writeable(m5, 1, fwidthbuf, 9, "a0-9");
  menu_submenu(m4, txtedit_MFormatText, m5);
  menu_submenu(txtedit__menu, txtedit_MEdit, m4);

  m5 = txtoptmenu_make(s->t);
  menu_submenu(txtedit__menu, txtedit_MDisplay, m5);
}

static void txtedit__menusetflags(void *a) {
  txtedit_state *s = (txtedit_state *) a;
  BOOL noscrap = txtscrap_selectowner() == 0;
  BOOL scrapnothere = txtscrap_selectowner() != s->t;

  menu_setflags(m1, txtedit_MOverwrite, s->overwrite, FALSE);
  menu_setflags(m1, txtedit_MColTab, ! s->wordtab, FALSE);
  menu_setflags(m1, txtedit_MWordwrap, s->wordwrap, FALSE);

#if TRACE
  menu_setflags(m1, txtedit_MTrace, trace_is_on(), FALSE);
  menu_setflags(m1, txtedit_MNoTrace, ! trace_is_on(), FALSE);
#endif

  menu_setflags(m3, txtedit_MSelSave,   FALSE, scrapnothere);
#if PRINT
  menu_setflags(m3, txtedit_MSelPrint,  FALSE, noscrap);
#endif
  menu_setflags(m3, txtedit_MSelCopy,   FALSE, noscrap);
  menu_setflags(m3, txtedit_MSelMove,   FALSE, noscrap);
  menu_setflags(m3, txtedit_MSelDelete, FALSE, noscrap);
  menu_setflags(m3, txtedit_MSelClear,  FALSE, noscrap);
  menu_setflags(m3, txtedit_MSelIndent, FALSE, noscrap);

  (void) txtoptmenu_make(s->t); /* set flags for this. */
}

static void txtedit__help_handler(void *a, char *hit)
{
  txtedit_state *s = (txtedit_state *) a;

  s = s; /* to avoid compiler warning */
  if (help_genmessage("HELP", hit))
    ;
  else
  {
    hit[2] = 0; /* try truncated form */
    help_genmessage("HELPX", hit);
  }
}

744
static menu txtedit_menumaker(void *a) {
Neil Turton's avatar
Neil Turton committed
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
  txtedit_state *s = (txtedit_state *) a;

    /* IDJ: 30-Jul-91: insert current filetype */
    if (((unsigned int) s->ty.ld >> 20) == 0xfff)
    {
        char *p;

        os_swi4r(OS_FSControl, 18, 0, 0xfff & (s->ty.ld >> 8), 0, 0,
                 0, (int*) &filetypebuff[0], (int*) &filetypebuff[4]);
        p = filetypebuff;
        while (*p > ' ' && p < filetypebuff + 8) p++;
        *p = 0;
    }
    else
       filetypebuff[0] = 0;

  txtwin_setcurrentwindow(s->t);
  if (txtedit__menu == 0) txtedit__menumaker(a);
  txtedit__menusetflags(a);
  help_register_handler(txtedit__help_handler, s);
  return txtedit__menu;
}

menu txtedit_menu(txtedit_state *s) {
  return txtedit_menumaker((void*) s);
}

Kevin Bracey's avatar
Kevin Bracey committed
772
static int txtedit_noticeseveral(int *c, unsigned *count)
Neil Turton's avatar
Neil Turton committed
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845

/* Look for more characters like c. If there are no more, return FALSE with
count=1. If there are more, increase count on return. If you read ahead
a separate char then put it in c, and return TRUE. */

{

unsigned c1;

c1 = *c;
*count = 1;

while (c1 == *c)

     {
     if (akbd_pollkey(c))
       if (*c == c1)
         ++*count;
       else
         return 1;
     else
       return 0;
     }
return 0;
}

/* -------- Wordwrap. -------- */

#if WORDWRAP

static int txtedit__parawidth(txtedit_state *s) {
  int width;
  if (s->wordwrap && sscanf(fwidthbuf, "%i", &width) == 1) {
    return width;
  } else {
    return 0; /* means do no formatting. */
  };
}

static void txtedit_normalisepara(txtedit_state *s) {
  txtmisc_normalisepara(s->t, txtedit__parawidth(s));
}

static void txtedit_donormalisepara(txtedit_state *s) {
  BOOL waswrap = s->wordwrap;

  visdelay_begin();
  /* 05-Jan-90 - used to format next para if at end of para */
  #if FALSE
    while (txt_charatdot(s->t) == '\n' && txtmisc_paraend(s->t, txt_dot(s->t))) txt_movedot(s->t, 1);
  #else
    /* If between paragraphs, move to the start of the next one. */
    if (txt_dot(s->t) == 0 || txt_charat(s->t, txt_dot(s->t) -1) == '\n')
      while (txt_charatdot(s->t) == '\n') txt_movedot(s->t, 1);
  #endif

  s->wordwrap = TRUE;
  txtedit_normalisepara(s);
  s->wordwrap = waswrap;
#if FALSE
  txt_setdot(s->t, txtmisc_eop(s->t, 1 + txt_dot(s->t)));
#else
  txt_setdot(s->t, 1 + txtmisc_eop(s->t, txt_dot(s->t)));
#endif

  visdelay_end();
}

#endif

/* ---end of WordWrap stuff ----- */


Kevin Bracey's avatar
Kevin Bracey committed
846
static int txtedit_keyboardinput(txtedit_state *s, int *c)
Neil Turton's avatar
Neil Turton committed
847 848 849 850 851 852 853 854 855 856 857 858

/* c is a character code. Process this, and any following. If you have to
poll ahead and yet not use what you find, put it in c and return TRUE.
Otherwise, return FALSE. */

{

char a[txtedit_AMax];
unsigned count;
int result;

count = 0;
859
result = 0;
Neil Turton's avatar
Neil Turton committed
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880

while (count < txtedit_AMax)
     {
     a[count++] = *c % 256;
     if (! akbd_pollkey(c))
       break;
     if (*c == 13) *c = 10; /* newlines etc. */
     if ((*c < 32 || *c >= 127) && *c != 10)

       /* This may mean that some funny chars get done individually:
       not important compared to normal chars. */

       {
       result = 1;
       break;
       }

     }

tracef1("KeyboardInput of %d chars.\n", count);

881
txt_setcharoptions(s->t, txt_CARET, 0);
Neil Turton's avatar
Neil Turton committed
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950

#if OVERWRITE
/* Replace characters, until the next newline in the text. */
{
  int i = 0;
  if (s->overwrite && a[0] != '\n')
    while (i < count && txt_charat(s->t, txt_dot(s->t) + i) != '\n') i++;
  txt_replacechars(s->t, i, a, count);
};
#else
txt_replacechars(s->t, 0, a, count);
#endif

#if WORDWRAP
if (count > 1 || a[0] != '\n') {
  /* don't do it if he just hit RETURN. */
  txtedit_normalisepara(s);
}
#endif

txt_movedot(s->t, count);
txt_setcharoptions(s->t, txt_CARET, txt_CARET);

return(result);

}



/* -------- Mouse Manipulation. -------- */

/*
This is an area of the design with many surprises.

I am unlike the Mac etc. in that the caret and selection are separate.
*/

#if FALSE
void txtedit_mouse(txtedit_state *s, txt_mouseeventflag mflags, txt_index at)

{

int drag, selectwasrecent;
txtedit_SELACTION action;

drag = (((mflags & txt_MSELOLD) != 0) ||
        ((mflags & txt_MEXTOLD) != 0));

tracef1("Mouse drag=%d.\n", drag);

if (!drag)
  {

  if ((mflags & txt_MEXACT) != 0)
    {
    if (s->seltype == txtedit_CHARSEL)
      s->seltype = txtedit_WORDSEL;
    else if (s->seltype == txtedit_WORDSEL)
          s->seltype = txtedit_LINESEL;
    else
          s->seltype = txtedit_CHARSEL;
    }
  else
    s->seltype = txtedit_CHARSEL;
  }

tracef1("Mouse selType=%d.\n", s->seltype);

selectwasrecent = s->selectrecent;
951
s->selectrecent = FALSE;
Neil Turton's avatar
Neil Turton committed
952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
if ((mflags & txt_MEXTEND) != 0)
  action = txtedit_EXT;

else if ((mflags & txt_MSELECT) != 0)

       /* Polling Ctl is only done at the beginning of the drag. */

       {
       action = txtedit_SEL;
       s->selectrecent = (s->seltype == txtedit_CHARSEL);

       /* not set on multi-click, but that's OK because we'll be setting
       the selection anyway. */

       if (drag)
         {
#if FALSE
         if (s->selectctl)
           action = txtedit_SEL; /* >>>> was SEL for trial drag. */
         else
#endif
           if (at != txt_dot(s->t))
             {
             /* Treat this case as an EXT, by popular demand. */
             action = txtedit_EXT; /* drag SEL -> make selection. */
             s->selectrecent = FALSE;
             }
         }
       else
         {
         s->selectctl = akbd_pollctl();
         if (s->selectctl)
           {
           action = txtedit_CTLSEL;
986
           s->selectrecent = FALSE;
Neil Turton's avatar
Neil Turton committed
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
           }
         txt_movemarker(s->t, &s->selpivot, at);
         }

       }

    /* This implies that multi-drag-select does a new trial selection, rather
          than a drag. I think that this is more consistent with the chosen model.
    */
else
  action = txtedit_NONE;

tracef1("Mouse action=%d.\n", action);

if (action == txtedit_NONE)
  action = action; /* do nothing */
else if (s->seltype == txtedit_WORDSEL)
       txtmisc_selectpointandword(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
else if (s->seltype == txtedit_LINESEL)
       txtmisc_selectpointandline(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
else if (action == txtedit_SEL) /* drag or not, don't care */
       {

#if FALSE
         /* For CLI window, this operation cancels the carets in all other
         text windows. A bit sneaky, but should do the trick. */
         /* >>>> This fix now moved to txtar. What a mess! */
         {
           txtedit_state *states = txtedits;
           while (states != 0) {
             if (states != s) {
               txt_setcharoptions(s->t, txt_CARET, 0);
             };
             states = states->next;
           };
         };
#endif

         if (txt_dot(s->t) != at || !drag)
           /* not doing it reduces flicker: yuk, tweaky! */
           txt_setdot(s->t, at);

        if ((txt_charoptions(s->t) & txt_CARET) == 0)
          txt_setcharoptions(s->t, txt_CARET, txt_CARET);

       }

else if (drag)
         /* ext or ctl-sel, don't care */
         txtscrap_setselect(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
else if (action == txtedit_EXT)
       {
       /* first click of Extend: must set selPivot */
       /* decide if from sel or from current selection */
       /* >>>> New simpler experiment: now that you can set the selection by dragging SELECT,
       it seems better to make EXTEND *always* ext the selection if the selection exists.
       This removes any need for "selectwasrecent". */
       if (txt_selectset(s->t) /* && !selectwasrecent */)
         txt_movemarker(s->t, &s->selpivot,
                        txtmisc_furthestaway(s->t, at, txt_selectstart(s->t), txt_selectend(s->t)));
       else
         txt_movemarker(s->t, &s->selpivot, txt_dot(s->t));
       txtscrap_setselect(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
       }
else /* action = ctlsel, not drag */
    {
    txt_movemarker(s->t, &s->selpivot, at);
    txtscrap_setselect(s->t, at, at + 1);
    }

}
#else
/* New mouse handler:
  drag SELECT -> like the mac.
*/
static void txtedit_mouse(txtedit_state *s, txt_mouseeventflag mflags, txt_index at)

{

txtedit_SELACTION action;
BOOL selectwasrecent = s->selectrecent;
Robert Sprowson's avatar
Robert Sprowson committed
1068 1069
BOOL drag = (((mflags & txt_MSELOLD) != 0) ||
            ((mflags & txt_MEXTOLD) != 0));
Neil Turton's avatar
Neil Turton committed
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181

s->selectrecent = FALSE;

tracef1("Mouse drag=%d.\n", drag);

if (!drag)
  {

  if ((mflags & txt_MEXACT) != 0)
    {
    if (s->seltype == txtedit_CHARSEL)
      s->seltype = txtedit_WORDSEL;
    else if (s->seltype == txtedit_WORDSEL)
          s->seltype = txtedit_LINESEL;
    else
          s->seltype = txtedit_CHARSEL;
    }
  else
    s->seltype = txtedit_CHARSEL;
  }

tracef1("Mouse selType=%d.\n", s->seltype);

if ((mflags & txt_MEXTEND) != 0) action = txtedit_EXT;

else if ((mflags & txt_MSELECT) != 0)

       /* Polling Ctl is only done at the beginning of the drag. */

       {
       action = txtedit_SEL;

       /* not set on multi-click, but that's OK because we'll be setting
       the selection anyway. */

       if (drag)
         {
           if (at != txt_dot(s->t))
             {
             /* Treat this case as an EXT, by popular demand. */
             action = txtedit_EXT; /* drag SEL -> make selection. */
             if (selectwasrecent) txtscrap_setselect(s->t, 0, 0); /* make a new selection. */
             }
         }
       else
         {
         s->selectrecent = TRUE;
         s->selectctl = akbd_pollctl();
         if (s->selectctl) action = txtedit_CTLSEL;
         if (s->seltype == txtedit_CHARSEL) {
           txt_movemarker(s->t, &s->selpivot, at);
         } else if (s->seltype == txtedit_WORDSEL) {
           txt_movemarker(s->t, &s->selpivot, txtmisc_bow(s->t, at));
         } else { /* s->seltype == txtedit_LINESEL */
           txt_movemarker(s->t, &s->selpivot, txtmisc_bol(s->t, at));
         };
         }

       }

    /* This implies that multi-drag-select does a new trial selection, rather
          than a drag. I think that this is more consistent with the chosen model.
    */
else
  action = txtedit_NONE;

tracef1("Mouse action=%d.\n", action);

if (action == txtedit_NONE)
  action = action; /* do nothing */
else if (s->seltype == txtedit_WORDSEL)
  {
       if (s->selectrecent) txt_movemarker(s->t, &s->selpivot, at);
       txtmisc_selectpointandword(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
       if (s->selectrecent) txt_movemarker(s->t, &s->selpivot, txt_selectstart(s->t));
  }
else if (s->seltype == txtedit_LINESEL)
       txtmisc_selectpointandline(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
else if (action == txtedit_SEL) /* drag or not, don't care */
       {

         if (txt_dot(s->t) != at || !drag)
           /* not doing it reduces flicker: yuk, tweaky! */
           txt_setdot(s->t, at);

        if ((txt_charoptions(s->t) & txt_CARET) == 0)
          txt_setcharoptions(s->t, txt_CARET, txt_CARET);

       }

else if (drag)
         /* ext or ctl-sel, don't care */
         txtscrap_setselect(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
else if (action == txtedit_EXT)
       {
       if (txt_selectset(s->t))
         txt_movemarker(s->t, &s->selpivot,
                        txtmisc_furthestaway(s->t, at, txt_selectstart(s->t), txt_selectend(s->t)));
       else
         txt_movemarker(s->t, &s->selpivot, txt_dot(s->t));
       txtscrap_setselect(s->t, txt_indexofmarker(s->t, &s->selpivot), at);
       }
else /* action = ctlsel, not drag */
    {
    txt_movemarker(s->t, &s->selpivot, at);
    txtscrap_setselect(s->t, at, at + 1);
    }

}
#endif


Kevin Bracey's avatar
Kevin Bracey committed
1182
static void txtedit_exchangedotandselect(txtedit_state *s)
Neil Turton's avatar
Neil Turton committed
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
{

txt owner;
txt_index at, dot;

owner = txtscrap_selectowner();
if (owner != NULL)
  {
  at = txt_selectstart(owner);
  dot = txt_dot(s->t);
  if (txtmisc_eof(s->t) && dot != 0)
    --dot;
  txtscrap_setselect(s->t, dot, dot + 1);
  txt_setdot(owner, at);
  }
}

static BOOL escflag = FALSE; /* for escaping from long searches. */

void txtedit__redomajor(txtedit_state *s, int harmless); /* forw ref */

static void eschandler(int type) {
  type=type;
  (void) signal(SIGINT, &eschandler);
  escflag = TRUE;
}


static void txtedit__extend_findbox(wimp_w whandle, int size)
{
   wimp_wstate state;
   wimp_icon magic_icon, found_icon;
   int growth;
   template *t;
   int small_size = 0;

   /* belt and braces code to ensure no probs, when dragging window, and pressing F5 */
   /* seems to cause probs, if we don't do the following */
   if ((t = template_find("find")) != 0)
      small_size = t->window.box.y1 - t->window.box.y0;

   /* get the window state */
   wimpt_noerr(wimp_get_wind_state(whandle, &state));

   /* use icon defs to set size of window */
   wimp_get_icon_info(whandle, txtedit_FiMagic, &magic_icon);
   wimp_get_icon_info(whandle, txtedit_FiFound, &found_icon);

   growth = magic_icon.box.y0 - found_icon.box.y0;

   /* change bottom of window */
   if (size == txtedit_small_findbox)
       state.o.box.y0 = state.o.box.y1 - small_size;
   else
       state.o.box.y0 = state.o.box.y1 - small_size - growth;

   /* open it again */
   wimpt_noerr(wimp_open_wind(&state.o));
}




static int txtedit_getnumeric(dbox d, dbox_field f)
{
    wimp_icon icon;
    wimpt_noerr(wimp_get_icon_info(dbox_syshandle(d), f, &icon));
    if ((icon.flags & wimp_ISELECTED) != 0)
       return 1;
    else
       return 0;
}

/* 2-Feb-90 IDJ: Experiment with catching raw events on the find dbox to
                    solve opening wrong size problem on drag
*/

static BOOL txtedit__findbox_rawevents(dbox d, void *event, void *handle)
{
   wimp_eventstr *e = (wimp_eventstr *)event;

     /* event handling:  EOPEN:  open to appropriate size
                         else:   pass it on to the help handler (yuk!)
     */
   switch(e->e)
   {
      case wimp_EOPEN:
           /* see if magic chars is set (if so make findbox big) */
         { wimp_icon icon;
#ifdef ALLOW_OLD_PATTERNS
           wimp_icon icon_reg;
#endif
           wimp_w find_handle = dbox_syshandle(d);
           wimp_get_icon_info(find_handle, txtedit_FiMagic, &icon);
#ifdef ALLOW_OLD_PATTERNS

           wimp_get_icon_info(find_handle, txtedit_FiRegularExpressions, &icon_reg);
#endif

           /* IDJ 31-Jan-90: Magic is now a click icon */
           /* When magic is on, the extra icons appear - when not, they go away */
           wimpt_noerr(wimp_open_wind(&e->data.o));
           if ((icon.flags & wimp_ISELECTED) != 0
#ifdef ALLOW_OLD_PATTERNS
|| (icon_reg.flags & wimp_ISELECTED) != 0
#endif
)
             txtedit__extend_findbox(find_handle, txtedit_large_findbox);
           else
             txtedit__extend_findbox(find_handle, txtedit_small_findbox);
         }
         return TRUE;

      default:
           /* pass it on to the interactive help handler */
           return help_dboxrawevents(d, event, handle);
   }
}

static BOOL txtedit__use_ambiguous(dbox find)
{
   char replace[256];
   int i = 0;

   dbox_getfield(find, txtedit_FiReplace, replace, 255);

   while (i < 255 && replace[i] != 0)
   {
      if (replace[i] == txtfind_field_ch && isdigit(replace[i+1])) return TRUE;
      i++;
   }

   return FALSE;
}


static void txtedit__swap_icons(wimp_w w, int old_lo, int old_hi, int new_lo, int new_hi)
{
   int i;

   /* --- get rid of old icons --- */
   for (i = old_lo; i <= old_hi; i++) wimpt_noerr(wimp_set_icon_state(w, i, wimp_IDELETED, wimp_IDELETED));

   /* --- re-incarnate new icons --- */
   for (i = new_lo; i <= new_hi; i++) wimpt_noerr(wimp_set_icon_state(w, i, 0, wimp_IDELETED));
}


Kevin Bracey's avatar
Kevin Bracey committed
1331
static void txtedit_find(txtedit_state *s)
Neil Turton's avatar
Neil Turton committed
1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
{

static dbox       find = NULL;
static dbox       found = NULL;
char              finds[256], repls[256], previousFind[256], previousReplace[256];

txt_index         at, wasat, endat;
dbox_field        cmd1, cmd2;
int               loopflag1, loopflag2, majorEdits, undoneEdits;
BOOL              magic, Case, oldMagic, oldCase, previous = FALSE;
#ifdef ALLOW_OLD_PATTERNS
BOOL              oldRegular;
#endif
Pattern           *pattern = NULL;
wimp_w            find_handle;

#ifdef FIELDNUM
Ambiguous_entry ambiguous[MAX_AMBIGUOUS];
SubPattern sub_patterns[128];
int amb;
int sub;
int TD1[256];
#endif



majorEdits = 0;
undoneEdits = 0;

if (find == NULL) {
  find = dbox_new("find");
  if (find == 0) return;
};

find_handle = dbox_syshandle(find);

#if FALSE
dbox_raw_eventhandler(find, help_dboxrawevents, "FIND");
#endif
dbox_raw_eventhandler(find, txtedit__findbox_rawevents, "FIND");

dbox_setfield(find, txtedit_FiMsg, "");

if (found == NULL) {
  found = dbox_new("found");
  if (found == 0) return;
};
dbox_raw_eventhandler(found, help_dboxrawevents, "FOUND");

oldMagic = txtedit_getnumeric(find, txtedit_FiMagic);
oldCase = dbox_getnumeric(find, txtedit_FiCase);
#ifdef ALLOW_OLD_PATTERNS
oldRegular = txtedit_getnumeric(find, txtedit_FiRegularExpressions);
#endif
dbox_getfield(find, txtedit_FiFind, &previousFind[0], 255);
dbox_getfield(find, txtedit_FiReplace, &previousReplace[0], 255);

#if FALSE
dbox_setnumeric(find, txtedit_FiMagic, FALSE);
dbox_setnumeric(find, txtedit_FiCase, FALSE);
#endif
/* >>>> Maybe these should be reset every time. I suspect, however, that
they are things that people will typically leave set for longish periods.
Thus, let's try not setting them. */

dbox_setfield(find, txtedit_FiFind, "");
dbox_setfield(find, txtedit_FiReplace, "");


dbox_show(find);

/* 2-2-90 IDJ extra safety in case dbox is wrong size */
   if (oldMagic
#ifdef ALLOW_OLD_PATTERNS
|| oldRegular
#endif
)
       txtedit__extend_findbox(find_handle, txtedit_large_findbox);
   else
       txtedit__extend_findbox(find_handle, txtedit_small_findbox);


loopflag1 = 1;

while (loopflag1)

{
     if (previous)
     {
         cmd1 = dbox_fillin(find);
         previous = FALSE;
     }
     else
         cmd1 = dbox_fillin_fixedcaret(find);

     switch (cmd1)

     {
     case txtedit_FiPrevious:
         { int latest_magic = txtedit_getnumeric(find, txtedit_FiMagic);
#ifdef ALLOW_OLD_PATTERNS
           int latest_regular = txtedit_getnumeric(find, txtedit_FiRegularExpressions);
#endif

           dbox_setnumeric(find, txtedit_FiMagic, oldMagic);
#ifdef ALLOW_OLD_PATTERNS
           dbox_setnumeric(find, txtedit_FiRegularExpressions, oldRegular);
#endif
           /* IDJ 31-Jan-90 May need to change size of dbox */
           /* check with WRS that previous really does mean this */
           if (latest_magic != oldMagic
#ifdef ALLOW_OLD_PATTERNS
|| latest_regular != oldRegular
#endif
)
           {
#ifdef ALLOW_OLD_PATTERNS
              if (oldMagic)
                  txtedit__swap_icons(find_handle, txtedit_FiAny, txtedit_FiHex, txtedit_FiBackGnd, txtedit_FiFoundString);
              else if (oldRegular)
                  txtedit__swap_icons(find_handle, txtedit_FiBackGnd, txtedit_FiFoundString, txtedit_FiAny, txtedit_FiHex);
#endif
              if (oldMagic
#ifdef ALLOW_OLD_PATTERNS
|| oldRegular
#endif
              ) txtedit__extend_findbox(find_handle, txtedit_large_findbox);
              else txtedit__extend_findbox(find_handle, txtedit_small_findbox);
           }

           dbox_setnumeric(find, txtedit_FiCase, oldCase);
           dbox_setfield(find, txtedit_FiFind, &previousFind[0]);
           dbox_setfield(find, txtedit_FiReplace, &previousReplace[0]);
           previous = TRUE;
           break;
         }

     case txtedit_FiCount:
         dbox_getfield(find, txtedit_FiFind, &finds[0], 255);
         magic = txtedit_getnumeric(find, txtedit_FiMagic)
#ifdef ALLOW_OLD_PATTERNS
|| txtedit_getnumeric(find, txtedit_FiRegularExpressions)
#endif
;
         Case = dbox_getnumeric(find, txtedit_FiCase);

         if (finds[0] == 0) break;
         /* 20-Dec-88 WRS: if null string to search for, ignore the search. */

         dbox_setfield(find, txtedit_FiMsg, msgs_lookup(MSGS_txt31));

         at = txt_dot(s->t);
         {
           int count = 0;
1486
           int x, y;
Neil Turton's avatar
Neil Turton committed
1487 1488 1489 1490 1491 1492 1493
           char msg[40];
           typedef void SignalHandler(int);
           SignalHandler *oldeschandler;

           visdelay_begin();
           oldeschandler = signal(SIGINT, &eschandler);
           escflag = FALSE;
1494 1495
           x = 0; y = 0;
           wimpt_noerr(os_byte(229, &x, &y));
Neil Turton's avatar
Neil Turton committed
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527

           wasat = at;

           /* IDJ Jan-90 -- Change so that pattern is lexed ONCE, and then search done */
           pattern = txtfind_build_pattern(&finds[0], magic, !Case
#ifdef ALLOW_OLD_PATTERNS
, txtedit_getnumeric(find, txtedit_FiMagic)
#endif
#ifdef FIELDNUM
, 0
#endif
);

           /* IDJ Oct-90 -- Also now use enhanced Boyer-Moore on leading substring */
           if (pattern)
               txtfind_build_TD1(TD1, pattern, !Case);

           while (txtfind_find(s->t, &at, pattern, !Case
#ifdef FIELDNUM
, 0 ,0 , FALSE              /* IDJ: 5-Apr-90: don't need ambiguous patterns for counting */
#endif
, TD1
) != -1)
           {
             if (at == wasat) { /* foolish thing to count. */
               break;
             };
             count++;
             /* tracef2("counting, at=%i count=%i.\n", at, count); */
             if (escflag) break;
           };

1528 1529
           x = 1; y = 0;
           wimpt_noerr(os_byte(229, &x, &y));
Neil Turton's avatar
Neil Turton committed
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817
           (void) signal(SIGINT, oldeschandler);
           visdelay_end();

           sprintf(msg, msgs_lookup(MSGS_txt32), count);
           dbox_setfield(find, txtedit_FiMsg, msg);
         };
         break;

     case txtedit_FiGo:
         dbox_getfield(find, txtedit_FiFind, &finds[0], 255);
         dbox_getfield(find, txtedit_FiReplace, &repls[0], 255);
         magic = txtedit_getnumeric(find, txtedit_FiMagic)
#ifdef ALLOW_OLD_PATTERNS
|| txtedit_getnumeric(find, txtedit_FiRegularExpressions)
#endif
;
         Case = dbox_getnumeric(find, txtedit_FiCase);

         if (finds[0] == 0) break;
         /* 20-Dec-88 WRS: if null string to search for, ignore the search. */

         dbox_setfield(find, txtedit_FiMsg, msgs_lookup(MSGS_txt33));

         txtundo_separate_major_edits(s->t);
         majorEdits++;

         wasat = txt_dot(s->t);
         endat = wasat;

         visdelay_begin();

         /* IDJ Jan-90 -- parse pattern just once */
#ifdef FIELDNUM
         for (amb = 0; amb < MAX_AMBIGUOUS; amb++)
              ambiguous[amb].start = ambiguous[amb].end = -1;
         for (sub = 0; sub < 128; sub++)
         {
            sub_patterns[sub].start_node = 0xffffffff;
            sub_patterns[sub].flags = 0;
            sub_patterns[sub].start_pos = -1;
         }
#endif
         pattern = txtfind_build_pattern(&finds[0], magic, !Case
#ifdef ALLOW_OLD_PATTERNS
, txtedit_getnumeric(find, txtedit_FiMagic)
#endif
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?sub_patterns:0
#endif
);

         /* IDJ Oct-90 -- Also now use enhanced Boyer-Moore on leading substring */
         if (pattern)
             txtfind_build_TD1(TD1, pattern, !Case);

         at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, 0 , 0 , FALSE
#endif
, TD1
);
         visdelay_end();

         if (at == -1)
         {
           dbox_setfield(find, txtedit_FiMsg, msgs_lookup(MSGS_txt34));
           txt_setdot(s->t, wasat);
         }
         else
         {
           txt_setdot(s->t, at);
           txtscrap_setselect(s->t, at, endat);
           dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt35));
           dbox_hide(find);
           dbox_show(found);

           loopflag2 = 1;

           while (loopflag2)

           {

             cmd2 = dbox_fillin(found);

             switch (cmd2)

             {

             case txtedit_FoCont:

                 if (undoneEdits)
                 {
                   txtundo_commit(s->t);
                   undoneEdits = 0;
                 }
                 txtundo_separate_major_edits(s->t);
                 majorEdits++;

                 /* we can only rely on dot being right since people may
                    have messed us up with Undo/Redo. So we search
                    again to get our start and end points */

                 dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt33));
                 wasat = txt_dot(s->t);
                 endat = wasat;
                 visdelay_begin();
                 at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, 0 , 0 , FALSE
#endif
, TD1
);
                 visdelay_end();

                 if (at == wasat) {
                   visdelay_begin();
                   at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, 0 , 0 , FALSE
#endif
, TD1
);
                   visdelay_end();
                 };

                 if (at == -1)
                   dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt34));
                 else
                 {
                   txt_setdot(s->t, at);
                   txtscrap_setselect(s->t, at, endat);
                   dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt35));
                 }
                 break;    /* txtedit_FoCont */

             case txtedit_FoRep:

                 if (undoneEdits)
                 {
                   txtundo_commit(s->t);
                   undoneEdits = 0;
                 }
                 txtundo_separate_major_edits(s->t);
                 majorEdits++;

                 /* we can only rely on dot being right since people may
                    have messed us up with Undo/Redo. So we search
                    again to get our start and end points */

                 dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt33));
                 wasat = txt_dot(s->t);
                 endat = wasat;
                 visdelay_begin();

                 at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?ambiguous:0
, (txtedit__use_ambiguous(find))?sub_patterns:0
, FALSE
#endif
, TD1
);

                 if (at == wasat)
                 {
#ifdef FIELDNUM
                   /* try the search again(!) to patch up field#'s */
                   if (txtedit__use_ambiguous(find))
                   {
                      endat = wasat;
                      at = txtfind_find(s->t, &endat, pattern, !Case, (txtedit__use_ambiguous(find))?ambiguous:0, (txtedit__use_ambiguous(find))?sub_patterns:0, TRUE, TD1);
                   }
#endif
                   txtfind_replace(s->t, at, &endat, &repls[0], magic
#ifdef FIELDNUM
, ambiguous
#endif
#ifdef ALLOW_OLD_PATTERNS
, txtedit_getnumeric(find, txtedit_FiMagic)
#endif
);
                   txtscrap_setselect(s->t, at, endat);

                   dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt33));
                   at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?ambiguous:0
, (txtedit__use_ambiguous(find))?sub_patterns:0
, FALSE
#endif
, TD1
);

                   if (at == -1)
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt34));
                   else
                   {
                     txt_setdot(s->t, at);
                     txtscrap_setselect(s->t, at, endat);
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt35));
                   }
                 }
                 else
                 {
                   if (at == -1)
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt34));
                   else
                   {
                     txt_setdot(s->t, at);
                     txtscrap_setselect(s->t, at, endat);
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt36));
                   }
                 };

                 visdelay_end();
                 txtedit_settexttitle(s);
                 break;    /* txtedit_FoRep */

             case txtedit_FoLastRep:

                 if (undoneEdits)
                 {
                   txtundo_commit(s->t);
                   undoneEdits = 0;
                 }
                 txtundo_separate_major_edits(s->t);
                 majorEdits++;

                 /* we can only rely on dot being right since people may
                    have messed us up with Undo/Redo. So we search
                    again to get our start and end points */

                 dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt33));
                 wasat = txt_dot(s->t);
                 endat = wasat;
                 at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?ambiguous:0
, (txtedit__use_ambiguous(find))?sub_patterns:0
, FALSE
#endif
, TD1
);

                 if (at == wasat)
                 {
#ifdef FIELDNUM
                   /* try the search again(!) to patch up field#'s */
                   if (txtedit__use_ambiguous(find))
                   {
                      endat = wasat;
                      at = txtfind_find(s->t, &endat, pattern, !Case, (txtedit__use_ambiguous(find))?ambiguous:0, (txtedit__use_ambiguous(find))?sub_patterns:0, TRUE, TD1);
                   }
#endif
                   txtfind_replace(s->t, at, &endat, &repls[0], magic
#ifdef FIELDNUM
, ambiguous
#endif
#ifdef ALLOW_OLD_PATTERNS
, txtedit_getnumeric(find, txtedit_FiMagic)
#endif
);
                   txtscrap_setselect(s->t, at, endat);
                   loopflag2 = 0;
                   loopflag1 = 0;
                 }
                 else
                 {
                   if (at == -1)
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt34));
                   else
                   {
                     txt_setdot(s->t, at);
                     txtscrap_setselect(s->t, at, endat);
                     dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt37));
                   }
                 }
                 txtedit_settexttitle(s);
                 break;    /* txtedit_FoCont FoRep FoLastRep */

             case txtedit_FoEndRep:

             /* Global replace: very similar to end-of-file-replace, but with
                  display turned off.
                  In practice, found to be more popular: scratch the old one.
             */
             {
                 int count = 0;
1818
                 int x, y;
Neil Turton's avatar
Neil Turton committed
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
                 char a[40];
                 txt_index startat;
                 typedef void SignalHandler(int);
                 SignalHandler *oldeschandler;

                 if (undoneEdits)
                 {
                   txtundo_commit(s->t);
                   undoneEdits = 0;
                 }
                 txtundo_separate_major_edits(s->t);
                 majorEdits++;

                 /* we can only rely on dot being right since people may
                    have messed us up with Undo/Redo. So we search
                    again to get our start and end points */

                 dbox_setfield(found, txtedit_FoMsg, msgs_lookup(MSGS_txt33));

                 visdelay_begin();
                 oldeschandler = signal(SIGINT, &eschandler);
                 escflag = FALSE;
1841 1842
                 x = 0; y = 0;
                 wimpt_noerr(os_byte(229, &x, &y));
Neil Turton's avatar
Neil Turton committed
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901

                 txt_setcharoptions(s->t, txt_DISPLAY, 0);

                 endat = txt_dot(s->t);
                 startat = endat;
#ifdef FIELDNUM
                 wasat = endat;
#endif
                 at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?ambiguous:0
, (txtedit__use_ambiguous(find))?sub_patterns:0
, FALSE
#endif
, TD1
);

                 /* IDJ: 1-Jul-91: added check that we're not stuck in one place at == wasat */
                 while (at != -1 && at != endat)
                 {

#ifdef FIELDNUM
                   /* try the search again(!) to patch up field#'s */
                   if (txtedit__use_ambiguous(find))
                   {
                      /*endat = wasat;*/
                      txt_setdot(s->t, at);
                      endat = at;
                      at = txtfind_find(s->t, &endat, pattern, !Case, ambiguous, sub_patterns, TRUE, TD1);
                   }
#endif
                   txt_setdot(s->t, at);
                   txtfind_replace(s->t, at, &endat, &repls[0], magic
#ifdef FIELDNUM
, ambiguous
#endif
#ifdef ALLOW_OLD_PATTERNS
, txtedit_getnumeric(find, txtedit_FiMagic)
#endif
);
                   count++;

#ifdef FIELDNUM
                   wasat = endat;
#endif
                   at = txtfind_find(s->t, &endat, pattern, !Case
#ifdef FIELDNUM
, (txtedit__use_ambiguous(find))?ambiguous:0
, (txtedit__use_ambiguous(find))?sub_patterns:0
, FALSE
#endif
, TD1
);
                   if (escflag) break;
                 }

                 txt_setdot(s->t, startat);
                 txt_setcharoptions(s->t, txt_DISPLAY, txt_DISPLAY);

1902 1903
                 x = 1; y = 0;
                 wimpt_noerr(os_byte(229, &x, &y));
Neil Turton's avatar
Neil Turton committed
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140