xterm-34.diff.txt

--- /build/x11r6/XFree86-current/xc/doc/specs/xterm/ctlseqs.ms.orig     Sun Nov 24 11:02:48 1996
+++ /build/x11r6/XFree86-current/xc/doc/specs/xterm/ctlseqs.ms  Sun Jan  5 16:26:41 1997
@@ -193,6 +193,7 @@
 .[] x x
 .[] | |
 .[] } }
+.[] ! !
 .[] c" \(lq
 .[] c~ ~
 .[] Sc \fIc\fP
@@ -559,8 +560,11 @@
 .IP \\*(Cs\\*(Ps\\*s\\*^
 Scroll down \*(Ps lines (default = 1) (SD, according to ISO)
 .
+.IP \\*(Cs\\*(Pm\\*s\\*`
+Character Position Absolute  [column] (default = [row,1]) (HPA)
+.
 .IP \\*(Cs\\*(Ps\\*s\\*b
-Repeat the preceding graphic character \*(Ps times.
+Repeat the preceding graphic character \*(Ps times (REP)
 .
 .IP \\*(Cs\\*(Ps\\*s\\*c
 Send Device Attributes (DA)
@@ -583,9 +587,6 @@
   \*(Ps = \*4 \(-> Insert Mode (IRM)
   \*(Ps = \*2\*0 \(-> Automatic Newline (LNM)
 .
-.IP \\*(Cs\\*(Pm\\*s\\*`
-Character Position Absolute  [column] (default = [row,1]) (HPA)
-.
 .IP \\*(Cs\\*(Pm\\*s\\*l
 Reset Mode (RM)
   \*(Ps = \*4 \(-> Replace Mode (IRM)
@@ -644,6 +645,9 @@
   \*(Ps = \*2\*6 \(-> Report Keyboard status as
 \*(Cs\*?\*2\*7\*s\*;\*s\*1\*s\*;\*s\*0\*s\*;\*s\*0\*s\*n (North American)
 .
+.IP \\*(Cs\\*s\\*!\\*p
+Soft terminal reset (DECSTR)
+.
 .IP \\*(Cs\\*(Ps\\*s\\*;\\*(Ps\\*s\\*(c"\\*p
 Set conformance level (DECSCL)
 Valid values for the first parameter:
@@ -818,6 +822,8 @@
 the mouse within that range until button release, and then sends the
 program the release coordinates.
 It is enabled by specifying parameter 1001 to DECSET.
+Highlighting is performed only for button 1, though other button events
+can be received.
 Warning: use of this mode requires a cooperating program or it will
 hang \fIxterm.\fP
 On button press, the same information as for normal tracking is
@@ -879,7 +885,7 @@
 .IP \\*(Es\\*(Si
 End 4015 APL mode (ignored by \fIxterm\fP) (ESC Ctrl-O)
 .IP \\*(Es\\*(Eb
-COPY (Save Tektronix Codes to file COPYyy-mm-dd.hh:mm:ss) (ESC Ctrl-W)
+COPY (Save Tektronix Codes to file COPYyyyy-mm-dd.hh:mm:ss) (ESC Ctrl-W)
 .IP \\*(Es\\*(Ca
 Bypass Condition (ESC Ctrl-X)
 .IP \\*(Es\\*(Su
--- /build/x11r6/XFree86-current/xc/programs/xterm/VTPrsTbl.c.orig      Sun Nov 24 11:02:48 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/VTPrsTbl.c   Sun Jan  5 16:13:49 1997
@@ -404,7 +404,7 @@
 CASE_IGNORE,
 /*     SP              !               "               #       */
 CASE_ESC_IGNORE,
-CASE_ESC_IGNORE,
+CASE_CSI_EX_STATE,
 CASE_CSI_QUOTE_STATE,
 CASE_ESC_IGNORE,
 /*     $               %               &               '       */
@@ -514,6 +514,330 @@
 CASE_GROUND_STATE,
 /*     x               y               z               {       */
 CASE_DECREQTPARM,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     |               }               ~               DEL     */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      0x80            0x81            0x82            0x83    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x84            0x85            0x86            0x87    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x88            0x89            0x8a            0x8b    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x8c            0x8d            0x8e            0x8f    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x90            0x91            0x92            0x93    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x94            0x95            0x96            0x97    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x98            0x99            0x9a            0x9b    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      0x9c            0x9d            0x9e            0x9f    */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*      nobreakspace    exclamdown      cent            sterling        */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      currency        yen             brokenbar       section         */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      diaeresis       copyright       ordfeminine     guillemotleft   */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      notsign         hyphen          registered      macron          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      degree          plusminus       twosuperior     threesuperior   */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      acute           mu              paragraph       periodcentered  */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      cedilla         onesuperior     masculine       guillemotright  */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      onequarter      onehalf         threequarters   questiondown    */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Agrave          Aacute          Acircumflex     Atilde          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Adiaeresis      Aring           AE              Ccedilla        */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Egrave          Eacute          Ecircumflex     Ediaeresis      */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Igrave          Iacute          Icircumflex     Idiaeresis      */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Eth             Ntilde          Ograve          Oacute          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Ocircumflex     Otilde          Odiaeresis      multiply        */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Ooblique        Ugrave          Uacute          Ucircumflex     */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      Udiaeresis      Yacute          Thorn           ssharp          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      agrave          aacute          acircumflex     atilde          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      adiaeresis      aring           ae              ccedilla        */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      egrave          eacute          ecircumflex     ediaeresis      */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      igrave          iacute          icircumflex     idiaeresis      */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      eth             ntilde          ograve          oacute          */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      ocircumflex     otilde          odiaeresis      division        */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      oslash          ugrave          uacute          ucircumflex     */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*      udiaeresis      yacute          thorn           ydiaeresis      */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+};
+
+Const PARSE_T csi_ex_table[] =         /* ESC ! */
+{
+/*     NUL             SOH             STX             ETX     */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*     EOT             ENQ             ACK             BEL     */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_BELL,
+/*     BS              HT              NL              VT      */
+CASE_BS,
+CASE_TAB,
+CASE_VMOT,
+CASE_VMOT,
+/*     NP              CR              SO              SI      */
+CASE_VMOT,
+CASE_CR,
+CASE_SO,
+CASE_SI,
+/*     DLE             DC1             DC2             DC3     */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*     DC4             NAK             SYN             ETB     */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*     CAN             EM              SUB             ESC     */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_ESC,
+/*     FS              GS              RS              US      */
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+CASE_IGNORE,
+/*     SP              !               "               #       */
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+/*     $               %               &               '       */
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+/*     (               )               *               +       */
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+/*     ,               -               .               /       */
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+CASE_ESC_IGNORE,
+/*     0               1               2               3       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     4               5               6               7       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     8               9               :               ;       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     <               =               >               ?       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     @               A               B               C       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     D               E               F               G       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     H               I               J               K       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     L               M               N               O       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     P               Q               R               S       */
+CASE_IGNORE_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     T               U               V               W       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     X               Y               Z               [       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     \               ]               ^               _       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     `               a               b               c       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     d               e               f               g       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     h               i               j               k       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     l               m               n               o       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     p               q               r               s       */
+CASE_DECSTR,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     t               u               v               w       */
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+CASE_GROUND_STATE,
+/*     x               y               z               {       */
+CASE_GROUND_STATE,
 CASE_GROUND_STATE,
 CASE_GROUND_STATE,
 CASE_GROUND_STATE,
--- /build/x11r6/XFree86-current/xc/programs/xterm/VTparse.def.orig     Sun Nov 24 11:02:48 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/VTparse.def  Sun Jan  5 16:12:10 1997
@@ -115,3 +115,5 @@
 CASE_DECRPTUI
 CASE_VT52_CUP
 CASE_REP
+CASE_CSI_EX_STATE
+CASE_DECSTR
--- /build/x11r6/XFree86-current/xc/programs/xterm/VTparse.h.orig       Sun Nov 24 11:02:48 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/VTparse.h    Sun Jan  5 16:14:07 1997
@@ -38,6 +38,7 @@
 typedef char PARSE_T;
 
 extern Const PARSE_T ansi_table[];
+extern Const PARSE_T csi_ex_table[];
 extern Const PARSE_T csi_quo_table[];
 extern Const PARSE_T csi_table[];
 extern Const PARSE_T dec2_table[];
@@ -176,3 +177,5 @@
 #define CASE_DECRPTUI 105
 #define CASE_VT52_CUP 106
 #define CASE_REP 107
+#define CASE_CSI_EX_STATE 108
+#define CASE_DECSTR 109
--- /build/x11r6/XFree86-current/xc/programs/xterm/charproc.c.orig      Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/charproc.c   Sun Jan  5 17:05:03 1997
@@ -132,13 +132,15 @@
 static void VTallocbuf PROTO((void));
 static void VTparse PROTO((void));
 static void WriteText PROTO(( TScreen *screen, char *str, int len, unsigned flags, unsigned fg, unsigned bg));
-static void ansi_modes PROTO((XtermWidget termw, void (*func)(unsigned *p, int mask)));
-static void bitclr PROTO((unsigned *p, int mask));
-static void bitset PROTO((unsigned *p, int mask));
+static void ansi_modes PROTO((XtermWidget termw, void (*func)(unsigned *p, unsigned mask)));
+static void bitclr PROTO((unsigned *p, unsigned mask));
+static void bitcpy PROTO((unsigned *p, unsigned q, unsigned mask));
+static void bitset PROTO((unsigned *p, unsigned mask));
 static void dotext PROTO((TScreen *screen, unsigned flags, int charset, Char *buf, Char *ptr, unsigned fg, unsigned bg));
-static void dpmodes PROTO((XtermWidget termw, void (*func)(unsigned *p, int mask)));
+static void dpmodes PROTO((XtermWidget termw, void (*func)(unsigned *p, unsigned mask)));
 static void report_win_label PROTO((TScreen *screen, int code, XTextProperty *text, Status ok));
 static void restoremodes PROTO((XtermWidget termw));
+static void resetCharsets PROTO((TScreen *screen));
 static void savemodes PROTO((XtermWidget termw));
 static void set_vt_box PROTO((TScreen *screen));
 static void unparseputn PROTO((unsigned int n, int fd));
@@ -159,6 +161,7 @@
 static void clrColorUL PROTO((void));
 static void setColorBD PROTO((void));
 static void setColorUL PROTO((void));
+static void resetColor PROTO((void));
 #endif
 
 #define        DEFAULT         -1
@@ -860,8 +863,30 @@
        }
 }
 
+static void
+resetColor()
+{
+       clrColorBD(); /* first */
+       clrColorUL(); /* second */
+       if (term->flags & FG_COLOR)
+               SGR_Foreground(-1);
+       if (term->flags & BG_COLOR)
+               SGR_Background(-1);
+}
 #endif /* OPT_ISO_COLORS */
 
+static void resetCharsets(screen)
+       TScreen *screen;
+{
+       screen->gsets[0] = 'B';                 /* ASCII_G              */
+       screen->gsets[1] = '0';                 /* line drawing         */
+       screen->gsets[2] = 'B';                 /* DEC supplemental.    */
+       screen->gsets[3] = 'B';
+       screen->curgl = 0;                      /* G0 => GL.            */
+       screen->curgr = 2;                      /* G2 => GR.            */
+       screen->curss = 0;                      /* No single shift.     */
+}
+
 static void VTparse()
 {
        /* Buffer for processing strings (e.g., OSC ... ST) */
@@ -1387,14 +1412,7 @@
                                 case 0:
                                        term->flags &=
                                                ~(INVERSE|BOLD|UNDERLINE|INVISIBLE);
-                                       if_OPT_ISO_COLORS(screen,{
-                                               clrColorBD(); /* first */
-                                               clrColorUL(); /* second */
-                                               if (term->flags & FG_COLOR)
-                                                       SGR_Foreground(-1);
-                                               if (term->flags & BG_COLOR)
-                                                       SGR_Background(-1);
-                                       })
+                                       if_OPT_ISO_COLORS(screen,{resetColor();})
                                        break;
                                 case 1:        /* Bold                         */
                                        /* FALLTHRU */
@@ -1647,14 +1665,14 @@
 
                 case CASE_DECKPAM:
                        /* DECKPAM */
-                       term->keyboard.flags |= KYPD_APL;
+                       term->keyboard.flags |= MODE_DECKPAM;
                        update_appkeypad();
                        parsestate = groundtable;
                        break;
 
                 case CASE_DECKPNM:
                        /* DECKPNM */
-                       term->keyboard.flags &= ~KYPD_APL;
+                       term->keyboard.flags &= ~MODE_DECKPAM;
                        update_appkeypad();
                        parsestate = groundtable;
                        break;
@@ -1859,6 +1877,11 @@
                        parsestate = esc_sp_table;
                        break;
 
+                case CASE_CSI_EX_STATE:
+                       /* esc exclamation */
+                       parsestate = csi_ex_table;
+                       break;
+
                 case CASE_S7C1T:
                        screen->control_eight_bits = False;
                        parsestate = groundtable;
@@ -1885,6 +1908,12 @@
                        parsestate = groundtable;
                        break;
 
+                case CASE_DECSTR:
+                       /* DECSTR */
+                       VTReset(FALSE);
+                       parsestate = groundtable;
+                       break;
+
                 case CASE_REP:
                        /* REP */
                        if (lastchar >= 0 && isprint(lastchar)) {
@@ -2405,7 +2434,7 @@
 static void
 ansi_modes(termw, func)
     XtermWidget        termw;
-    void (*func) PROTO((unsigned *p, int mask));
+    void (*func) PROTO((unsigned *p, unsigned mask));
 {
        register int    i;
 
@@ -2437,7 +2466,7 @@
 static void
 dpmodes(termw, func)
     XtermWidget        termw;
-    void (*func) PROTO((unsigned *p, int mask));
+    void (*func) PROTO((unsigned *p, unsigned mask));
 {
        register TScreen        *screen = &termw->screen;
        register int    i, j;
@@ -2445,17 +2474,12 @@
        for (i=0; i<nparam; ++i) {
                switch (param[i]) {
                case 1:                 /* DECCKM                       */
-                       (*func)(&termw->keyboard.flags, CURSOR_APL);
+                       (*func)(&termw->keyboard.flags, MODE_DECCKM);
                        update_appcursor();
                        break;
                case 2:                 /* ANSI/VT52 mode               */
                        if (func == bitset) {   /* ANSI (VT100) */
-                               screen->gsets[0] =
-                               screen->gsets[1] =
-                               screen->gsets[2] =
-                               screen->gsets[3] = 'B';
-                               screen->curgl = 0;
-                               screen->curgr = 2;
+                               resetCharsets(screen);
                                if_OPT_VT52_MODE(screen,{
                                        screen->ansi_level = 1;})
                        }
@@ -2464,9 +2488,7 @@
                                screen->ansi_level = 0;
                                param[0] = 0;
                                param[1] = 0;
-                               screen->curgl = 0;
-                               screen->gsets[0] = 'B';
-                               screen->gsets[1] = '0';
+                               resetCharsets(screen);
                        }
 #endif
                        break;
@@ -2613,7 +2635,7 @@
                switch (param[i]) {
                case 1:                 /* DECCKM                       */
                        screen->save_modes[0] = termw->keyboard.flags &
-                        CURSOR_APL;
+                        MODE_DECCKM;
                        break;
                case 3:                 /* DECCOLM                      */
                        if(screen->c132)
@@ -2679,9 +2701,8 @@
        for (i = 0; i < nparam; i++) {
                switch (param[i]) {
                case 1:                 /* DECCKM                       */
-                       termw->keyboard.flags &= ~CURSOR_APL;
-                       termw->keyboard.flags |= screen->save_modes[0] &
-                        CURSOR_APL;
+                       bitcpy(&termw->keyboard.flags,
+                               screen->save_modes[0], MODE_DECCKM);
                        update_appcursor();
                        break;
                case 3:                 /* DECCOLM                      */
@@ -2692,9 +2713,9 @@
                                 ? 132 : 80) != ((termw->flags & IN132COLUMNS)
                                 ? 132 : 80) || j != screen->max_col + 1)
                                        RequestResize(termw, -1, j, TRUE);
-                               termw->flags &= ~IN132COLUMNS;
-                               termw->flags |= screen->save_modes[1] &
-                                IN132COLUMNS;
+                               bitcpy(&termw->flags,
+                                       screen->save_modes[1],
+                                       IN132COLUMNS);
                        }
                        break;
                case 4:                 /* DECSCLM (slow scroll)        */
@@ -2704,27 +2725,23 @@
                                        FlushScroll(screen);
                        } else
                                screen->jumpscroll = 1;
-                       termw->flags &= ~SMOOTHSCROLL;
-                       termw->flags |= screen->save_modes[2] & SMOOTHSCROLL;
+                       bitcpy(&termw->flags, screen->save_modes[2], SMOOTHSCROLL);
                        update_jumpscroll();
                        break;
                case 5:                 /* DECSCNM                      */
                        if((screen->save_modes[3] ^ termw->flags) & REVERSE_VIDEO) {
-                               termw->flags &= ~REVERSE_VIDEO;
-                               termw->flags |= screen->save_modes[3] & REVERSE_VIDEO;
+                               bitcpy(&termw->flags, screen->save_modes[3], REVERSE_VIDEO);
                                ReverseVideo(termw);
                                /* update_reversevideo done in RevVid */
                        }
                        break;
                case 6:                 /* DECOM                        */
-                       termw->flags &= ~ORIGIN;
-                       termw->flags |= screen->save_modes[4] & ORIGIN;
+                       bitcpy(&termw->flags, screen->save_modes[4], ORIGIN);
                        CursorSet(screen, 0, 0, termw->flags);
                        break;
 
                case 7:                 /* DECAWM                       */
-                       termw->flags &= ~WRAPAROUND;
-                       termw->flags |= screen->save_modes[5] & WRAPAROUND;
+                       bitcpy(&termw->flags, screen->save_modes[5], WRAPAROUND);
                        update_autowrap();
                        break;
                case 8:                 /* DECARM                       */
@@ -2747,8 +2764,7 @@
                        update_marginbell();
                        break;
                case 45:                /* reverse wraparound   */
-                       termw->flags &= ~REVERSEWRAP;
-                       termw->flags |= screen->save_modes[13] & REVERSEWRAP;
+                       bitcpy(&termw->flags, screen->save_modes[13], REVERSEWRAP);
                        update_reversewrap();
                        break;
 #ifdef ALLOWLOGGING
@@ -2959,7 +2975,7 @@
  */
 static void bitset(p, mask)
     unsigned *p;
-    int mask;
+    unsigned mask;
 {
        *p |= mask;
 }
@@ -2969,11 +2985,23 @@
  */
 static void bitclr(p, mask)
     unsigned *p;
-    int mask;
+    unsigned mask;
 {
        *p &= ~mask;
 }
 
+/*
+ * Copy bits from one word to another, given a mask
+ */
+static void bitcpy(p, q, mask)
+    unsigned *p;
+    unsigned q;
+    unsigned mask;
+{
+       bitclr(p, mask);
+       bitset(p, q & mask);
+}
+
 void
 unparseputc1(c, fd)
        int c;
@@ -3691,13 +3719,7 @@
 
        /* Reset variables used by ANSI emulation. */
 
-       screen->gsets[0] = 'B';                 /* ASCII_G              */
-       screen->gsets[1] = '0';                 /* line drawing         */
-       screen->gsets[2] = 'B';                 /* DEC supplemental.    */
-       screen->gsets[3] = 'B';
-       screen->curgl = 0;                      /* G0 => GL.            */
-       screen->curgr = 2;                      /* G2 => GR.            */
-       screen->curss = 0;                      /* No single shift.     */
+       resetCharsets(screen);
 
        XDefineCursor(screen->display, VShellWindow, screen->pointer_cursor);
 
@@ -4118,28 +4140,44 @@
 }
 #endif /* OPT_BLINK_CURS */
 
+/*
+ * Implement soft or hard (full) reset of the VTxxx emulation.  There are a
+ * couple of differences from real DEC VTxxx terminals (to avoid breaking
+ * applications which have come to rely on xterm doing this):
+ *
+ *     + autowrap mode should be reset (instead it's reset to the resource
+ *       default).
+ */
 void
 VTReset(full)
     Boolean full;
 {
        register TScreen *screen = &term->screen;
 
+       /* make cursor visible */
+       screen->cursor_set = ON;
+
        /* reset scrolling region */
        screen->top_marg = 0;
        screen->bot_marg = screen->max_row;
-       term->flags &= ~ORIGIN;
-       if(full) {
+
+       bitclr(&term->flags, ORIGIN);
+
+       if_OPT_ISO_COLORS(screen,{ resetColor(); })
+
+       /* Reset character-sets to initial state */
+       resetCharsets(screen);
+
+       /* Reset DECSCA */
+       bitclr(&term->flags, PROTECTED);
+       screen->protected_mode = OFF_PROTECT;
+
+       if (full) {     /* RIS */
                TabReset (term->tabs);
                term->keyboard.flags = 0;
                update_appcursor();
                update_appkeypad();
-               screen->gsets[0] = 'B';
-               screen->gsets[1] = '0';
-               screen->gsets[2] = 'B';
-               screen->gsets[3] = 'B';
-               screen->curgl = 0;
-               screen->curgr = 2;
-               screen->curss = 0;
+
                FromAlternate(screen);
                ClearScreen(screen);
                screen->cursor_state = OFF;
@@ -4151,8 +4189,10 @@
                update_autowrap();
                update_reversewrap();
                update_autolinefeed();
+
                screen->jumpscroll = !(term->flags & SMOOTHSCROLL);
                update_jumpscroll();
+
                if(screen->c132 && (term->flags & IN132COLUMNS)) {
                        Dimension junk;
                        XtMakeResizeRequest(
@@ -4167,6 +4207,26 @@
                                xevents();
                }
                CursorSet(screen, 0, 0, term->flags);
+               CursorSave(term, &screen->sc);
+       } else {        /* DECSTR */
+               /*
+                * There's a tiny difference, to accommodate usage of xterm. 
+                * We reset autowrap to the resource values rather than turning
+                * it off.
+                *
+                * FIXME: also reset AM, DECNKM when they're implemented.
+                */
+               term->keyboard.flags &= ~(MODE_DECCKM);
+               bitcpy(&term->flags, term->initflags, WRAPAROUND|REVERSEWRAP);
+               bitclr(&term->flags, INSERT|INVERSE|BOLD|UNDERLINE|INVISIBLE);
+               if_OPT_ISO_COLORS(screen,{resetColor();})
+               update_appcursor();
+               update_autowrap();
+               update_reversewrap();
+
+               CursorSave(term, &screen->sc);
+               screen->sc.row =
+               screen->sc.col = 0;
        }
        longjmp(vtjmpbuf, 1);   /* force ground state in parser */
 }
--- /build/x11r6/XFree86-current/xc/programs/xterm/input.c.orig Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/input.c      Sun Jan  5 16:06:15 1997
@@ -128,7 +128,7 @@
                key = TRUE;
         } else if (IsCursorKey(keysym) &&
                keysym != XK_Prior && keysym != XK_Next) {
-                       if (keyboard->flags & CURSOR_APL) {
+                       if (keyboard->flags & MODE_DECCKM) {
                        reply.a_type = SS3;
                        reply.a_final = cur[keysym-XK_Home];
                        VT52_CURSOR_KEYS
@@ -187,7 +187,7 @@
                 && keysym == XK_KP_Add)
                        keysym = XK_KP_Separator;
 #endif
-               if (keyboard->flags & KYPD_APL) {
+               if (keyboard->flags & MODE_DECKPAM)     {
                        reply.a_type   = SS3;
                        reply.a_final = kypd_apl[keysym-XK_KP_Space];
                        VT52_KEYPAD
--- /build/x11r6/XFree86-current/xc/programs/xterm/main.c.orig  Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/main.c       Sun Jan  5 16:06:15 1997
@@ -179,7 +179,6 @@
 #define USE_SYSV_TERMIO
 #undef  TIOCSLTC
 #include <sys/termio.h>
-#undef CAPS_LOCK
 #endif
 
 #ifdef CSRG_BASED
@@ -194,8 +193,6 @@
 #include <sys/stat.h>
 
 #ifdef Lynx
-#undef CAPS_LOCK
-#define CAPS_LOCK      0x01
 #ifndef BSDLY
 #define BSDLY  0
 #endif
@@ -1005,8 +1002,6 @@
 Widget toplevel;
 Bool waiting_for_initial_map;
 
-extern void do_hangup();
-
 /*
  * DeleteWindow(): Action proc to implement ICCCM delete_window.
  */
@@ -1494,12 +1489,12 @@
        term->initflags = term->flags;
 
        if (term->misc.appcursorDefault) {
-           term->keyboard.flags |= CURSOR_APL;
+           term->keyboard.flags |= MODE_DECCKM;
            update_appcursor();
        }
 
        if (term->misc.appkeypadDefault) {
-           term->keyboard.flags |= KYPD_APL;
+           term->keyboard.flags |= MODE_DECKPAM;
            update_appkeypad();
        }
 
@@ -2329,9 +2324,6 @@
 #else
                int pgrp = getpid();
 #endif
-#ifdef USE_SYSV_TERMIO
-               char numbuf[12];
-#endif /* USE_SYSV_TERMIO */
 #if defined(UTMP) && defined(USE_SYSV_UTMP)
                char* ptyname;
                char* ptynameptr = 0;
@@ -3120,10 +3112,13 @@
 
 #ifdef USE_SYSV_ENVVARS
 #ifndef TIOCSWINSZ
+               {
+               char numbuf[12];
                sprintf (numbuf, "%d", screen->max_col + 1);
                Setenv("COLUMNS=", numbuf);
                sprintf (numbuf, "%d", screen->max_row + 1);
                Setenv("LINES=", numbuf);
+               }
 #endif
 #ifdef UTMP
                if (pw) {       /* SVR4 doesn't provide these */
--- /build/x11r6/XFree86-current/xc/programs/xterm/menu.c.orig  Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/menu.c       Sun Jan  5 16:06:15 1997
@@ -643,7 +643,7 @@
     Widget gw;
     XtPointer closure, data;
 {
-    term->keyboard.flags ^= CURSOR_APL;
+    term->keyboard.flags ^= MODE_DECCKM;
     update_appcursor();
 }
 
@@ -652,7 +652,7 @@
     Widget gw;
     XtPointer closure, data;
 {
-    term->keyboard.flags ^= KYPD_APL;
+    term->keyboard.flags ^= MODE_DECKPAM;
     update_appkeypad();
 }
 
@@ -1176,7 +1176,7 @@
     String *params;
     Cardinal *param_count;
 {
-    handle_toggle (do_appcursor, (int) (term->keyboard.flags & CURSOR_APL),
+    handle_toggle (do_appcursor, (int) (term->keyboard.flags & MODE_DECCKM),
                   params, *param_count, w, (XtPointer)0, (XtPointer)0);
 }
 
@@ -1186,7 +1186,7 @@
     String *params;
     Cardinal *param_count;
 {
-    handle_toggle (do_appkeypad, (int) (term->keyboard.flags & KYPD_APL),
+    handle_toggle (do_appkeypad, (int) (term->keyboard.flags & MODE_DECKPAM),
                   params, *param_count, w, (XtPointer)0, (XtPointer)0);
 }
 
--- /build/x11r6/XFree86-current/xc/programs/xterm/menu.h.orig  Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/menu.h       Sun Jan  5 16:06:15 1997
@@ -259,12 +259,12 @@
 #define update_appcursor() \
   update_menu_item (term->screen.vtMenu, \
                    vtMenuEntries[vtMenu_appcursor].widget, \
-                   (term->keyboard.flags & CURSOR_APL))
+                   (term->keyboard.flags & MODE_DECCKM))
 
 #define update_appkeypad() \
   update_menu_item (term->screen.vtMenu, \
                    vtMenuEntries[vtMenu_appkeypad].widget, \
-                   (term->keyboard.flags & KYPD_APL))
+                   (term->keyboard.flags & MODE_DECKPAM))
 
 #define update_scrollkey() \
   update_menu_item (term->screen.vtMenu, \
--- /build/x11r6/XFree86-current/xc/programs/xterm/misc.c.orig  Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/misc.c       Sun Jan  5 15:56:08 1997
@@ -1338,6 +1338,7 @@
     exit(1);
 }
 
+int
 XStrCmp(s1, s2)
 char *s1, *s2;
 {
--- /build/x11r6/XFree86-current/xc/programs/xterm/os2main.c.orig       Tue Aug 20 15:08:28 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/os2main.c    Sun Jan  5 16:06:15 1997
@@ -879,12 +879,12 @@
        term->initflags = term->flags;
 
        if (term->misc.appcursorDefault) {
-           term->keyboard.flags |= CURSOR_APL;
+           term->keyboard.flags |= MODE_DECCKM;
            update_appcursor();
        }
 
        if (term->misc.appkeypadDefault) {
-           term->keyboard.flags |= KYPD_APL;
+           term->keyboard.flags |= MODE_DECKPAM;
            update_appkeypad();
        }
 
--- /build/x11r6/XFree86-current/xc/programs/xterm/ptyx.h.orig  Fri Dec 27 03:01:57 1996
+++ /build/x11r6/XFree86-current/xc/programs/xterm/ptyx.h       Sun Jan  5 16:06:15 1997
@@ -617,10 +617,9 @@
     TekClassPart tek_class;
 } TekClassRec;
 
-/* define masks for flags */
-#define CAPS_LOCK      0x01
-#define KYPD_APL       0x02
-#define CURSOR_APL     0x04
+/* define masks for keyboard.flags */
+#define MODE_DECKPAM   0x02    /* keypad application mode */
+#define MODE_DECCKM    0x04    /* cursor keys */
 
 
 #define N_MARGINBELL   10