JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Do not eat ESC character if control string is not properly terminated.
[st.git] / st.c
diff --git a/st.c b/st.c
index f91eb8d..d2261e2 100644 (file)
--- a/st.c
+++ b/st.c
@@ -149,7 +149,7 @@ enum charset {
 enum escape_state {
        ESC_START      = 1,
        ESC_CSI        = 2,
-       ESC_STR        = 4,  /* DSC, OSC, PM, APC */
+       ESC_STR        = 4,  /* DCS, OSC, PM, APC */
        ESC_ALTCHARSET = 8,
        ESC_STR_END    = 16, /* a final string was encountered */
        ESC_TEST       = 32, /* Enter in test mode */
@@ -2169,7 +2169,7 @@ strhandle(void) {
        case 'k': /* old title set compatibility */
                xsettitle(strescseq.args[0]);
                return;
-       case 'P': /* DSC -- Device Control String */
+       case 'P': /* DCS -- Device Control String */
        case '_': /* APC -- Application Program Command */
        case '^': /* PM -- Privacy Message */
                return;
@@ -2298,7 +2298,7 @@ techo(char *buf, int len) {
        for(; len > 0; buf++, len--) {
                char c = *buf;
 
-               if(c < 0x20 || c == 0177) { /* control code */
+               if(BETWEEN(c, 0x00, 0x1f) || c == 0x7f) { /* control code */
                        if(c != '\n' && c != '\r' && c != '\t') {
                                c ^= '\x40';
                                tputc("^", 1);
@@ -2452,10 +2452,6 @@ tputc(char *c, int len) {
                                csiparse();
                                csihandle();
                        }
-               } else if(term.esc & ESC_STR_END) {
-                       term.esc = 0;
-                       if(ascii == '\\')
-                               strhandle();
                } else if(term.esc & ESC_ALTCHARSET) {
                        tdeftran(ascii);
                        tselcs();
@@ -2545,7 +2541,9 @@ tputc(char *c, int len) {
                                tcursor(CURSOR_LOAD);
                                term.esc = 0;
                                break;
-                       case '\\': /* ST -- Stop */
+                       case '\\': /* ST -- String Terminator */
+                               if(term.esc & ESC_STR_END)
+                                       strhandle();
                                term.esc = 0;
                                break;
                        default: