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 100 101 102 103 104 105 106 107 108 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 140 141 142 143 144 145 146 147 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 330 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 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 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 425 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 744 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 772 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 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 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 951 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 986 987 988
|
#include "vseeci.h"
#include <v/vcmdwin.h>
// ==================>>> vSeeCI::vSeeCI <<<=================
vSeeCI::vSeeCI(vTextEditor* textEd, vCmdWindow* cw)
: vTextEdCmdInterp(textEd, cw)
{
lex_def = 1;
CmdCount = 1;
param_count = 1;
cmdmode = Cmd;
countWait = 0; // start in cmdmode
slastl = savlen = nxtsav = 0; // Save Buff stuff
_SaveBuff = new char*[SBAllocLines]; // build save in 500 line incrs.
for (long lx = 0 ; lx < SBAllocLines ; ++lx)
_SaveBuff[lx] = 0;
_maxSBLines = SBAllocLines - 1;
}
// ==================>>> vSeeCI::~vSeeCI <<<================
vSeeCI::~vSeeCI()
{
if (_SaveBuff)
{
for (long lx = 0 ; lx < _maxSBLines ;++lx) // delete contents
{
if (_SaveBuff[lx])
delete [] _SaveBuff[lx];
}
delete [] _SaveBuff; // free SaveBuff // delete line array
}
}
// =====================>>> vTextEdCmdInterp::InitCmdInterp <<<====================
void vSeeCI::InitCmdInterp()
{
te()->ChangeInsMode(te()->GetEdState().ins_mode,"Command ");
}
// =====================>>> vSeeCI::ProcessKey <<<====================
int vSeeCI::ProcessKey(vKey key, unsigned int shift)
{
if (vk_IsModifier(key)) // ignore modifiers
return -1;
// return vTextEdCmdInterp::ProcessKey(key,shift);
return edit(key,shift);
}
// =============================>>> vSeeCI::edit <<<==========================
int vSeeCI::edit(vKey chr, unsigned int shift)
{
// Hard wired See command interp.
int s_succ, retval;
static int ins_set[] = /* allowable commands for insert */
{
'i', 'o', 'X'-'@', 'T'-'@', 'g', 'Y'-'@', 'y', 0
};
static int jump_set[] = /* commands to not reset jump memory */
{
'j', 'm', '?', 'n', 0
};
vKey lexval = chr; // @@ For now, simple translation
if (cmdmode == Ins) // in insert mode
{
// This code allows the keypad keys to still move
// the cursor around while still staying in insert mode...
retval = 1;
switch (lexval)
{
case vk_BackSpace: /* delete last character */
retval = te()->charDelete(-CmdCount);
break;
case vk_Delete:
case vk_KP_Delete:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
te()->lineDelete(CmdCount);
else
retval = te()->charDelete(CmdCount);
break;
}
#ifdef CMDS_IN_INSERT
case vk_Home:
case vk_KP_Home:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
retval = te()->lineGoto(1);
else
te()->lineBeginning();
break;
}
case vk_End:
case vk_KP_End:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
te()->bufferBottom();
else
te()->lineEnd();
break;
}
case vk_Page_Up:
case vk_KP_Page_Up:
{
if (shift & VKM_Ctrl)
te()->scrollDown(-CmdCount * te()->GetRows());
else
retval = te()->lineDown((long)(-CmdCount * te()->GetRows()));
break;
}
case vk_Up:
case vk_KP_Up:
{
if (shift & VKM_Shift)
retval = te()->lineDownBeg(-CmdCount);
else
retval = te()->lineDown(-CmdCount);
break;
}
case vk_Page_Down:
case vk_KP_Page_Down:
{
if (shift & VKM_Ctrl)
te()->scrollDown(CmdCount * te()->GetRows());
else
retval = te()->lineDown(
(long) te()->minl((CmdCount * te()->GetRows()),
(long)(te()->GetLines() - te()->GetCurLine() + 1)));
break;
}
case vk_KP_Down:
case vk_Down:
{
if (shift & VKM_Shift)
retval = te()->lineDownBeg(CmdCount);
else
retval = te()->lineDown(CmdCount);
break;
}
case vk_Left:
case vk_KP_Left:
{
if (shift & VKM_Ctrl || shift & VKM_Shift)
retval = te()->wordRight(-CmdCount);
else
retval = te()->charRight(-CmdCount,1);
break;
}
case vk_Right:
case vk_KP_Right:
{
if (shift & VKM_Ctrl ||shift & VKM_Shift)
retval = te()->wordRight(CmdCount);
else
retval = te()->charRight(CmdCount,1);
break;
}
#endif
case vk_KP_Insert:
case vk_Insert:
{
te()->SetInsMode(!(te()->GetEdState().ins_mode));
break;
}
case vk_Escape:
{
cmdmode = Cmd;
te()->ChangeInsMode(te()->GetEdState().ins_mode,"Command ");
return 1; // done!
}
default:
retval = te()->defaultKeyIn(lexval, shift);
break;
}
return retval;
}
else if (cmdmode == Find) // in Find pattern mode
{
char tmp[2] = "x";
if (chr == vk_Escape)
{
cmdmode = Cmd;
te()->ChangeInsMode(te()->GetEdState().ins_mode,"Command ");
te()->SetFindPat(newFindPat);
return 1;
}
else if (chr == vk_BackSpace)
{
int pl = strlen(newFindPat);
if (pl > 0)
newFindPat[pl-1] = 0; // wipe last char
te()->StatusMessage(newFindPat);
return 1;
}
tmp[0] = lexval; // add to pattern
if (strlen(newFindPat) < MAX_LINE)
{
strcat(newFindPat, tmp);
}
te()->StatusMessage(newFindPat);
return 1;
}
te()->ChangeInsMode(te()->GetEdState().ins_mode,"Command ");
if (lexval >= '0' && lexval <= '9' || lexval == '-')
{
if (countWait == 0)
{
countWait = 1;
if (lexval == '-')
{
CmdCount = 1; // - implies 1
countWait = -1;
}
else
CmdCount = lexval - '0';
return 1;
}
else if (lexval == '-')
{
countWait = -1;
return 1;
}
else if (lexval >= '0' && lexval <= '9') // it is a count
{
if (countWait < 0 && CmdCount == 1)
CmdCount = 0; // user entering value
CmdCount = (CmdCount * 10) + (lexval - '0');
return 1;
}
}
if (countWait != 0)
{
CmdCount *= countWait; // negative?
countWait = 0; // done building count
}
s_succ = 1;
if (te()->GetCurLine() < 1) // make sure legal command for empty buffer
{
if (!inset(lexval,ins_set))
{
te()->StatusMessage("Can't, buffer empty. Insert 1st ");
return 1;
}
}
// if (did_insert) /* was last command an insert? */
// {
// auto_tidy(); /* auto format text */
// did_insert = 0;
// }
if (!inset(lexval,jump_set))
te()->SetJLine(te()->GetCurLine()); // sets previous line for Jump
switch (lexval)
{
case 'C'-'@': // ^C : Copy ; Shift-^C: fold case
{
te()->EditCopy();
break;
}
case 'D'-'@': /* down in column */
case vk_KP_Down:
case vk_Down:
{
if (shift & VKM_Shift)
retval = te()->lineDownBeg(CmdCount);
else
retval = te()->lineDown(CmdCount);
break;
}
case 'E'-'@': /* edit repeat buffer */
// if (lex_def) /* default 1 passed */
// CmdCount = rptuse + 1; /* use current repeat loop */
// retval = edit_rpt(CmdCount); /* edit repeat buffer */
break;
case 'F'-'@': // ^F: find next, Shift-^F: find/replace
{
if (shift & VKM_Shift) // Shift-^F
{
retval = te()->EditCommand(edFindNext, CmdCount);
//ED(target) = T_FIND_RPL;
// (void) build_find(0,1,(int)CmdCount); /* set up find build first */
}
else
{
retval = te()->EditCommand(edFindNext, CmdCount);
}
break;
}
case 'G'-'@': /* unkill last line killed */
//@@ retval = unkill();
break;
case vk_BackSpace: /* delete last character */
retval = te()->charDelete(-CmdCount);
break;
case vk_Tab:
{
retval = te()->wordRight(CmdCount);
}
case 'J'-'@': /* set range by character */
//@@ retval = add_to_range(CmdCount,0);
break;
case 'K'-'@': // ^K: Kill line
{
te()->lineDelete(CmdCount);
break;
}
case 'L'-'@': /* goto line */
{
retval = te()->lineGoto(CmdCount);
break;
}
case 'M'-'@': /* (RETURN) set range */
// retval = add_to_range(CmdCount,1);
break;
case 'N'-'@': /* return to noted location */
{
retval = te()->EditCommand(edNoteGoto,CmdCount);
break;
}
case 'P'-'@': /* page up */
{
retval = te()->lineDown((long)(-CmdCount * te()->GetRows()));
break;
}
case vk_Page_Up:
case vk_KP_Page_Up:
{
if (shift & VKM_Ctrl)
te()->scrollDown(-CmdCount * te()->GetRows());
else
retval = te()->lineDown((long)(-CmdCount * te()->GetRows()));
break;
}
case 'Q'-'@': // ^Q - save/close this file
{
cmdWin()->WindowCommand(M_SaveClose,1,(CmdType)0);
break;
}
case 'T'-'@': /* abort */
//@@ abort_session();
break;
case 'U'-'@': /* up in column */
case vk_Up:
case vk_KP_Up:
{
if (shift & VKM_Shift)
retval = te()->lineDownBeg(-CmdCount);
else
retval = te()->lineDown(-CmdCount);
break;
}
case 'V'-'@': // ^V: Paste
{
te()->EditPaste();
break;
}
case 'X'-'@': // ^X : Cut
{
te()->EditCut();
break;
}
case 'Y'-'@': /* append external file to save buffer */
//@@ retval = addfil(CmdCount);
break;
case '"': /* kill rest of line */
{
retval = te()->lineDeleteToEnd();
break;
}
case '#': /* ex. rpt k n times */
//@ ED(target) = T_EXEC_RPT; /* execute the repeat loop */
//@@ param_count = CmdCount; /* remember the count */
break;
case '&': /* execute repeat buffer again */
//&& if (CmdCount != 1)
//&& ED(echof)=FALSE; /* turn off echo */
//&& rptcnt[rptuse] = CmdCount > 0 ? CmdCount : (-CmdCount);
break;
case '\'': /* kill previous part of line */
{
retval = te()->lineDeleteFront();
break;
}
case '*': /* insert the find pattern */
//@@ succ = ins_pat();
break;
case '+': /* insert counter value */
//@@ ins_counter();
break;
case ',': /* move to beginning of line */
{
te()->lineBeginning();
break;
}
case '.': /* move to end of the line */
{
te()->lineEnd();
break;
}
case '/': /* delete last thing manipulated */
retval = RemoveLast();
break;
case ';': /* find again */
{
// @@ add code to handle Finds from repeat buffer
retval = te()->EditCommand(edFindNext, CmdCount);
break;
}
case '<': /* define/execute repeat loop */
//@@ ED(target) = T_RPT;
//@@ (void) rpt_build(0,1,CmdCount);
break;
case '=': /* remove last and enter insert mode */
{
if ((retval = RemoveLast()))
{
cmdmode = Ins;
te()->ChangeInsMode(te()->GetEdState().ins_mode);
}
break;
}
case '@': /* execute key macro */
//@@ param_count = CmdCount; /* remember the count */
//@@ ED(target) = T_EXEC_KM;
break;
case '[': /* backwards jump over word */
{
retval = te()->wordRight(-CmdCount);
break;
}
case '\\': /* replace */
//@@ succ = replace();
break;
case ']': /* balance match */
{
retval = te()->BalMatch(CmdCount);
break;
}
case '^': /* reverse find */
//@@ ED(target) = T_FIND;
//@@ (void) build_find(0,1,(int)(-CmdCount)); /* set up find build first */
break;
case '_': /* kill word */
//@@ if (!(succ = wordr(CmdCount)))
//@@ break;
//@@ retval = rmvlst();
break;
case 'a': /* append to save buffer */
retval = save(CmdCount,1);
break;
case 'b': /* goto top of page */
{
retval = te()->lineGoto(1);
break;
}
case vk_Home:
case vk_KP_Home:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
retval = te()->lineGoto(1);
else
te()->lineBeginning();
break;
}
case 'c': /* change characters */
if ((retval = te()->charDelete(CmdCount)) )
{
cmdmode = Ins;
te()->ChangeInsMode(te()->GetEdState().ins_mode);
}
break;
case 'D':
case 'd': /* down line */
retval = te()->lineDownBeg(CmdCount);
break;
case 'e': /* goto to bottom of page */
te()->bufferBottom();
break;
case vk_End:
case vk_KP_End:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
te()->bufferBottom();
else
te()->lineEnd();
break;
}
case 'F': // F: set find pattern only - unechoed
{
cmdmode = Find;
te()->ChangeInsMode(te()->GetEdState().ins_mode,"Find Pat");
newFindPat[0] = 0; // no pattern yet
break;
}
case 'f': // f: find via dialog
{
// @@ add code to handle Finds from repeat buffer
te()->SetFindPat(""); // new pattern each time!
retval = te()->EditCommand(edFind, CmdCount);
break;
}
case 'g': /* get move buffer */
retval = getsav();
break;
case 'I':
if (CmdCount >= 1)
retval = te()->charInsert(CmdCount);
break;
case 'i': /* insert */
cmdmode = Ins;
te()->ChangeInsMode(te()->GetEdState().ins_mode);
break;
case 'j': /* jump back to last location */
{
long itmp = te()->GetCurLine();
retval = te()->lineGoto(te()->JLine());
te()->SetJLine(itmp);
break;
}
case 'k': /* delete next character */
retval = te()->charDelete(CmdCount);
break;
case vk_Delete:
case vk_KP_Delete:
{
if (shift & VKM_Shift || shift & VKM_Ctrl)
te()->lineDelete(CmdCount);
else
retval = te()->charDelete(CmdCount);
break;
}
case 'l': /* left */
retval = te()->charRight(-CmdCount,1);
break;
case vk_Left:
case vk_KP_Left:
{
if (shift & VKM_Ctrl || shift & VKM_Shift)
retval = te()->wordRight(-CmdCount);
else
retval = te()->charRight(-CmdCount,1);
break;
}
case 'n': /* save current location */
retval = te()->EditCommand(edNoteLocation, CmdCount);
break;
case 'o': /* open new line */
retval = te()->lineOpen(CmdCount);
cmdmode = Ins;
te()->ChangeInsMode(te()->GetEdState().ins_mode);
break;
case 'O': /* overtype */
case vk_KP_Insert:
case vk_Insert:
{
te()->SetInsMode(!(te()->GetEdState().ins_mode));
break;
}
case 'p': /* page down screen */
retval = te()->lineDown(
(long) te()->minl((CmdCount * te()->GetRows()),
(long)(te()->GetLines() - te()->GetCurLine() + 1)));
break;
case vk_Page_Down:
case vk_KP_Page_Down:
{
if (shift & VKM_Ctrl)
te()->scrollDown(CmdCount * te()->GetRows());
else
retval = te()->lineDown(
(long) te()->minl((CmdCount * te()->GetRows()),
(long)(te()->GetLines() - te()->GetCurLine() + 1)));
break;
}
case 'r': /* right */
retval = te()->charRight(CmdCount,1);
break;
case vk_Right:
case vk_KP_Right:
{
if (shift & VKM_Ctrl ||shift & VKM_Shift)
retval = te()->wordRight(CmdCount);
else
retval = te()->charRight(CmdCount,1);
break;
}
case 's': /* save lines in move buffer */
retval = save(CmdCount,0);
break;
case 't': /* tidy up screen */
//@@ succ = neaten(CmdCount);
break;
case 'U':
case 'u': /* up line */
retval = te()->lineDownBeg(-CmdCount);
break;
case 'v': /* verify */
te()->Verify();
break;
case 'y': /* write save buffer to file */
//@@ succ = addfil(-CmdCount);
break;
case '~': /* '~': change case */
retval = te()->charFoldCase(CmdCount);
break;
//@@ case Cxa: /* abandon file */
//@@ clear_mark_range(); /* no range now */
//@@ abandon_changes();
//@@ break;
//@@ case Cxf: /* copy selection to find */
//@@ succ = copy_selection(1);
//@@ break;
//@@ case Cxk: /* define/execute key macro */
//@@ ED(target) = T_BUILD_KM;
//@@ (void) km_build(0);
//@@ break;
//@@ case Cxr: /* copy selection to replace */
//@@ succ = copy_selection(0);
//@@ break;
#ifdef XXXYYYX
case Cxcf: /* replace again */
if (s_succ = succ = do_find(1,1,1)) /* find first */
{
succ = replace(); /* do the replacement */
}
break;
#endif
default:
retval = 0;
break;
} /* end of switch */
if (! retval) // handle repeat loops
return 0;
else
oldlex = lexval;
CmdCount = 1;
return 1;
}
/* =============================>>> vSeeCI::inset <<<============================= */
int vSeeCI::inset(int val, int *set)
{
/* return true if val is in set set */
while (*set)
if (val == *set++)
return 1;
return 0;
}
/* =============================>>> vSeeCI::rmvlst <<<============================= */
int vSeeCI::RemoveLast(void)
{ /* RemoveLast - delete the previous thing found or manipulated
length of oldlen is set by insert, find, and save
may also use savlen if set by save */
static int rmv_set[] =
{
'f', 'F' - '@', '^', 's', 'g', ';', 'a', 'I'-'@', '[', '_', 0
};
if (te()->RemoveMarkRange()) /* was a mark range to remove */
return 1; /* all done */
if (!inset(oldlex,rmv_set))
return 0;
te()->ClearMarkRange(); /* no range now */
if (savlen > 0)
{
int oldech = te()->GetEdState().echof;
if (savlen > 1)
te()->SetEchoF(0);
if (te()->GetCurLine() == te()->GetLines()-1 && slastl != 0)
{
--savlen; /* reduce the count */
if (savlen > 0)
{
te()->lineDelete(-savlen); /* kill off previous lines */
}
te()->lineDelete((long) 1); /* kill the last line */
if (oldech)
te()->SetEchoF(oldech);
te()->Verify();
}
else
{
te()->lineDelete(-savlen); /* kill off savlen lines */
if (oldech)
te()->SetEchoF(oldech);
if (savlen > 1)
te()->Verify();
}
}
else if (te()->OldLen() != 0)
{
if (! te()->charDelete((long)-te()->OldLen()) )
return 0;
}
te()->SetOldLen(0); /* don't allow multiple deletes! */
savlen = (-1);
return 1;
}
// =============================>>> vSeeCI::save <<<=========================
int vSeeCI::save(long cnt, int app)
{ /* save - save cnt lines in save buffer */
long l, lend;
int old_ef = te()->GetEdState().echof; // remember state of echo flag
if (cnt < 0)
return 0;
if (te()->GetCurLine() == te()->GetLines()-1 && slastl != 0)
{
te()->ErrorMsg("Can't save last line twice! ");
return 0;
}
te()->SetOldLen(0); /* use savlin instead */
if ((oldlex != 's' && !app) || cnt == 0)
{ /* if new save, cnt == 0 and not appending */
// Clear old save buffer - delete storage for lines
for (long lx = 0 ; lx < nxtsav ; ++lx) // copy old lines
if (_SaveBuff[lx])
delete [] _SaveBuff[lx]; // free space
slastl = savlen = nxtsav = 0; /* reset these guys */
if (cnt == 0)
{
return 1;
}
}
if (oldlex != 'a' && app) /* need to reset savlen for append */
savlen = 0;
if (cnt > 10)
te()->SetEchoF(0);
lend = (te()->GetCurLine()+cnt-1 < te()->GetLines()-1)
? te()->GetCurLine()+cnt-1
: te()->GetLines()-1 ;
for (l = te()->GetCurLine() ; l <= lend ; ++l)
{
if (nxtsav >= _maxSBLines) // check for max lines
{
if (!reallocSaveBuff())
{
if (cnt > 10)
{
te()->SetEchoF(old_ef);
te()->Verify();
}
te()->ErrorMsg("Not enough memory for save ");
return 0;
}
}
char line[MAX_LINE + 2];
te()->getLine(line, MAX_LINE, l); // fetch the line
char* cp = new char[strlen(line) + 1];
strcpy(cp, line);
_SaveBuff[nxtsav++] = cp; // copy the line to buffer
++savlen; /* savlen for rmvlst */
if (te()->GetCurLine() == te()->GetLines()-1) /* don't save last line twice! */
{
slastl = 1;
break;
}
(void) te()->lineDownBeg(1);
}
if (cnt > 10)
{
te()->SetEchoF(old_ef);
te()->Verify();
}
return 1;
}
//========================>>> vSeeCI::reallocSaveBuff <<<======================
int vSeeCI::reallocSaveBuff()
{
BUFFPTR* oldLines = _SaveBuff;
_SaveBuff = new char*[_maxSBLines + SBAllocLines];
if (!_SaveBuff)
{
_SaveBuff = oldLines; // failed to get more lines
return 0;
}
long lx;
for (lx = 0 ; lx <= _maxSBLines ; ++lx) // copy old lines
_SaveBuff[lx] = oldLines[lx];
_maxSBLines = _maxSBLines + SBAllocLines - 1; // safety factor
for (; lx <= _maxSBLines ; ++lx) // null new lines
_SaveBuff[lx] = 0;
delete [] oldLines; // free the old lines
return 1;
}
//=============================>>> vSeeCI::getsav <<<==========================
int vSeeCI::getsav()
{ /* ## getsav - get text from save buffer */
long lx;
int ix;
if (nxtsav <= 0) /* nothing to get */
{
return 1;
}
int old_ef = te()->GetEdState().echof;
te()->SetEchoF(0);
te()->ClearMarkRange(); /* no range now */
// If someday I want the insert to be allowed in the middle
// of a line, then the easiest way is to insert the first line
// of the save buffer char by char, then bulk insert the rest
// after the next line. For now, just insert in front of current
// line.
te()->lineBeginning(); // force to beginning
long curLine = te()->GetCurLine(); // find current line
for (lx = nxtsav - 1 ; lx >= 0 ; --lx)
te()->insertLine(_SaveBuff[lx], curLine); // insert the lines backwards
te()->lineDownBeg(nxtsav); // go back down to where we were
te()->IncChanges(); /* note changes */
te()->SetOldLen(0); // fix up this stuff
te()->SetEchoF(1);
te()->Verify();
return 1;
}
#ifdef XXYYXX
//=============================>>> vSeeCI::ins_pat <<<=============================
#ifdef ANSI_C
int ins_pat(void)
#else
int ins_pat()
#endif
{
char *chrp;
if (!*pat_buff)
return 0;
for (chrp = pat_buff ; *chrp ; ) /* simply insert pattern buffer */
{
if (!ins_chr((int)*chrp++)) /* make sure it works */
return 0;
}
return 1;
}
#endif
|