JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Ignore NUL character as a padding character. Telnet may use this. Patch of
[st.git] / st.c
diff --git a/st.c b/st.c
index 8741145..da895c6 100644 (file)
--- a/st.c
+++ b/st.c
@@ -296,6 +296,7 @@ static void xcopy(void);
 static void xdrawcursor(void);
 static void xinit(void);
 static void xloadcols(void);
+static void xresettitle(void);
 static void xseturgency(int);
 static void xsetsel(char*);
 static void xresize(int, int);
@@ -355,7 +356,7 @@ static STREscape strescseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
-static FILE *fileio;
+static int iofd = -1;
 static char **opt_cmd  = NULL;
 static char *opt_io    = NULL;
 static char *opt_title = NULL;
@@ -773,6 +774,13 @@ execsh(void) {
        unsetenv("LINES");
        unsetenv("TERMCAP");
 
+       signal(SIGCHLD, SIG_DFL);
+       signal(SIGHUP, SIG_DFL);
+       signal(SIGINT, SIG_DFL);
+       signal(SIGQUIT, SIG_DFL);
+       signal(SIGTERM, SIG_DFL);
+       signal(SIGALRM, SIG_DFL);
+
        DEFAULT(envshell, SHELL);
        putenv("TERM="TNAME);
        args = opt_cmd ? opt_cmd : (char*[]){envshell, "-i", NULL};
@@ -821,9 +829,9 @@ ttynew(void) {
                signal(SIGCHLD, sigchld);
                if(opt_io) {
                        if(!strcmp(opt_io, "-")) {
-                               fileio = stdout;
+                               iofd = STDOUT_FILENO;
                        } else {
-                               if(!(fileio = fopen(opt_io, "w"))) {
+                               if((iofd = open(opt_io, O_WRONLY | O_CREAT, 0666)) < 0) {
                                        fprintf(stderr, "Error opening %s:%s\n",
                                                opt_io, strerror(errno));
                                }
@@ -1171,6 +1179,7 @@ tsetattr(int *attr, int l) {
                case 7:
                        term.c.attr.mode |= ATTR_REVERSE;
                        break;
+               case 21:
                case 22:
                        term.c.attr.mode &= ~ATTR_BOLD;
                        break;
@@ -1599,10 +1608,8 @@ void
 tputc(char *c) {
        char ascii = *c;
 
-       if(fileio) {
-               putc(ascii, fileio);
-               fflush(fileio);
-       }
+       if(iofd != -1)
+               write(iofd, c, 1);
 
        if(term.esc & ESC_START) {
                if(term.esc & ESC_CSI) {
@@ -1685,6 +1692,7 @@ tputc(char *c) {
                        case 'c': /* RIS -- Reset to inital state */
                                treset();
                                term.esc = 0;
+                               xresettitle();
                                break;
                        case '=': /* DECPAM -- Application keypad */
                                term.mode |= MODE_APPKEYPAD;
@@ -1715,6 +1723,8 @@ tputc(char *c) {
                if(sel.bx != -1 && BETWEEN(term.c.y, sel.by, sel.ey))
                        sel.bx = -1;
                switch(ascii) {
+               case '\0': /* padding character, do nothing */
+                       break;
                case '\t':
                        tputtab(1);
                        break;
@@ -2027,7 +2037,7 @@ xinit(void) {
 
        xw.xembed = XInternAtom(xw.dpy, "_XEMBED", False);
 
-       XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st");
+       xresettitle();
        XMapWindow(xw.dpy, xw.win);
        xhints();
        XSync(xw.dpy, 0);
@@ -2124,6 +2134,11 @@ xdrawcursor(void) {
 }
 
 void
+xresettitle(void) {
+       XStoreName(xw.dpy, xw.win, opt_title ? opt_title : "st");
+}
+
+void
 redraw(void) {
        struct timespec tv = {0, REDRAW_TIMEOUT * 1000};
        tfulldirt();