Annotation of freem/src/service.c, revision 1.1
1.1 ! snw 1: /*
! 2: * *
! 3: * * *
! 4: * * *
! 5: * ***************
! 6: * * * * *
! 7: * * MUMPS *
! 8: * * * * *
! 9: * ***************
! 10: * * *
! 11: * * *
! 12: * *
! 13: *
! 14: * service.c
! 15: * terminal and sequential I/O handling,
! 16: * file and global locking
! 17: *
! 18: *
! 19: * Author: Serena Willis <jpw@coherent-logic.com>
! 20: * Copyright (C) 1998 MUG Deutschland
! 21: * Copyright (C) 2020 Coherent Logic Development LLC
! 22: *
! 23: *
! 24: * This file is part of FreeM.
! 25: *
! 26: * FreeM is free software: you can redistribute it and/or modify
! 27: * it under the terms of the GNU Affero Public License as published by
! 28: * the Free Software Foundation, either version 3 of the License, or
! 29: * (at your option) any later version.
! 30: *
! 31: * FreeM is distributed in the hope that it will be useful,
! 32: * but WITHOUT ANY WARRANTY; without even the implied warranty of
! 33: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 34: * GNU Affero Public License for more details.
! 35: *
! 36: * You should have received a copy of the GNU Affero Public License
! 37: * along with FreeM. If not, see <https://www.gnu.org/licenses/>.
! 38: *
! 39: **/
! 40:
! 41: #include <errno.h>
! 42: #include <sys/types.h>
! 43:
! 44: #if !defined(__OpenBSD__) && !defined(__FreeBSD__)
! 45: # include <sys/timeb.h>
! 46: #endif
! 47:
! 48: #include <sys/ioctl.h>
! 49: #include <unistd.h>
! 50: #include <stdlib.h>
! 51:
! 52: #ifdef AMIGA68K
! 53: #include <sys/fcntl.h>
! 54: #endif
! 55:
! 56: #define MAXZAS NESTLEVLS
! 57: #include "mpsdef.h"
! 58:
! 59: #include <time.h>
! 60:
! 61: #ifdef USE_SYS_TIME_H
! 62: #include <sys/time.h>
! 63: #endif
! 64:
! 65: #include "events.h"
! 66:
! 67: long int tell ();
! 68: unsigned alarm ();
! 69: void ris ();
! 70:
! 71:
! 72: #ifdef SCO
! 73: int scosgr (short att, short bwflag);
! 74: #endif
! 75:
! 76: /* system services */
! 77: #include <termios.h>
! 78: #include <fcntl.h>
! 79:
! 80: /* search 'string' for occurence of 'pattrn'
! 81: * return: 0='not found' nbr='pattern begins at nbr' */
! 82: long int find (char *string, char *pattrn)
! 83: {
! 84: short i;
! 85: short j;
! 86: register int k;
! 87: register int l;
! 88:
! 89: i = 0;
! 90:
! 91: while (pattrn[i] != EOL) i++; /* $l of 2nd arg */
! 92:
! 93: if (i == 1) {
! 94:
! 95: l = pattrn[0];
! 96: k = 0;
! 97:
! 98: while (string[k] != EOL) {
! 99:
! 100: if (string[k++] == l) return k;
! 101:
! 102: }
! 103:
! 104: return 0L;
! 105:
! 106: }
! 107:
! 108: j = stlen (string);
! 109:
! 110: for (k = 0; k < j; k++) {
! 111:
! 112: l = 0;
! 113:
! 114:
! 115: l10:
! 116:
! 117: if (string[k + l] != pattrn[l]) continue;
! 118: if (++l < i) goto l10;
! 119:
! 120: return ++k;
! 121:
! 122: }
! 123:
! 124: return 0L;
! 125: } /* end of find() */
! 126:
! 127: /* called by exclusive KILL to search 'exceptions' for occurence of 'variable'
! 128: * return: 1='not found, can be killed' 0='cannot be killed' */
! 129: short int kill_ok (char *exceptions, char *variable)
! 130: {
! 131: short i;
! 132: short j;
! 133: register int k;
! 134: register int l;
! 135:
! 136: j = stlen (exceptions);
! 137: i = stlen (variable);
! 138:
! 139: for (k = 0; k < j; k++) {
! 140:
! 141: for (l = 0; l < i; l++) {
! 142:
! 143: if (exceptions[k + l] != variable[l]) {
! 144:
! 145: if (exceptions[k + l] == SP && variable[l] == DELIM) return FALSE;
! 146:
! 147: goto outerspace;
! 148:
! 149: }
! 150:
! 151: }
! 152:
! 153: return FALSE;
! 154:
! 155:
! 156: outerspace:; /* the semicolon apparently needs to be here in this case. */
! 157: /* break time. */
! 158:
! 159: }
! 160:
! 161: return TRUE;
! 162: } /* end of kill_ok */
! 163:
! 164: /* write this format */
! 165: void write_f (char *intext)
! 166: {
! 167: char outtext[256]; /* output string */
! 168: short l;
! 169: int i;
! 170: char final;
! 171: int csi;
! 172:
! 173: csi = FALSE;
! 174: l = stlen (intext);
! 175:
! 176: if (l < 2) return; /* not recognized */
! 177:
! 178: for (i = 0; i < l; i++) {
! 179:
! 180: if (intext[i] == DELIM) break;
! 181:
! 182: }
! 183:
! 184:
! 185: intext[i] = EOL;
! 186:
! 187: /* CUB - Cursor Backward */
! 188: if (!stcmp (intext, "CUB\201")) {
! 189:
! 190: csi = TRUE;
! 191: final = 'D';
! 192:
! 193: goto end;
! 194:
! 195: }
! 196:
! 197: /* CUD - Cursor Down */
! 198: if (!stcmp (intext, "CUD\201")) {
! 199:
! 200: csi = TRUE;
! 201: final = 'B';
! 202:
! 203: goto end;
! 204:
! 205: }
! 206:
! 207: /* CUF - Cursor Forward */
! 208: if (!stcmp (intext, "CUF\201")) {
! 209:
! 210: csi = TRUE;
! 211: final = 'C';
! 212:
! 213: goto end;
! 214:
! 215: }
! 216:
! 217: /* CUP - Cursor Position */
! 218: /* HVP - Horizontal and vertical Position */
! 219: if (!stcmp (intext, "CUP\201") || !stcmp (intext, "HVP\201")) {
! 220:
! 221: csi = TRUE;
! 222: final = 'H';
! 223:
! 224: goto end;
! 225:
! 226: }
! 227:
! 228: /* CUU - Cursor Up */
! 229: if (!stcmp (intext, "CUU\201")) {
! 230:
! 231: csi = TRUE;
! 232: final = 'A';
! 233:
! 234: goto end;
! 235:
! 236: }
! 237:
! 238: /* DCH - Delete Character */
! 239: if (!stcmp (intext, "DCH\201")) {
! 240:
! 241: csi = TRUE;
! 242: final = 'P';
! 243:
! 244: goto end;
! 245:
! 246: }
! 247:
! 248: /* ICH - Insert Character */
! 249: if (!stcmp (intext, "ICH\201")) {
! 250:
! 251: csi = TRUE;
! 252: final = '@';
! 253:
! 254: goto end;
! 255:
! 256: }
! 257:
! 258: /* DL - Delete Line */
! 259: if (!stcmp (intext, "DL\201")) {
! 260:
! 261: csi = TRUE;
! 262: final = 'M';
! 263:
! 264: goto end;
! 265:
! 266: }
! 267:
! 268: /* IL - Insert Line */
! 269: if (!stcmp (intext, "IL\201")) {
! 270:
! 271: csi = TRUE;
! 272: final = 'L';
! 273:
! 274: goto end;
! 275:
! 276: }
! 277:
! 278: /* SU - Scroll Up = pan down */
! 279: if (!stcmp (intext, "SU\201")) {
! 280:
! 281: csi = TRUE;
! 282: final = 'S';
! 283:
! 284: goto end;
! 285:
! 286: }
! 287:
! 288: /* SD - Scroll Down = pan up */
! 289: if (!stcmp (intext, "SD\201")) {
! 290:
! 291: csi = TRUE;
! 292: final = 'T';
! 293:
! 294: goto end;
! 295:
! 296: }
! 297:
! 298: /* DA - Device Attributes */
! 299: if (!stcmp (intext, "DA\201")) {
! 300:
! 301: csi = TRUE;
! 302: final = 'c';
! 303:
! 304: goto end;
! 305:
! 306: }
! 307:
! 308: /* DSR - Device Status Report */
! 309: if (!stcmp (intext, "DSR\201")) {
! 310:
! 311: csi = TRUE;
! 312: final = 'n';
! 313:
! 314: goto end;
! 315:
! 316: }
! 317:
! 318: /* ED - Erase Display */
! 319: if (!stcmp (intext, "ED\201")) {
! 320:
! 321: csi = TRUE;
! 322: final = 'J';
! 323:
! 324: goto end;
! 325:
! 326: }
! 327:
! 328: /* EL - Erase Line */
! 329: if (!stcmp (intext, "EL\201")) {
! 330:
! 331: csi = TRUE;
! 332: final = 'K';
! 333:
! 334: goto end;
! 335:
! 336: }
! 337:
! 338: /* ECH - Erase Character */
! 339: if (!stcmp (intext, "ECH\201")) {
! 340:
! 341: csi = TRUE;
! 342: final = 'X';
! 343:
! 344: goto end;
! 345:
! 346: }
! 347:
! 348: /* HTS - Horizontal Tabulation Set */
! 349: if (!stcmp (intext, "HTS\201")) {
! 350:
! 351: final = 'H';
! 352:
! 353: goto end;
! 354:
! 355: }
! 356:
! 357: /* IND - Index */
! 358: if (!stcmp (intext, "IND\201")) {
! 359:
! 360: final = 'D';
! 361:
! 362: goto end;
! 363:
! 364: }
! 365:
! 366: /* NEL - NExt Line */
! 367: if (!stcmp (intext, "NEL\201")) {
! 368:
! 369: final = 'E';
! 370:
! 371: goto end;
! 372:
! 373: }
! 374:
! 375: if (!stcmp (intext, "SSA\201")) {
! 376:
! 377: final = 'F';
! 378:
! 379: goto end;
! 380:
! 381: }
! 382:
! 383: if (!stcmp (intext, "ESA\201")) {
! 384:
! 385: final = 'G';
! 386:
! 387: goto end;
! 388:
! 389: }
! 390:
! 391: if (!stcmp (intext, "HTJ\201")) {
! 392:
! 393: final = 'I';
! 394:
! 395: goto end;
! 396:
! 397: }
! 398:
! 399: if (!stcmp (intext, "VTS\201")) {
! 400:
! 401: final = 'J';
! 402:
! 403: goto end;
! 404:
! 405: }
! 406:
! 407: if (!stcmp (intext, "PLD\201")) {
! 408:
! 409: final = 'K';
! 410:
! 411: goto end;
! 412:
! 413: }
! 414:
! 415: if (!stcmp (intext, "PLU\201")) {
! 416:
! 417: final = 'L';
! 418:
! 419: goto end;
! 420:
! 421: }
! 422:
! 423: /* RI - Reverse Index */
! 424: if (!stcmp (intext, "RI\201")) {
! 425:
! 426: final = 'M';
! 427:
! 428: goto end;
! 429:
! 430: }
! 431:
! 432: /* SS2 - Single Shift G2 */
! 433: if (!stcmp (intext, "SS2\201")) {
! 434:
! 435: final = 'N';
! 436:
! 437: goto end;
! 438:
! 439: }
! 440:
! 441: /* SS3 - Single Shift G3 */
! 442: if (!stcmp (intext, "SS3\201")) {
! 443:
! 444: final = 'O';
! 445:
! 446: goto end;
! 447:
! 448: }
! 449:
! 450: /* DCS - Device Control String introducer */
! 451: if (!stcmp (intext, "DCS\201")) {
! 452:
! 453: final = 'P';
! 454:
! 455: goto end;
! 456:
! 457: }
! 458:
! 459: if (!stcmp (intext, "PU1\201")) {
! 460:
! 461: final = 'Q';
! 462:
! 463: goto end;
! 464:
! 465: }
! 466:
! 467: if (!stcmp (intext, "PU2\201")) {
! 468:
! 469: final = 'R';
! 470:
! 471: goto end;
! 472:
! 473: }
! 474:
! 475: if (!stcmp (intext, "STS\201")) {
! 476:
! 477: final = 'S';
! 478:
! 479: goto end;
! 480:
! 481: }
! 482:
! 483: if (!stcmp (intext, "CCH\201")) {
! 484:
! 485: final = 'T';
! 486:
! 487: goto end;
! 488:
! 489: }
! 490:
! 491: if (!stcmp (intext, "MW\201")) {
! 492:
! 493: final = 'U';
! 494:
! 495: goto end;
! 496:
! 497: }
! 498:
! 499: if (!stcmp (intext, "SPA\201")) {
! 500:
! 501: final = 'V';
! 502:
! 503: goto end;
! 504:
! 505: }
! 506:
! 507: if (!stcmp (intext, "EPA\201")) {
! 508:
! 509: final = 'W';
! 510:
! 511: goto end;
! 512:
! 513: }
! 514:
! 515: /* CSI - Command String Introducer */
! 516: if (!stcmp (intext, "CSI\201")) {
! 517:
! 518: final = '[';
! 519:
! 520: goto end;
! 521:
! 522: }
! 523:
! 524: /* ST - device control String Terminator */
! 525: if (!stcmp (intext, "ST\201")) {
! 526:
! 527: final = '\\';
! 528:
! 529: goto end;
! 530:
! 531: }
! 532:
! 533: if (!stcmp (intext, "OSC\201")) {
! 534:
! 535: final = ']';
! 536:
! 537: goto end;
! 538:
! 539: }
! 540:
! 541: if (!stcmp (intext, "PM\201")) {
! 542:
! 543: final = '^';
! 544:
! 545: goto end;
! 546:
! 547: }
! 548:
! 549: if (!stcmp (intext, "APC\201")) {
! 550:
! 551: final = '_';
! 552:
! 553: goto end;
! 554:
! 555: }
! 556:
! 557: /* RIS - Reset to Initial State */
! 558: if (!stcmp (intext, "RIS\201")) {
! 559:
! 560: final = 'c';
! 561:
! 562: goto end;
! 563:
! 564: }
! 565:
! 566: /* RM - Reset Mode */
! 567: if (!stcmp (intext, "RM\201")) {
! 568:
! 569: csi = TRUE;
! 570: final = 'l';
! 571:
! 572: goto end;
! 573:
! 574: }
! 575:
! 576: /* SGR - Select Graphic Rendition */
! 577: if (!stcmp (intext, "SGR\201")) {
! 578:
! 579: csi = TRUE;
! 580: final = 'm';
! 581:
! 582: goto end;
! 583:
! 584: }
! 585:
! 586: /* SM - Set Mode */
! 587: if (!stcmp (intext, "SM\201")) {
! 588:
! 589: csi = TRUE;
! 590: final = 'h';
! 591:
! 592: goto end;
! 593:
! 594: }
! 595:
! 596: /* TBC - Tabulation Clear */
! 597: if (!stcmp (intext, "TBC\201")) {
! 598:
! 599: csi = TRUE;
! 600: final = 'g';
! 601:
! 602: goto end;
! 603:
! 604: }
! 605:
! 606: if (!stcmp (intext, "NUL\201")) {
! 607:
! 608: final = NUL;
! 609:
! 610: goto controls;
! 611:
! 612: }
! 613:
! 614: if (!stcmp (intext, "SOH\201")) {
! 615:
! 616: final = SOH;
! 617:
! 618: goto controls;
! 619:
! 620: }
! 621:
! 622: if (!stcmp (intext, "STX\201")) {
! 623:
! 624: final = STX;
! 625:
! 626: goto controls;
! 627:
! 628: }
! 629:
! 630: if (!stcmp (intext, "ETX\201")) {
! 631:
! 632: final = ETX;
! 633:
! 634: goto controls;
! 635:
! 636: }
! 637:
! 638: if (!stcmp (intext, "EOT\201")) {
! 639:
! 640: final = EOT;
! 641:
! 642: goto controls;
! 643:
! 644: }
! 645:
! 646: if (!stcmp (intext, "ENQ\201")) {
! 647:
! 648: final = ENQ;
! 649:
! 650: goto controls;
! 651:
! 652: }
! 653:
! 654: if (!stcmp (intext, "ACK\201")) {
! 655:
! 656: final = ACK;
! 657:
! 658: goto controls;
! 659:
! 660: }
! 661:
! 662: if (!stcmp (intext, "BEL\201")) {
! 663:
! 664: final = BEL;
! 665:
! 666: goto controls;
! 667:
! 668: }
! 669:
! 670: if (!stcmp (intext, "BS\201")) {
! 671:
! 672: final = BS;
! 673:
! 674: goto controls;
! 675:
! 676: }
! 677:
! 678: if (!stcmp (intext, "HT\201")) {
! 679:
! 680: final = TAB;
! 681:
! 682: goto controls;
! 683:
! 684: }
! 685:
! 686: if (!stcmp (intext, "LF\201")) {
! 687:
! 688: final = LF;
! 689:
! 690: goto controls;
! 691:
! 692: }
! 693:
! 694: if (!stcmp (intext, "VT\201")) {
! 695:
! 696: final = VT;
! 697:
! 698: goto controls;
! 699:
! 700: }
! 701:
! 702: if (!stcmp (intext, "FF\201")) {
! 703:
! 704: final = FF;
! 705:
! 706: goto controls;
! 707:
! 708: }
! 709:
! 710: if (!stcmp (intext, "CR\201")) {
! 711:
! 712: final = CR;
! 713:
! 714: goto controls;
! 715:
! 716: }
! 717:
! 718: if (!stcmp (intext, "SO\201")) {
! 719:
! 720: final = SO;
! 721:
! 722: goto controls;
! 723:
! 724: }
! 725:
! 726: if (!stcmp (intext, "SI\201")) {
! 727:
! 728: final = SI;
! 729:
! 730: goto controls;
! 731:
! 732: }
! 733:
! 734: if (!stcmp (intext, "DLE\201")) {
! 735:
! 736: final = DLE;
! 737:
! 738: goto controls;
! 739:
! 740: }
! 741:
! 742: if (!stcmp (intext, "DC1\201")) {
! 743:
! 744: final = DC1;
! 745:
! 746: goto controls;
! 747:
! 748: }
! 749:
! 750: if (!stcmp (intext, "DC2\201")) {
! 751:
! 752: final = DC2;
! 753:
! 754: goto controls;
! 755:
! 756: }
! 757:
! 758: if (!stcmp (intext, "DC3\201")) {
! 759:
! 760: final = DC3;
! 761:
! 762: goto controls;
! 763:
! 764: }
! 765:
! 766: if (!stcmp (intext, "DC4\201")) {
! 767:
! 768: final = DC4;
! 769:
! 770: goto controls;
! 771:
! 772: }
! 773:
! 774: if (!stcmp (intext, "NAK\201")) {
! 775:
! 776: final = NAK;
! 777:
! 778: goto controls;
! 779:
! 780: }
! 781:
! 782: if (!stcmp (intext, "SYN\201")) {
! 783:
! 784: final = SYN;
! 785:
! 786: goto controls;
! 787:
! 788: }
! 789:
! 790: if (!stcmp (intext, "ETB\201")) {
! 791:
! 792: final = ETB;
! 793:
! 794: goto controls;
! 795:
! 796: }
! 797:
! 798: if (!stcmp (intext, "CAN\201")) {
! 799:
! 800: final = CAN;
! 801:
! 802: goto controls;
! 803:
! 804: }
! 805:
! 806: if (!stcmp (intext, "EM\201")) {
! 807:
! 808: final = EM;
! 809:
! 810: goto controls;
! 811:
! 812: }
! 813:
! 814: if (!stcmp (intext, "SUB\201")) {
! 815:
! 816: final = SUB;
! 817:
! 818: goto controls;
! 819:
! 820: }
! 821:
! 822: if (!stcmp (intext, "ESC\201")) {
! 823:
! 824: final = ESC;
! 825:
! 826: goto controls;
! 827:
! 828: }
! 829:
! 830: if (!stcmp (intext, "FS\201")) {
! 831:
! 832: final = FS;
! 833:
! 834: goto controls;
! 835:
! 836: }
! 837:
! 838: if (!stcmp (intext, "GS\201")) {
! 839:
! 840: final = GS;
! 841:
! 842: goto controls;
! 843:
! 844: }
! 845:
! 846:
! 847: if (!stcmp (intext, "RS\201")) {
! 848:
! 849: final = RS;
! 850:
! 851: goto controls;
! 852:
! 853: }
! 854:
! 855: if (!stcmp (intext, "US\201")) {
! 856:
! 857: final = US;
! 858:
! 859: goto controls;
! 860:
! 861: }
! 862:
! 863: if (!stcmp (intext, "DEL\201")) {
! 864:
! 865: final = DEL;
! 866:
! 867: goto controls;
! 868:
! 869: }
! 870:
! 871: /* DECKPAM Keypad Application Mode */
! 872: if (!stcmp (intext, "DECKPAM\201")) {
! 873:
! 874: final = '=';
! 875:
! 876: goto end;
! 877:
! 878: }
! 879:
! 880: /* DECKPNM Keypad Numeric Mode */
! 881: if (!stcmp (intext, "DECKPNM\201")) {
! 882:
! 883: final = '>';
! 884:
! 885: goto end;
! 886:
! 887: }
! 888:
! 889: /* DECLL Load LEDs */
! 890: if (!stcmp (intext, "DECLL\201")) {
! 891:
! 892: csi = TRUE;
! 893: final = 'q';
! 894:
! 895: goto end;
! 896:
! 897: }
! 898:
! 899: /* DECRC Restore Cursor */
! 900: if (!stcmp (intext, "DECRC\201")) {
! 901:
! 902: final = '8';
! 903:
! 904: goto end;
! 905:
! 906: }
! 907:
! 908: /* DECSC Save Cursor */
! 909: if (!stcmp (intext, "DECSC\201")) {
! 910:
! 911: final = '7';
! 912:
! 913: goto end;
! 914:
! 915: }
! 916:
! 917: /* DECSTBM Set Top & Bottom Margins */
! 918: if (!stcmp (intext, "TBM\201") ||
! 919:
! 920: !stcmp (intext, "DECSTBM\201")) {
! 921:
! 922: csi = TRUE;
! 923: final = 'r';
! 924:
! 925: goto end;
! 926:
! 927: }
! 928:
! 929: /* ZAS Alternate Screen */
! 930: if (!stcmp (intext, "ZAS\201")) {
! 931:
! 932: csi = TRUE;
! 933: final = '~';
! 934:
! 935: goto end;
! 936:
! 937: }
! 938:
! 939: return; /* code not recognized */
! 940:
! 941: controls:
! 942: outtext[0] = final;
! 943: outtext[1] = EOL;
! 944:
! 945: write_m (outtext);
! 946:
! 947: return;
! 948:
! 949: end:
! 950:
! 951: outtext[0] = ESC;
! 952:
! 953: if (csi++) outtext[1] = '[';
! 954:
! 955: while (++i < l) {
! 956:
! 957: if ((outtext[csi] = intext[i]) == DELIM) outtext[csi] = ';';
! 958:
! 959: csi++;
! 960:
! 961: }
! 962:
! 963: outtext[csi++] = final;
! 964: outtext[csi] = EOL;
! 965:
! 966: write_m (outtext);
! 967:
! 968: return;
! 969: } /* end of write_f() */
! 970:
! 971: /* Output on HOME device */
! 972: void writeHOME (char *text)
! 973: {
! 974:
! 975: struct winsize terminal_window;
! 976: static char initflag = TRUE; /* initialisation flag */
! 977: static char esc = 0; /* esc processing flag */
! 978: static char dcs = 0; /* device control processing flag */
! 979:
! 980: static short args[ARGS_IN_ESC];
! 981: static short argcnt = 0;
! 982: static short noargs = TRUE;
! 983: static char tmp[512];
! 984: static short foreground = TRUE; /* foreground flag */
! 985: static struct vtstyp *vts;
! 986:
! 987: /* external struct vtstyp *screen; active screen */
! 988: static struct vtstyp *altscr; /* background screen */
! 989: static struct vtstyp *zases[MAXZAS];
! 990: static int zaslevel = 0;
! 991:
! 992: /* SGR and CSI=cF have ***different*** color codes */
! 993: #ifdef COLOR
! 994: static char coltrans[8] =
! 995: {0, 4, 2, 6, 1, 5, 3, 7};
! 996:
! 997: #endif /* COLOR */
! 998:
! 999:
! 1000: short tmpx;
! 1001: register int ch;
! 1002: register int j;
! 1003: register int i;
! 1004: short k;
! 1005:
! 1006: /* we assume the HOME device is an ASCII machine according
! 1007: * to ANSI X3.4, X3.64 etc with 24 lines and 80 columns
! 1008: * so we look not only at controls as the MUMPS X11.1-1984
! 1009: * demands, but as well at esc sequences and device control
! 1010: * strings.
! 1011: *
! 1012: * In addition we assume, that the terminal cannot handle
! 1013: * tab_clear (CSI 3g) nor tab_set (ESC H) so these functions
! 1014: * are emulated here. For most terminals that might
! 1015: * not be neccesary. With 'PROC_TAB' we may switch versions.
! 1016: *
! 1017: * We support the VT100 on PC-"Terminals"
! 1018: * where there is no TBM so we have to emulate
! 1019: * scoll up /down with LF,RI and autowrap. SGR is somewhat
! 1020: * crazy on the PC and there is a lot of code to fix that.
! 1021: * The PC completely ignores SGRs it does not fully recognize.
! 1022: * E.g. SGR(7,4) will not work while SGR(4,7) at least inverts
! 1023: * the display.
! 1024: * CSI 10 p (invert INVERS at active position)
! 1025: * is being emulated too.
! 1026: * We emulate the terminal software so we have always an image
! 1027: * of the screen in memory. That enables us to have features like
! 1028: * CSI 0 ~ (private sequence: change screen)
! 1029: * CSI 1 ~ (private sequence: output to foreground screen)
! 1030: * CSI 2 ~ (private sequence: output to background screen)
! 1031: * CSI 3 ~ (private sequence: save foreground to background)
! 1032: * CSI 4 ~ (private sequence: screen restore)
! 1033: * and the 'hardcopy function'
! 1034: */
! 1035: if (initflag) {
! 1036:
! 1037: /* TODO: why are we casting to void here? */
! 1038: (void) ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminal_window);
! 1039:
! 1040: n_lines = terminal_window.ws_row;
! 1041: n_columns = terminal_window.ws_col;
! 1042:
! 1043: screen = (struct vtstyp *) calloc (1, sizeof (struct vtstyp));
! 1044:
! 1045: ris (screen);
! 1046: altscr = (struct vtstyp *) calloc (1, sizeof (struct vtstyp));
! 1047:
! 1048: ris (altscr);
! 1049: initflag = FALSE;
! 1050:
! 1051: }
! 1052:
! 1053: opnfile[HOME] = stdout;
! 1054: tmpx = 0;
! 1055: j = 0;
! 1056:
! 1057: while ((ch = text[j++]) != EOL) {
! 1058:
! 1059: if (ch == NUL) continue;
! 1060:
! 1061: if (tmpx > 480) {
! 1062:
! 1063: tmp[tmpx] = EOL;
! 1064: tmpx = 0;
! 1065:
! 1066: if (foreground) m_output (tmp);
! 1067:
! 1068: }
! 1069:
! 1070:
! 1071: if (RightMargin && xpos[HOME] > RightMargin && esc == 0) {
! 1072:
! 1073: --j;
! 1074:
! 1075: tmp[tmpx++] = CR;
! 1076: xpos[HOME] = 0;
! 1077: ch = LF;
! 1078:
! 1079: }
! 1080:
! 1081: /* what in the name of good and holy is this macro abuse nonsense? */
! 1082:
! 1083: #ifdef PROC_TAB
! 1084: if (ch != TAB) tmp[tmpx++] = ch;
! 1085: #else
! 1086: tmp[tmpx++] = ch;
! 1087: #endif /* PROC_TAB */
! 1088:
! 1089:
! 1090: if (UNSIGN (ch) >= SP && ch != DEL) { /* printable characters */
! 1091:
! 1092: if (esc == 0) { /* no esc/dcs in progress; wrap-around */
! 1093:
! 1094: (*screen).screenx[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]] = ch;
! 1095:
! 1096: if ((*screen).savarg == FALSE) {
! 1097:
! 1098:
! 1099: #ifdef COLOR
! 1100: (*screen).screenc[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]] = (*screen).col;
! 1101: #endif /* COLOR */
! 1102:
! 1103: (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]] = (*screen).att;
! 1104:
! 1105: }
! 1106:
! 1107: if (dcs == 0 && ++xpos[HOME] >= n_columns) {
! 1108:
! 1109: xpos[HOME] = 0;
! 1110:
! 1111: if ((*screen).rollflag) goto pLF;
! 1112:
! 1113: ypos[HOME] = (*screen).sc_lo;
! 1114:
! 1115: }
! 1116:
! 1117: continue;
! 1118:
! 1119: }
! 1120:
! 1121: if (esc == 1) { /* esc_sequence in progress */
! 1122:
! 1123: if (ch == '[') { /* CSI command string starts */
! 1124: esc = 2;
! 1125: continue;
! 1126: }
! 1127: else if (ch == 'H') { /* HTS set tab at $X */
! 1128: (*screen).tabs[xpos[HOME]] = 1;
! 1129: }
! 1130: else if (ch == 'M') { /* RI cursor up *//* upper margin of scroll area: scroll down */
! 1131:
! 1132: if (ypos[HOME] == (*screen).sc_up) {
! 1133:
! 1134: k = (*screen).sclines[(*screen).sc_lo];
! 1135:
! 1136: for (i = (*screen).sc_lo; i > (*screen).sc_up; i--) (*screen).sclines[i] = (*screen).sclines[i - 1];
! 1137:
! 1138: (*screen).sclines[(*screen).sc_up] = k;
! 1139:
! 1140: for (i = 0; i < n_columns; i++) {
! 1141:
! 1142: (*screen).screenx[k][i] = SP;
! 1143: (*screen).screena[k][i] = (*screen).att;
! 1144:
! 1145:
! 1146: #ifdef COLOR
! 1147: (*screen).screenc[k][i] = (*screen).col;
! 1148: #endif /* COLOR */
! 1149:
! 1150: }
! 1151:
! 1152: if (foreground) {
! 1153:
! 1154: tmp[tmpx - 2] = EOL;
! 1155: m_output (tmp);
! 1156:
! 1157: tmpx = 0;
! 1158: part_ref (screen, (*screen).sc_up, (*screen).sc_lo);
! 1159:
! 1160: }
! 1161: }
! 1162:
! 1163: if (ypos[HOME] != 0 && ypos[HOME] != (*screen).sc_up) ypos[HOME]--;
! 1164:
! 1165: tmp[tmpx++] = ESC;
! 1166: tmp[tmpx++] = '[';
! 1167:
! 1168: if (ypos[HOME] > 8) tmp[tmpx++] = (1 + ypos[HOME]) / 10 + '0';
! 1169:
! 1170: tmp[tmpx++] = (1 + ypos[HOME]) % 10 + '0';
! 1171:
! 1172: if (xpos[HOME] > 0) {
! 1173:
! 1174: tmp[tmpx++] = ';';
! 1175:
! 1176: if (xpos[HOME] > 8) tmp[tmpx++] = (1 + xpos[HOME]) / 10 + '0';
! 1177:
! 1178: tmp[tmpx++] = (1 + xpos[HOME]) % 10 + '0';
! 1179:
! 1180: }
! 1181:
! 1182: tmp[tmpx++] = 'H';
! 1183:
! 1184: }
! 1185: else if (ch == 'E') { /* NEL new line */
! 1186:
! 1187: /* RI */
! 1188:
! 1189: xpos[HOME] = 0;
! 1190: esc = 0;
! 1191:
! 1192: goto pLF;
! 1193:
! 1194: }
! 1195: else if (ch == 'Q') { /* DCS Device control string */
! 1196: dcs = 1;
! 1197: }
! 1198: else if (ch == '\\') { /* ST String terminator (DCS) */
! 1199: dcs = 0;
! 1200: }
! 1201: else if (ch == '7') { /* DEC CS Cursor Save */
! 1202:
! 1203: (*screen).csx[(*screen).cs] = xpos[HOME];
! 1204: (*screen).csy[(*screen).cs] = ypos[HOME];
! 1205:
! 1206: if (++((*screen).cs) >= CSLEN) (*screen).cs = CSLEN - 1;
! 1207:
! 1208: }
! 1209: else if (ch == '8') { /* DEC CRST Cursor Restore */
! 1210:
! 1211: if (--((*screen).cs) <= 0) (*screen).cs = 0;
! 1212:
! 1213: xpos[HOME] = (*screen).csx[(*screen).cs];
! 1214: ypos[HOME] = (*screen).csy[(*screen).cs];
! 1215:
! 1216: /* make sure cursor is at desired position */
! 1217: tmp[tmpx++] = ESC;
! 1218: tmp[tmpx++] = '[';
! 1219:
! 1220: if (ypos[HOME] > 8) tmp[tmpx++] = (1 + ypos[HOME]) / 10 + '0';
! 1221:
! 1222: tmp[tmpx++] = (1 + ypos[HOME]) % 10 + '0';
! 1223:
! 1224: if (xpos[HOME] > 0) {
! 1225:
! 1226: tmp[tmpx++] = ';';
! 1227:
! 1228: if (xpos[HOME] > 8) tmp[tmpx++] = (1 + xpos[HOME]) / 10 + '0';
! 1229:
! 1230: tmp[tmpx++] = (1 + xpos[HOME]) % 10 + '0';
! 1231:
! 1232: }
! 1233:
! 1234: tmp[tmpx++] = 'H';
! 1235:
! 1236: }
! 1237: else if (ch == 'c') { /* RIS Reset to initial state */
! 1238:
! 1239: esc = 0;
! 1240: dcs = 0;
! 1241: foreground = TRUE;
! 1242: xpos[HOME] = 0;
! 1243: ypos[HOME] = 0;
! 1244:
! 1245: ris (screen);
! 1246:
! 1247: }
! 1248: else if (ch == '(' || ch == ')') {
! 1249: continue;
! 1250: }
! 1251:
! 1252: esc = 0;
! 1253:
! 1254: continue;
! 1255:
! 1256: } /* end if (esc==1) */
! 1257:
! 1258: /* command string (esc [) in progress */
! 1259: /* numeric arguments ? */
! 1260: if (ch >= '0' && ch <= '9') {
! 1261:
! 1262: noargs = FALSE;
! 1263: args[argcnt] = args[argcnt] * 10 + ch - '0';
! 1264:
! 1265: continue;
! 1266:
! 1267: }
! 1268:
! 1269: if (ch == ';') {
! 1270:
! 1271: args[++argcnt] = 0;
! 1272:
! 1273: continue;
! 1274:
! 1275: }
! 1276:
! 1277: if (ch == '=') {
! 1278: esc = 3;
! 1279: continue;
! 1280: } /* color sequence */
! 1281:
! 1282: if (esc == 3) {
! 1283:
! 1284: esc = 0;
! 1285:
! 1286:
! 1287: #ifdef COLOR
! 1288: if (ch == 'F') { /* foreground color */
! 1289:
! 1290: (*screen).col = (((*screen).col & ~017) | (args[0] & 017));
! 1291:
! 1292: tmp[tmpx++] = ESC; /* reverse background */
! 1293: tmp[tmpx++] = '[';
! 1294: tmp[tmpx++] = '=';
! 1295:
! 1296: if (args[0] > 9) tmp[tmpx++] = '0' + (args[0] / 10);
! 1297:
! 1298: tmp[tmpx++] = '0' + (args[0] % 10);
! 1299: tmp[tmpx++] = 'I';
! 1300:
! 1301: continue;
! 1302:
! 1303: }
! 1304:
! 1305: if (ch == 'G') { /* background color */
! 1306:
! 1307: (*screen).col = (((*screen).col & 017) | (args[0] * 16));
! 1308:
! 1309: tmp[tmpx++] = ESC; /* reverse forground */
! 1310: tmp[tmpx++] = '[';
! 1311: tmp[tmpx++] = '=';
! 1312:
! 1313: if (args[0] > 9) tmp[tmpx++] = '0' + (args[0] / 10);
! 1314:
! 1315: tmp[tmpx++] = '0' + (args[0] % 10);
! 1316: tmp[tmpx++] = 'H';
! 1317:
! 1318: continue;
! 1319:
! 1320: }
! 1321: #endif /* COLOR */
! 1322:
! 1323:
! 1324: continue;
! 1325:
! 1326: } /* if (esc == 3) */
! 1327:
! 1328: if (ch < '@') continue;
! 1329:
! 1330: /* check final characters */
! 1331: if (ch == 'A') { /* CUU cursor up */
! 1332:
! 1333: do {
! 1334:
! 1335: if (--ypos[HOME] < 0) ypos[HOME] = 0;
! 1336:
! 1337: }
! 1338: while (--args[0] > 0);
! 1339:
! 1340: }
! 1341: else if (ch == 'B') { /* CUD cursor down */
! 1342:
! 1343: do {
! 1344:
! 1345: if (++ypos[HOME] >= (n_lines - 1)) ypos[HOME] = (n_lines - 1);
! 1346:
! 1347: }
! 1348: while (--args[0] > 0);
! 1349:
! 1350: }
! 1351: else if (ch == 'C') { /* CUF cursor right */
! 1352:
! 1353: do {
! 1354:
! 1355: if (++xpos[HOME] >= n_columns) xpos[HOME] = (n_columns - 1);
! 1356:
! 1357: }
! 1358: while (--args[0] > 0);
! 1359:
! 1360: }
! 1361: else if (ch == 'D') { /* CUB cursor left */
! 1362:
! 1363: do {
! 1364:
! 1365: if (--xpos[HOME] < 0) xpos[HOME] = 0;
! 1366:
! 1367: }
! 1368: while (--args[0] > 0) ;
! 1369:
! 1370: }
! 1371: else if (ch == 'H') { /* CUP cursor position */
! 1372:
! 1373: i = --args[0];
! 1374:
! 1375: if (i < 0) i = 0;
! 1376: if (i <= n_lines) ypos[HOME] = i;
! 1377:
! 1378: i = --args[1];
! 1379:
! 1380: if (i < 0) i = 0;
! 1381: if (i < n_columns) xpos[HOME] = i;
! 1382:
! 1383: }
! 1384: else if (ch == 'K') { /* EL erase line */
! 1385:
! 1386: int k;
! 1387:
! 1388: i = 0;
! 1389: k = n_columns;
! 1390:
! 1391: if (args[0] == 0) i = xpos[HOME];
! 1392: if (args[0] == 1) k = xpos[HOME] + 1;
! 1393:
! 1394: while (i < k) {
! 1395:
! 1396: (*screen).screenx[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = SP;
! 1397: (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = 0; /* not 'att' */
! 1398:
! 1399:
! 1400: #ifdef COLOR
! 1401: (*screen).screenc[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = (*screen).col;
! 1402: #endif /* COLOR */
! 1403:
! 1404: i++;
! 1405:
! 1406: }
! 1407: }
! 1408: else /* TODO: this bogosity must go away. */
! 1409:
! 1410:
! 1411: ED:
! 1412: if (ch == 'J') { /* ED erase display */
! 1413:
! 1414: register int k;
! 1415:
! 1416: #ifdef COLOR
! 1417: unsigned char color;
! 1418: #endif /* COLOR (COLOR is forced on in mpsdef.h or mpsdef0.h) */
! 1419:
! 1420: i = 0;
! 1421: k = n_columns;
! 1422:
! 1423: if (args[0] == 0) i = xpos[HOME];
! 1424: if (args[0] == 1) k = xpos[HOME] + 1;
! 1425:
! 1426:
! 1427: #ifdef COLOR
! 1428: color = (*screen).col;
! 1429: #endif /* COLOR */
! 1430:
! 1431: while (i < k) { /* clear current line */
! 1432:
! 1433: /* TODO: revisit this commented-out section. Was part of the
! 1434: * original support for terminals larger than 80x25.
! 1435: * Possibly responsible for screen state corruption?
! 1436: *
! 1437: * Ref: issue #95
! 1438: * https://gitlab.coherent-logic.com/jpw/freem/-/issues/95
! 1439: */
! 1440: /*
! 1441: (*screen).screenx[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = SP;
! 1442: (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = 0;*/
! 1443:
! 1444: (*screen).screenx[ypos[HOME]][i] = SP;
! 1445: (*screen).screena[ypos[HOME]][i] = 0; /* not 'att' */
! 1446:
! 1447: #ifdef COLOR
! 1448: (*screen).screenc[ypos[HOME]][i] = color;
! 1449: #endif /* COLOR */
! 1450:
! 1451: i++;
! 1452:
! 1453: }
! 1454:
! 1455: /* clear rest of screen */
! 1456: if (args[0] != 1) {
! 1457:
! 1458: for (k = ypos[HOME] + 1; k < n_lines; k++) {
! 1459:
! 1460: for (i = 0; i < n_columns; i++) {
! 1461:
! 1462: /* TODO: revisit; see above */
! 1463: /* (*screen).screenx[(unsigned int) (*screen).sclines[k]][i] = SP; */
! 1464: (*screen).screenx[k][i] = SP;
! 1465: (*screen).screena[k][i] = 0;
! 1466:
! 1467:
! 1468: #ifdef COLOR
! 1469: (*screen).screenc[k][i] = color;
! 1470: #endif /* COLOR */
! 1471:
! 1472: }
! 1473:
! 1474: }
! 1475:
! 1476: }
! 1477:
! 1478: /* clear beginning of screen */
! 1479: if (args[0] != 0) {
! 1480:
! 1481: for (k = 0; k < ypos[HOME]; k++) {
! 1482:
! 1483: for (i = 0; i < n_columns; i++) {
! 1484:
! 1485: (*screen).screenx[k][i] = SP;
! 1486: (*screen).screena[k][i] = 0;
! 1487:
! 1488:
! 1489: #ifdef COLOR
! 1490: (*screen).screenc[k][i] = color;
! 1491: #endif /* COLOR */
! 1492:
! 1493: }
! 1494:
! 1495: }
! 1496:
! 1497: }
! 1498:
! 1499:
! 1500: #ifdef SCO
! 1501: if (foreground) {
! 1502:
! 1503: if ((*screen).lin24) tmp[tmpx - 1] = CAN;
! 1504:
! 1505: tmp[tmpx] = EOL;
! 1506: m_output (tmp);
! 1507:
! 1508: tmpx = 0;
! 1509: part_ref (screen, 0, n_lines - 1);
! 1510:
! 1511: }
! 1512: #endif /* SCO */
! 1513:
! 1514: }
! 1515: /* end ED */
! 1516: else if (ch == 'p') { /* private */
! 1517:
! 1518: if (args[0] == 10) {
! 1519:
! 1520: /* invert 'inverse' at */
! 1521: /* current cursor pos. */
! 1522:
! 1523: (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]] ^= 0100;
! 1524:
! 1525: #ifdef SCO
! 1526:
! 1527: /* now we're in the meat of the really bizarre SCO UNIX terminal I/O stuff.
! 1528: most of this will need to be reworked. */
! 1529:
! 1530: if (foreground) {
! 1531:
! 1532: k = (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]];
! 1533:
! 1534: if (((*screen).att & 01) != (k & 01)) tmp[tmpx++] = (k & 01) ? SO : SI;
! 1535:
! 1536: k = scosgr (k, (*screen).bw);
! 1537:
! 1538: tmp[tmpx++] = ESC;
! 1539: tmp[tmpx++] = '[';
! 1540:
! 1541: if ((*screen).bw) tmp[tmpx++] = '7';
! 1542:
! 1543: tmp[tmpx++] = 'm';
! 1544: tmp[tmpx++] = ESC;
! 1545: tmp[tmpx++] = '[';
! 1546:
! 1547: if (k & 02) {
! 1548: tmp[tmpx++] = '1';
! 1549: tmp[tmpx++] = ';';
! 1550: } /* SCO !!! Yeah, SCO. What of it? Such a useful comment... */
! 1551:
! 1552: if (k & 04) {
! 1553: tmp[tmpx++] = '3';
! 1554: tmp[tmpx++] = ';';
! 1555: }
! 1556:
! 1557: if (k & 010) {
! 1558: tmp[tmpx++] = '4';
! 1559: tmp[tmpx++] = ';';
! 1560: }
! 1561:
! 1562: if (k & 020) {
! 1563: tmp[tmpx++] = '5';
! 1564: tmp[tmpx++] = ';';
! 1565: }
! 1566:
! 1567: if (k & 040) {
! 1568: tmp[tmpx++] = '6';
! 1569: tmp[tmpx++] = ';';
! 1570: }
! 1571:
! 1572: if (k & 0100) {
! 1573: tmp[tmpx++] = '7';
! 1574: tmp[tmpx++] = ';';
! 1575: }
! 1576:
! 1577: if (k & 0200) {
! 1578: tmp[tmpx++] = '8';
! 1579: tmp[tmpx++] = ';';
! 1580: }
! 1581:
! 1582: if (tmp[tmpx - 1] == ';') tmpx--;
! 1583:
! 1584: tmp[tmpx++] = 'm';
! 1585: tmp[tmpx++] = (*screen).screenx[(unsigned int) (*screen).sclines[ypos[HOME]]][xpos[HOME]];
! 1586: tmp[tmpx++] = ESC;
! 1587: tmp[tmpx++] = '[';
! 1588: k = ypos[HOME] + 1;
! 1589:
! 1590: if (k > 9) tmp[tmpx++] = k / 10 + '0';
! 1591:
! 1592: tmp[tmpx++] = k % 10 + '0';
! 1593:
! 1594: if (xpos[HOME]) {
! 1595:
! 1596: tmp[tmpx++] = ';';
! 1597: k = xpos[HOME] + 1;
! 1598:
! 1599: if (k > 9) tmp[tmpx++] = k / 10 + '0';
! 1600:
! 1601: tmp[tmpx++] = k % 10 + '0';
! 1602:
! 1603: }
! 1604:
! 1605: tmp[tmpx++] = 'H';
! 1606:
! 1607: if (k != screen->att) {
! 1608:
! 1609: k = scosgr ((*screen).att, (*screen).bw);
! 1610:
! 1611: tmp[tmpx++] = (k & 01) ? SO : SI;
! 1612: tmp[tmpx++] = ESC;
! 1613: tmp[tmpx++] = '[';
! 1614: tmp[tmpx++] = '0';
! 1615:
! 1616: if (k & 02) {
! 1617: tmp[tmpx++] = ';';
! 1618: tmp[tmpx++] = '1';
! 1619: } /* SCO !!! Again... what about it? */
! 1620:
! 1621: if (k & 04) {
! 1622: tmp[tmpx++] = ';';
! 1623: tmp[tmpx++] = '3';
! 1624: }
! 1625:
! 1626: if (k & 010) {
! 1627: tmp[tmpx++] = ';';
! 1628: tmp[tmpx++] = '4';
! 1629: }
! 1630:
! 1631: if (k & 020) {
! 1632: tmp[tmpx++] = ';';
! 1633: tmp[tmpx++] = '5';
! 1634: }
! 1635:
! 1636: if (k & 040) {
! 1637: tmp[tmpx++] = ';';
! 1638: tmp[tmpx++] = '6';
! 1639: }
! 1640:
! 1641: if (k & 0100) {
! 1642: tmp[tmpx++] = ';';
! 1643: tmp[tmpx++] = '7';
! 1644: }
! 1645:
! 1646: if (k & 0200) {
! 1647: tmp[tmpx++] = ';';
! 1648: tmp[tmpx++] = '8';
! 1649: }
! 1650:
! 1651: tmp[tmpx++] = 'm';
! 1652:
! 1653: }
! 1654:
! 1655: }
! 1656: #endif /* SCO */
! 1657:
! 1658: }
! 1659: }
! 1660: else if (ch == 'r') { /* TBM Top_Bottom Margin */
! 1661:
! 1662: register int k;
! 1663:
! 1664: if (noargs || ((*screen).sc_up = (--args[0])) <= 0) (*screen).sc_up = 0;
! 1665:
! 1666: /* TODO: Revisit. This still appears to be hardcoded to the old fixed terminal size.
! 1667: * Ref issue #95
! 1668: */
! 1669: if (!argcnt || (((*screen).sc_lo = (--args[1])) > 24) || ((*screen).sc_lo == 23 && (*screen).lin24 == TRUE)) {
! 1670: (*screen).sc_lo = (*screen).lin24 ? 23 : 24;
! 1671: }
! 1672:
! 1673: /* restore old cursor position */
! 1674: tmp[tmpx++] = ESC;
! 1675: tmp[tmpx++] = '[';
! 1676: k = ypos[HOME] + 1;
! 1677:
! 1678: if (k > 9) tmp[tmpx++] = k / 10 + '0';
! 1679:
! 1680: tmp[tmpx++] = k % 10 + '0';
! 1681:
! 1682: if (xpos[HOME]) {
! 1683:
! 1684: tmp[tmpx++] = ';';
! 1685: k = xpos[HOME] + 1;
! 1686:
! 1687: if (k > 9) tmp[tmpx++] = k / 10 + '0';
! 1688:
! 1689: tmp[tmpx++] = k % 10 + '0';
! 1690:
! 1691: }
! 1692:
! 1693: tmp[tmpx++] = 'H';
! 1694:
! 1695: }
! 1696: else if (ch == 's') { /* CS Cursor Save */
! 1697:
! 1698: (*screen).csx[(*screen).cs] = xpos[HOME];
! 1699: (*screen).csy[(*screen).cs] = ypos[HOME];
! 1700: (*screen).cssgr[(*screen).cs] = (*screen).att;
! 1701:
! 1702:
! 1703: #ifdef COLOR
! 1704: (*screen).cscol[(*screen).cs] = (*screen).col;
! 1705: #endif /* COLOR */
! 1706:
! 1707: if (++((*screen).cs) >= CSLEN) (*screen).cs = CSLEN - 1;
! 1708:
! 1709: }
! 1710: else if (ch == 'u') {
! 1711:
! 1712: /* CRST Cursor Unsave (if no args) */
! 1713: /* those bloody bastards made 'CSI u' and CSI 0 u' */
! 1714: /* different. flag 'noargs' distinguishes */
! 1715:
! 1716: /* bloody bastards, eh? this whole module is a bloody bastard,
! 1717: * so I seriously have no idea what the hell you're complaining
! 1718: * about, Mr. ha-Ashkenaz.
! 1719: */
! 1720:
! 1721: if (noargs) {
! 1722:
! 1723:
! 1724: #ifdef COLOR
! 1725: int color;
! 1726: #endif /* COLOR */
! 1727:
! 1728: if (--((*screen).cs) <= 0) (*screen).cs = 0;
! 1729:
! 1730: xpos[HOME] = (*screen).csx[(*screen).cs];
! 1731: ypos[HOME] = (*screen).csy[(*screen).cs];
! 1732:
! 1733: (*screen).att = (*screen).cssgr[(*screen).cs];
! 1734:
! 1735:
! 1736: #ifdef COLOR
! 1737: (*screen).col = (*screen).cscol[(*screen).cs];
! 1738: color = (*screen).col;
! 1739: #endif /* COLOR */
! 1740:
! 1741: /* make sure cursor is at desired position */
! 1742: tmp[tmpx++] = ESC;
! 1743: tmp[tmpx++] = '[';
! 1744:
! 1745: if (ypos[HOME] > 8) tmp[tmpx++] = (1 + ypos[HOME]) / 10 + '0';
! 1746:
! 1747: tmp[tmpx++] = (1 + ypos[HOME]) % 10 + '0';
! 1748:
! 1749: if (xpos[HOME] > 0) {
! 1750:
! 1751: tmp[tmpx++] = ';';
! 1752:
! 1753: if (xpos[HOME] > 8) tmp[tmpx++] = (1 + xpos[HOME]) / 10 + '0';
! 1754:
! 1755: tmp[tmpx++] = (1 + xpos[HOME]) % 10 + '0';
! 1756:
! 1757: }
! 1758:
! 1759: tmp[tmpx++] = 'H';
! 1760:
! 1761:
! 1762: #ifdef COLOR
! 1763:
! 1764: /* make sure cursor has right color */
! 1765: tmp[tmpx++] = ESC; /* background color */
! 1766: tmp[tmpx++] = '[';
! 1767: tmp[tmpx++] = '=';
! 1768:
! 1769: if (color / 16 > 9) tmp[tmpx++] = '0' + (color / 16 / 10);
! 1770:
! 1771: tmp[tmpx++] = '0' + (color / 16 % 10);
! 1772: tmp[tmpx++] = 'G';
! 1773: tmp[tmpx++] = ESC; /* reverse foreground col */
! 1774: tmp[tmpx++] = '[';
! 1775: tmp[tmpx++] = '=';
! 1776:
! 1777: if (color / 16 > 9) tmp[tmpx++] = '0' + (color / 16 / 10);
! 1778:
! 1779: tmp[tmpx++] = '0' + (color / 16 % 10);
! 1780: tmp[tmpx++] = 'H';
! 1781: tmp[tmpx++] = ESC; /* foreground color */
! 1782: tmp[tmpx++] = '[';
! 1783: tmp[tmpx++] = '=';
! 1784:
! 1785: if (color % 16 > 9) tmp[tmpx++] = '0' + (color % 16 / 10);
! 1786:
! 1787: tmp[tmpx++] = '0' + (color % 16 % 10);
! 1788: tmp[tmpx++] = 'F';
! 1789: tmp[tmpx++] = ESC; /* reverse background col */
! 1790: tmp[tmpx++] = '[';
! 1791: tmp[tmpx++] = '=';
! 1792:
! 1793: if (color % 16 > 9) tmp[tmpx++] = '0' + (color % 16 / 10);
! 1794:
! 1795: tmp[tmpx++] = '0' + (color % 16 % 10);
! 1796: tmp[tmpx++] = 'I';
! 1797: #endif /* COLOR */
! 1798:
! 1799: }
! 1800: else if (args[0] == 0) {
! 1801:
! 1802: (*screen).lin24 = FALSE;
! 1803:
! 1804: if ((*screen).sc_lo == 23) (*screen).sc_lo = 24;
! 1805:
! 1806: }
! 1807: else if (args[0] == 1) {
! 1808:
! 1809: (*screen).lin24 = TRUE;
! 1810:
! 1811: if ((*screen).sc_lo == 24) (*screen).sc_lo = 23;
! 1812:
! 1813: }
! 1814: else if (args[0] == 8) {
! 1815: (*screen).rollflag = FALSE;
! 1816: }
! 1817: else if (args[0] == 9) {
! 1818: (*screen).rollflag = TRUE;
! 1819: }
! 1820: #ifdef SCO
! 1821: else if (args[0] == 20) {
! 1822:
! 1823: (*screen).bw = FALSE;
! 1824:
! 1825: if (foreground) {
! 1826:
! 1827: tmp[tmpx] = EOL;
! 1828: m_output (tmp);
! 1829:
! 1830: tmpx = 0;
! 1831: part_ref (screen, 0, n_lines - 1);
! 1832:
! 1833: }
! 1834:
! 1835: }
! 1836: else if (args[0] == 21) {
! 1837:
! 1838: (*screen).bw = TRUE;
! 1839:
! 1840: if (foreground) {
! 1841:
! 1842: tmp[tmpx] = EOL;
! 1843: m_output (tmp);
! 1844:
! 1845: tmpx = 0;
! 1846: part_ref (screen, 0, n_lines - 1);
! 1847:
! 1848: }
! 1849:
! 1850: }
! 1851: #endif /* SCO */
! 1852:
! 1853: }
! 1854: else if (ch == 'X') { /* ECH Erase Character */
! 1855:
! 1856: if ((k = args[0]) < 1) k = 1;
! 1857: if ((k + xpos[HOME]) > n_columns) k = n_columns - xpos[HOME];
! 1858:
! 1859: i = xpos[HOME];
! 1860: k = i + k;
! 1861:
! 1862: while (i < k) {
! 1863:
! 1864: (*screen).screenx[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = SP;
! 1865: (*screen).screena[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = 0; /* not 'att' */
! 1866:
! 1867:
! 1868: #ifdef COLOR
! 1869: (*screen).screenc[(unsigned int) (*screen).sclines[ypos[HOME]]][i] = (*screen).col;
! 1870: #endif /* COLOR */
! 1871:
! 1872: i++;
! 1873:
! 1874: }
! 1875:
! 1876: } else if (ch == 'g') { /* TBC Tabulation clear */
! 1877:
! 1878: if (args[0] == 3) {
! 1879: /* clear all */
! 1880: for (i = 0; i < n_columns; (*screen).tabs[i++] = 0) ;
! 1881: }
! 1882: else if (args[0] == 0) {
! 1883: /* clear one */
! 1884: (*screen).tabs[xpos[HOME]] = 0;
! 1885: }
! 1886:
! 1887:
! 1888: #ifdef SCO
! 1889: while (tmpx >= 0) if (tmp[--tmpx] == ESC) break;
! 1890:
! 1891: tmp[tmpx] = NUL;
! 1892: ch = NUL;
! 1893: #endif /* SCO */
! 1894:
! 1895: }
! 1896: else if (ch == 'm') { /* SGR Select Graphic Rendition */
! 1897:
! 1898: (*screen).att &= 01; /* clear att */
! 1899:
! 1900:
! 1901: #ifdef SCO
! 1902: while (tmpx > 0 && tmp[--tmpx] != ESC);
! 1903:
! 1904: ch = CAN;
! 1905: #endif /* SCO */
! 1906:
! 1907: i = argcnt;
! 1908:
! 1909: while (i >= 0) {
! 1910:
! 1911: if (((*screen).savarg = (args[i] == 50))) continue;
! 1912:
! 1913:
! 1914: #ifdef SCO /* process save SGR(1) in position of SGR(2) */
! 1915: if (args[i] == 1) args[i] = 2;
! 1916: #endif /* SCO */
! 1917:
! 1918: #ifdef COLOR
! 1919: if (args[i] > 29 && args[i] < 38) { /* foregr.color */
! 1920: (*screen).col = ((*screen).col & ~017) | coltrans[args[i] - 30];
! 1921: }
! 1922:
! 1923: if (args[i] > 39 && args[i] < 48) { /* backgr.color */
! 1924: (*screen).col = (((*screen).col & 017) | (coltrans[args[i] - 40] * 16));
! 1925: }
! 1926:
! 1927: #endif /* COLOR */
! 1928:
! 1929: if (args[i] > 1 && args[i] < 9) (*screen).att |= (1 << (args[i] - 1));
! 1930: if (args[i] == 0) (*screen).att &= 01; /* clear att */
! 1931:
! 1932: i--;
! 1933:
! 1934: }
! 1935:
! 1936: #ifdef SCO
! 1937: tmp[tmpx++] = ESC;
! 1938: tmp[tmpx++] = '[';
! 1939: if ((*screen).bw) tmp[tmpx++] = '7';
! 1940:
! 1941: tmp[tmpx++] = 'm';
! 1942:
! 1943:
! 1944: #ifdef COLOR
! 1945: tmp[tmpx++] = ESC;
! 1946: tmp[tmpx++] = '[';
! 1947: tmp[tmpx++] = '=';
! 1948: if ((*screen).col / 16 > 9) tmp[tmpx++] = '0' + ((*screen).col / 16 / 10);
! 1949:
! 1950: tmp[tmpx++] = '0' + ((*screen).col / 16 % 10);
! 1951: tmp[tmpx++] = 'G';
! 1952: tmp[tmpx++] = ESC;
! 1953: tmp[tmpx++] = '[';
! 1954: tmp[tmpx++] = '=';
! 1955: if ((*screen).col / 16 > 9) tmp[tmpx++] = '0' + ((*screen).col / 16 / 10);
! 1956:
! 1957: tmp[tmpx++] = '0' + ((*screen).col / 16 % 10);
! 1958: tmp[tmpx++] = 'H';
! 1959: tmp[tmpx++] = ESC;
! 1960: tmp[tmpx++] = '[';
! 1961: tmp[tmpx++] = '=';
! 1962: if ((*screen).col % 16 > 9) tmp[tmpx++] = '0' + ((*screen).col % 16 / 10);
! 1963:
! 1964: tmp[tmpx++] = '0' + ((*screen).col % 16 % 10);
! 1965: tmp[tmpx++] = 'F';
! 1966: tmp[tmpx++] = ESC;
! 1967: tmp[tmpx++] = '[';
! 1968: tmp[tmpx++] = '=';
! 1969: if ((*screen).col % 16 > 9) tmp[tmpx++] = '0' + ((*screen).col % 16 / 10);
! 1970:
! 1971: tmp[tmpx++] = '0' + ((*screen).col % 16 % 10);
! 1972: tmp[tmpx++] = 'I';
! 1973: #endif /* COLOR */
! 1974:
! 1975: if ((*screen).att & ~01) {
! 1976:
! 1977: int j;
! 1978:
! 1979: j = scosgr ((*screen).att & ~01, (*screen).bw);
! 1980:
! 1981: tmp[tmpx++] = ESC;
! 1982: tmp[tmpx++] = '[';
! 1983:
! 1984: if (j & 02) {
! 1985: tmp[tmpx++] = '1';
! 1986: tmp[tmpx++] = ';';
! 1987: }
! 1988:
! 1989: if (j & 04) {
! 1990: tmp[tmpx++] = '3';
! 1991: tmp[tmpx++] = ';';
! 1992: }
! 1993:
! 1994: if (j & 010) {
! 1995: tmp[tmpx++] = '4';
! 1996: tmp[tmpx++] = ';';
! 1997: }
! 1998:
! 1999: if (j & 020) {
! 2000: tmp[tmpx++] = '5';
! 2001: tmp[tmpx++] = ';';
! 2002: }
! 2003:
! 2004: if (j & 040) {
! 2005: tmp[tmpx++] = '6';
! 2006: tmp[tmpx++] = ';';
! 2007: }
! 2008:
! 2009: if (j & 0100) {
! 2010: tmp[tmpx++] = '7';
! 2011: tmp[tmpx++] = ';';
! 2012: }
! 2013:
! 2014: if (j & 0200) {
! 2015: tmp[tmpx++] = '8';
! 2016: tmp[tmpx++] = ';';
! 2017: }
! 2018:
! 2019: if (tmp[tmpx - 1] == ';') tmpx--;
! 2020:
! 2021: tmp[tmpx++] = 'm';
! 2022:
! 2023: }
! 2024: #endif /* SCO */
! 2025:
! 2026: }
! 2027: else if (ch == 'P') { /* DCH Delete Character */
! 2028: int j;
! 2029:
! 2030: if ((j = args[0]) == 0) j = 1;
! 2031:
! 2032: k = (*screen).sclines[ypos[HOME]];
! 2033:
! 2034: for (i = xpos[HOME]; i < (n_columns - j); i++) {
! 2035:
! 2036: (*screen).screenx[k][i] = (*screen).screenx[k][i + j];
! 2037: (*screen).screena[k][i] = (*screen).screena[k][i + j];
! 2038:
! 2039:
! 2040: #ifdef COLOR
! 2041: (*screen).screenc[k][i] = (*screen).screenc[k][i + j];
! 2042: #endif /* COLOR */
! 2043:
! 2044: }
! 2045:
! 2046: for (; i < n_columns; i++) {
! 2047:
! 2048: (*screen).screenx[k][i] = SP;
! 2049: (*screen).screena[k][i] = (*screen).att;
! 2050:
! 2051:
! 2052: #ifdef COLOR
! 2053: (*screen).screenc[k][i] = (*screen).col;
! 2054: #endif /* COLOR */
! 2055:
! 2056: }
! 2057:
! 2058:
! 2059: } else if (ch == '@') { /* ICH Insert Character */
! 2060: int j;
! 2061:
! 2062: if ((j = args[0]) == 0) j = 1;
! 2063:
! 2064: k = (*screen).sclines[ypos[HOME]];
! 2065:
! 2066: for (i = (n_columns - 1); i >= (xpos[HOME] + j); i--) {
! 2067:
! 2068: (*screen).screenx[k][i] = (*screen).screenx[k][i - j];
! 2069: (*screen).screena[k][i] = (*screen).screena[k][i - j];
! 2070:
! 2071:
! 2072: #ifdef COLOR
! 2073: (*screen).screenc[k][i] = (*screen).screenc[k][i - j];
! 2074: #endif /* COLOR */
! 2075:
! 2076: }
! 2077:
! 2078: for (; i >= xpos[HOME]; i--) {
! 2079:
! 2080: (*screen).screenx[k][i] = SP;
! 2081: (*screen).screena[k][i] = (*screen).att;
! 2082:
! 2083:
! 2084: #ifdef COLOR
! 2085: (*screen).screenc[k][i] = (*screen).col;
! 2086: #endif /* COLOR */
! 2087:
! 2088: }
! 2089:
! 2090: } else if (ch == 'M') { /* DL Delete Line */
! 2091: int j = args[0];
! 2092:
! 2093: do {
! 2094:
! 2095: k = (*screen).sclines[ypos[HOME]];
! 2096:
! 2097: for (i = ypos[HOME]; i < (*screen).sc_lo; i++) (*screen).sclines[i] = (*screen).sclines[i + 1];
! 2098:
! 2099: (*screen).sclines[i] = k;
! 2100:
! 2101: for (i = 0; i < n_columns; i++) {
! 2102:
! 2103: (*screen).screenx[k][i] = SP;
! 2104: (*screen).screena[k][i] = (*screen).att;
! 2105:
! 2106:
! 2107: #ifdef COLOR
! 2108: (*screen).screenc[k][i] = (*screen).col;
! 2109: #endif /* COLOR */
! 2110:
! 2111: }
! 2112:
! 2113: } while (--j > 0);
! 2114:
! 2115: xpos[HOME] = 0;
! 2116:
! 2117:
! 2118: #ifdef SCO
! 2119: if (foreground) {
! 2120:
! 2121: tmp[tmpx - 1] = CAN; /* do not send DL */
! 2122: tmp[tmpx] = EOL;
! 2123: m_output (tmp);
! 2124:
! 2125: tmpx = 0;
! 2126: part_ref (screen, (*screen).sc_up, n_lines - 1);
! 2127:
! 2128: }
! 2129:
! 2130: #endif /* SCO */
! 2131:
! 2132: }
! 2133: else if (ch == 'L') { /* IL Insert Line */
! 2134: int j = args[0];
! 2135:
! 2136: do {
! 2137: k = (*screen).sclines[(*screen).sc_lo];
! 2138:
! 2139: for (i = (*screen).sc_lo; i > ypos[HOME]; i--) {
! 2140: (*screen).sclines[i] = (*screen).sclines[i - 1];
! 2141: }
! 2142:
! 2143: (*screen).sclines[ypos[HOME]] = k;
! 2144:
! 2145: for (i = 0; i < n_columns; i++) {
! 2146:
! 2147: (*screen).screenx[k][i] = SP;
! 2148: (*screen).screena[k][i] = (*screen).att;
! 2149:
! 2150:
! 2151: #ifdef COLOR
! 2152: (*screen).screenc[k][i] = (*screen).col;
! 2153: #endif /* COLOR */
! 2154:
! 2155: }
! 2156: } while (--j > 0);
! 2157:
! 2158: xpos[HOME] = 0;
! 2159:
! 2160:
! 2161: #ifdef SCO
! 2162: if (foreground) {
! 2163:
! 2164: tmp[tmpx - 1] = CAN; /* do not send IL */
! 2165: tmp[tmpx] = EOL;
! 2166: m_output (tmp);
! 2167:
! 2168: tmpx = 0;
! 2169: part_ref (screen, (*screen).sc_up, n_lines - 1);
! 2170:
! 2171: }
! 2172: #endif /* SCO */
! 2173:
! 2174: }
! 2175: else if (ch == 'S') { /* SU Scroll up */
! 2176: int j = args[0];
! 2177:
! 2178: do {
! 2179:
! 2180: k = (*screen).sclines[(*screen).sc_up];
! 2181:
! 2182: for (i = (*screen).sc_up; i < (*screen).sc_lo; i++) {
! 2183: (*screen).sclines[i] = (*screen).sclines[i + 1];
! 2184: }
! 2185:
! 2186: (*screen).sclines[i] = k;
! 2187:
! 2188: for (i = 0; i < n_columns; i++) {
! 2189:
! 2190: (*screen).screenx[k][i] = SP;
! 2191: (*screen).screena[k][i] = (*screen).att;
! 2192:
! 2193:
! 2194: #ifdef COLOR
! 2195: (*screen).screenc[k][i] = (*screen).col;
! 2196: #endif /* COLOR */
! 2197:
! 2198: }
! 2199:
! 2200: } while (--j > 0);
! 2201:
! 2202:
! 2203: #ifdef SCO
! 2204: if (foreground) {
! 2205:
! 2206: tmp[tmpx - 1] = 'A'; /* do not send SU */
! 2207: tmp[tmpx] = EOL;
! 2208: m_output (tmp);
! 2209:
! 2210: tmpx = 0;
! 2211: part_ref (screen, (*screen).sc_up, n_lines - 1);
! 2212:
! 2213: }
! 2214: #endif /* SCO */
! 2215:
! 2216: }
! 2217: else if (ch == 'T') { /* SD Scroll down */
! 2218:
! 2219: int j = args[0];
! 2220:
! 2221: do {
! 2222:
! 2223: k = (*screen).sclines[(*screen).sc_lo];
! 2224:
! 2225: for (i = (*screen).sc_lo; i > (*screen).sc_up; i--) {
! 2226: (*screen).sclines[i] = (*screen).sclines[i - 1];
! 2227: }
! 2228:
! 2229: (*screen).sclines[i] = k;
! 2230:
! 2231: for (i = 0; i < n_columns; i++) {
! 2232:
! 2233: (*screen).screenx[k][i] = SP;
! 2234: (*screen).screena[k][i] = (*screen).att;
! 2235:
! 2236:
! 2237: #ifdef COLOR
! 2238: (*screen).screenc[k][i] = (*screen).col;
! 2239: #endif /* COLOR */
! 2240:
! 2241: }
! 2242:
! 2243: } while (--j > 0);
! 2244:
! 2245:
! 2246: #ifdef SCO
! 2247:
! 2248: if (foreground) {
! 2249:
! 2250: tmp[tmpx - 1] = 'A'; /* do not send SD */
! 2251: tmp[tmpx] = EOL;
! 2252: m_output (tmp);
! 2253:
! 2254: tmpx = 0;
! 2255: part_ref (screen, (*screen).sc_up, n_lines - 1);
! 2256:
! 2257: }
! 2258:
! 2259: #endif /* SCO */
! 2260:
! 2261: } else if (ch == 'Z') { /* CBT Cursor backward tab */
! 2262:
! 2263: if ((i = xpos[HOME] - 1) < 1) i = 1;
! 2264:
! 2265: do {
! 2266:
! 2267: while ((*screen).tabs[--i] == 0) {
! 2268:
! 2269: if (i < 0) {
! 2270: i++;
! 2271: break;
! 2272: }
! 2273:
! 2274: }
! 2275:
! 2276: if (i == 0) break;
! 2277:
! 2278: } while (args[0]-- > 0);
! 2279:
! 2280: xpos[HOME] = i;
! 2281:
! 2282:
! 2283: #ifdef PROC_TAB
! 2284: tmp[tmpx++] = CR;
! 2285:
! 2286: if ((xpos[HOME] = i) != 0) {
! 2287:
! 2288: tmp[tmpx++] = ESC;
! 2289: tmp[tmpx++] = '[';
! 2290:
! 2291: if (i > 9) tmp[tmpx++] = i / 10 + '0';
! 2292:
! 2293: tmp[tmpx++] = i % 10 + '0';
! 2294: tmp[tmpx++] = 'C';
! 2295:
! 2296: }
! 2297:
! 2298: #endif /* PROC_TAB */
! 2299:
! 2300: }
! 2301:
! 2302: if (ch != '~') goto zasend;
! 2303:
! 2304: /* ZAS Alternate Screen stuff */
! 2305: /* the following is better programmed with */
! 2306: /* 'switch' but some compilers do not have */
! 2307: /* enough power to swallow the implied stack */
! 2308: /* depth */
! 2309: /* switch (args[0]) */
! 2310:
! 2311: i = args[0];
! 2312:
! 2313: if (i == 1) goto zas1;
! 2314: if (i == 2) goto zas2;
! 2315: if (i == 3) goto zas3;
! 2316: if (i == 4) goto zas4;
! 2317: if (i == 5) goto zas5;
! 2318: if (i != 0) goto zas6;
! 2319:
! 2320: /* zas0: exchange foreground/background */
! 2321: tmp[tmpx] = EOL;
! 2322: tmpx = 0;
! 2323:
! 2324: if (foreground) m_output (tmp);
! 2325:
! 2326: /* exchange parameters of screen */
! 2327: (*screen).Xpos = xpos[HOME];
! 2328: (*screen).Ypos = ypos[HOME];
! 2329:
! 2330: vts = screen;
! 2331: screen = altscr;
! 2332: altscr = vts;
! 2333:
! 2334: xpos[HOME] = (*screen).Xpos;
! 2335: ypos[HOME] = (*screen).Ypos;
! 2336:
! 2337:
! 2338: zas4: /* refresh foreground */
! 2339:
! 2340: tmpx = 0;
! 2341:
! 2342: if (foreground) part_ref (screen, 0, n_lines - 1);
! 2343:
! 2344: goto zasend;
! 2345:
! 2346:
! 2347: zas1: /* foreground screen */
! 2348:
! 2349: if (foreground) goto zasend;
! 2350:
! 2351: foreground = TRUE;
! 2352:
! 2353:
! 2354: pPRIVATE: /* exchange parameters of screen */
! 2355:
! 2356: (*screen).Xpos = xpos[HOME];
! 2357: (*screen).Ypos = ypos[HOME];
! 2358:
! 2359: vts = screen;
! 2360: screen = altscr;
! 2361: altscr = vts;
! 2362:
! 2363: xpos[HOME] = (*screen).Xpos;
! 2364: ypos[HOME] = (*screen).Ypos;
! 2365:
! 2366: tmpx = 0;
! 2367:
! 2368: goto zasend;
! 2369:
! 2370:
! 2371: zas2: /* background screen */
! 2372:
! 2373: if (foreground == FALSE) goto zasend;
! 2374:
! 2375: tmp[tmpx] = EOL;
! 2376: m_output (tmp);
! 2377:
! 2378: foreground = FALSE;
! 2379:
! 2380: goto pPRIVATE;
! 2381:
! 2382:
! 2383: zas3: /* save foreground to back */
! 2384:
! 2385: stcpy0 ((char *) altscr, (const char *) screen, sizeof (struct vtstyp));
! 2386:
! 2387: goto zasend;
! 2388:
! 2389:
! 2390: zas5: /* push screen */
! 2391:
! 2392: if (zaslevel >= MAXZAS) goto zasend;
! 2393:
! 2394: vts = (struct vtstyp *) calloc (1, sizeof (struct vtstyp));
! 2395: zases[zaslevel++] = vts;
! 2396:
! 2397: (*screen).Xpos = xpos[HOME];
! 2398: (*screen).Ypos = ypos[HOME];
! 2399:
! 2400: stcpy0 ((char *) vts, (const char *) screen, sizeof (struct vtstyp));
! 2401:
! 2402: goto zasend;
! 2403:
! 2404:
! 2405: zas6: /* pop screen */
! 2406:
! 2407: if (--zaslevel < 0) {
! 2408: zaslevel = 0;
! 2409: goto zasend;
! 2410: }
! 2411:
! 2412: vts = zases[zaslevel];
! 2413:
! 2414:
! 2415: #ifdef SCO
! 2416: i = (*screen).bw; /* do not pop bw state */
! 2417: #endif /* SCO */
! 2418:
! 2419: stcpy0 ((char *) screen, (const char *) vts, sizeof (struct vtstyp));
! 2420:
! 2421:
! 2422: #ifdef SCO
! 2423: (*screen).bw = i;
! 2424: #endif /* SCO */
! 2425:
! 2426: xpos[HOME] = (*screen).Xpos;
! 2427: ypos[HOME] = (*screen).Ypos;
! 2428:
! 2429: free (vts);
! 2430:
! 2431: goto zas4;
! 2432: /* end zas6 */
! 2433:
! 2434:
! 2435: zasend: /* stuf we do when we're finished doing other zassy things */
! 2436:
! 2437: argcnt = 0;
! 2438: noargs = TRUE;
! 2439: esc = 0;
! 2440:
! 2441: continue;
! 2442:
! 2443: } /* end 'printable' characters */
! 2444:
! 2445: if ((esc = (ch == ESC))) {
! 2446:
! 2447: for (ch = 0; ch < ARGS_IN_ESC; args[ch++] = 0);
! 2448:
! 2449: argcnt = 0;
! 2450: noargs = TRUE;
! 2451:
! 2452: continue;
! 2453:
! 2454: }
! 2455:
! 2456: if (ch == LF) {
! 2457:
! 2458:
! 2459: pLF:
! 2460:
! 2461: if ((ypos[HOME] <= (*screen).sc_up) || (ypos[HOME] > (*screen).sc_lo)) {
! 2462:
! 2463: if (++ypos[HOME] >= (n_lines - 1)) {
! 2464: ypos[HOME] = (n_lines - 1);
! 2465: }
! 2466:
! 2467: if (ch == LF) tmpx--;
! 2468:
! 2469: tmp[tmpx++] = ESC;
! 2470: tmp[tmpx++] = '[';
! 2471:
! 2472: if (ypos[HOME] > 8) tmp[tmpx++] = (1 + ypos[HOME]) / 10 + '0';
! 2473:
! 2474: tmp[tmpx++] = (1 + ypos[HOME]) % 10 + '0';
! 2475:
! 2476: if (xpos[HOME] > 0) {
! 2477:
! 2478: tmp[tmpx++] = ';';
! 2479:
! 2480: if (xpos[HOME] > 8) tmp[tmpx++] = (1 + xpos[HOME]) / 10 + '0';
! 2481:
! 2482: tmp[tmpx++] = (1 + xpos[HOME]) % 10 + '0';
! 2483:
! 2484: }
! 2485:
! 2486: tmp[tmpx++] = 'H';
! 2487:
! 2488: }
! 2489: else if (ypos[HOME] < (*screen).sc_lo) {
! 2490:
! 2491: /* within scroll area */
! 2492: if (++ypos[HOME] >= (n_lines - 1)) {
! 2493: ypos[HOME] = (n_lines - 1);
! 2494: }
! 2495:
! 2496: }
! 2497: else {
! 2498:
! 2499: /* lower margin of scroll area: scroll up */
! 2500: xpos[HOME] = 0;
! 2501:
! 2502:
! 2503: #ifdef SCO
! 2504: if ((ch != LF) && (!(*screen).lin24) && (ypos[HOME] == (*screen).sc_lo) && (ypos[HOME] == n_lines - 1)) {
! 2505: continue;
! 2506: }
! 2507: #endif /* SCO */
! 2508:
! 2509: /* TODO: find out what 'rollflag' is */
! 2510: /* if ((*screen).rollflag==FALSE) continue; */
! 2511: k = (*screen).sclines[(*screen).sc_up];
! 2512:
! 2513: for (i = (*screen).sc_up; i < (*screen).sc_lo; i++) {
! 2514: (*screen).sclines[i] = (*screen).sclines[i + 1];
! 2515: }
! 2516:
! 2517: (*screen).sclines[(*screen).sc_lo] = k;
! 2518:
! 2519: for (i = 0; i < n_columns; i++) {
! 2520:
! 2521: (*screen).screenx[k][i] = SP;
! 2522: (*screen).screena[k][i] = (*screen).att;
! 2523:
! 2524: #ifdef COLOR
! 2525: (*screen).screenc[k][i] = (*screen).col;
! 2526: #endif /* COLOR */
! 2527:
! 2528: }
! 2529:
! 2530:
! 2531: #ifdef SCO
! 2532: tmp[tmpx] = EOL;
! 2533: tmpx = 0;
! 2534:
! 2535: if (foreground) {
! 2536: m_output (tmp);
! 2537: part_ref (screen, (*screen).sc_up, (*screen).sc_lo);
! 2538: }
! 2539: #endif /* SCO */
! 2540:
! 2541: }
! 2542:
! 2543: continue;
! 2544:
! 2545: } /* if (ch == LF) */
! 2546:
! 2547: if (ch == CR) {
! 2548: xpos[HOME] = 0;
! 2549: continue;
! 2550: }
! 2551:
! 2552: if (ch == BS) {
! 2553:
! 2554: if (--xpos[HOME] < 0) xpos[HOME] = 0;
! 2555:
! 2556: continue;
! 2557:
! 2558: }
! 2559:
! 2560: /* FORM FEED: clear screen */
! 2561: if (ch == FF) {
! 2562:
! 2563: xpos[HOME] = 0;
! 2564: ypos[HOME] = 0;
! 2565:
! 2566: ch = 'J';
! 2567:
! 2568: tmp[tmpx - 1] = ESC;
! 2569: tmp[tmpx++] = '[';
! 2570: tmp[tmpx++] = 'H';
! 2571: tmp[tmpx++] = ESC;
! 2572: tmp[tmpx++] = '[';
! 2573: tmp[tmpx++] = ch;
! 2574:
! 2575: args[0] = 0;
! 2576: noargs = TRUE;
! 2577: argcnt = 0;
! 2578:
! 2579: goto ED;
! 2580:
! 2581: }
! 2582:
! 2583: if (ch == TAB) {
! 2584:
! 2585: k = xpos[HOME];
! 2586:
! 2587: if ((i = k + 1) >= n_columns) i = (n_columns - 1);
! 2588:
! 2589: while ((*screen).tabs[i] == 0) {
! 2590:
! 2591: if (i >= n_columns) {
! 2592: i = (n_columns - 1);
! 2593: break;
! 2594: }
! 2595:
! 2596: i++;
! 2597:
! 2598: }
! 2599:
! 2600:
! 2601: #ifdef PROC_TAB
! 2602: if (i != k) {
! 2603:
! 2604: tmp[tmpx++] = CR;
! 2605:
! 2606: if ((xpos[HOME] = i) != 0) {
! 2607:
! 2608: tmp[tmpx++] = ESC;
! 2609: tmp[tmpx++] = '[';
! 2610:
! 2611: if (i > 9) tmp[tmpx++] = i / 10 + '0';
! 2612:
! 2613: tmp[tmpx++] = i % 10 + '0';
! 2614: tmp[tmpx++] = 'C';
! 2615:
! 2616: }
! 2617:
! 2618: }
! 2619: #endif /* PROC_TAB */
! 2620:
! 2621: continue;
! 2622: }
! 2623:
! 2624: /* SI Shift In */
! 2625: if (ch == SI) (*screen).att &= ~01; /* clear SO-Bit */
! 2626:
! 2627: /* SO Shift Out */
! 2628: if (ch == SO) (*screen).att |= 01; /* set SO-Bit */
! 2629:
! 2630: if (ch == CAN) { /* CANcel ESC_esquence */
! 2631: esc = argcnt = noargs = 0;
! 2632: continue;
! 2633: }
! 2634:
! 2635: } /* end while */
! 2636:
! 2637: tmp[tmpx] = EOL;
! 2638:
! 2639: if (foreground) m_output (tmp);
! 2640:
! 2641: return;
! 2642:
! 2643: } /* end writeHOME() */
! 2644:
! 2645:
! 2646: #ifdef SCO
! 2647:
! 2648: /*att screen attributes byte */
! 2649: /*bwflag black_on_white flag */
! 2650: int scosgr (short att, short bwflag)
! 2651: {
! 2652:
! 2653: att = att & ~044; /* suppress SGR(3) and SGR(6) */
! 2654:
! 2655: if (att & 0200) return att & 0201; /* no display */
! 2656: if (bwflag) att ^= 0100; /* toggle inverse */
! 2657: if (att & 0100) return att & 0121; /* inverse, evtl. incl. blink */
! 2658: if (att & 032) return att & 033; /* other valid combinations */
! 2659:
! 2660: return att;
! 2661:
! 2662: } /* end scosgr() */
! 2663:
! 2664: #endif /* SCO */
! 2665:
! 2666: /* init Screen params */
! 2667: void ris (struct vtstyp *scr)
! 2668: {
! 2669: short i;
! 2670: short l;
! 2671:
! 2672: scr->att = 0;
! 2673:
! 2674: #ifdef COLOR
! 2675: scr->col = 7; /* default color is white on black */
! 2676: #endif /* COLOR */
! 2677:
! 2678: scr->Xpos = 0;
! 2679: scr->Ypos = 0;
! 2680:
! 2681: for (i = 0; i < CSLEN; i++) {
! 2682: scr->csx[i] = 0;
! 2683: scr->csy[i] = 0;
! 2684: }
! 2685:
! 2686: scr->cs = 0;
! 2687: scr->sc_up = 0;
! 2688: scr->sc_lo = n_lines;
! 2689:
! 2690: for (i = 0; i <= n_lines; i++) {
! 2691:
! 2692: scr->sclines[i] = i;
! 2693:
! 2694: for (l = 0; l < n_columns; l++) {
! 2695:
! 2696: scr->screenx[i][l] = SP;
! 2697: scr->screena[i][l] = 0;
! 2698:
! 2699:
! 2700: #ifdef COLOR
! 2701: scr->screenc[i][l] = 7; /* default color is white on black */
! 2702: #endif /* COLOR */
! 2703:
! 2704: }
! 2705:
! 2706: }
! 2707:
! 2708: /* TABS */
! 2709: for (i = 0; i <= n_columns; i++) scr->tabs[i] = 0;
! 2710: for (i = 7; i <= n_columns; i += 8) scr->tabs[i] = 1;
! 2711:
! 2712: scr->rollflag = TRUE; /* Roll or Page mode */
! 2713: scr->lin24 = FALSE; /* 24 lines or 25 lines mode (MUST BE FALSE!!!!) */
! 2714: scr->savarg = FALSE;
! 2715:
! 2716: for (i = 0; i < CSLEN; i++) scr->cssgr[i] = FALSE; /* save SGR flag */
! 2717:
! 2718: return;
! 2719:
! 2720: } /* end ris() */
! 2721:
! 2722: /* refresh (foreground) screen partially */
! 2723: void part_ref (struct vtstyp *scr, short from, short to)
! 2724: {
! 2725: short k;
! 2726: short l;
! 2727: short max;
! 2728: unsigned char exa;
! 2729: unsigned char exc;
! 2730: short i;
! 2731: unsigned char *linea;
! 2732: unsigned char *linex;
! 2733: unsigned char *linec;
! 2734: unsigned char ch;
! 2735: unsigned char tmp[1300];
! 2736:
! 2737: /* build up alternate screen */
! 2738: /* reset SGR,TBM;white on black,go HOME; 25 Lines */
! 2739: stcpy (tmp, "\017\033[m\033[37;40m\033[r\033[H\033[0u\201");
! 2740: m_output (tmp);
! 2741:
! 2742:
! 2743: #ifndef PROC_TAB
! 2744:
! 2745: k = 0;
! 2746: i = 0; /* set TABs */
! 2747:
! 2748: tmp[k++] = ESC;
! 2749: tmp[k++] = '[';
! 2750:
! 2751: if (from > 8) tmp[k++] = '0' + (from + 1) / 10;
! 2752:
! 2753: tmp[k++] = '0' + (from + 1) % 10;
! 2754: tmp[k++] = 'H';
! 2755:
! 2756: for (l = 0; l < n_columns; l++) {
! 2757:
! 2758: tmp[k++] = SP;
! 2759:
! 2760: if ((*scr).tabs[l]) {
! 2761:
! 2762: tmp[k++] = ESC;
! 2763: tmp[k++] = 'H';
! 2764:
! 2765: i = k;
! 2766:
! 2767: }
! 2768:
! 2769: }
! 2770:
! 2771: tmp[i++] = CR;
! 2772: tmp[i] = EOL;
! 2773: m_output (tmp);
! 2774:
! 2775: #endif /* PROC_TAB */
! 2776:
! 2777: k = 0;
! 2778:
! 2779: for (i = from; i <= to; i++) {
! 2780:
! 2781: tmp[k++] = ESC; /* CUP(i) */
! 2782: tmp[k++] = '[';
! 2783:
! 2784: if (i > 8) tmp[k++] = (i + 1) / 10 + '0';
! 2785: if (i > 0) tmp[k++] = (i + 1) % 10 + '0';
! 2786:
! 2787: tmp[k++] = 'H';
! 2788:
! 2789: linex = (*scr).screenx[(unsigned int) (*scr).sclines[i]];
! 2790: linea = (*scr).screena[(unsigned int) (*scr).sclines[i]];
! 2791:
! 2792: #ifdef COLOR
! 2793: linec = (*scr).screenc[(unsigned int) (*scr).sclines[i]];
! 2794: #endif /* COLOR */
! 2795:
! 2796: for (max = n_columns - 1; max > 0; max--) {
! 2797:
! 2798: if (linex[max] != SP) break;
! 2799: if (linea[max] != linea[max - 1]) break;
! 2800: if (linec[max] != linec[max - 1]) break;
! 2801:
! 2802: }
! 2803:
! 2804: exa = ~linea[0]; /* dummy value to trigger argument codes on 1st char */
! 2805: exc = ~linec[0]; /* dummy value to trigger argument codes on 1st char */
! 2806:
! 2807: for (l = 0; l <= max; l++) {
! 2808:
! 2809: if (l == (n_columns - 1) && (i == (n_lines))) continue;
! 2810:
! 2811: #ifndef LINUX
! 2812: #ifdef COLOR
! 2813: if (exc != linec[l]) { /* set color */
! 2814:
! 2815: if ((exc / 16) != (linec[l] / 16)) { /* background color */
! 2816:
! 2817: tmp[k++] = ESC;
! 2818: tmp[k++] = '[';
! 2819: tmp[k++] = '=';
! 2820: tmp[k++] = '0';
! 2821:
! 2822: if (linec[l] / 16 > 9) tmp[k++] = '0' + linec[l] / 16 / 10;
! 2823:
! 2824: tmp[k++] = '0' + linec[l] / 16 % 10;
! 2825: tmp[k++] = 'G';
! 2826: tmp[k++] = ESC; /* background == reverse foreground */
! 2827: tmp[k++] = '[';
! 2828: tmp[k++] = '=';
! 2829: tmp[k++] = '0';
! 2830:
! 2831: if (linec[l] / 16 > 9) tmp[k++] = '0' + linec[l] / 16 / 10;
! 2832:
! 2833: tmp[k++] = '0' + linec[l] / 16 % 10;
! 2834: tmp[k++] = 'H';
! 2835:
! 2836: }
! 2837:
! 2838: if ((exc % 16) != (linec[l] % 16)) { /* foreground color */
! 2839:
! 2840: tmp[k++] = ESC;
! 2841: tmp[k++] = '[';
! 2842: tmp[k++] = '=';
! 2843: tmp[k++] = '0';
! 2844:
! 2845: if (linec[l] % 16 > 9) tmp[k++] = '0' + linec[l] % 16 / 10;
! 2846:
! 2847: tmp[k++] = '0' + linec[l] % 16 % 10;
! 2848: tmp[k++] = 'F';
! 2849: tmp[k++] = ESC; /* foreground == reverse background */
! 2850: tmp[k++] = '[';
! 2851: tmp[k++] = '=';
! 2852: tmp[k++] = '0';
! 2853:
! 2854: if (linec[l] % 16 > 9) tmp[k++] = '0' + linec[l] % 16 / 10;
! 2855:
! 2856: tmp[k++] = '0' + linec[l] % 16 % 10;
! 2857: tmp[k++] = 'I';
! 2858:
! 2859: }
! 2860:
! 2861: exc = linec[l];
! 2862:
! 2863: }
! 2864:
! 2865: #endif /* COLOR */
! 2866: #endif /* LINUX */
! 2867:
! 2868: if (exa != linea[l]) { /* set attribute */
! 2869:
! 2870: short p;
! 2871: short xatt;
! 2872:
! 2873: p = exa;
! 2874: exa = linea[l];
! 2875:
! 2876: if ((p & 01) != (exa & 01)) tmp[k++] = (exa & 01) ? SO : SI;
! 2877:
! 2878: if ((p & ~01) != (exa & ~01)) {
! 2879:
! 2880: xatt = exa;
! 2881:
! 2882:
! 2883: #ifdef SCO
! 2884: xatt = scosgr (xatt, (*scr).bw);
! 2885: #endif /* SCO */
! 2886:
! 2887: tmp[k++] = ESC;
! 2888: tmp[k++] = '[';
! 2889:
! 2890:
! 2891: #ifdef SCO
! 2892: if ((*scr).bw) tmp[k++] = '7';
! 2893: #endif /* SCO */
! 2894:
! 2895: tmp[k++] = 'm';
! 2896: tmp[k++] = ESC;
! 2897: tmp[k++] = '[';
! 2898:
! 2899: if (xatt & 02) {
! 2900:
! 2901:
! 2902: #ifdef SCO
! 2903: tmp[k++] = '1';
! 2904: #else
! 2905: tmp[k++] = '2';
! 2906: #endif /* SCO */
! 2907:
! 2908: tmp[k++] = ';';
! 2909: }
! 2910:
! 2911: if (xatt & 04) {
! 2912: tmp[k++] = '3';
! 2913: tmp[k++] = ';';
! 2914: }
! 2915:
! 2916: if (xatt & 010) {
! 2917: tmp[k++] = '4';
! 2918: tmp[k++] = ';';
! 2919: }
! 2920:
! 2921: if (xatt & 020) {
! 2922: tmp[k++] = '5';
! 2923: tmp[k++] = ';';
! 2924: }
! 2925:
! 2926: if (xatt & 040) {
! 2927: tmp[k++] = '6';
! 2928: tmp[k++] = ';';
! 2929: }
! 2930:
! 2931: if (xatt & 0100) {
! 2932: tmp[k++] = '7';
! 2933: tmp[k++] = ';';
! 2934: }
! 2935:
! 2936: if (xatt & 0200) {
! 2937: tmp[k++] = '8';
! 2938: tmp[k++] = ';';
! 2939: }
! 2940:
! 2941: if (tmp[k - 1] == ';') k--;
! 2942:
! 2943: tmp[k++] = 'm';
! 2944:
! 2945: }
! 2946:
! 2947: }
! 2948:
! 2949: tmp[k++] = linex[l];
! 2950:
! 2951: }
! 2952:
! 2953: if (max + 1 < n_columns) {
! 2954: tmp[k++] = ESC;
! 2955: tmp[k++] = '[';
! 2956: tmp[k++] = 'K';
! 2957: }
! 2958:
! 2959: tmp[k] = EOL;
! 2960: k = mcmnd;
! 2961: mcmnd = 'w';
! 2962: ch = (*codptr);
! 2963: *codptr = ',';
! 2964:
! 2965: m_output (tmp);
! 2966:
! 2967: *codptr = ch;
! 2968: mcmnd = k;
! 2969:
! 2970: k = 0;
! 2971:
! 2972: }
! 2973:
! 2974: /* 'saved' cursor position */
! 2975: /* actual cursor position & actual attribute */
! 2976: /* 'flush' output */
! 2977: k = 0;
! 2978:
! 2979:
! 2980: #ifndef SCO
! 2981:
! 2982: tmp[k++] = ESC; /* restore CursorSave Position */
! 2983: tmp[k++] = '[';
! 2984: i = (*scr).csy[(*scr).cs] + 1;
! 2985:
! 2986: if (i > 9) tmp[k++] = '0' + i / 10;
! 2987:
! 2988: tmp[k++] = '0' + i % 10;
! 2989: tmp[k++] = ';';
! 2990:
! 2991: i = (*scr).csx[(*scr).cs] + 1;
! 2992:
! 2993: if (i > 9) tmp[k++] = '0' + i / 10;
! 2994:
! 2995: tmp[k++] = '0' + i % 10;
! 2996: tmp[k++] = 'H';
! 2997: tmp[k++] = ESC; /* DEC Cursor SAVE */
! 2998: tmp[k++] = '7';
! 2999: tmp[k++] = ESC; /* ANSI (?) Cursor SAVE */
! 3000: tmp[k++] = '[';
! 3001: tmp[k++] = 's';
! 3002: tmp[k++] = ESC; /* restore 24/25 line mode */
! 3003: tmp[k++] = '[';
! 3004: tmp[k++] = '0' + (*scr).lin24;
! 3005: tmp[k++] = 'u';
! 3006: tmp[k++] = ESC; /* restore Scroll area */
! 3007: tmp[k++] = '[';
! 3008:
! 3009: if (((*scr).sc_up) > 8) tmp[k++] = '0' + ((*scr).sc_up + 1) / 10;
! 3010:
! 3011: tmp[k++] = '0' + ((*scr).sc_up + 1) % 10;
! 3012: tmp[k++] = ';';
! 3013:
! 3014: if (((*scr).sc_lo) > 8) tmp[k++] = '0' + ((*scr).sc_lo + 1) / 10;
! 3015:
! 3016: tmp[k++] = '0' + ((*scr).sc_lo + 1) % 10;
! 3017: tmp[k++] = 'r';
! 3018:
! 3019: #endif /* not SCO */
! 3020:
! 3021: #ifndef LINUX
! 3022: #ifdef COLOR
! 3023:
! 3024: tmp[k++] = ESC; /* restore foreground color */
! 3025: tmp[k++] = '[';
! 3026: tmp[k++] = '=';
! 3027:
! 3028: if (((*scr).col) % 16 > 9) tmp[k++] = '0' + ((*scr).col) % 16 / 10;
! 3029:
! 3030: tmp[k++] = '0' + ((*scr).col) % 16 % 10;
! 3031: tmp[k++] = 'F';
! 3032: tmp[k++] = ESC; /* restore reverse background color */
! 3033: tmp[k++] = '[';
! 3034: tmp[k++] = '=';
! 3035:
! 3036: if (((*scr).col) % 16 > 9) tmp[k++] = '0' + ((*scr).col) % 16 / 10;
! 3037:
! 3038: tmp[k++] = '0' + ((*scr).col) % 16 % 10;
! 3039: tmp[k++] = 'I';
! 3040: tmp[k++] = ESC; /* restore background color */
! 3041: tmp[k++] = '[';
! 3042: tmp[k++] = '=';
! 3043:
! 3044: if (((*scr).col) / 16 > 9) tmp[k++] = '0' + ((*scr).col) / 16 / 10;
! 3045:
! 3046: tmp[k++] = '0' + ((*scr).col) / 16 % 10;
! 3047: tmp[k++] = 'G';
! 3048: tmp[k++] = ESC; /* restore reverse foreground color */
! 3049: tmp[k++] = '[';
! 3050: tmp[k++] = '=';
! 3051:
! 3052: if (((*scr).col) / 16 > 9) tmp[k++] = '0' + ((*scr).col) / 16 / 10;
! 3053:
! 3054: tmp[k++] = '0' + ((*scr).col) / 16 % 10;
! 3055: tmp[k++] = 'H';
! 3056:
! 3057: #endif /* COLOR */
! 3058: #endif /* LINUX */
! 3059:
! 3060: tmp[k++] = ESC; /* restore CursorPosition */
! 3061: tmp[k++] = '[';
! 3062:
! 3063: if (ypos[HOME] > 8) tmp[k++] = '0' + (ypos[HOME] + 1) / 10;
! 3064:
! 3065: tmp[k++] = '0' + (ypos[HOME] + 1) % 10;
! 3066: tmp[k++] = ';';
! 3067:
! 3068: if (xpos[HOME] > 8) tmp[k++] = '0' + (xpos[HOME] + 1) / 10;
! 3069:
! 3070: tmp[k++] = '0' + (xpos[HOME] + 1) % 10;
! 3071: tmp[k++] = 'H';
! 3072:
! 3073: i = UNSIGN ((*scr).att);
! 3074:
! 3075: tmp[k++] = ((i & 01) ? SO : SI);
! 3076: tmp[k++] = ESC; /* restore graphic attributes */
! 3077: tmp[k++] = '[';
! 3078:
! 3079:
! 3080: #ifdef SCO
! 3081:
! 3082: if ((*scr).bw) tmp[k++] = '7';
! 3083:
! 3084: tmp[k++] = 'm';
! 3085: tmp[k++] = ESC;
! 3086: tmp[k++] = '[';
! 3087:
! 3088: i = scosgr (i, (*scr).bw);
! 3089:
! 3090: if (i & 02) {
! 3091: tmp[k++] = '1';
! 3092: tmp[k++] = ';';
! 3093: }
! 3094:
! 3095: #else
! 3096:
! 3097: if (i & 02) {
! 3098: tmp[k++] = '2';
! 3099: tmp[k++] = ';';
! 3100: }
! 3101:
! 3102: #endif /* SCO */
! 3103:
! 3104: if (i & 04) {
! 3105: tmp[k++] = '3';
! 3106: tmp[k++] = ';';
! 3107: }
! 3108:
! 3109: if (i & 010) {
! 3110: tmp[k++] = '4';
! 3111: tmp[k++] = ';';
! 3112: }
! 3113:
! 3114: if (i & 020) {
! 3115: tmp[k++] = '5';
! 3116: tmp[k++] = ';';
! 3117: }
! 3118:
! 3119: if (i & 040) {
! 3120: tmp[k++] = '6';
! 3121: tmp[k++] = ';';
! 3122: }
! 3123:
! 3124: if (i & 0100) {
! 3125: tmp[k++] = '7';
! 3126: tmp[k++] = ';';
! 3127: }
! 3128:
! 3129: if (i & 0200) {
! 3130: tmp[k++] = '8';
! 3131: tmp[k++] = ';';
! 3132: }
! 3133:
! 3134: if (tmp[k - 1] == ';') k--;
! 3135:
! 3136: tmp[k++] = 'm';
! 3137: tmp[k] = EOL;
! 3138:
! 3139: k = mcmnd;
! 3140: mcmnd = 0;
! 3141:
! 3142: m_output (tmp);
! 3143:
! 3144: mcmnd = k;
! 3145:
! 3146: return;
! 3147:
! 3148: } /* end part_ref() */
! 3149:
! 3150: /* delayed write for higher system throughput */
! 3151: void m_output (char *text)
! 3152: {
! 3153: static char buffer[2048];
! 3154: static int p = 0;
! 3155: char *G;
! 3156: int i;
! 3157: int ch;
! 3158:
! 3159: if (io == HOME) opnfile[io] = stdout;
! 3160:
! 3161: G = SIflag[io] ? G0O[io] : G1O[io];
! 3162:
! 3163: i = 0;
! 3164:
! 3165: while ((ch = text[i++]) != EOL) {
! 3166:
! 3167: ch = UNSIGN (ch);
! 3168:
! 3169: if (ESCflag[io] == FALSE && ch >= NUL && ch < 255) ch = G[ch];
! 3170:
! 3171: buffer[p++] = ch;
! 3172:
! 3173: if (ch == SI) {
! 3174: SIflag[io] = TRUE;
! 3175: G = G0O[io];
! 3176: }
! 3177:
! 3178: if (ch == SO) {
! 3179: SIflag[io] = FALSE;
! 3180: G = G1O[io];
! 3181: }
! 3182:
! 3183: if (ch == ESC) {
! 3184: ESCflag[io] = TRUE;
! 3185: continue;
! 3186: }
! 3187:
! 3188: if (ch == '[' && ESCflag[io]) {
! 3189: ESCflag[io] = 2;
! 3190: continue;
! 3191: }
! 3192:
! 3193: if (ch >= '@' && ch < DEL) ESCflag[io] = FALSE;
! 3194: if (ch != NUL) continue;
! 3195:
! 3196: fputs (buffer, opnfile[io]);
! 3197:
! 3198: p = 0; /* NUL needs special treatment */
! 3199:
! 3200: fputc (NUL, opnfile[io]); /* 'cause unix uses it as delim */
! 3201:
! 3202: }
! 3203:
! 3204: buffer[p] = NUL;
! 3205:
! 3206: if (mcmnd == 'w' && *codptr == ',' && (p < 1536)) return;
! 3207:
! 3208: if (fm_nodelay[io]) {
! 3209:
! 3210: if (setjmp (sjbuf)) {
! 3211: merr_raise (NOWRITE);
! 3212: goto done;
! 3213: }
! 3214:
! 3215: sig_attach (SIGALRM, &ontimo);
! 3216: alarm (3);
! 3217:
! 3218: }
! 3219:
! 3220: fputs (buffer, opnfile[io]);
! 3221:
! 3222: p = 0;
! 3223:
! 3224: if (mcmnd == '*') fputc (EOL, opnfile[io]); /* special treatment for EOL */
! 3225: if (demomode) fputc (d0char, opnfile[io]);
! 3226:
! 3227: fflush (opnfile[io]);
! 3228:
! 3229:
! 3230: done:
! 3231:
! 3232: alarm (0); /* reset alarm request */
! 3233:
! 3234: return;
! 3235:
! 3236: } /* end of m_output() */
! 3237:
! 3238:
! 3239: void write_m (char *text)
! 3240: {
! 3241: static char esc = 0; /* esc processing flag */
! 3242: static char tmp[512];
! 3243: register int i;
! 3244: register int j;
! 3245: register int ch;
! 3246:
! 3247: if (io == HOME) {
! 3248:
! 3249: opnfile[HOME] = stdout;
! 3250:
! 3251: if (frm_filter == FALSE) {
! 3252: writeHOME (text);
! 3253: return;
! 3254: }
! 3255:
! 3256: }
! 3257:
! 3258: /* 'normal' output for devices other than HOME */
! 3259: j = 0;
! 3260: i = 0;
! 3261:
! 3262: while ((ch = text[j++]) != EOL) {
! 3263:
! 3264: tmp[i++] = ch;
! 3265:
! 3266: if (ch >= SP) {
! 3267:
! 3268: if (esc == 0) {
! 3269: xpos[io]++;
! 3270: continue;
! 3271: }
! 3272:
! 3273: if (ch == '[') {
! 3274: esc = 2;
! 3275: continue;
! 3276: }
! 3277:
! 3278: if (ch >= '@' || esc == 1) esc = 0;
! 3279:
! 3280: continue;
! 3281:
! 3282: }
! 3283:
! 3284: esc = (ch == ESC);
! 3285:
! 3286: if (ch == LF) {
! 3287:
! 3288: ypos[io]++;
! 3289:
! 3290: if (crlf[io]) xpos[io] = 0;
! 3291:
! 3292: continue;
! 3293:
! 3294: }
! 3295:
! 3296: if (ch == CR) {
! 3297: xpos[io] = 0;
! 3298: continue;
! 3299: }
! 3300:
! 3301: if (ch == BS) {
! 3302: if (--xpos[io] < 0) xpos[io] = 0;
! 3303: continue;
! 3304: }
! 3305:
! 3306: if (ch == FF) {
! 3307:
! 3308: xpos[io] = 0;
! 3309: ypos[io] = 0;
! 3310:
! 3311: continue;
! 3312:
! 3313: }
! 3314:
! 3315: if (ch == TAB) {
! 3316: xpos[io] += 8 - (xpos[io] % 8);
! 3317: }
! 3318:
! 3319: } /* end while */
! 3320:
! 3321: tmp[i] = EOL;
! 3322:
! 3323: m_output (tmp);
! 3324:
! 3325: xpos[io] &= 0377;
! 3326: ypos[io] &= 0377;
! 3327:
! 3328: return;
! 3329:
! 3330: } /* end of write_m() */
! 3331:
! 3332: /* tab to number 'col' column' */
! 3333: void write_t (short int col)
! 3334: {
! 3335: short int i;
! 3336: short int j;
! 3337: char tmp[256]; /* Not tied to STRLEN necessarily*/
! 3338:
! 3339: if (col <= xpos[io]) return;
! 3340: if (col > (sizeof(tmp)-1)) col = (sizeof(tmp)-1); /* guard against buffer overflow */
! 3341:
! 3342: j = xpos[io];
! 3343: i = 0;
! 3344:
! 3345: while (j++ < col) tmp[i++] = SP;
! 3346:
! 3347: tmp[i] = EOL;
! 3348:
! 3349: write_m (tmp);
! 3350:
! 3351: return;
! 3352:
! 3353: } /* end of write_t() */
! 3354:
! 3355: void ontimo ()
! 3356: { /* handle timeout (for read) */
! 3357: longjmp (sjbuf, 1);
! 3358: } /* end of ontimo() */
! 3359:
! 3360: /* Try to read up to 'length' characters from current 'io'
! 3361: * If 'length' == zero a single character read is performed and
! 3362: * its $ASCII value is returned in 'stuff'.
! 3363: * A negative value of 'timeout' means there's no timeout.
! 3364: * a zero value looks whether a character has been typed in already
! 3365: * a positive value terminates the read after 'timeout' seconds
! 3366: * a timeout will set $TEST to TRUE if successfull, FALSE otherwise
! 3367: *
! 3368: * timeouts 1 .. 3 are done by polling,
! 3369: * higher timeouts request an alarm. that different treatment is
! 3370: * necessary, because timeouts may be up to 2 seconds early.
! 3371: * polling on higher timeouts would be require too much system resources
! 3372: * just for nothing.
! 3373: * maximum timeout is 32767 (2**15-1) seconds (about 9 hrs)
! 3374: * There are no provisions to handle overflow.
! 3375: */
! 3376: void read_m (char *stuff, long read_timeout, short read_timeoutms, short length)
! 3377: {
! 3378: static char previous[2][256] = {{EOL}, {EOL}}; /* all static: longjmp! */
! 3379: static short p_toggle = 0;
! 3380: static char term_key[256] = {EOL, EOL};
! 3381: static short int escptr;
! 3382: static short int single;
! 3383: static short int timoflag; /* timeout flag */
! 3384: static long int timex;
! 3385: static short int timexms;
! 3386: static short int i;
! 3387: static int ch;
! 3388:
! 3389: #ifdef USE_GETTIMEOFDAY
! 3390: static struct timeval timebuffer;
! 3391: #else
! 3392: static struct timeb timebuffer;
! 3393: #endif
! 3394:
! 3395: escptr = 0;
! 3396: single = 0;
! 3397: timoflag = FALSE;
! 3398:
! 3399: /* Not necessarily tied to STRLEN */
! 3400:
! 3401: if (length > 255) length = 255;
! 3402:
! 3403: stuff[length] = EOL;
! 3404: stuff[0] = EOL;
! 3405:
! 3406: if (length < 1) single = length = 1;
! 3407:
! 3408: timex = 0L;
! 3409: timexms = 0;
! 3410:
! 3411: if (io == HOME) opnfile[HOME] = stdin;
! 3412:
! 3413: if (io == HOME && !frm_filter) {
! 3414:
! 3415: if (NOTYPEAHEAD) fflush (stdin); /* ignore previous input */
! 3416:
! 3417: if (read_timeout >= 0) {
! 3418:
! 3419: test = TRUE;
! 3420:
! 3421: if (read_timeout > 2 && read_timeout <= 32767) { /* cave small/large values */
! 3422:
! 3423: if (setjmp (sjbuf)) {
! 3424:
! 3425: test = FALSE;
! 3426: timoflag = TRUE;
! 3427:
! 3428: goto done;
! 3429:
! 3430: }
! 3431:
! 3432: sig_attach (SIGALRM, &ontimo);
! 3433: alarm ((unsigned) read_timeout);
! 3434:
! 3435: read_timeout = (-1L);
! 3436:
! 3437: }
! 3438: else {
! 3439:
! 3440: if (read_timeout >= 0) {
! 3441:
! 3442:
! 3443: #ifdef USE_GETTIMEOFDAY
! 3444:
! 3445: gettimeofday (&timebuffer, NULL); /* get current time */
! 3446:
! 3447: read_timeout += timebuffer.tv_sec; /* target time */
! 3448: read_timeoutms += timebuffer.tv_usec;
! 3449:
! 3450: #else
! 3451:
! 3452: ftime (&timebuffer); /* get current time */
! 3453:
! 3454: read_timeout += timebuffer.time; /* target time */
! 3455: read_timeoutms += timebuffer.millitm;
! 3456:
! 3457: #endif
! 3458:
! 3459: if (read_timeoutms > 999) {
! 3460: read_timeoutms -= 1000;
! 3461: read_timeout++;
! 3462: }
! 3463:
! 3464: }
! 3465:
! 3466: }
! 3467:
! 3468: }
! 3469:
! 3470: zb[0] = EOL;
! 3471: zb[1] = EOL;
! 3472: zcc = FALSE;
! 3473:
! 3474: for (i = 0; i < length; i++) {
! 3475:
! 3476: if (merr () == INRPT) {
! 3477:
! 3478: if (--i < 0) i = 0;
! 3479: stuff[i] = EOL;
! 3480:
! 3481: break;
! 3482: }
! 3483:
! 3484: if (evt_async_enabled && (merr () == ASYNC)) break;
! 3485:
! 3486: /* TODO: remove old FreeM "journaling" nonsense here */
! 3487: if (jour_flag < 0) {
! 3488:
! 3489: if ((ch = fgetc (jouraccess)) == EOF) {
! 3490:
! 3491: jour_flag = 0;
! 3492:
! 3493: fclose (jouraccess);
! 3494:
! 3495: jouraccess = NULL;
! 3496:
! 3497: }
! 3498: else {
! 3499:
! 3500: if (ch == SI) {
! 3501: test = FALSE;
! 3502: break;
! 3503: } /* timeout char */
! 3504:
! 3505: }
! 3506:
! 3507: }
! 3508:
! 3509:
! 3510: if (jour_flag >= 0) {
! 3511:
! 3512: if (ug_buf[HOME][0] != EOL) {
! 3513: ch = ug_buf[HOME][0];
! 3514: stcpy (ug_buf[HOME], &ug_buf[HOME][1]);
! 3515: }
! 3516: else {
! 3517: if (read_timeout >= 0)
! 3518: #ifdef SYSFIVE
! 3519: {
! 3520: if (rdchk0 (&ch) == 1) {
! 3521: }
! 3522: #else
! 3523: {
! 3524:
! 3525: if (rdchk (fileno (stdin)) > 0)
! 3526: ch = getc (stdin);
! 3527: #endif /* SYSFIVE */
! 3528: else {
! 3529:
! 3530: if (read_timeout < 0) {
! 3531:
! 3532: test = FALSE;
! 3533: timoflag = TRUE;
! 3534: stuff[i] = EOL;
! 3535:
! 3536: break;
! 3537:
! 3538: }
! 3539: #ifdef USE_GETTIMEOFDAY
! 3540: gettimeofday (&timebuffer, NULL); /* get current time */
! 3541: if ((read_timeout < timebuffer.tv_sec) ||
! 3542: ((read_timeout == timebuffer.tv_sec) &&
! 3543: (read_timeoutms <= timebuffer.tv_usec))) {
! 3544: #else
! 3545: ftime (&timebuffer); /* get current time */
! 3546: if ((read_timeout < timebuffer.time) ||
! 3547: ((read_timeout == timebuffer.time) &&
! 3548: (read_timeoutms <= timebuffer.millitm))) {
! 3549: #endif
! 3550:
! 3551: test = FALSE;
! 3552: timoflag = TRUE;
! 3553: stuff[i] = EOL;
! 3554: break;
! 3555: }
! 3556:
! 3557: i--;
! 3558: continue;
! 3559:
! 3560: }
! 3561: }
! 3562: else {
! 3563: ch = getc (stdin);
! 3564: }
! 3565: }
! 3566: }
! 3567:
! 3568: if (UNSIGN (ch) == 255) {
! 3569: i--;
! 3570: continue;
! 3571: } /* illegal char */
! 3572:
! 3573: if (CONVUPPER) { /* convert to uppercase ? */
! 3574: if (ch >= 'a' && ch <= 'z') ch -= 32;
! 3575: }
! 3576:
! 3577: /* on CTRL/O suspend execution until next CTRL/O */
! 3578: if (ch == SI && CTRLOPROC) {
! 3579:
! 3580: printf ("\033[8p\033[4u"); /* screen dark, timeout off */
! 3581:
! 3582: while ((ch = getc (stdin)) != SI); /* loop until CTRL/O */
! 3583:
! 3584: printf ("\033[9p\033[5u"); /* screen light, timeout on */
! 3585:
! 3586: i--;
! 3587: continue;
! 3588: }
! 3589:
! 3590: zb[0] = ch;
! 3591:
! 3592: if (single == 0) {
! 3593:
! 3594: if (ch == ESC) {
! 3595:
! 3596: i--;
! 3597:
! 3598: term_key[0] = ESC;
! 3599: escptr = 1;
! 3600:
! 3601: continue;
! 3602:
! 3603: }
! 3604:
! 3605: if (escptr) {
! 3606:
! 3607: short j;
! 3608:
! 3609: i--;
! 3610:
! 3611: term_key[escptr++] = ch;
! 3612: term_key[escptr] = EOL;
! 3613:
! 3614: if (ch == '[' && escptr == 2) continue; /* CSI */
! 3615:
! 3616: /* DECs PF1..PF4 and Keypad application */
! 3617: if (ch == 'O' && PF1flag && escptr == 2) continue;
! 3618: if (escptr > 2 && (ch < '@' || ch >= DEL)) continue;
! 3619:
! 3620: if (ESCSEQPROC) {
! 3621: stcpy (zb, term_key);
! 3622: break;
! 3623: }
! 3624:
! 3625: if (escptr == 2) {
! 3626:
! 3627: if (ch == '9') { /* to begin of string */
! 3628:
! 3629: while (i >= 0) {
! 3630:
! 3631: if (ECHOON) {
! 3632:
! 3633: if (xpos[HOME] > 0) {
! 3634: write_m ("\033[D\201");
! 3635: }
! 3636: else {
! 3637: write_m ("\033M\033[79C\201");
! 3638: }
! 3639:
! 3640: }
! 3641:
! 3642: i--;
! 3643:
! 3644: }
! 3645:
! 3646: escptr = 0;
! 3647:
! 3648: continue;
! 3649:
! 3650: }
! 3651: else if (ch == ':') { /* to end of string */
! 3652:
! 3653: while (stuff[i] != EOL && stuff[i + 1] != EOL) {
! 3654:
! 3655: if (ECHOON) {
! 3656:
! 3657: if (xpos[HOME] < (n_columns - 1)) {
! 3658: write_m ("\033[C\201");
! 3659: }
! 3660: else {
! 3661: write_m ("\012\015\201");
! 3662: }
! 3663:
! 3664: }
! 3665:
! 3666: i++;
! 3667:
! 3668: }
! 3669:
! 3670: escptr = 0;
! 3671:
! 3672: continue;
! 3673:
! 3674: }
! 3675:
! 3676: }
! 3677:
! 3678: if (escptr == 3) {
! 3679:
! 3680: if (ch == 'D') { /* CUB left arrow */
! 3681:
! 3682: if (i >= 0) {
! 3683:
! 3684: if (ECHOON) {
! 3685:
! 3686: if (xpos[HOME] > 0) {
! 3687: write_m (term_key);
! 3688: }
! 3689: else {
! 3690: write_m ("\033M\033[79C\201");
! 3691: }
! 3692:
! 3693: }
! 3694:
! 3695: i--;
! 3696:
! 3697: }
! 3698:
! 3699: escptr = 0;
! 3700:
! 3701: continue;
! 3702:
! 3703: }
! 3704:
! 3705: if (stuff[i + 1] == EOL) {
! 3706: escptr = 0;
! 3707: continue;
! 3708: }
! 3709:
! 3710: if (ch == 'C') { /* CUF right arrow */
! 3711:
! 3712: if (ECHOON) {
! 3713:
! 3714: if (xpos[HOME] < (n_columns - 1)) {
! 3715: write_m (term_key);
! 3716: }
! 3717: else {
! 3718: write_m ("\012\015\201");
! 3719: }
! 3720:
! 3721: }
! 3722:
! 3723: i++;
! 3724:
! 3725: escptr = 0;
! 3726:
! 3727: continue;
! 3728:
! 3729: }
! 3730:
! 3731: if (ch == 'P') { /* DCH Delete Character */
! 3732:
! 3733: ch = i + 1;
! 3734:
! 3735: if (stuff[ch] != EOL) {
! 3736: while ((stuff[ch] = stuff[ch + 1]) != EOL) ch++;
! 3737: }
! 3738:
! 3739: if (ECHOON) {
! 3740:
! 3741: ch = xpos[HOME] + 1;
! 3742: j = ypos[HOME] + 1;
! 3743:
! 3744: stcpy (term_key, &stuff[i + 1]);
! 3745: stcat (term_key, " \033[\201");
! 3746: intstr (&term_key[stlen (term_key)], j);
! 3747: stcat (term_key, ";\201");
! 3748: intstr (&term_key[stlen (term_key)], ch);
! 3749: stcat (term_key, "H\201");
! 3750:
! 3751: write_m (term_key);
! 3752:
! 3753: }
! 3754:
! 3755: escptr = 0;
! 3756:
! 3757: continue;
! 3758:
! 3759: }
! 3760:
! 3761: if (ch == '@') { /* ICH Insert Character */
! 3762:
! 3763: ch = i;
! 3764: while (stuff[ch++] != EOL);
! 3765:
! 3766: while (ch > i) {
! 3767: stuff[ch] = stuff[ch - 1];
! 3768: ch--;
! 3769: }
! 3770:
! 3771: stuff[i + 1] = SP;
! 3772:
! 3773: if (ECHOON) {
! 3774:
! 3775: ch = xpos[HOME] + 1;
! 3776: j = ypos[HOME] + 1;
! 3777:
! 3778: stcpy (term_key, &stuff[i + 1]);
! 3779: stcat (term_key, "\033[\201");
! 3780: intstr (&term_key[stlen (term_key)], j);
! 3781: stcat (term_key, ";\201");
! 3782: intstr (&term_key[stlen (term_key)], ch);
! 3783: stcat (term_key, "H\201");
! 3784:
! 3785: write_m (term_key);
! 3786:
! 3787: }
! 3788:
! 3789: escptr = 0;
! 3790:
! 3791: continue;
! 3792:
! 3793: }
! 3794: }
! 3795:
! 3796: /* VT100 Functionkey */
! 3797: if (ch == '~' && (escptr == 4 || escptr == 5)) {
! 3798:
! 3799: j = term_key[2] - '0';
! 3800:
! 3801: if (term_key[3] != ch) j = j * 10 + term_key[3] - '0';
! 3802: if (j < 1 || j > 44) j = 0;
! 3803:
! 3804: }
! 3805: else {
! 3806: /* SCO Functionkey */
! 3807: j = find ("@ABCDFGHIJKLMNOP0_dTVX ;\"#$%&\'<=*+,-./123UWY\201", &term_key[1]);
! 3808: }
! 3809:
! 3810: escptr = 0;
! 3811:
! 3812: /* key unknown or without a value */
! 3813: if (j == 0 || zfunkey[j - 1][0] == EOL) continue;
! 3814:
! 3815: /* put key in input buffer, ignore overflow */
! 3816: {
! 3817: char tmp[256];
! 3818:
! 3819: stcpy (tmp, ug_buf[HOME]);
! 3820: stcpy (ug_buf[HOME], zfunkey[--j]);
! 3821: stcat (ug_buf[HOME], tmp);
! 3822: }
! 3823:
! 3824: continue;
! 3825: }
! 3826:
! 3827: term_key[0] = ch;
! 3828: term_key[1] = EOL;
! 3829:
! 3830: if (find (LineTerm, term_key)) break;
! 3831:
! 3832: if (ch == BS || ch == DEL) {
! 3833:
! 3834: if (stuff[i] != EOL) { /* DEL within string */
! 3835:
! 3836: if (ch == BS && i > 0) {
! 3837:
! 3838: if (ECHOON) {
! 3839:
! 3840: if (xpos[HOME] > 0) {
! 3841: write_m ("\033[D\201");
! 3842: }
! 3843: else {
! 3844: write_m ("\033M\033[79C\201");
! 3845: }
! 3846:
! 3847: }
! 3848:
! 3849: i--;
! 3850:
! 3851: }
! 3852:
! 3853: ch = i;
! 3854: if (stuff[ch] != EOL) {
! 3855: while ((stuff[ch] = stuff[ch + 1]) != EOL) ch++;
! 3856: }
! 3857:
! 3858: if (ECHOON) {
! 3859:
! 3860: int j;
! 3861:
! 3862: ch = xpos[HOME] + 1;
! 3863: j = ypos[HOME] + 1;
! 3864:
! 3865: stcpy (term_key, &stuff[i]);
! 3866: stcat (term_key, " \033[\201");
! 3867: intstr (&term_key[stlen (term_key)], j);
! 3868: stcat (term_key, ";\201");
! 3869: intstr (&term_key[stlen (term_key)], ch);
! 3870: stcat (term_key, "H\201");
! 3871:
! 3872: write_m (term_key);
! 3873:
! 3874: }
! 3875:
! 3876: continue;
! 3877:
! 3878: }
! 3879:
! 3880: if (i > 0) {
! 3881:
! 3882: if (ECHOON) {
! 3883:
! 3884: if (DELMODE) {
! 3885:
! 3886: if (xpos[HOME] > 0) {
! 3887: write_m ("\010 \010\201");
! 3888: }
! 3889: else {
! 3890: write_m ("\033M\033[79C\033[P\201");
! 3891: }
! 3892:
! 3893: } else {
! 3894: write_m ("\\\201");
! 3895: }
! 3896:
! 3897: }
! 3898:
! 3899: i--;
! 3900:
! 3901: ch = i;
! 3902:
! 3903: while ((stuff[ch] = stuff[ch + 1]) != EOL) ch++;
! 3904:
! 3905: }
! 3906: else if (DELEMPTY) {
! 3907:
! 3908: /* empty string delete? */
! 3909: stuff[0] = EOL;
! 3910: i = 1;
! 3911: term_key[0] = ch;
! 3912:
! 3913: break;
! 3914:
! 3915: }
! 3916:
! 3917: i--;
! 3918:
! 3919: continue;
! 3920:
! 3921: }
! 3922:
! 3923: if (ch == NAK || ch == DC2) { /* CTRL/U deletes all input */
! 3924:
! 3925: while (stuff[i] != EOL) {
! 3926:
! 3927: if (ECHOON) {
! 3928:
! 3929: if (xpos[HOME] < (n_columns - 1)) {
! 3930: write_m ("\033[C\201");
! 3931: }
! 3932: else {
! 3933: write_m ("\012\015\201");
! 3934: }
! 3935:
! 3936: }
! 3937:
! 3938: i++;
! 3939:
! 3940: }
! 3941:
! 3942: while (i > 0) {
! 3943:
! 3944: if (ECHOON) {
! 3945:
! 3946: if (DELMODE) {
! 3947:
! 3948: if (xpos[HOME] > 0) {
! 3949: write_m ("\010 \010\201");
! 3950: }
! 3951: else {
! 3952: write_m ("\033M\033[79C\033[P\201");
! 3953: }
! 3954:
! 3955: }
! 3956: else {
! 3957: write_m ("\\\201");
! 3958: }
! 3959:
! 3960: }
! 3961:
! 3962: stuff[i--] = EOL;
! 3963:
! 3964: }
! 3965:
! 3966: stuff[i--] = EOL;
! 3967:
! 3968: if (ch == NAK) continue;
! 3969:
! 3970: /* (ch==DC2) *//* CTRL/R Retypes last input */
! 3971:
! 3972: i = stcpy (stuff, previous[p_toggle]);
! 3973:
! 3974: stuff[i--] = EOL;
! 3975:
! 3976: toggle (p_toggle);
! 3977:
! 3978: if (ECHOON) write_m (stuff);
! 3979:
! 3980: continue;
! 3981: }
! 3982:
! 3983: if (ch == STX && (zbreakon || hardcopy)) {
! 3984:
! 3985: if (zbreakon) zbflag = TRUE;
! 3986:
! 3987: if (i > 0) {
! 3988: if (ECHOON) write_m ("\010 \010\201");
! 3989: }
! 3990:
! 3991: i--;
! 3992:
! 3993: continue;
! 3994:
! 3995: }
! 3996:
! 3997: if (ch == BrkKey) { /* CTRL/C may interrupt */
! 3998:
! 3999: i--;
! 4000:
! 4001: if (breakon) {
! 4002:
! 4003: stuff[i] = EOL;
! 4004: merr_raise (INRPT);
! 4005:
! 4006: return;
! 4007:
! 4008: }
! 4009:
! 4010: continue;
! 4011: }
! 4012:
! 4013: /* ignore non programmed CTRL/ key ?? */
! 4014: if (ch < SP && (ch != TAB || nstx) && NOCTRLS) { /* TAB may be a programmed key */
! 4015: i--;
! 4016: continue;
! 4017: }
! 4018:
! 4019: } /* if (single == 0) */
! 4020:
! 4021: if (stuff[i] == EOL) stuff[i + 1] = EOL;
! 4022: if (ch < 255) ch = (SIflag[io] ? G0I[io] : G1I[io])[UNSIGN (ch)];
! 4023:
! 4024: stuff[i] = ch;
! 4025:
! 4026: if (ECHOON) {
! 4027:
! 4028: term_key[0] = ch;
! 4029: term_key[1] = EOL;
! 4030:
! 4031: write_m (term_key);
! 4032:
! 4033: }
! 4034:
! 4035: } /* ??????????? may need to run through preprocessor to see where the heck this goes */
! 4036: }
! 4037: else { /* $io != HOME */
! 4038: int fd;
! 4039: int fdstat;
! 4040:
! 4041: fd = 0;
! 4042:
! 4043:
! 4044: #if defined(SYSFIVE) && !defined(__AMIGA) && !defined(MSDOS)
! 4045:
! 4046: if (read_timeout >= 0) {
! 4047:
! 4048: fd = fileno (opnfile[io]);
! 4049: fdstat = fcntl (fd, F_GETFL);
! 4050:
! 4051: fcntl (fd, F_SETFL, fdstat | O_NDELAY);
! 4052:
! 4053: }
! 4054:
! 4055: #endif /* SYSFIVE */
! 4056:
! 4057: for (i = 0; i < length; i++) {
! 4058:
! 4059: if (merr () == INRPT) {
! 4060:
! 4061: if (--i < 0) i = 0;
! 4062:
! 4063: stuff[i] = EOL;
! 4064:
! 4065: break;
! 4066:
! 4067: }
! 4068:
! 4069: if (ug_buf[io][0] != EOL) {
! 4070: ch = ug_buf[io][0];
! 4071: stcpy (ug_buf[io], &ug_buf[io][1]);
! 4072: }
! 4073: else if (read_timeout >= 0)
! 4074: {
! 4075: test = TRUE;
! 4076:
! 4077: #ifdef SYSFIVE
! 4078: if (fread (&ch, 1, 1, opnfile[io]) < 1)
! 4079: #else
! 4080: if (rdchk (fileno (opnfile[io])) == 0 || ((ch = fgetc (opnfile[io])) == EOF))
! 4081: #endif /* SYSFIVE */
! 4082:
! 4083: {
! 4084: if (--read_timeout < 0) {
! 4085:
! 4086: test = FALSE;
! 4087: timoflag = TRUE;
! 4088: stuff[i] = EOL;
! 4089:
! 4090: break;
! 4091:
! 4092: }
! 4093:
! 4094: sleep (1);
! 4095:
! 4096: i--;
! 4097:
! 4098: continue;
! 4099:
! 4100: }
! 4101:
! 4102: ch = UNSIGN (ch);
! 4103: }
! 4104: else {
! 4105: ch = fgetc (opnfile[io]);
! 4106: }
! 4107:
! 4108: stuff[i] = ch;
! 4109:
! 4110: if (ch == EOF) {
! 4111: /* EOF halts filtered mps */
! 4112: if ((io == HOME) && frm_filter) merr_raise (INRPT);
! 4113:
! 4114: stuff[i] = EOL;
! 4115:
! 4116: break;
! 4117: }
! 4118:
! 4119: if (single) break;
! 4120:
! 4121: if (ch == LF && crlf[io]) {
! 4122: i--;
! 4123: continue;
! 4124: }
! 4125:
! 4126: if ((ch == CR) || (ch == LF)) {
! 4127: int ch0;
! 4128:
! 4129: stuff[i] = EOL;
! 4130:
! 4131: /* if input terminates with CR/LF or LF/CR take both */
! 4132: /* as a single termination character. So it is possible */
! 4133: /* to get correct input from files written by mumps */
! 4134: /* itself with CR/LF line termination */
! 4135:
! 4136: #if defined(SYSFIVE) && !defined(__AMIGA) && !defined(MSDOS)
! 4137:
! 4138: if (fd == 0) {
! 4139:
! 4140: fd = fileno (opnfile[io]);
! 4141: fdstat = fcntl (fd, F_GETFL);
! 4142:
! 4143: fcntl (fd, F_SETFL, fdstat | O_NDELAY);
! 4144:
! 4145: }
! 4146:
! 4147: if (fread (&ch0, 1, 1, opnfile[io]) == 1) {
! 4148: ch0 = UNSIGN (ch0);
! 4149:
! 4150: #else
! 4151: #if !defined(__AMIGA) && !defined(MSDOS)
! 4152:
! 4153: if (rdchk (fileno (opnfile[io])) == 1) {
! 4154: ch0 = fgetc (opnfile[io]);
! 4155:
! 4156: #else
! 4157:
! 4158: #if defined(__AMIGA)
! 4159:
! 4160: if (rdchk0 (fileno (opnfile[io])) == 1) {
! 4161: ch0 = fgetc (opnfile[io]);
! 4162: #endif
! 4163:
! 4164: #endif /* __AMIGA */
! 4165:
! 4166: #if defined(MSDOS)
! 4167: if (1) {
! 4168: ch0 = fgetc (opnfile[io]);
! 4169: #endif
! 4170:
! 4171: #endif /* SYSFIVE */
! 4172:
! 4173: if ((ch == CR && ch0 != LF) || (ch == LF && ch0 != CR))
! 4174: ungetc (ch0, opnfile[io]);
! 4175: }
! 4176:
! 4177: break;
! 4178: }
! 4179:
! 4180: if (UNSIGN (stuff[i]) < 255)
! 4181: stuff[i] = (SIflag[io] ? G0I[io] : G1I[io])[UNSIGN (stuff[i])];
! 4182: }
! 4183:
! 4184: #if defined(SYSFIVE) && !defined(__AMIGA)
! 4185: if (fd) fcntl (fd, F_SETFL, fdstat);
! 4186: #endif /* SYSFIVE */
! 4187:
! 4188: } /* if ((ch == CR) || (ch == LF)) */
! 4189:
! 4190:
! 4191: done:
! 4192:
! 4193: alarm (0); /* reset alarm request */
! 4194:
! 4195: if (io == HOME && jour_flag > 0) {
! 4196:
! 4197: char tmp[256];
! 4198:
! 4199: tmp[stcpy (tmp, stuff)] = NUL;
! 4200: fputs (tmp, jouraccess);
! 4201:
! 4202: if (timoflag) {
! 4203:
! 4204: tmp[0] = SI;
! 4205: tmp[1] = NUL; /* CTRL/O as timeout char */
! 4206:
! 4207: fputs (tmp, jouraccess);
! 4208:
! 4209: }
! 4210: else if ((i < length) || (stuff[0] == NUL && zb[0] == ESC)) {
! 4211:
! 4212: /* save termination char if meaningful */
! 4213: tmp[stcpy (tmp, zb)] = NUL;
! 4214: fputs (tmp, jouraccess);
! 4215:
! 4216: }
! 4217:
! 4218: }
! 4219:
! 4220: if (single) { /* to ASCII */
! 4221:
! 4222: if (timoflag) {
! 4223: stuff[0] = '-';
! 4224: stuff[1] = '1';
! 4225: stuff[2] = EOL;
! 4226: }
! 4227: else {
! 4228: intstr (stuff, UNSIGN (stuff[0]));
! 4229: }
! 4230:
! 4231: }
! 4232: else if (io == HOME && stuff[0] != EOL) {
! 4233: stcpy (previous[toggle (p_toggle)], stuff);
! 4234: }
! 4235:
! 4236: return;
! 4237:
! 4238: } /* end of read_m() */
! 4239:
! 4240: #if defined(SYSFIVE)
! 4241: /* UNIX system V has no 'rdchk' function. We must do it ourselves */
! 4242:
! 4243: #if !defined(__AMIGA) && !defined(MSDOS)
! 4244:
! 4245: int rdchk0 (int *data)
! 4246: {
! 4247: static int x;
! 4248: static int firsttime = TRUE;
! 4249: int retcode;
! 4250: char ch;
! 4251:
! 4252: if (firsttime) {
! 4253: x = fcntl (0, F_GETFL);
! 4254: firsttime = FALSE;
! 4255: }
! 4256:
! 4257: fcntl (0, F_SETFL, x | O_NDELAY);
! 4258:
! 4259: retcode = read (0, &ch, 1);
! 4260:
! 4261: fcntl (0, F_SETFL, x);
! 4262:
! 4263: *data = (retcode > 0) ? ch : NUL;
! 4264:
! 4265: return retcode;
! 4266:
! 4267: } /* end rdchk0() */
! 4268:
! 4269: #else
! 4270:
! 4271: int rdchk0 (int *data)
! 4272: {
! 4273: /* TODO: flesh out on m68k-amigaos */
! 4274: return TRUE;
! 4275: }
! 4276:
! 4277: #endif
! 4278:
! 4279: /******************************************************************************/
! 4280: /* under XENIX the system has an intrinsic function 'locking'. */
! 4281: /* under UNIX System V it must be done with fcntl. */
! 4282: /* the difference is, that the XENIX locking blocks all other accesses */
! 4283: /* whereas UNIX System V gives only protection if all users of a file */
! 4284: /* use 'locking'. */
! 4285: /* since 'fcntl' is not properly documented, the outcome in any cases of */
! 4286: /* errors is uncertain. */
! 4287:
! 4288: #ifdef AMIGA68K
! 4289:
! 4290: int locking (int fd, int action, long count)
! 4291: {
! 4292: /* TODO: flesh out on m68k-amigaos */
! 4293: return 0;
! 4294: }
! 4295:
! 4296: #else
! 4297:
! 4298: /* fd = file descriptor of file to be locked */
! 4299: /* action = action to be performed */
! 4300: /* count area to be locked */
! 4301: int locking (int fd, int action, long count)
! 4302: {
! 4303:
! 4304: struct flock lock;
! 4305:
! 4306: lock.l_whence = 1; /* lock from current position */
! 4307: lock.l_start = 0;
! 4308: lock.l_len = count;
! 4309: lock.l_pid = getpid ();
! 4310:
! 4311: if (lonelyflag) return 0; /* no LOCK if single user */
! 4312:
! 4313: switch (action) {
! 4314:
! 4315:
! 4316: case 0: /* LK_UNLK free previously locked area */
! 4317:
! 4318: lock.l_type = F_UNLCK;
! 4319: fcntl (fd, F_SETLK, &lock);
! 4320:
! 4321: break;
! 4322:
! 4323:
! 4324: case 1: /* LK_LOCK lock against others reading and writing my data */
! 4325:
! 4326: lock.l_type = F_WRLCK;
! 4327: fcntl (fd, F_SETLKW, &lock);
! 4328:
! 4329: break;
! 4330:
! 4331:
! 4332: case 2: /* LK_NBLCK lock against others reading and writing my data, don't block */
! 4333:
! 4334: lock.l_type = F_WRLCK;
! 4335: fcntl (fd, F_SETLK, &lock);
! 4336:
! 4337: break;
! 4338:
! 4339:
! 4340: case 3: /* LK_RLCK lock against others writing my data */
! 4341:
! 4342: lock.l_type = F_RDLCK;
! 4343: fcntl (fd, F_SETLKW, &lock);
! 4344:
! 4345: break;
! 4346:
! 4347:
! 4348: case 4: /* LK_NBRLCK lock against others writing my data, don't block */
! 4349:
! 4350: lock.l_type = F_RDLCK;
! 4351: fcntl (fd, F_SETLK, &lock);
! 4352:
! 4353: break;
! 4354:
! 4355: }
! 4356:
! 4357: return 0; /* action properly performed */
! 4358:
! 4359: } /* end locking() */
! 4360:
! 4361: #endif
! 4362:
! 4363: #ifdef OLDUNIX
! 4364:
! 4365: /* set io_parameters to mumps/unix conventions */
! 4366: /* action: 0 = UNIX; 1 = MUMPS */
! 4367: void set_io (short action)
! 4368: {
! 4369: if (lio_mode == action) return;
! 4370:
! 4371: static char del;
! 4372: static char fs;
! 4373: struct termio tpara;
! 4374:
! 4375: if (frm_filter) return; /* nothing special if used as filter */
! 4376:
! 4377: fflush (stdin);
! 4378: fflush (stdout);
! 4379: fflush (stderr);
! 4380:
! 4381: ioctl (0, TCGETA, &tpara); /* get paramters */
! 4382:
! 4383: if (action == UNIX) {
! 4384:
! 4385: lio_mode = UNIX;
! 4386:
! 4387: tpara.c_lflag |= (ECHO | ICANON); /* enable echo/no cbreak mode */
! 4388: tpara.c_iflag |= ICRNL; /* cr-lf mapping */
! 4389: tpara.c_oflag |= ONLCR; /* cr-lf mapping */
! 4390: tpara.c_cc[VINTR] = del; /* interrupt */
! 4391: tpara.c_cc[VQUIT] = fs; /* quit */
! 4392: tpara.c_cc[VMIN] = EOT;
! 4393: tpara.c_cc[VTIME] = -1;
! 4394:
! 4395: }
! 4396: else { /* action == MUMPS */
! 4397:
! 4398: lio_mode = MUMPS;
! 4399:
! 4400: tpara.c_lflag &= (~(ECHO | ICANON)); /* disable echo/cbreak mode */
! 4401: tpara.c_iflag &= ~ICRNL; /* cr-lf mapping */
! 4402: tpara.c_oflag &= ~ONLCR; /* cr-lf mapping */
! 4403: del = tpara.c_cc[VINTR]; /* save previous state of */
! 4404: fs = tpara.c_cc[VQUIT]; /* quit and interrupt */
! 4405: tpara.c_cc[VINTR] = BrkKey; /* interrupt = CTRL/C */
! 4406: tpara.c_cc[VQUIT] = (zbreakon || hardcopy) ? STX : -1; /* zbreak/hardcopy */
! 4407: tpara.c_cc[VMIN] = 1;
! 4408: tpara.c_cc[VTIME] = 1;
! 4409:
! 4410: }
! 4411:
! 4412: ioctl (0, TCSETA, &tpara);
! 4413:
! 4414: return;
! 4415:
! 4416: } /* end of set_io() */
! 4417:
! 4418:
! 4419: /* break_char: */
! 4420: /* -1 = break disabled */
! 4421: /* ETX = MUMPS break */
! 4422: /* DEL = UNIX quit */
! 4423: void set_break (short break_char)
! 4424: {
! 4425: struct termio arg;
! 4426:
! 4427: ioctl (0, TCGETA, &arg);
! 4428:
! 4429: arg.c_cc[VINTR] = break_char; /* interrupt = CTRL/C */
! 4430:
! 4431: ioctl (0, TCSETA, &arg);
! 4432:
! 4433: return;
! 4434:
! 4435: } /* end of set_break() */
! 4436:
! 4437: /* quit_char: */
! 4438: /* -1 = quit disabled */
! 4439: /* STX = MUMPS CTRL/B */
! 4440: /* DEL = UNIX quit */
! 4441: void set_zbreak (short quit_char)
! 4442: {
! 4443: struct termio arg;
! 4444:
! 4445: ioctl (0, TCGETA, &arg);
! 4446:
! 4447: arg.c_cc[VQUIT] = quit_char;
! 4448:
! 4449: ioctl (0, TCSETA, &arg);
! 4450:
! 4451: return;
! 4452:
! 4453: } /* end of set_zbreak() */
! 4454:
! 4455: #else
! 4456:
! 4457: void set_io (short action) /* set io_parameters to mumps/unix conventions */
! 4458: {
! 4459: static struct termios unixtermio;
! 4460: struct termios termios_p;
! 4461:
! 4462: if (lio_mode == action) return;
! 4463:
! 4464: if (frm_filter) return; /* nothing special if used as filter */
! 4465:
! 4466: if (action == UNIX) {
! 4467: lio_mode = UNIX;
! 4468:
! 4469: tcsetattr (0, TCSADRAIN, &unixtermio);
! 4470: }
! 4471: else { /* action == MUMPS */
! 4472: lio_mode = MUMPS;
! 4473:
! 4474: tcgetattr (0, &unixtermio); /* get unix paramters */
! 4475: tcgetattr (0, &termios_p); /* get paramters */
! 4476:
! 4477: termios_p.c_lflag &= (~(ECHO | ICANON)); /* disable echo/cbreak mode */
! 4478: termios_p.c_iflag &= ~ICRNL; /* cr-lf mapping */
! 4479: termios_p.c_oflag &= ~ONLCR; /* cr-lf mapping */
! 4480: termios_p.c_cc[VINTR] = BrkKey; /* interrupt = CTRL/C */
! 4481: termios_p.c_cc[VQUIT] = (zbreakon || hardcopy) ? STX : -1; /* zbreak/hardcopy */
! 4482: termios_p.c_cc[VMIN] = 1;
! 4483: termios_p.c_cc[VTIME] = 1;
! 4484:
! 4485: tcsetattr (0, TCSADRAIN, &termios_p); /* set paramters */
! 4486:
! 4487: }
! 4488:
! 4489: return;
! 4490:
! 4491: } /* end of set_io() */
! 4492:
! 4493: void set_break (short break_char)
! 4494: {
! 4495: struct termios termios_p;
! 4496:
! 4497: tcgetattr (0, &termios_p);
! 4498:
! 4499: termios_p.c_cc[VINTR] = break_char; /* interrupt = CTRL/C */
! 4500:
! 4501: tcsetattr (0, TCSADRAIN, &termios_p); /* set paramters */
! 4502:
! 4503: return;
! 4504:
! 4505: } /* end of set_break() */
! 4506:
! 4507: void set_zbreak (short quit_char)
! 4508: {
! 4509:
! 4510: struct termios termios_p;
! 4511:
! 4512: tcgetattr (0, &termios_p);
! 4513:
! 4514: termios_p.c_cc[VQUIT] = quit_char;
! 4515:
! 4516: tcsetattr (0, TCSADRAIN, &termios_p); /* set paramters */
! 4517:
! 4518: return;
! 4519:
! 4520: } /* end of set_zbreak() */
! 4521:
! 4522: #endif /* OLDUNIX */
! 4523:
! 4524: #else
! 4525:
! 4526: /* same for XENIX */
! 4527: void set_io (short action) /* set io_parameters to mumps/unix conventions */
! 4528: {
! 4529: static char del;
! 4530: static char fs;
! 4531: struct sgttyb tt;
! 4532: struct tchars tc;
! 4533:
! 4534: if (frm_filter) return; /* nothing special if used as filter */
! 4535:
! 4536: fflush (stdin);
! 4537: fflush (stdout);
! 4538: fflush (stderr);
! 4539:
! 4540: ioctl (0, TIOCGETP, &tt);
! 4541: ioctl (0, TIOCGETC, &tc);
! 4542:
! 4543: if (action == UNIX) {
! 4544:
! 4545: tt.sg_flags &= ~02; /* no cbreak mode */
! 4546: tt.sg_flags |= (010 | 020); /* echo ; CR to LF map */
! 4547: tc.t_quitc = fs; /* quit */
! 4548: tc.t_intrc = del; /* interrupt */
! 4549:
! 4550: /* we desperately tried to do it with DEL - but it didn't work */
! 4551:
! 4552: }
! 4553: else { /* action == MUMPS */
! 4554:
! 4555: tt.sg_flags |= 02; /* cbreak mode */
! 4556: tt.sg_flags &= (~010 & ~020); /* 10 no echo; 20 no CR map */
! 4557: del = tc.t_intrc; /* save previous state of */
! 4558: fs = tc.t_quitc; /* quit and interrupt */
! 4559: tc.t_intrc = BrkKey; /* interrupt = CTRL/C */
! 4560: tc.t_quitc = (zbreakon || hardcopy) ? STX : -1; /* zbreak/hardcopy */
! 4561:
! 4562: }
! 4563:
! 4564: ioctl (0, TIOCSETP, &tt);
! 4565: ioctl (0, TIOCSETC, &tc);
! 4566:
! 4567: } /* end of set_io() */
! 4568:
! 4569: void set_break (short break_char)
! 4570: {
! 4571: struct tchars tc;
! 4572:
! 4573: ioctl (0, TIOCGETC, &tc);
! 4574:
! 4575: tc.t_intrc = break_char;
! 4576:
! 4577: ioctl (0, TIOCSETC, &tc);
! 4578:
! 4579: return;
! 4580:
! 4581: } /* end of set_break */
! 4582:
! 4583: void set_zbreak (short quit_char)
! 4584: {
! 4585: struct tchars tc;
! 4586:
! 4587:
! 4588: ioctl (0, TIOCGETC, &tc);
! 4589:
! 4590: tc.t_quitc = quit_char;
! 4591:
! 4592: ioctl (0, TIOCSETC, &tc);
! 4593:
! 4594: return;
! 4595:
! 4596: } /* end of set_zbreak */
! 4597:
! 4598: #endif /* SYSFIVE */
! 4599:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>