Sun Jul 30 11:47:08 2023 UTC ()
Pull up following revision(s) (requested by uwe in ticket #257):
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.25
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.26
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.27
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.28
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.29
	sys/dev/wscons/wsemul_vt100.c: revision 1.50
	sys/dev/wscons/wsemul_vt100.c: revision 1.51
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.30
	sys/dev/wscons/wsemul_vt100_subr.c: revision 1.31

Fix off by one (Crystal Kolipe in tech-kern@)

Add rin, indn, vpa, hpa, and cbt terminfo capabilities (Crystal Kolipe)

wscons(4): Ignore nonsense tab stops in vt100 emulation.

wscons(4): Paranoia: Clamp numbers of rows and columns.

wsemul_vt100_subr: don't assert unsigned ncols >= 0

wsemul_vt100_subr: spell edp->tabs assertion with NULL

Avoid overflow with too many ';' (David Leadbeater)

Prefix all messages with the method name

wsemul_vt100_subr: complete the refactoring from 2010
In 1.20 refactoring, functions in this file were changed to accept a
pointer to the new base class instead of the full emuldata:
  -wsemul_vt100_foo(struct wsemul_vt100_emuldata *edp, ...)
  +wsemul_vt100_foo(struct vt100base_data *edp, ...)
but the argument name was not changed.  While this saved on the diff
churn back then, it created a rather unfortunate situation where the
same emulation state variables are referred to differently in this
file and other vt100 emulation files.  Complete that old change by
renaming the base class arguments to match the variable name used for
it in other files.

Same object code is generated.


(martin)
diff -r1.49 -r1.49.4.1 src/sys/dev/wscons/wsemul_vt100.c
diff -r1.24 -r1.24.30.1 src/sys/dev/wscons/wsemul_vt100_subr.c

cvs diff -r1.49 -r1.49.4.1 src/sys/dev/wscons/wsemul_vt100.c (expand / switch to unified diff)

--- src/sys/dev/wscons/wsemul_vt100.c 2022/01/02 23:46:21 1.49
+++ src/sys/dev/wscons/wsemul_vt100.c 2023/07/30 11:47:08 1.49.4.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wsemul_vt100.c,v 1.49 2022/01/02 23:46:21 uwe Exp $ */ 1/* $NetBSD: wsemul_vt100.c,v 1.49.4.1 2023/07/30 11:47:08 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved. 5 * Matthias Drochner. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,27 +17,27 @@ @@ -17,27 +17,27 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * 26 *
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.49 2022/01/02 23:46:21 uwe Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.49.4.1 2023/07/30 11:47:08 martin Exp $");
31 31
32#ifdef _KERNEL_OPT 32#ifdef _KERNEL_OPT
33#include "opt_wsmsgattrs.h" 33#include "opt_wsmsgattrs.h"
34#endif 34#endif
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/time.h> 38#include <sys/time.h>
39#include <sys/malloc.h> 39#include <sys/malloc.h>
40#include <sys/fcntl.h> 40#include <sys/fcntl.h>
41 41
42#include <dev/wscons/wsconsio.h> 42#include <dev/wscons/wsconsio.h>
43#include <dev/wscons/wsdisplayvar.h> 43#include <dev/wscons/wsdisplayvar.h>
@@ -283,28 +283,34 @@ wsemul_vt100_detach(void *cookie, u_int  @@ -283,28 +283,34 @@ wsemul_vt100_detach(void *cookie, u_int
283 f(edp->decgraphtab) 283 f(edp->decgraphtab)
284 f(edp->dectechtab) 284 f(edp->dectechtab)
285 f(edp->nrctab) 285 f(edp->nrctab)
286#undef f 286#undef f
287 if (edp != &wsemul_vt100_console_emuldata) 287 if (edp != &wsemul_vt100_console_emuldata)
288 free(edp, M_DEVBUF); 288 free(edp, M_DEVBUF);
289} 289}
290 290
291static void 291static void
292wsemul_vt100_resize(void * cookie, const struct wsscreen_descr *type) 292wsemul_vt100_resize(void * cookie, const struct wsscreen_descr *type)
293{ 293{
294 struct wsemul_vt100_emuldata *edp = cookie; 294 struct wsemul_vt100_emuldata *edp = cookie;
295 295
296 edp->bd.nrows = type->nrows; 296 /* XXX match malloc size in wsemul_vt100_attach */
297 edp->bd.ncols = type->ncols; 297 KASSERT(type->nrows >= 0);
 298 KASSERT(type->ncols >= 0);
 299 KASSERT(type->nrows <= 1024);
 300 KASSERT(type->ncols <= 1024);
 301
 302 edp->bd.nrows = MAX(0, MIN(type->nrows, 1024));
 303 edp->bd.ncols = MAX(0, MIN(type->ncols, 1024));
298 wsemul_vt100_reset(edp); 304 wsemul_vt100_reset(edp);
299 wsemul_vt100_resetop(cookie, WSEMUL_CLEARSCREEN); 305 wsemul_vt100_resetop(cookie, WSEMUL_CLEARSCREEN);
300} 306}
301 307
302static void 308static void
303wsemul_vt100_resetop(void *cookie, enum wsemul_resetops op) 309wsemul_vt100_resetop(void *cookie, enum wsemul_resetops op)
304{ 310{
305 struct wsemul_vt100_emuldata *edp = cookie; 311 struct wsemul_vt100_emuldata *edp = cookie;
306 struct vt100base_data *vd = &edp->bd; 312 struct vt100base_data *vd = &edp->bd;
307 313
308 switch (op) { 314 switch (op) {
309 case WSEMUL_RESET: 315 case WSEMUL_RESET:
310 wsemul_vt100_reset(edp); 316 wsemul_vt100_reset(edp);
@@ -612,27 +618,27 @@ wsemul_vt100_output_esc(struct wsemul_vt @@ -612,27 +618,27 @@ wsemul_vt100_output_esc(struct wsemul_vt
612 case '#': 618 case '#':
613 return VT100_EMUL_STATE_ESC_HASH; 619 return VT100_EMUL_STATE_ESC_HASH;
614 case ' ': /* 7/8 bit */ 620 case ' ': /* 7/8 bit */
615 return VT100_EMUL_STATE_ESC_SPC; 621 return VT100_EMUL_STATE_ESC_SPC;
616 case ']': /* OSC operating system command */ 622 case ']': /* OSC operating system command */
617 case '^': /* PM privacy message */ 623 case '^': /* PM privacy message */
618 case '_': /* APC application program command */ 624 case '_': /* APC application program command */
619 /* ignored */ 625 /* ignored */
620 return VT100_EMUL_STATE_STRING; 626 return VT100_EMUL_STATE_STRING;
621 case '<': /* exit VT52 mode - ignored */ 627 case '<': /* exit VT52 mode - ignored */
622 break; 628 break;
623 default: 629 default:
624#ifdef VT100_PRINTUNKNOWN 630#ifdef VT100_PRINTUNKNOWN
625 printf("ESC%c unknown\n", c); 631 printf("%s: ESC%c unknown\n", __func__, c);
626#endif 632#endif
627 break; 633 break;
628 } 634 }
629 return VT100_EMUL_STATE_NORMAL; 635 return VT100_EMUL_STATE_NORMAL;
630} 636}
631 637
632static u_int 638static u_int
633wsemul_vt100_output_scs94(struct wsemul_vt100_emuldata *edp, u_char c) 639wsemul_vt100_output_scs94(struct wsemul_vt100_emuldata *edp, u_char c)
634{ 640{
635 switch (c) { 641 switch (c) {
636 case '%': /* probably DEC supplemental graphic */ 642 case '%': /* probably DEC supplemental graphic */
637 return VT100_EMUL_STATE_SCS94_PERCENT; 643 return VT100_EMUL_STATE_SCS94_PERCENT;
638 case 'A': /* british / national */ 644 case 'A': /* british / national */
@@ -643,44 +649,46 @@ wsemul_vt100_output_scs94(struct wsemul_ @@ -643,44 +649,46 @@ wsemul_vt100_output_scs94(struct wsemul_
643 break; 649 break;
644 case '<': /* user preferred supplemental */ 650 case '<': /* user preferred supplemental */
645 /* XXX not really "user" preferred */ 651 /* XXX not really "user" preferred */
646 edp->chartab_G[edp->designating] = edp->isolatin1tab; 652 edp->chartab_G[edp->designating] = edp->isolatin1tab;
647 break; 653 break;
648 case '0': /* DEC special graphic */ 654 case '0': /* DEC special graphic */
649 edp->chartab_G[edp->designating] = edp->decgraphtab; 655 edp->chartab_G[edp->designating] = edp->decgraphtab;
650 break; 656 break;
651 case '>': /* DEC tech */ 657 case '>': /* DEC tech */
652 edp->chartab_G[edp->designating] = edp->dectechtab; 658 edp->chartab_G[edp->designating] = edp->dectechtab;
653 break; 659 break;
654 default: 660 default:
655#ifdef VT100_PRINTUNKNOWN 661#ifdef VT100_PRINTUNKNOWN
656 printf("ESC%c%c unknown\n", edp->designating + '(', c); 662 printf("%s: ESC%c%c unknown\n", __func__,
 663 edp->designating + '(', c);
657#endif 664#endif
658 break; 665 break;
659 } 666 }
660 return VT100_EMUL_STATE_NORMAL; 667 return VT100_EMUL_STATE_NORMAL;
661} 668}
662 669
663static u_int 670static u_int
664wsemul_vt100_output_scs94_percent(struct wsemul_vt100_emuldata *edp, u_char c) 671wsemul_vt100_output_scs94_percent(struct wsemul_vt100_emuldata *edp, u_char c)
665{ 672{
666 switch (c) { 673 switch (c) {
667 case '5': /* DEC supplemental graphic */ 674 case '5': /* DEC supplemental graphic */
668 /* XXX there are differences */ 675 /* XXX there are differences */
669 edp->chartab_G[edp->designating] = edp->isolatin1tab; 676 edp->chartab_G[edp->designating] = edp->isolatin1tab;
670 break; 677 break;
671 default: 678 default:
672#ifdef VT100_PRINTUNKNOWN 679#ifdef VT100_PRINTUNKNOWN
673 printf("ESC%c%%%c unknown\n", edp->designating + '(', c); 680 printf("%s: ESC%c%%%c unknown\n",
 681 __func__, edp->designating + '(', c);
674#endif 682#endif
675 break; 683 break;
676 } 684 }
677 return VT100_EMUL_STATE_NORMAL; 685 return VT100_EMUL_STATE_NORMAL;
678} 686}
679 687
680static u_int 688static u_int
681wsemul_vt100_output_scs96(struct wsemul_vt100_emuldata *edp, u_char c) 689wsemul_vt100_output_scs96(struct wsemul_vt100_emuldata *edp, u_char c)
682{ 690{
683 int nrc; 691 int nrc;
684 692
685 switch (c) { 693 switch (c) {
686 case '%': /* probably portuguese */ 694 case '%': /* probably portuguese */
@@ -712,63 +720,65 @@ wsemul_vt100_output_scs96(struct wsemul_ @@ -712,63 +720,65 @@ wsemul_vt100_output_scs96(struct wsemul_
712 case 'Z': /* spanish */ 720 case 'Z': /* spanish */
713 nrc = 9; 721 nrc = 9;
714 goto setnrc; 722 goto setnrc;
715 case '7': case 'H': /* swedish */ 723 case '7': case 'H': /* swedish */
716 nrc = 10; 724 nrc = 10;
717 goto setnrc; 725 goto setnrc;
718 case '=': /* swiss */ 726 case '=': /* swiss */
719 nrc = 11; 727 nrc = 11;
720setnrc: 728setnrc:
721 vt100_setnrc(edp, nrc); /* what table ??? */ 729 vt100_setnrc(edp, nrc); /* what table ??? */
722 break; 730 break;
723 default: 731 default:
724#ifdef VT100_PRINTUNKNOWN 732#ifdef VT100_PRINTUNKNOWN
725 printf("ESC%c%c unknown\n", edp->designating + '-' - 1, c); 733 printf("%s: ESC%c%c unknown\n",
 734 __func__, edp->designating + '-' - 1, c);
726#endif 735#endif
727 break; 736 break;
728 } 737 }
729 return VT100_EMUL_STATE_NORMAL; 738 return VT100_EMUL_STATE_NORMAL;
730} 739}
731 740
732static u_int 741static u_int
733wsemul_vt100_output_scs96_percent(struct wsemul_vt100_emuldata *edp, u_char c) 742wsemul_vt100_output_scs96_percent(struct wsemul_vt100_emuldata *edp, u_char c)
734{ 743{
735 switch (c) { 744 switch (c) {
736 case '6': /* portuguese */ 745 case '6': /* portuguese */
737 vt100_setnrc(edp, 8); 746 vt100_setnrc(edp, 8);
738 break; 747 break;
739 default: 748 default:
740#ifdef VT100_PRINTUNKNOWN 749#ifdef VT100_PRINTUNKNOWN
741 printf("ESC%c%%%c unknown\n", edp->designating + '-', c); 750 printf("%s: ESC%c%%%c unknown\n",
 751 __func__, edp->designating + '-', c);
742#endif 752#endif
743 break; 753 break;
744 } 754 }
745 return VT100_EMUL_STATE_NORMAL; 755 return VT100_EMUL_STATE_NORMAL;
746} 756}
747 757
748static u_int 758static u_int
749wsemul_vt100_output_esc_spc(struct wsemul_vt100_emuldata *edp, 759wsemul_vt100_output_esc_spc(struct wsemul_vt100_emuldata *edp,
750 u_char c) 760 u_char c)
751{ 761{
752 switch (c) { 762 switch (c) {
753 case 'F': /* 7-bit controls */ 763 case 'F': /* 7-bit controls */
754 case 'G': /* 8-bit controls */ 764 case 'G': /* 8-bit controls */
755#ifdef VT100_PRINTNOTIMPL 765#ifdef VT100_PRINTNOTIMPL
756 printf("ESC<SPC>%c ignored\n", c); 766 printf("%s: ESC<SPC>%c ignored\n", __func__, c);
757#endif 767#endif
758 break; 768 break;
759 default: 769 default:
760#ifdef VT100_PRINTUNKNOWN 770#ifdef VT100_PRINTUNKNOWN
761 printf("ESC<SPC>%c unknown\n", c); 771 printf("%s: ESC<SPC>%c unknown\n", __func__, c);
762#endif 772#endif
763 break; 773 break;
764 } 774 }
765 return VT100_EMUL_STATE_NORMAL; 775 return VT100_EMUL_STATE_NORMAL;
766} 776}
767 777
768static u_int 778static u_int
769wsemul_vt100_output_string(struct wsemul_vt100_emuldata *edp, u_char c) 779wsemul_vt100_output_string(struct wsemul_vt100_emuldata *edp, u_char c)
770{ 780{
771 struct vt100base_data *vd = &edp->bd; 781 struct vt100base_data *vd = &edp->bd;
772 782
773 if (vd->dcstype && vd->dcspos < DCS_MAXLEN) 783 if (vd->dcstype && vd->dcspos < DCS_MAXLEN)
774 vd->dcsarg[vd->dcspos++] = c; 784 vd->dcsarg[vd->dcspos++] = c;
@@ -791,95 +801,96 @@ static u_int @@ -791,95 +801,96 @@ static u_int
791wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c) 801wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c)
792{ 802{
793 struct vt100base_data *vd = &edp->bd; 803 struct vt100base_data *vd = &edp->bd;
794 804
795 switch (c) { 805 switch (c) {
796 case '0': case '1': case '2': case '3': case '4': 806 case '0': case '1': case '2': case '3': case '4':
797 case '5': case '6': case '7': case '8': case '9': 807 case '5': case '6': case '7': case '8': case '9':
798 /* argument digit */ 808 /* argument digit */
799 if (vd->nargs > VT100_EMUL_NARGS - 1) 809 if (vd->nargs > VT100_EMUL_NARGS - 1)
800 break; 810 break;
801 vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) + 811 vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
802 (c - '0'); 812 (c - '0');
803 break; 813 break;
804 case ';': /* argument terminator */ 
805 vd->nargs++; 
806 break; 
807 default: 814 default:
808 vd->nargs++; 815 vd->nargs++;
809 if (vd->nargs > VT100_EMUL_NARGS) { 816 if (vd->nargs > VT100_EMUL_NARGS) {
810#ifdef VT100_DEBUG 817#ifdef VT100_DEBUG
811 printf("vt100: too many arguments\n"); 818 printf("%s: too many arguments\n", __func__);
812#endif 819#endif
813 vd->nargs = VT100_EMUL_NARGS; 820 vd->nargs = VT100_EMUL_NARGS;
814 } 821 }
 822 if (c == ';') /* argument terminator */
 823 break;
815 switch (c) { 824 switch (c) {
816 case '$': 825 case '$':
817 return VT100_EMUL_STATE_DCS_DOLLAR; 826 return VT100_EMUL_STATE_DCS_DOLLAR;
818 case '{': /* DECDLD soft charset */ 827 case '{': /* DECDLD soft charset */
819 case '!': /* DECRQUPSS user preferred supplemental set */ 828 case '!': /* DECRQUPSS user preferred supplemental set */
820 /* 'u' must follow - need another state */ 829 /* 'u' must follow - need another state */
821 case '|': /* DECUDK program F6..F20 */ 830 case '|': /* DECUDK program F6..F20 */
822#ifdef VT100_PRINTNOTIMPL 831#ifdef VT100_PRINTNOTIMPL
823 printf("DCS%c ignored\n", c); 832 printf("%s: DCS%c ignored\n", __func__, c);
824#endif 833#endif
825 break; 834 break;
826 default: 835 default:
827#ifdef VT100_PRINTUNKNOWN 836#ifdef VT100_PRINTUNKNOWN
828 printf("DCS%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1)); 837 printf("%s: DCS%c (%d, %d) unknown\n",
 838 __func__, c, ARG(vd, 0), ARG(vd, 1));
829#endif 839#endif
830 break; 840 break;
831 } 841 }
832 return VT100_EMUL_STATE_STRING; 842 return VT100_EMUL_STATE_STRING;
833 } 843 }
834 844
835 return VT100_EMUL_STATE_DCS; 845 return VT100_EMUL_STATE_DCS;
836} 846}
837 847
838static u_int 848static u_int
839wsemul_vt100_output_dcs_dollar(struct wsemul_vt100_emuldata *edp, u_char c) 849wsemul_vt100_output_dcs_dollar(struct wsemul_vt100_emuldata *edp, u_char c)
840{ 850{
841 struct vt100base_data *vd = &edp->bd; 851 struct vt100base_data *vd = &edp->bd;
842 852
843 switch (c) { 853 switch (c) {
844 case 'p': /* DECRSTS terminal state restore */ 854 case 'p': /* DECRSTS terminal state restore */
845 case 'q': /* DECRQSS control function request */ 855 case 'q': /* DECRQSS control function request */
846#ifdef VT100_PRINTNOTIMPL 856#ifdef VT100_PRINTNOTIMPL
847 printf("DCS$%c ignored\n", c); 857 printf("%s: DCS$%c ignored\n", __func__, c);
848#endif 858#endif
849 break; 859 break;
850 case 't': /* DECRSPS restore presentation state */ 860 case 't': /* DECRSPS restore presentation state */
851 switch (ARG(vd, 0)) { 861 switch (ARG(vd, 0)) {
852 case 0: /* error */ 862 case 0: /* error */
853 break; 863 break;
854 case 1: /* cursor information restore */ 864 case 1: /* cursor information restore */
855#ifdef VT100_PRINTNOTIMPL 865#ifdef VT100_PRINTNOTIMPL
856 printf("DCS1$t ignored\n"); 866 printf("%s: DCS1$t ignored\n", __func__);
857#endif 867#endif
858 break; 868 break;
859 case 2: /* tab stop restore */ 869 case 2: /* tab stop restore */
860 vd->dcspos = 0; 870 vd->dcspos = 0;
861 vd->dcstype = DCSTYPE_TABRESTORE; 871 vd->dcstype = DCSTYPE_TABRESTORE;
862 break; 872 break;
863 default: 873 default:
864#ifdef VT100_PRINTUNKNOWN 874#ifdef VT100_PRINTUNKNOWN
865 printf("DCS%d$t unknown\n", ARG(vd, 0)); 875 printf("%s: DCS%d$t unknown\n", __func__, ARG(vd, 0));
866#endif 876#endif
867 break; 877 break;
868 } 878 }
869 break; 879 break;
870 default: 880 default:
871#ifdef VT100_PRINTUNKNOWN 881#ifdef VT100_PRINTUNKNOWN
872 printf("DCS$%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1)); 882 printf("%s: DCS$%c (%d, %d) unknown\n",
 883 __func__, c, ARG(vd, 0), ARG(vd, 1));
873#endif 884#endif
874 break; 885 break;
875 } 886 }
876 return VT100_EMUL_STATE_STRING; 887 return VT100_EMUL_STATE_STRING;
877} 888}
878 889
879static u_int 890static u_int
880wsemul_vt100_output_esc_hash(struct wsemul_vt100_emuldata *edp, u_char c) 891wsemul_vt100_output_esc_hash(struct wsemul_vt100_emuldata *edp, u_char c)
881{ 892{
882 struct vt100base_data *vd = &edp->bd; 893 struct vt100base_data *vd = &edp->bd;
883 int i, j; 894 int i, j;
884 895
885 switch (c) { 896 switch (c) {
@@ -915,68 +926,67 @@ wsemul_vt100_output_esc_hash(struct wsem @@ -915,68 +926,67 @@ wsemul_vt100_output_esc_hash(struct wsem
915 vd->ccol = (vd->ncols >> 1) - 1; 926 vd->ccol = (vd->ncols >> 1) - 1;
916 } 927 }
917 break; 928 break;
918 case '8': /* DECALN */ 929 case '8': /* DECALN */
919 for (i = 0; i < vd->nrows; i++) 930 for (i = 0; i < vd->nrows; i++)
920 for (j = 0; j < vd->ncols; j++) 931 for (j = 0; j < vd->ncols; j++)
921 (*vd->emulops->putchar)(vd->emulcookie, i, j, 932 (*vd->emulops->putchar)(vd->emulcookie, i, j,
922 'E', vd->curattr); 933 'E', vd->curattr);
923 vd->ccol = 0; 934 vd->ccol = 0;
924 vd->crow = 0; 935 vd->crow = 0;
925 break; 936 break;
926 default: 937 default:
927#ifdef VT100_PRINTUNKNOWN 938#ifdef VT100_PRINTUNKNOWN
928 printf("ESC#%c unknown\n", c); 939 printf("%s: ESC#%c unknown\n", __func__, c);
929#endif 940#endif
930 break; 941 break;
931 } 942 }
932 return VT100_EMUL_STATE_NORMAL; 943 return VT100_EMUL_STATE_NORMAL;
933} 944}
934 945
935static u_int 946static u_int
936wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c) 947wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c)
937{ 948{
938 struct vt100base_data *vd = &edp->bd; 949 struct vt100base_data *vd = &edp->bd;
939 950
940 switch (c) { 951 switch (c) {
941 case '0': case '1': case '2': case '3': case '4': 952 case '0': case '1': case '2': case '3': case '4':
942 case '5': case '6': case '7': case '8': case '9': 953 case '5': case '6': case '7': case '8': case '9':
943 /* argument digit */ 954 /* argument digit */
944 if (vd->nargs > VT100_EMUL_NARGS - 1) 955 if (vd->nargs > VT100_EMUL_NARGS - 1)
945 break; 956 break;
946 vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) + 957 vd->args[vd->nargs] = (vd->args[vd->nargs] * 10) +
947 (c - '0'); 958 (c - '0');
948 break; 959 break;
949 case ';': /* argument terminator */ 
950 vd->nargs++; 
951 break; 
952 case '?': /* DEC specific */ 960 case '?': /* DEC specific */
953 case '>': /* DA query */ 961 case '>': /* DA query */
954 vd->modif1 = c; 962 vd->modif1 = c;
955 break; 963 break;
956 case '!': 964 case '!':
957 case '"': 965 case '"':
958 case '$': 966 case '$':
959 case '&': 967 case '&':
960 vd->modif2 = c; 968 vd->modif2 = c;
961 break; 969 break;
962 default: /* end of escape sequence */ 970 default: /* end of escape sequence, argument terminator */
963 vd->nargs++; 971 vd->nargs++;
964 if (vd->nargs > VT100_EMUL_NARGS) { 972 if (vd->nargs > VT100_EMUL_NARGS) {
965#ifdef VT100_DEBUG 973#ifdef VT100_DEBUG
966 printf("vt100: too many arguments\n"); 974 printf("%s: too many arguments\n", __func__);
967#endif 975#endif
968 vd->nargs = VT100_EMUL_NARGS; 976 vd->nargs = VT100_EMUL_NARGS;
969 } 977 }
 978 if (c == ';') /* argument terminator */
 979 break;
970 wsemul_vt100_handle_csi(vd, c); 980 wsemul_vt100_handle_csi(vd, c);
971 return VT100_EMUL_STATE_NORMAL; 981 return VT100_EMUL_STATE_NORMAL;
972 } 982 }
973 return VT100_EMUL_STATE_CSI; 983 return VT100_EMUL_STATE_CSI;
974} 984}
975 985
976static void 986static void
977wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel) 987wsemul_vt100_output(void *cookie, const u_char *data, u_int count, int kernel)
978{ 988{
979 struct wsemul_vt100_emuldata *edp = cookie; 989 struct wsemul_vt100_emuldata *edp = cookie;
980 struct vt100base_data *vd = &edp->bd; 990 struct vt100base_data *vd = &edp->bd;
981 991
982#ifdef DIAGNOSTIC 992#ifdef DIAGNOSTIC
@@ -1032,28 +1042,28 @@ wsemul_vt100_setmsgattrs(void *cookie, c @@ -1032,28 +1042,28 @@ wsemul_vt100_setmsgattrs(void *cookie, c
1032 vd->msgattrs.default_bg = vd->msgattrs.kernel_bg = 0; 1042 vd->msgattrs.default_bg = vd->msgattrs.kernel_bg = 0;
1033 vd->msgattrs.default_fg = vd->msgattrs.kernel_fg = 0; 1043 vd->msgattrs.default_fg = vd->msgattrs.kernel_fg = 0;
1034 } 1044 }
1035 1045
1036 error = (*vd->emulops->allocattr)(vd->emulcookie, 1046 error = (*vd->emulops->allocattr)(vd->emulcookie,
1037 vd->msgattrs.default_fg, 1047 vd->msgattrs.default_fg,
1038 vd->msgattrs.default_bg, 1048 vd->msgattrs.default_bg,
1039 vd->msgattrs.default_attrs, 1049 vd->msgattrs.default_attrs,
1040 &tmp); 1050 &tmp);
1041#ifndef VT100_DEBUG 1051#ifndef VT100_DEBUG
1042 __USE(error); 1052 __USE(error);
1043#else 1053#else
1044 if (error) 1054 if (error)
1045 printf("vt100: failed to allocate attribute for default " 1055 printf("%s: failed to allocate attribute for default "
1046 "messages\n"); 1056 "messages\n", __func__);
1047 else 1057 else
1048#endif 1058#endif
1049 { 1059 {
1050 if (vd->curattr == vd->defattr) { 1060 if (vd->curattr == vd->defattr) {
1051 vd->bkgdattr = vd->curattr = tmp; 1061 vd->bkgdattr = vd->curattr = tmp;
1052 vd->attrflags = vd->msgattrs.default_attrs; 1062 vd->attrflags = vd->msgattrs.default_attrs;
1053 vd->bgcol = vd->msgattrs.default_bg; 1063 vd->bgcol = vd->msgattrs.default_bg;
1054 vd->fgcol = vd->msgattrs.default_fg; 1064 vd->fgcol = vd->msgattrs.default_fg;
1055 } else { 1065 } else {
1056 edp->savedbkgdattr = edp->savedattr = tmp; 1066 edp->savedbkgdattr = edp->savedattr = tmp;
1057 edp->savedattrflags = vd->msgattrs.default_attrs; 1067 edp->savedattrflags = vd->msgattrs.default_attrs;
1058 edp->savedbgcol = vd->msgattrs.default_bg; 1068 edp->savedbgcol = vd->msgattrs.default_bg;
1059 edp->savedfgcol = vd->msgattrs.default_fg; 1069 edp->savedfgcol = vd->msgattrs.default_fg;
@@ -1061,25 +1071,25 @@ wsemul_vt100_setmsgattrs(void *cookie, c @@ -1061,25 +1071,25 @@ wsemul_vt100_setmsgattrs(void *cookie, c
1061 if (vd->emulops->replaceattr != NULL) 1071 if (vd->emulops->replaceattr != NULL)
1062 (*vd->emulops->replaceattr)(vd->emulcookie, 1072 (*vd->emulops->replaceattr)(vd->emulcookie,
1063 vd->defattr, tmp); 1073 vd->defattr, tmp);
1064 vd->defattr = tmp; 1074 vd->defattr = tmp;
1065 } 1075 }
1066 1076
1067 error = (*vd->emulops->allocattr)(vd->emulcookie, 1077 error = (*vd->emulops->allocattr)(vd->emulcookie,
1068 vd->msgattrs.kernel_fg, 1078 vd->msgattrs.kernel_fg,
1069 vd->msgattrs.kernel_bg, 1079 vd->msgattrs.kernel_bg,
1070 vd->msgattrs.kernel_attrs, 1080 vd->msgattrs.kernel_attrs,
1071 &tmp); 1081 &tmp);
1072#ifdef VT100_DEBUG 1082#ifdef VT100_DEBUG
1073 if (error) 1083 if (error)
1074 printf("vt100: failed to allocate attribute for kernel " 1084 printf("%s: failed to allocate attribute for kernel "
1075 "messages\n"); 1085 "messages\n", __func__);
1076 else 1086 else
1077#endif 1087#endif
1078 { 1088 {
1079 if (vd->emulops->replaceattr != NULL) 1089 if (vd->emulops->replaceattr != NULL)
1080 (*vd->emulops->replaceattr)(vd->emulcookie, 1090 (*vd->emulops->replaceattr)(vd->emulcookie,
1081 edp->kernattr, tmp); 1091 edp->kernattr, tmp);
1082 edp->kernattr = tmp; 1092 edp->kernattr = tmp;
1083 } 1093 }
1084} 1094}
1085#endif /* WSDISPLAY_CUSTOM_OUTPUT */ 1095#endif /* WSDISPLAY_CUSTOM_OUTPUT */

cvs diff -r1.24 -r1.24.30.1 src/sys/dev/wscons/wsemul_vt100_subr.c (expand / switch to unified diff)

--- src/sys/dev/wscons/wsemul_vt100_subr.c 2018/12/06 01:42:20 1.24
+++ src/sys/dev/wscons/wsemul_vt100_subr.c 2023/07/30 11:47:08 1.24.30.1
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wsemul_vt100_subr.c,v 1.24 2018/12/06 01:42:20 uwe Exp $ */ 1/* $NetBSD: wsemul_vt100_subr.c,v 1.24.30.1 2023/07/30 11:47:08 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved. 5 * Matthias Drochner. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -17,486 +17,514 @@ @@ -17,486 +17,514 @@
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * 26 *
27 */ 27 */
28 28
29#include <sys/cdefs.h> 29#include <sys/cdefs.h>
30__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_subr.c,v 1.24 2018/12/06 01:42:20 uwe Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100_subr.c,v 1.24.30.1 2023/07/30 11:47:08 martin Exp $");
31 31
32#include <sys/param.h> 32#include <sys/param.h>
33#include <sys/systm.h> 33#include <sys/systm.h>
34 34
35#include <dev/wscons/wsconsio.h> 35#include <dev/wscons/wsconsio.h>
36#include <dev/wscons/wsksymvar.h> 36#include <dev/wscons/wsksymvar.h>
37#include <dev/wscons/wsdisplayvar.h> 37#include <dev/wscons/wsdisplayvar.h>
38#include <dev/wscons/wsemulvar.h> 38#include <dev/wscons/wsemulvar.h>
39#include <dev/wscons/vt100_base.h> 39#include <dev/wscons/vt100_base.h>
40 40
41#ifdef _KERNEL_OPT 41#ifdef _KERNEL_OPT
42#include "opt_wsemul.h" 42#include "opt_wsemul.h"
43#endif 43#endif
44 44
45static int vt100_selectattribute(struct vt100base_data *, 45static int vt100_selectattribute(struct vt100base_data *,
46 int, int, int, long *, long *); 46 int, int, int, long *, long *);
47static int vt100_ansimode(struct vt100base_data *, int, int); 47static int vt100_ansimode(struct vt100base_data *, int, int);
48static int vt100_decmode(struct vt100base_data *, int, int); 48static int vt100_decmode(struct vt100base_data *, int, int);
49#define VTMODE_SET 33 49#define VTMODE_SET 33
50#define VTMODE_RESET 44 50#define VTMODE_RESET 44
51#define VTMODE_REPORT 55 51#define VTMODE_REPORT 55
52 52
53/* 53/*
54 * scroll up within scrolling region 54 * scroll up within scrolling region
55 */ 55 */
56void 56void
57wsemul_vt100_scrollup(struct vt100base_data *edp, int n) 57wsemul_vt100_scrollup(struct vt100base_data *vd, int n)
58{ 58{
59 int help; 59 int help;
60 60
61 if (n > edp->scrreg_nrows) 61 if (n > vd->scrreg_nrows)
62 n = edp->scrreg_nrows; 62 n = vd->scrreg_nrows;
63 63
64 help = edp->scrreg_nrows - n; 64 help = vd->scrreg_nrows - n;
65 if (help > 0) { 65 if (help > 0) {
66 (*edp->emulops->copyrows)(edp->emulcookie, 66 (*vd->emulops->copyrows)(vd->emulcookie,
67 edp->scrreg_startrow + n, 67 vd->scrreg_startrow + n,
68 edp->scrreg_startrow, 68 vd->scrreg_startrow,
69 help); 69 help);
70 if (edp->dblwid) 70 if (vd->dblwid)
71 memmove(&edp->dblwid[edp->scrreg_startrow], 71 memmove(&vd->dblwid[vd->scrreg_startrow],
72 &edp->dblwid[edp->scrreg_startrow + n], 72 &vd->dblwid[vd->scrreg_startrow + n],
73 help); 73 help);
74 } 74 }
75 (*edp->emulops->eraserows)(edp->emulcookie, 75 (*vd->emulops->eraserows)(vd->emulcookie,
76 edp->scrreg_startrow + help, n, 76 vd->scrreg_startrow + help, n,
77 edp->bkgdattr); 77 vd->bkgdattr);
78 if (edp->dblwid) 78 if (vd->dblwid)
79 memset(&edp->dblwid[edp->scrreg_startrow + help], 0, n); 79 memset(&vd->dblwid[vd->scrreg_startrow + help], 0, n);
80 CHECK_DW(edp); 80 CHECK_DW(vd);
81} 81}
82 82
83/* 83/*
84 * scroll down within scrolling region 84 * scroll down within scrolling region
85 */ 85 */
86void 86void
87wsemul_vt100_scrolldown(struct vt100base_data *edp, int n) 87wsemul_vt100_scrolldown(struct vt100base_data *vd, int n)
88{ 88{
89 int help; 89 int help;
90 90
91 if (n > edp->scrreg_nrows) 91 if (n > vd->scrreg_nrows)
92 n = edp->scrreg_nrows; 92 n = vd->scrreg_nrows;
93 93
94 help = edp->scrreg_nrows - n; 94 help = vd->scrreg_nrows - n;
95 if (help > 0) { 95 if (help > 0) {
96 (*edp->emulops->copyrows)(edp->emulcookie, 96 (*vd->emulops->copyrows)(vd->emulcookie,
97 edp->scrreg_startrow, 97 vd->scrreg_startrow,
98 edp->scrreg_startrow + n, 98 vd->scrreg_startrow + n,
99 help); 99 help);
100 if (edp->dblwid) 100 if (vd->dblwid)
101 memmove(&edp->dblwid[edp->scrreg_startrow + n], 101 memmove(&vd->dblwid[vd->scrreg_startrow + n],
102 &edp->dblwid[edp->scrreg_startrow], 102 &vd->dblwid[vd->scrreg_startrow],
103 help); 103 help);
104 } 104 }
105 (*edp->emulops->eraserows)(edp->emulcookie, 105 (*vd->emulops->eraserows)(vd->emulcookie,
106 edp->scrreg_startrow, n, 106 vd->scrreg_startrow, n,
107 edp->bkgdattr); 107 vd->bkgdattr);
108 if (edp->dblwid) 108 if (vd->dblwid)
109 memset(&edp->dblwid[edp->scrreg_startrow], 0, n); 109 memset(&vd->dblwid[vd->scrreg_startrow], 0, n);
110 CHECK_DW(edp); 110 CHECK_DW(vd);
111} 111}
112 112
113/* 113/*
114 * erase in display 114 * erase in display
115 */ 115 */
116void 116void
117wsemul_vt100_ed(struct vt100base_data *edp, int arg) 117wsemul_vt100_ed(struct vt100base_data *vd, int arg)
118{ 118{
119 int n; 119 int n;
120 120
121 switch (arg) { 121 switch (arg) {
122 case 0: /* cursor to end */ 122 case 0: /* cursor to end */
123 ERASECOLS(edp, edp->ccol, COLS_LEFT(edp) + 1, edp->bkgdattr); 123 ERASECOLS(vd, vd->ccol, COLS_LEFT(vd) + 1, vd->bkgdattr);
124 n = edp->nrows - edp->crow - 1; 124 n = vd->nrows - vd->crow - 1;
125 if (n > 0) { 125 if (n > 0) {
126 (*edp->emulops->eraserows)(edp->emulcookie, 126 (*vd->emulops->eraserows)(vd->emulcookie,
127 edp->crow + 1, n, 127 vd->crow + 1, n,
128 edp->bkgdattr); 128 vd->bkgdattr);
129 if (edp->dblwid) 129 if (vd->dblwid)
130 memset(&edp->dblwid[edp->crow + 1], 0, n); 130 memset(&vd->dblwid[vd->crow + 1], 0, n);
131 } 131 }
132 break; 132 break;
133 case 1: /* beginning to cursor */ 133 case 1: /* beginning to cursor */
134 if (edp->crow > 0) { 134 if (vd->crow > 0) {
135 (*edp->emulops->eraserows)(edp->emulcookie, 135 (*vd->emulops->eraserows)(vd->emulcookie,
136 0, edp->crow, 136 0, vd->crow,
137 edp->bkgdattr); 137 vd->bkgdattr);
138 if (edp->dblwid) 138 if (vd->dblwid)
139 memset(&edp->dblwid[0], 0, edp->crow); 139 memset(&vd->dblwid[0], 0, vd->crow);
140 } 140 }
141 ERASECOLS(edp, 0, edp->ccol + 1, edp->bkgdattr); 141 ERASECOLS(vd, 0, vd->ccol + 1, vd->bkgdattr);
142 break; 142 break;
143 case 2: /* complete display */ 143 case 2: /* complete display */
144 (*edp->emulops->eraserows)(edp->emulcookie, 144 (*vd->emulops->eraserows)(vd->emulcookie,
145 0, edp->nrows, 145 0, vd->nrows,
146 edp->bkgdattr); 146 vd->bkgdattr);
147 if (edp->dblwid) 147 if (vd->dblwid)
148 memset(&edp->dblwid[0], 0, edp->nrows); 148 memset(&vd->dblwid[0], 0, vd->nrows);
149 break; 149 break;
150 default: 150 default:
151#ifdef VT100_PRINTUNKNOWN 151#ifdef VT100_PRINTUNKNOWN
152 printf("ed(%d) unknown\n", arg); 152 printf("ed(%d) unknown\n", arg);
153#endif 153#endif
154 break; 154 break;
155 } 155 }
156 CHECK_DW(edp); 156 CHECK_DW(vd);
157} 157}
158 158
159/* 159/*
160 * erase in line 160 * erase in line
161 */ 161 */
162void 162void
163wsemul_vt100_el(struct vt100base_data *edp, int arg) 163wsemul_vt100_el(struct vt100base_data *vd, int arg)
164{ 164{
165 switch (arg) { 165 switch (arg) {
166 case 0: /* cursor to end */ 166 case 0: /* cursor to end */
167 ERASECOLS(edp, edp->ccol, COLS_LEFT(edp) + 1, edp->bkgdattr); 167 ERASECOLS(vd, vd->ccol, COLS_LEFT(vd) + 1, vd->bkgdattr);
168 break; 168 break;
169 case 1: /* beginning to cursor */ 169 case 1: /* beginning to cursor */
170 ERASECOLS(edp, 0, edp->ccol + 1, edp->bkgdattr); 170 ERASECOLS(vd, 0, vd->ccol + 1, vd->bkgdattr);
171 break; 171 break;
172 case 2: /* complete line */ 172 case 2: /* complete line */
173 (*edp->emulops->erasecols)(edp->emulcookie, edp->crow, 173 (*vd->emulops->erasecols)(vd->emulcookie, vd->crow,
174 0, edp->ncols, 174 0, vd->ncols,
175 edp->bkgdattr); 175 vd->bkgdattr);
176 break; 176 break;
177 default: 177 default:
178#ifdef VT100_PRINTUNKNOWN 178#ifdef VT100_PRINTUNKNOWN
179 printf("el(%d) unknown\n", arg); 179 printf("el(%d) unknown\n", arg);
180#endif 180#endif
181 break; 181 break;
182 } 182 }
183} 183}
184 184
185/* 185/*
186 * handle commands after CSI (ESC[) 186 * handle commands after CSI (ESC[)
187 */ 187 */
188void 188void
189wsemul_vt100_handle_csi(struct vt100base_data *edp, u_char c) 189wsemul_vt100_handle_csi(struct vt100base_data *vd, u_char c)
190{ 190{
191 int n, help, flags, fgcol, bgcol; 191 int n, m, help, flags, fgcol, bgcol;
192 long attr, bkgdattr; 192 long attr, bkgdattr;
193 193
194#define A3(a, b, c) (((a) << 16) | ((b) << 8) | (c)) 194#define A3(a, b, c) (((a) << 16) | ((b) << 8) | (c))
195 switch (A3(edp->modif1, edp->modif2, c)) { 195 switch (A3(vd->modif1, vd->modif2, c)) {
196 case A3('>', '\0', 'c'): /* DA secondary */ 196 case A3('>', '\0', 'c'): /* DA secondary */
197 wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID2, 197 wsdisplay_emulinput(vd->cbcookie, WSEMUL_VT_ID2,
198 sizeof(WSEMUL_VT_ID2)); 198 sizeof(WSEMUL_VT_ID2) - 1);
199 break; 199 break;
200 200
201 case A3('\0', '\0', 'J'): /* ED selective erase in display */ 201 case A3('\0', '\0', 'J'): /* ED selective erase in display */
202 case A3('?', '\0', 'J'): /* DECSED selective erase in display */ 202 case A3('?', '\0', 'J'): /* DECSED selective erase in display */
203 wsemul_vt100_ed(edp, ARG(edp, 0)); 203 wsemul_vt100_ed(vd, ARG(vd, 0));
204 break; 204 break;
205 case A3('\0', '\0', 'K'): /* EL selective erase in line */ 205 case A3('\0', '\0', 'K'): /* EL selective erase in line */
206 case A3('?', '\0', 'K'): /* DECSEL selective erase in line */ 206 case A3('?', '\0', 'K'): /* DECSEL selective erase in line */
207 wsemul_vt100_el(edp, ARG(edp, 0)); 207 wsemul_vt100_el(vd, ARG(vd, 0));
208 break; 208 break;
209 case A3('\0', '\0', 'h'): /* SM */ 209 case A3('\0', '\0', 'h'): /* SM */
210 for (n = 0; n < edp->nargs; n++) 210 for (n = 0; n < vd->nargs; n++)
211 vt100_ansimode(edp, ARG(edp, n), VTMODE_SET); 211 vt100_ansimode(vd, ARG(vd, n), VTMODE_SET);
212 break; 212 break;
213 case A3('?', '\0', 'h'): /* DECSM */ 213 case A3('?', '\0', 'h'): /* DECSM */
214 for (n = 0; n < edp->nargs; n++) 214 for (n = 0; n < vd->nargs; n++)
215 vt100_decmode(edp, ARG(edp, n), VTMODE_SET); 215 vt100_decmode(vd, ARG(vd, n), VTMODE_SET);
216 break; 216 break;
217 case A3('\0', '\0', 'l'): /* RM */ 217 case A3('\0', '\0', 'l'): /* RM */
218 for (n = 0; n < edp->nargs; n++) 218 for (n = 0; n < vd->nargs; n++)
219 vt100_ansimode(edp, ARG(edp, n), VTMODE_RESET); 219 vt100_ansimode(vd, ARG(vd, n), VTMODE_RESET);
220 break; 220 break;
221 case A3('?', '\0', 'l'): /* DECRM */ 221 case A3('?', '\0', 'l'): /* DECRM */
222 for (n = 0; n < edp->nargs; n++) 222 for (n = 0; n < vd->nargs; n++)
223 vt100_decmode(edp, ARG(edp, n), VTMODE_RESET); 223 vt100_decmode(vd, ARG(vd, n), VTMODE_RESET);
224 break; 224 break;
225 case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */ 225 case A3('\0', '$', 'p'): /* DECRQM request mode ANSI */
226 vt100_ansimode(edp, ARG(edp, 0), VTMODE_REPORT); 226 vt100_ansimode(vd, ARG(vd, 0), VTMODE_REPORT);
227 break; 227 break;
228 case A3('?', '$', 'p'): /* DECRQM request mode DEC */ 228 case A3('?', '$', 'p'): /* DECRQM request mode DEC */
229 vt100_decmode(edp, ARG(edp, 0), VTMODE_REPORT); 229 vt100_decmode(vd, ARG(vd, 0), VTMODE_REPORT);
230 break; 230 break;
231 case A3('\0', '\0', 'i'): /* MC printer controller mode */ 231 case A3('\0', '\0', 'i'): /* MC printer controller mode */
232 case A3('?', '\0', 'i'): /* MC printer controller mode */ 232 case A3('?', '\0', 'i'): /* MC printer controller mode */
233 switch (ARG(edp, 0)) { 233 switch (ARG(vd, 0)) {
234 case 0: /* print screen */ 234 case 0: /* print screen */
235 case 1: /* print cursor line */ 235 case 1: /* print cursor line */
236 case 4: /* off */ 236 case 4: /* off */
237 case 5: /* on */ 237 case 5: /* on */
238#ifdef VT100_PRINTNOTIMPL 238#ifdef VT100_PRINTNOTIMPL
239 printf("CSI%di ignored\n", ARG(edp, 0)); 239 printf("CSI%di ignored\n", ARG(vd, 0));
240#endif 240#endif
241 break; 241 break;
242 default: 242 default:
243#ifdef VT100_PRINTUNKNOWN 243#ifdef VT100_PRINTUNKNOWN
244 printf("CSI%di unknown\n", ARG(edp, 0)); 244 printf("CSI%di unknown\n", ARG(vd, 0));
245#endif 245#endif
246 break; 246 break;
247 } 247 }
248 break; 248 break;
249 249
250#define A2(a, b) (((a) << 8) | (b)) 250#define A2(a, b) (((a) << 8) | (b))
251#if 0 /* XXX */ 251#if 0 /* XXX: edp not available here */
252 case A2('!', 'p'): /* DECSTR soft reset VT300 only */ 252 case A2('!', 'p'): /* DECSTR soft reset VT300 only */
253 wsemul_vt100_reset(edp); 253 wsemul_vt100_reset(edp);
254 break; 254 break;
255#endif 255#endif
256 256
257 case A2('"', 'p'): /* DECSCL */ 257 case A2('"', 'p'): /* DECSCL */
258 switch (ARG(edp, 0)) { 258 switch (ARG(vd, 0)) {
259 case 61: /* VT100 mode (no further arguments!) */ 259 case 61: /* VT100 mode (no further arguments!) */
260 break; 260 break;
261 case 62: 261 case 62:
262 case 63: /* VT300 mode */ 262 case 63: /* VT300 mode */
263 break; 263 break;
264 default: 264 default:
265#ifdef VT100_PRINTUNKNOWN 265#ifdef VT100_PRINTUNKNOWN
266 printf("CSI%d\"p unknown\n", ARG(edp, 0)); 266 printf("CSI%d\"p unknown\n", ARG(vd, 0));
267#endif 267#endif
268 break; 268 break;
269 } 269 }
270 switch (ARG(edp, 1)) { 270 switch (ARG(vd, 1)) {
271 case 0: 271 case 0:
272 case 2: /* 8-bit controls */ 272 case 2: /* 8-bit controls */
273#ifdef VT100_PRINTNOTIMPL 273#ifdef VT100_PRINTNOTIMPL
274 printf("CSI%d;%d\"p ignored\n", ARG(edp, 0), ARG(edp, 1)); 274 printf("CSI%d;%d\"p ignored\n", ARG(vd, 0), ARG(vd, 1));
275#endif 275#endif
276 break; 276 break;
277 case 1: /* 7-bit controls */ 277 case 1: /* 7-bit controls */
278 break; 278 break;
279 default: 279 default:
280#ifdef VT100_PRINTUNKNOWN 280#ifdef VT100_PRINTUNKNOWN
281 printf("CSI%d;%d\"p unknown\n", ARG(edp, 0), ARG(edp, 1)); 281 printf("CSI%d;%d\"p unknown\n", ARG(vd, 0), ARG(vd, 1));
282#endif 282#endif
283 break; 283 break;
284 } 284 }
285 break; 285 break;
286 case A2('"', 'q'): /* DECSCA select character attribute VT300 */ 286 case A2('"', 'q'): /* DECSCA select character attribute VT300 */
287 switch (ARG(edp, 0)) { 287 switch (ARG(vd, 0)) {
288 case 0: 288 case 0:
289 case 1: /* erasable */ 289 case 1: /* erasable */
290 break; 290 break;
291 case 2: /* not erasable */ 291 case 2: /* not erasable */
292#ifdef VT100_PRINTNOTIMPL 292#ifdef VT100_PRINTNOTIMPL
293 printf("CSI2\"q ignored\n"); 293 printf("CSI2\"q ignored\n");
294#endif 294#endif
295 break; 295 break;
296 default: 296 default:
297#ifdef VT100_PRINTUNKNOWN 297#ifdef VT100_PRINTUNKNOWN
298 printf("CSI%d\"q unknown\n", ARG(edp, 0)); 298 printf("CSI%d\"q unknown\n", ARG(vd, 0));
299#endif 299#endif
300 break; 300 break;
301 } 301 }
302 break; 302 break;
303 303
304 case A2('$', 'u'): /* DECRQTSR request terminal status report */ 304 case A2('$', 'u'): /* DECRQTSR request terminal status report */
305 switch (ARG(edp, 0)) { 305 switch (ARG(vd, 0)) {
306 case 0: /* ignored */ 306 case 0: /* ignored */
307 break; 307 break;
308 case 1: /* terminal state report */ 308 case 1: /* terminal state report */
309#ifdef VT100_PRINTNOTIMPL 309#ifdef VT100_PRINTNOTIMPL
310 printf("CSI1$u ignored\n"); 310 printf("CSI1$u ignored\n");
311#endif 311#endif
312 break; 312 break;
313 default: 313 default:
314#ifdef VT100_PRINTUNKNOWN 314#ifdef VT100_PRINTUNKNOWN
315 printf("CSI%d$u unknown\n", ARG(edp, 0)); 315 printf("CSI%d$u unknown\n", ARG(vd, 0));
316#endif 316#endif
317 break; 317 break;
318 } 318 }
319 break; 319 break;
320 case A2('$', 'w'): /* DECRQPSR request presentation status report 320 case A2('$', 'w'): /* DECRQPSR request presentation status report
321 (VT300 only) */ 321 (VT300 only) */
322 switch (ARG(edp, 0)) { 322 switch (ARG(vd, 0)) {
323 case 0: /* error */ 323 case 0: /* error */
324 break; 324 break;
325 case 1: /* cursor information report */ 325 case 1: /* cursor information report */
326#ifdef VT100_PRINTNOTIMPL 326#ifdef VT100_PRINTNOTIMPL
327 printf("CSI1$w ignored\n"); 327 printf("CSI1$w ignored\n");
328#endif 328#endif
329 break; 329 break;
330 case 2: /* tab stop report */ 330 case 2: /* tab stop report */
331 { 331 {
332 int i, j, ps = 0; 332 int i, j, ps = 0;
333 char buf[20]; 333 char buf[20];
334 KASSERT(edp->tabs != 0); 334 KASSERT(vd->tabs != NULL);
335 wsdisplay_emulinput(edp->cbcookie, "\033P2$u", 5); 335 wsdisplay_emulinput(vd->cbcookie, "\033P2$u", 5);
336 for (i = 0; i < edp->ncols; i++) 336 for (i = 0; i < vd->ncols; i++)
337 if (edp->tabs[i]) { 337 if (vd->tabs[i]) {
338 j = snprintf(buf, sizeof(buf), "%s%d", 338 j = snprintf(buf, sizeof(buf), "%s%d",
339 (ps ? "/" : ""), i + 1); 339 (ps ? "/" : ""), i + 1);
340 wsdisplay_emulinput(edp->cbcookie, 340 wsdisplay_emulinput(vd->cbcookie,
341 buf, j); 341 buf, j);
342 ps = 1; 342 ps = 1;
343 } 343 }
344 } 344 }
345 wsdisplay_emulinput(edp->cbcookie, "\033\\", 2); 345 wsdisplay_emulinput(vd->cbcookie, "\033\\", 2);
346 break; 346 break;
347 default: 347 default:
348#ifdef VT100_PRINTUNKNOWN 348#ifdef VT100_PRINTUNKNOWN
349 printf("CSI%d$w unknown\n", ARG(edp, 0)); 349 printf("CSI%d$w unknown\n", ARG(vd, 0));
350#endif 350#endif
351 break; 351 break;
352 } 352 }
353 break; 353 break;
354 case A2('$', '}'): /* DECSASD select active status display */ 354 case A2('$', '}'): /* DECSASD select active status display */
355 switch (ARG(edp, 0)) { 355 switch (ARG(vd, 0)) {
356 case 0: /* main display */ 356 case 0: /* main display */
357 case 1: /* status line */ 357 case 1: /* status line */
358#ifdef VT100_PRINTNOTIMPL 358#ifdef VT100_PRINTNOTIMPL
359 printf("CSI%d$} ignored\n", ARG(edp, 0)); 359 printf("CSI%d$} ignored\n", ARG(vd, 0));
360#endif 360#endif
361 break; 361 break;
362 default: 362 default:
363#ifdef VT100_PRINTUNKNOWN 363#ifdef VT100_PRINTUNKNOWN
364 printf("CSI%d$} unknown\n", ARG(edp, 0)); 364 printf("CSI%d$} unknown\n", ARG(vd, 0));
365#endif 365#endif
366 break; 366 break;
367 } 367 }
368 break; 368 break;
369 case A2('$', '~'): /* DECSSDD select status line type */ 369 case A2('$', '~'): /* DECSSDD select status line type */
370 switch (ARG(edp, 0)) { 370 switch (ARG(vd, 0)) {
371 case 0: /* none */ 371 case 0: /* none */
372 case 1: /* indicator */ 372 case 1: /* indicator */
373 case 2: /* host-writable */ 373 case 2: /* host-writable */
374#ifdef VT100_PRINTNOTIMPL 374#ifdef VT100_PRINTNOTIMPL
375 printf("CSI%d$~ ignored\n", ARG(edp, 0)); 375 printf("CSI%d$~ ignored\n", ARG(vd, 0));
376#endif 376#endif
377 break; 377 break;
378 default: 378 default:
379#ifdef VT100_PRINTUNKNOWN 379#ifdef VT100_PRINTUNKNOWN
380 printf("CSI%d$~ unknown\n", ARG(edp, 0)); 380 printf("CSI%d$~ unknown\n", ARG(vd, 0));
381#endif 381#endif
382 break; 382 break;
383 } 383 }
384 break; 384 break;
385 385
386 case A2('&', 'u'): /* DECRQUPSS request user preferred 386 case A2('&', 'u'): /* DECRQUPSS request user preferred
387 supplemental set */ 387 supplemental set */
388 wsdisplay_emulinput(edp->cbcookie, "\033P0!u%5\033\\", 9); 388 wsdisplay_emulinput(vd->cbcookie, "\033P0!u%5\033\\", 9);
389 break; 389 break;
390 390
391 case '@': /* ICH insert character VT300 only */ 391 case '@': /* ICH insert character VT300 only */
392 n = uimin(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1); 392 n = uimin(DEF1_ARG(vd, 0), COLS_LEFT(vd) + 1);
393 help = NCOLS(edp) - (edp->ccol + n); 393 help = NCOLS(vd) - (vd->ccol + n);
394 if (help > 0) 394 if (help > 0)
395 COPYCOLS(edp, edp->ccol, edp->ccol + n, help); 395 COPYCOLS(vd, vd->ccol, vd->ccol + n, help);
396 ERASECOLS(edp, edp->ccol, n, edp->bkgdattr); 396 ERASECOLS(vd, vd->ccol, n, vd->bkgdattr);
397 break; 397 break;
398 case 'A': /* CUU */ 398 case 'A': /* CUU */
399 edp->crow -= uimin(DEF1_ARG(edp, 0), ROWS_ABOVE(edp)); 399 vd->crow -= uimin(DEF1_ARG(vd, 0), ROWS_ABOVE(vd));
400 CHECK_DW(edp); 400 CHECK_DW(vd);
401 break; 401 break;
402 case 'B': /* CUD */ 402 case 'B': /* CUD */
403 edp->crow += uimin(DEF1_ARG(edp, 0), ROWS_BELOW(edp)); 403 vd->crow += uimin(DEF1_ARG(vd, 0), ROWS_BELOW(vd));
404 CHECK_DW(edp); 404 CHECK_DW(vd);
405 break; 405 break;
406 case 'C': /* CUF */ 406 case 'C': /* CUF */
407 edp->ccol += uimin(DEF1_ARG(edp, 0), COLS_LEFT(edp)); 407 vd->ccol += uimin(DEF1_ARG(vd, 0), COLS_LEFT(vd));
408 break; 408 break;
409 case 'D': /* CUB */ 409 case 'D': /* CUB */
410 edp->ccol -= uimin(DEF1_ARG(edp, 0), edp->ccol); 410 vd->ccol -= uimin(DEF1_ARG(vd, 0), vd->ccol);
411 edp->flags &= ~VTFL_LASTCHAR; 411 vd->flags &= ~VTFL_LASTCHAR;
 412 break;
 413 case 'G': /* CHA */
 414 vd->ccol = uimin(DEF1_ARG(vd, 0) - 1, vd->ncols -1);
412 break; 415 break;
413 case 'H': /* CUP */ 416 case 'H': /* CUP */
414 case 'f': /* HVP */ 417 case 'f': /* HVP */
415 if (edp->flags & VTFL_DECOM) 418 if (vd->flags & VTFL_DECOM)
416 edp->crow = edp->scrreg_startrow + 419 vd->crow = vd->scrreg_startrow +
417 uimin(DEF1_ARG(edp, 0), edp->scrreg_nrows) - 1; 420 uimin(DEF1_ARG(vd, 0), vd->scrreg_nrows) - 1;
418 else 421 else
419 edp->crow = uimin(DEF1_ARG(edp, 0), edp->nrows) - 1; 422 vd->crow = uimin(DEF1_ARG(vd, 0), vd->nrows) - 1;
420 CHECK_DW(edp); 423 CHECK_DW(vd);
421 edp->ccol = uimin(DEF1_ARG(edp, 1), NCOLS(edp)) - 1; 424 vd->ccol = uimin(DEF1_ARG(vd, 1), NCOLS(vd)) - 1;
422 edp->flags &= ~VTFL_LASTCHAR; 425 vd->flags &= ~VTFL_LASTCHAR;
423 break; 426 break;
424 case 'L': /* IL insert line */ 427 case 'L': /* IL insert line */
425 case 'M': /* DL delete line */ 428 case 'M': /* DL delete line */
426 n = uimin(DEF1_ARG(edp, 0), ROWS_BELOW(edp) + 1); 429 n = uimin(DEF1_ARG(vd, 0), ROWS_BELOW(vd) + 1);
427 { 430 {
428 int savscrstartrow, savscrnrows; 431 int savscrstartrow, savscrnrows;
429 savscrstartrow = edp->scrreg_startrow; 432 savscrstartrow = vd->scrreg_startrow;
430 savscrnrows = edp->scrreg_nrows; 433 savscrnrows = vd->scrreg_nrows;
431 edp->scrreg_nrows -= ROWS_ABOVE(edp); 434 vd->scrreg_nrows -= ROWS_ABOVE(vd);
432 edp->scrreg_startrow = edp->crow; 435 vd->scrreg_startrow = vd->crow;
433 if (c == 'L') 436 if (c == 'L')
434 wsemul_vt100_scrolldown(edp, n); 437 wsemul_vt100_scrolldown(vd, n);
435 else 438 else
436 wsemul_vt100_scrollup(edp, n); 439 wsemul_vt100_scrollup(vd, n);
437 edp->scrreg_startrow = savscrstartrow; 440 vd->scrreg_startrow = savscrstartrow;
438 edp->scrreg_nrows = savscrnrows; 441 vd->scrreg_nrows = savscrnrows;
439 } 442 }
440 break; 443 break;
441 case 'P': /* DCH delete character */ 444 case 'P': /* DCH delete character */
442 n = uimin(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1); 445 n = uimin(DEF1_ARG(vd, 0), COLS_LEFT(vd) + 1);
443 help = NCOLS(edp) - (edp->ccol + n); 446 help = NCOLS(vd) - (vd->ccol + n);
444 if (help > 0) 447 if (help > 0)
445 COPYCOLS(edp, edp->ccol + n, edp->ccol, help); 448 COPYCOLS(vd, vd->ccol + n, vd->ccol, help);
446 ERASECOLS(edp, NCOLS(edp) - n, n, edp->bkgdattr); 449 ERASECOLS(vd, NCOLS(vd) - n, n, vd->bkgdattr);
 450 break;
 451 case 'S': /* SU */
 452 wsemul_vt100_scrollup(vd, DEF1_ARG(vd, 0));
 453 break;
 454 case 'T': /* SD */
 455 wsemul_vt100_scrolldown(vd, DEF1_ARG(vd, 0));
447 break; 456 break;
448 case 'X': /* ECH erase character */ 457 case 'X': /* ECH erase character */
449 n = uimin(DEF1_ARG(edp, 0), COLS_LEFT(edp) + 1); 458 n = uimin(DEF1_ARG(vd, 0), COLS_LEFT(vd) + 1);
450 ERASECOLS(edp, edp->ccol, n, edp->bkgdattr); 459 ERASECOLS(vd, vd->ccol, n, vd->bkgdattr);
451 break; 460 break;
452 case 'c': /* DA primary */ 461 case 'Z': /* CBT */
453 if (ARG(edp, 0) == 0) 462 if (vd->ccol == 0)
454 wsdisplay_emulinput(edp->cbcookie, WSEMUL_VT_ID1, 463 break;
455 sizeof(WSEMUL_VT_ID1)); 464 for (m = 0; m < DEF1_ARG(vd, 0); m++) {
 465 if (vd->tabs) {
 466 for (n = vd->ccol - 1; n > 0; n--) {
 467 if (vd->tabs[n])
 468 break;
 469 }
 470 } else
 471 n = (vd->ccol - 1) & ~7;
 472 vd->ccol = n;
 473 if (n == 0)
 474 break;
 475 }
456 break; 476 break;
 477 case 'c': /* DA primary */
 478 if (ARG(vd, 0) == 0)
 479 wsdisplay_emulinput(vd->cbcookie, WSEMUL_VT_ID1,
 480 sizeof(WSEMUL_VT_ID1) - 1);
 481 break;
 482 case 'd': /* VPA */
 483 vd->crow = uimin(DEF1_ARG(vd, 0) - 1, vd->nrows - 1);
 484 break;
457 case 'g': /* TBC */ 485 case 'g': /* TBC */
458 KASSERT(edp->tabs != 0); 486 KASSERT(vd->tabs != NULL);
459 switch (ARG(edp, 0)) { 487 switch (ARG(vd, 0)) {
460 case 0: 488 case 0:
461 edp->tabs[edp->ccol] = 0; 489 vd->tabs[vd->ccol] = 0;
462 break; 490 break;
463 case 3: 491 case 3:
464 memset(edp->tabs, 0, edp->ncols); 492 memset(vd->tabs, 0, vd->ncols);
465 break; 493 break;
466 default: 494 default:
467#ifdef VT100_PRINTUNKNOWN 495#ifdef VT100_PRINTUNKNOWN
468 printf("CSI%dg unknown\n", ARG(edp, 0)); 496 printf("CSI%dg unknown\n", ARG(vd, 0));
469#endif 497#endif
470 break; 498 break;
471 } 499 }
472 break; 500 break;
473 case 'm': /* SGR select graphic rendition */ 501 case 'm': /* SGR select graphic rendition */
474 flags = edp->attrflags; 502 flags = vd->attrflags;
475 fgcol = edp->fgcol; 503 fgcol = vd->fgcol;
476 bgcol = edp->bgcol; 504 bgcol = vd->bgcol;
477 for (n = 0; n < edp->nargs; n++) { 505 for (n = 0; n < vd->nargs; n++) {
478 switch (ARG(edp, n)) { 506 switch (ARG(vd, n)) {
479 case 0: /* reset */ 507 case 0: /* reset */
480 if (n == edp->nargs - 1) { 508 if (n == vd->nargs - 1) {
481 edp->bkgdattr = edp->curattr = edp->defattr; 509 vd->bkgdattr = vd->curattr = vd->defattr;
482 edp->attrflags = edp->msgattrs.default_attrs; 510 vd->attrflags = vd->msgattrs.default_attrs;
483 edp->fgcol = edp->msgattrs.default_fg; 511 vd->fgcol = vd->msgattrs.default_fg;
484 edp->bgcol = edp->msgattrs.default_bg; 512 vd->bgcol = vd->msgattrs.default_bg;
485 return; 513 return;
486 } 514 }
487 flags = edp->msgattrs.default_attrs; 515 flags = vd->msgattrs.default_attrs;
488 fgcol = edp->msgattrs.default_fg; 516 fgcol = vd->msgattrs.default_fg;
489 bgcol = edp->msgattrs.default_bg; 517 bgcol = vd->msgattrs.default_bg;
490 break; 518 break;
491 case 1: /* bold */ 519 case 1: /* bold */
492 flags |= WSATTR_HILIT; 520 flags |= WSATTR_HILIT;
493 break; 521 break;
494 case 4: /* underline */ 522 case 4: /* underline */
495 flags |= WSATTR_UNDERLINE; 523 flags |= WSATTR_UNDERLINE;
496 break; 524 break;
497 case 5: /* blink */ 525 case 5: /* blink */
498 flags |= WSATTR_BLINK; 526 flags |= WSATTR_BLINK;
499 break; 527 break;
500 case 7: /* reverse */ 528 case 7: /* reverse */
501 flags |= WSATTR_REVERSE; 529 flags |= WSATTR_REVERSE;
502 break; 530 break;
@@ -506,320 +534,333 @@ wsemul_vt100_handle_csi(struct vt100base @@ -506,320 +534,333 @@ wsemul_vt100_handle_csi(struct vt100base
506 case 24: /* ~underline VT300 only */ 534 case 24: /* ~underline VT300 only */
507 flags &= ~WSATTR_UNDERLINE; 535 flags &= ~WSATTR_UNDERLINE;
508 break; 536 break;
509 case 25: /* ~blink VT300 only */ 537 case 25: /* ~blink VT300 only */
510 flags &= ~WSATTR_BLINK; 538 flags &= ~WSATTR_BLINK;
511 break; 539 break;
512 case 27: /* ~reverse VT300 only */ 540 case 27: /* ~reverse VT300 only */
513 flags &= ~WSATTR_REVERSE; 541 flags &= ~WSATTR_REVERSE;
514 break; 542 break;
515 case 30: case 31: case 32: case 33: 543 case 30: case 31: case 32: case 33:
516 case 34: case 35: case 36: case 37: 544 case 34: case 35: case 36: case 37:
517 /* fg color */ 545 /* fg color */
518 flags |= WSATTR_WSCOLORS; 546 flags |= WSATTR_WSCOLORS;
519 fgcol = ARG(edp, n) - 30; 547 fgcol = ARG(vd, n) - 30;
520 break; 548 break;
521 case 39: 549 case 39:
522 fgcol = edp->msgattrs.default_fg; 550 fgcol = vd->msgattrs.default_fg;
523 break; 551 break;
524 case 40: case 41: case 42: case 43: 552 case 40: case 41: case 42: case 43:
525 case 44: case 45: case 46: case 47: 553 case 44: case 45: case 46: case 47:
526 /* bg color */ 554 /* bg color */
527 flags |= WSATTR_WSCOLORS; 555 flags |= WSATTR_WSCOLORS;
528 bgcol = ARG(edp, n) - 40; 556 bgcol = ARG(vd, n) - 40;
529 break; 557 break;
530 case 49: 558 case 49:
531 bgcol = edp->msgattrs.default_bg; 559 bgcol = vd->msgattrs.default_bg;
532 break; 560 break;
533 default: 561 default:
534#ifdef VT100_PRINTUNKNOWN 562#ifdef VT100_PRINTUNKNOWN
535 printf("CSI%dm unknown\n", ARG(edp, n)); 563 printf("CSI%dm unknown\n", ARG(vd, n));
536#endif 564#endif
537 break; 565 break;
538 } 566 }
539 } 567 }
540 if (vt100_selectattribute(edp, flags, fgcol, bgcol, &attr, 568 if (vt100_selectattribute(vd, flags, fgcol, bgcol, &attr,
541 &bkgdattr)) { 569 &bkgdattr)) {
542#ifdef VT100_DEBUG 570#ifdef VT100_DEBUG
543 printf("error allocating attr %d/%d/%x\n", 571 printf("error allocating attr %d/%d/%x\n",
544 fgcol, bgcol, flags); 572 fgcol, bgcol, flags);
545#endif 573#endif
546 } else { 574 } else {
547 edp->curattr = attr; 575 vd->curattr = attr;
548 edp->bkgdattr = bkgdattr; 576 vd->bkgdattr = bkgdattr;
549 edp->attrflags = flags; 577 vd->attrflags = flags;
550 edp->fgcol = fgcol; 578 vd->fgcol = fgcol;
551 edp->bgcol = bgcol; 579 vd->bgcol = bgcol;
552 } 580 }
553 break; 581 break;
554 case 't': /* terminal size and such */ 582 case 't': /* terminal size and such */
555 switch (ARG(edp, 0)) { 583 switch (ARG(vd, 0)) {
556 case 18: { /* xterm size */ 584 case 18: { /* xterm size */
557 char buf[20]; 585 char buf[20];
558 586
559 n = snprintf(buf, sizeof(buf), "\033[8;%d;%dt", 587 n = snprintf(buf, sizeof(buf), "\033[8;%d;%dt",
560 edp->nrows, edp->ncols); 588 vd->nrows, vd->ncols);
561 wsdisplay_emulinput(edp->cbcookie, buf, n); 589 wsdisplay_emulinput(vd->cbcookie, buf, n);
562 } 590 }
563 break; 591 break;
564 } 592 }
565 break;  593 break;
566 case 'n': /* reports */ 594 case 'n': /* reports */
567 switch (ARG(edp, 0)) { 595 switch (ARG(vd, 0)) {
568 case 5: /* DSR operating status */ 596 case 5: /* DSR operating status */
569 /* 0 = OK, 3 = malfunction */ 597 /* 0 = OK, 3 = malfunction */
570 wsdisplay_emulinput(edp->cbcookie, "\033[0n", 4); 598 wsdisplay_emulinput(vd->cbcookie, "\033[0n", 4);
571 break; 599 break;
572 case 6: { /* DSR cursor position report */ 600 case 6: { /* DSR cursor position report */
573 char buf[20]; 601 char buf[20];
574 int row; 602 int row;
575 if (edp->flags & VTFL_DECOM) 603 if (vd->flags & VTFL_DECOM)
576 row = ROWS_ABOVE(edp); 604 row = ROWS_ABOVE(vd);
577 else 605 else
578 row = edp->crow; 606 row = vd->crow;
579 n = snprintf(buf, sizeof(buf), "\033[%d;%dR", 607 n = snprintf(buf, sizeof(buf), "\033[%d;%dR",
580 row + 1, edp->ccol + 1); 608 row + 1, vd->ccol + 1);
581 wsdisplay_emulinput(edp->cbcookie, buf, n); 609 wsdisplay_emulinput(vd->cbcookie, buf, n);
582 } 610 }
583 break; 611 break;
584 case 15: /* DSR printer status */ 612 case 15: /* DSR printer status */
585 /* 13 = no printer, 10 = ready, 11 = not ready */ 613 /* 13 = no printer, 10 = ready, 11 = not ready */
586 wsdisplay_emulinput(edp->cbcookie, "\033[?13n", 6); 614 wsdisplay_emulinput(vd->cbcookie, "\033[?13n", 6);
587 break; 615 break;
588 case 25: /* UDK status - VT300 only */ 616 case 25: /* UDK status - VT300 only */
589 /* 20 = locked, 21 = unlocked */ 617 /* 20 = locked, 21 = unlocked */
590 wsdisplay_emulinput(edp->cbcookie, "\033[?21n", 6); 618 wsdisplay_emulinput(vd->cbcookie, "\033[?21n", 6);
591 break; 619 break;
592 case 26: /* keyboard dialect */ 620 case 26: /* keyboard dialect */
593 /* 1 = north american , 7 = german */ 621 /* 1 = north american , 7 = german */
594 wsdisplay_emulinput(edp->cbcookie, "\033[?27;1n", 8); 622 wsdisplay_emulinput(vd->cbcookie, "\033[?27;1n", 8);
595 break; 623 break;
596 default: 624 default:
597#ifdef VT100_PRINTUNKNOWN 625#ifdef VT100_PRINTUNKNOWN
598 printf("CSI%dn unknown\n", ARG(edp, 0)); 626 printf("CSI%dn unknown\n", ARG(vd, 0));
599#endif 627#endif
600 break; 628 break;
601 } 629 }
602 break; 630 break;
603 case 'r': /* DECSTBM set top/bottom margins */ 631 case 'r': /* DECSTBM set top/bottom margins */
604 help = uimin(DEF1_ARG(edp, 0), edp->nrows) - 1; 632 help = uimin(DEF1_ARG(vd, 0), vd->nrows) - 1;
605 n = uimin(DEFx_ARG(edp, 1, edp->nrows), edp->nrows) - help; 633 n = uimin(DEFx_ARG(vd, 1, vd->nrows), vd->nrows) - help;
606 if (n < 2) { 634 if (n < 2) {
607 /* minimal scrolling region has 2 lines */ 635 /* minimal scrolling region has 2 lines */
608 return; 636 return;
609 } else { 637 } else {
610 edp->scrreg_startrow = help; 638 vd->scrreg_startrow = help;
611 edp->scrreg_nrows = n; 639 vd->scrreg_nrows = n;
612 } 640 }
613 edp->crow = ((edp->flags & VTFL_DECOM) ? 641 vd->crow = ((vd->flags & VTFL_DECOM) ?
614 edp->scrreg_startrow : 0); 642 vd->scrreg_startrow : 0);
615 edp->ccol = 0; 643 vd->ccol = 0;
616 break; 644 break;
617 case 'y': 645 case 'y':
618 switch (ARG(edp, 0)) { 646 switch (ARG(vd, 0)) {
619 case 4: /* DECTST invoke confidence test */ 647 case 4: /* DECTST invoke confidence test */
620 /* ignore */ 648 /* ignore */
621 break; 649 break;
622 default: 650 default:
623#ifdef VT100_PRINTUNKNOWN 651#ifdef VT100_PRINTUNKNOWN
624 printf("CSI%dy unknown\n", ARG(edp, 0)); 652 printf("CSI%dy unknown\n", ARG(vd, 0));
625#endif 653#endif
626 break; 654 break;
627 } 655 }
628 break; 656 break;
629 default: 657 default:
630#ifdef VT100_PRINTUNKNOWN 658#ifdef VT100_PRINTUNKNOWN
631 printf("CSI%c (%d, %d) unknown\n", c, ARG(edp, 0), ARG(edp, 1)); 659 printf("CSI%c (%d, %d) unknown\n", c, ARG(vd, 0), ARG(vd, 1));
632#endif 660#endif
633 break; 661 break;
634 } 662 }
635} 663}
636 664
637/* 665/*
638 * get an attribute from the graphics driver, 666 * get an attribute from the graphics driver,
639 * try to find replacements if the desired appearance 667 * try to find replacements if the desired appearance
640 * is not supported 668 * is not supported
641 */ 669 */
642static int 670static int
643vt100_selectattribute(struct vt100base_data *edp, 671vt100_selectattribute(struct vt100base_data *vd,
644 int flags, int fgcol, int bgcol, long *attr, long *bkgdattr) 672 int flags, int fgcol, int bgcol, long *attr, long *bkgdattr)
645{ 673{
646 int error; 674 int error;
647 675
648 if (!(edp->scrcapabilities & WSSCREEN_WSCOLORS)) { 676 if (!(vd->scrcapabilities & WSSCREEN_WSCOLORS)) {
649 flags &= ~WSATTR_WSCOLORS; 677 flags &= ~WSATTR_WSCOLORS;
650#ifdef VT100_DEBUG 678#ifdef VT100_DEBUG
651 printf("colors ignored (impossible)\n"); 679 printf("colors ignored (impossible)\n");
652#endif 680#endif
653 } else 681 } else
654 flags |= WSATTR_WSCOLORS; 682 flags |= WSATTR_WSCOLORS;
655 error = (*edp->emulops->allocattr)(edp->emulcookie, fgcol, bgcol, 683 error = (*vd->emulops->allocattr)(vd->emulcookie, fgcol, bgcol,
656 flags & WSATTR_WSCOLORS, bkgdattr); 684 flags & WSATTR_WSCOLORS, bkgdattr);
657 if (error) 685 if (error)
658 return (error); 686 return (error);
659 687
660 if ((flags & WSATTR_HILIT) && 688 if ((flags & WSATTR_HILIT) &&
661 !(edp->scrcapabilities & WSSCREEN_HILIT)) { 689 !(vd->scrcapabilities & WSSCREEN_HILIT)) {
662 flags &= ~WSATTR_HILIT; 690 flags &= ~WSATTR_HILIT;
663 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) { 691 if (vd->scrcapabilities & WSSCREEN_WSCOLORS) {
664#if defined(WSEMUL_VT100_HILIT_FG) && WSEMUL_VT100_HILIT_FG != -1 692#if defined(WSEMUL_VT100_HILIT_FG) && WSEMUL_VT100_HILIT_FG != -1
665 fgcol = WSEMUL_VT100_HILIT_FG; 693 fgcol = WSEMUL_VT100_HILIT_FG;
666#elif !defined(WSEMUL_VT100_HILIT_FG) 694#elif !defined(WSEMUL_VT100_HILIT_FG)
667 fgcol = WSCOL_RED; 695 fgcol = WSCOL_RED;
668#endif 696#endif
669#if defined(WSEMUL_VT100_HILIT_BG) && WSEMUL_VT100_HILIT_BG != -1 697#if defined(WSEMUL_VT100_HILIT_BG) && WSEMUL_VT100_HILIT_BG != -1
670 bgcol = WSEMUL_VT100_HILIT_BG; 698 bgcol = WSEMUL_VT100_HILIT_BG;
671#endif 699#endif
672 flags |= WSATTR_WSCOLORS; 700 flags |= WSATTR_WSCOLORS;
673 } else { 701 } else {
674#ifdef VT100_DEBUG 702#ifdef VT100_DEBUG
675 printf("bold ignored (impossible)\n"); 703 printf("bold ignored (impossible)\n");
676#endif 704#endif
677 } 705 }
678 } 706 }
679 if ((flags & WSATTR_UNDERLINE) && 707 if ((flags & WSATTR_UNDERLINE) &&
680 !(edp->scrcapabilities & WSSCREEN_UNDERLINE)) { 708 !(vd->scrcapabilities & WSSCREEN_UNDERLINE)) {
681 flags &= ~WSATTR_UNDERLINE; 709 flags &= ~WSATTR_UNDERLINE;
682 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) { 710 if (vd->scrcapabilities & WSSCREEN_WSCOLORS) {
683#if defined(WSEMUL_VT100_UNDERLINE_FG) && WSEMUL_VT100_UNDERLINE_FG != -1 711#if defined(WSEMUL_VT100_UNDERLINE_FG) && WSEMUL_VT100_UNDERLINE_FG != -1
684 fgcol = WSEMUL_VT100_UNDERLINE_FG; 712 fgcol = WSEMUL_VT100_UNDERLINE_FG;
685#endif 713#endif
686#if defined(WSEMUL_VT100_UNDERLINE_BG) && WSEMUL_VT100_UNDERLINE_BG != -1 714#if defined(WSEMUL_VT100_UNDERLINE_BG) && WSEMUL_VT100_UNDERLINE_BG != -1
687 bgcol = WSEMUL_VT100_UNDERLINE_BG; 715 bgcol = WSEMUL_VT100_UNDERLINE_BG;
688#elif !defined(WSEMUL_VT100_UNDERLINE_BG) 716#elif !defined(WSEMUL_VT100_UNDERLINE_BG)
689 bgcol = WSCOL_BROWN; 717 bgcol = WSCOL_BROWN;
690#endif 718#endif
691 flags |= WSATTR_WSCOLORS; 719 flags |= WSATTR_WSCOLORS;
692 } else { 720 } else {
693#ifdef VT100_DEBUG 721#ifdef VT100_DEBUG
694 printf("underline ignored (impossible)\n"); 722 printf("underline ignored (impossible)\n");
695#endif 723#endif
696 } 724 }
697 } 725 }
698 if ((flags & WSATTR_BLINK) && 726 if ((flags & WSATTR_BLINK) &&
699 !(edp->scrcapabilities & WSSCREEN_BLINK)) { 727 !(vd->scrcapabilities & WSSCREEN_BLINK)) {
700 flags &= ~WSATTR_BLINK; 728 flags &= ~WSATTR_BLINK;
701#ifdef VT100_DEBUG 729#ifdef VT100_DEBUG
702 printf("blink ignored (impossible)\n"); 730 printf("blink ignored (impossible)\n");
703#endif 731#endif
704 } 732 }
705 if ((flags & WSATTR_REVERSE) && 733 if ((flags & WSATTR_REVERSE) &&
706 !(edp->scrcapabilities & WSSCREEN_REVERSE)) { 734 !(vd->scrcapabilities & WSSCREEN_REVERSE)) {
707 flags &= ~WSATTR_REVERSE; 735 flags &= ~WSATTR_REVERSE;
708 if (edp->scrcapabilities & WSSCREEN_WSCOLORS) { 736 if (vd->scrcapabilities & WSSCREEN_WSCOLORS) {
709 int help; 737 int help;
710 help = bgcol; 738 help = bgcol;
711 bgcol = fgcol; 739 bgcol = fgcol;
712 fgcol = help; 740 fgcol = help;
713 flags |= WSATTR_WSCOLORS; 741 flags |= WSATTR_WSCOLORS;
714 } else { 742 } else {
715#ifdef VT100_DEBUG 743#ifdef VT100_DEBUG
716 printf("reverse ignored (impossible)\n"); 744 printf("reverse ignored (impossible)\n");
717#endif 745#endif
718 } 746 }
719 } 747 }
720 error = (*edp->emulops->allocattr)(edp->emulcookie, fgcol, bgcol, 748 error = (*vd->emulops->allocattr)(vd->emulcookie, fgcol, bgcol,
721 flags, attr); 749 flags, attr);
722 if (error) 750 if (error)
723 return (error); 751 return (error);
724 752
725 return (0); 753 return (0);
726} 754}
727 755
728/* 756/*
729 * handle device control sequences if the main state machine 757 * handle device control sequences if the main state machine
730 * told so by setting edp->dcstype to a nonzero value 758 * told so by setting vd->dcstype to a nonzero value
731 */ 759 */
732void 760void
733wsemul_vt100_handle_dcs(struct vt100base_data *edp) 761wsemul_vt100_handle_dcs(struct vt100base_data *vd)
734{ 762{
735 int i, pos; 763 int i, pos;
736 764
737 switch (edp->dcstype) { 765 switch (vd->dcstype) {
738 case 0: /* not handled */ 766 case 0: /* not handled */
739 return; 767 return;
740 case DCSTYPE_TABRESTORE: 768 case DCSTYPE_TABRESTORE:
741 KASSERT(edp->tabs != 0); 769 KASSERT(vd->tabs != NULL);
742 memset(edp->tabs, 0, edp->ncols); 770 KASSERT(vd->ncols <= 1024);
 771 memset(vd->tabs, 0, vd->ncols);
743 pos = 0; 772 pos = 0;
744 for (i = 0; i < edp->dcspos; i++) { 773 for (i = 0; i < vd->dcspos; i++) {
745 char c = edp->dcsarg[i]; 774 char c = vd->dcsarg[i];
746 switch (c) { 775 switch (c) {
747 case '0': case '1': case '2': case '3': case '4': 776 case '0': case '1': case '2': case '3': case '4':
748 case '5': case '6': case '7': case '8': case '9': 777 case '5': case '6': case '7': case '8': case '9': {
749 pos = pos * 10 + (edp->dcsarg[i] - '0'); 778 const int c0 = c - '0';
 779 if (pos < 0 ||
 780 pos > INT_MAX/10 ||
 781 pos * 10 > vd->ncols - c0) {
 782 pos = -1;
 783 break;
 784 }
 785 pos = pos * 10 + c0;
750 break; 786 break;
 787 }
751 case '/': 788 case '/':
752 if (pos > 0) 789 if (pos > 0) {
753 edp->tabs[pos - 1] = 1; 790 KASSERT(pos <= vd->ncols);
 791 vd->tabs[pos - 1] = 1;
 792 }
754 pos = 0; 793 pos = 0;
755 break; 794 break;
756 default: 795 default:
757#ifdef VT100_PRINTUNKNOWN 796#ifdef VT100_PRINTUNKNOWN
758 printf("unknown char %c in DCS\n", c); 797 printf("unknown char %c in DCS\n", c);
759#endif 798#endif
760 break; 799 break;
761 } 800 }
762 } 801 }
763 if (pos > 0) 802 if (pos > 0) {
764 edp->tabs[pos - 1] = 1; 803 KASSERT(pos <= vd->ncols);
 804 vd->tabs[pos - 1] = 1;
 805 }
765 break; 806 break;
766 default: 807 default:
767 panic("wsemul_vt100_handle_dcs: bad type %d", edp->dcstype); 808 panic("wsemul_vt100_handle_dcs: bad type %d", vd->dcstype);
768 } 809 }
769 edp->dcstype = 0; 810 vd->dcstype = 0;
770} 811}
771 812
772static int 813static int
773vt100_ansimode(struct vt100base_data *edp, int nr, int op) 814vt100_ansimode(struct vt100base_data *vd, int nr, int op)
774{ 815{
775 int res = 0; /* default: unknown */ 816 int res = 0; /* default: unknown */
776 817
777 switch (nr) { 818 switch (nr) {
778 case 2: /* KAM keyboard locked/unlocked */ 819 case 2: /* KAM keyboard locked/unlocked */
779 break; 820 break;
780 case 3: /* CRM control representation */ 821 case 3: /* CRM control representation */
781 break; 822 break;
782 case 4: /* IRM insert/replace characters */ 823 case 4: /* IRM insert/replace characters */
783 if (op == VTMODE_SET) 824 if (op == VTMODE_SET)
784 edp->flags |= VTFL_INSERTMODE; 825 vd->flags |= VTFL_INSERTMODE;
785 else if (op == VTMODE_RESET) 826 else if (op == VTMODE_RESET)
786 edp->flags &= ~VTFL_INSERTMODE; 827 vd->flags &= ~VTFL_INSERTMODE;
787 res = ((edp->flags & VTFL_INSERTMODE) ? 1 : 2); 828 res = ((vd->flags & VTFL_INSERTMODE) ? 1 : 2);
788 break; 829 break;
789 case 10: /* HEM horizontal editing (permanently reset) */ 830 case 10: /* HEM horizontal editing (permanently reset) */
790 res = 4; 831 res = 4;
791 break; 832 break;
792 case 12: /* SRM local echo off/on */ 833 case 12: /* SRM local echo off/on */
793 res = 4; /* permanently reset ??? */ 834 res = 4; /* permanently reset ??? */
794 break; 835 break;
795 case 20: /* LNM newline = newline/linefeed */ 836 case 20: /* LNM newline = newline/linefeed */
796 break; 837 break;
797 default: 838 default:
798#ifdef VT100_PRINTUNKNOWN 839#ifdef VT100_PRINTUNKNOWN
799 printf("ANSI mode %d unknown\n", nr); 840 printf("ANSI mode %d unknown\n", nr);
800#endif 841#endif
801 break; 842 break;
802 } 843 }
803 return (res); 844 return (res);
804} 845}
805 846
806static int 847static int
807vt100_decmode(struct vt100base_data *edp, int nr, int op) 848vt100_decmode(struct vt100base_data *vd, int nr, int op)
808{ 849{
809 int res = 0; /* default: unknown */ 850 int res = 0; /* default: unknown */
810 int flags; 851 int flags;
811 852
812 flags = edp->flags; 853 flags = vd->flags;
813 switch (nr) { 854 switch (nr) {
814 case 1: /* DECCKM application/nomal cursor keys */ 855 case 1: /* DECCKM application/nomal cursor keys */
815 if (op == VTMODE_SET) 856 if (op == VTMODE_SET)
816 flags |= VTFL_APPLCURSOR; 857 flags |= VTFL_APPLCURSOR;
817 else if (op == VTMODE_RESET) 858 else if (op == VTMODE_RESET)
818 flags &= ~VTFL_APPLCURSOR; 859 flags &= ~VTFL_APPLCURSOR;
819 res = ((flags & VTFL_APPLCURSOR) ? 1 : 2); 860 res = ((flags & VTFL_APPLCURSOR) ? 1 : 2);
820 break; 861 break;
821 case 2: /* DECANM ANSI vt100/vt52 */ 862 case 2: /* DECANM ANSI vt100/vt52 */
822 res = 3; /* permanently set ??? */ 863 res = 3; /* permanently set ??? */
823 break; 864 break;
824 case 3: /* DECCOLM 132/80 cols */ 865 case 3: /* DECCOLM 132/80 cols */
825 case 4: /* DECSCLM smooth/jump scroll */ 866 case 4: /* DECSCLM smooth/jump scroll */
@@ -841,41 +882,41 @@ vt100_decmode(struct vt100base_data *edp @@ -841,41 +882,41 @@ vt100_decmode(struct vt100base_data *edp
841 res = ((flags & VTFL_DECAWM) ? 1 : 2); 882 res = ((flags & VTFL_DECAWM) ? 1 : 2);
842 break; 883 break;
843 case 8: /* DECARM keyboard autorepeat */ 884 case 8: /* DECARM keyboard autorepeat */
844 break; 885 break;
845 case 18: /* DECPFF print form feed */ 886 case 18: /* DECPFF print form feed */
846 break; 887 break;
847 case 19: /* DECPEX printer extent: screen/scrolling region */ 888 case 19: /* DECPEX printer extent: screen/scrolling region */
848 break; 889 break;
849 case 25: /* DECTCEM text cursor on/off */ 890 case 25: /* DECTCEM text cursor on/off */
850 if (op == VTMODE_SET) 891 if (op == VTMODE_SET)
851 flags |= VTFL_CURSORON; 892 flags |= VTFL_CURSORON;
852 else if (op == VTMODE_RESET) 893 else if (op == VTMODE_RESET)
853 flags &= ~VTFL_CURSORON; 894 flags &= ~VTFL_CURSORON;
854 if (flags != edp->flags) 895 if (flags != vd->flags)
855 (*edp->emulops->cursor)(edp->emulcookie, 896 (*vd->emulops->cursor)(vd->emulcookie,
856 flags & VTFL_CURSORON, 897 flags & VTFL_CURSORON,
857 edp->crow, edp->ccol); 898 vd->crow, vd->ccol);
858 res = ((flags & VTFL_CURSORON) ? 1 : 2); 899 res = ((flags & VTFL_CURSORON) ? 1 : 2);
859 break; 900 break;
860 case 42: /* DECNRCM use 7-bit NRC / 901 case 42: /* DECNRCM use 7-bit NRC /
861 7/8 bit from DEC multilingual or ISO-latin-1*/ 902 7/8 bit from DEC multilingual or ISO-latin-1*/
862 if (op == VTMODE_SET) 903 if (op == VTMODE_SET)
863 flags |= VTFL_NATCHARSET; 904 flags |= VTFL_NATCHARSET;
864 else if (op == VTMODE_RESET) 905 else if (op == VTMODE_RESET)
865 flags &= ~VTFL_NATCHARSET; 906 flags &= ~VTFL_NATCHARSET;
866 res = ((flags & VTFL_NATCHARSET) ? 1 : 2); 907 res = ((flags & VTFL_NATCHARSET) ? 1 : 2);
867 break; 908 break;
868 case 66: /* DECNKM numeric keypad */ 909 case 66: /* DECNKM numeric keypad */
869 break; 910 break;
870 case 68: /* DECKBUM keyboard usage data processing/typewriter */ 911 case 68: /* DECKBUM keyboard usage data processing/typewriter */
871 break; 912 break;
872 default: 913 default:
873#ifdef VT100_PRINTUNKNOWN 914#ifdef VT100_PRINTUNKNOWN
874 printf("DEC mode %d unknown\n", nr); 915 printf("DEC mode %d unknown\n", nr);
875#endif 916#endif
876 break; 917 break;
877 } 918 }
878 edp->flags = flags; 919 vd->flags = flags;
879 920
880 return (res); 921 return (res);
881} 922}