JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Simplify a bit more tdeletechar and tinsertblank
[st.git] / st.c
diff --git a/st.c b/st.c
index 64384cd..e468d73 100644 (file)
--- a/st.c
+++ b/st.c
@@ -298,13 +298,13 @@ typedef struct {
 
 typedef union {
        int i;
-       unsigned int ui;
+       uint ui;
        float f;
        const void *v;
 } Arg;
 
 typedef struct {
-       unsigned int mod;
+       uint mod;
        KeySym keysym;
        void (*func)(const Arg *);
        const Arg arg;
@@ -549,12 +549,10 @@ xrealloc(void *p, size_t len) {
 
 char *
 xstrdup(char *s) {
-       char *p = strdup(s);
-
-       if (!p)
+       if((s = strdup(s)) == NULL)
                die("Out of memory\n");
 
-       return p;
+       return s;
 }
 
 size_t
@@ -1400,15 +1398,13 @@ tscrolldown(int orig, int n) {
 
        LIMIT(n, 0, term.bot-orig+1);
 
+       tsetdirt(orig, term.bot-n);
        tclearregion(0, term.bot-n+1, term.col-1, term.bot);
 
        for(i = term.bot; i >= orig+n; i--) {
                temp = term.line[i];
                term.line[i] = term.line[i-n];
                term.line[i-n] = temp;
-
-               term.dirty[i] = 1;
-               term.dirty[i-n] = 1;
        }
 
        selscroll(orig, n);
@@ -1418,17 +1414,16 @@ void
 tscrollup(int orig, int n) {
        int i;
        Line temp;
+
        LIMIT(n, 0, term.bot-orig+1);
 
        tclearregion(0, orig, term.col-1, orig+n-1);
+       tsetdirt(orig+n, term.bot);
 
        for(i = orig; i <= term.bot-n; i++) {
-                temp = term.line[i];
-                term.line[i] = term.line[i+n];
-                term.line[i+n] = temp;
-
-                term.dirty[i] = 1;
-                term.dirty[i+n] = 1;
+               temp = term.line[i];
+               term.line[i] = term.line[i+n];
+               term.line[i+n] = temp;
        }
 
        selscroll(orig, -n);
@@ -1544,8 +1539,7 @@ tsetchar(char *c, Glyph *attr, int x, int y) {
         * The table is proudly stolen from rxvt.
         */
        if(attr->mode & ATTR_GFX) {
-               if(c[0] >= 0x41 && c[0] <= 0x7e
-                               && vt100_0[c[0] - 0x41]) {
+               if(BETWEEN(c[0], 0x41, 0x7e) && vt100_0[c[0] - 0x41]) {
                        c = vt100_0[c[0] - 0x41];
                }
        }
@@ -1592,37 +1586,33 @@ tclearregion(int x1, int y1, int x2, int y2) {
 
 void
 tdeletechar(int n) {
-       int src = term.c.x + n;
-       int dst = term.c.x;
-       int size = term.col - src;
+       int dst, src, size;
+       Glyph *line;
 
-       term.dirty[term.c.y] = 1;
+       LIMIT(n, 0, term.col - term.c.x);
 
-       if(src >= term.col) {
-               tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
-               return;
-       }
+       dst = term.c.x;
+       src = term.c.x + n;
+       size = term.col - src;
+       line = term.line[term.c.y];
 
-       memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
-                       size * sizeof(Glyph));
+       memmove(&line[dst], &line[src], size * sizeof(Glyph));
        tclearregion(term.col-n, term.c.y, term.col-1, term.c.y);
 }
 
 void
 tinsertblank(int n) {
-       int src = term.c.x;
-       int dst = src + n;
-       int size = term.col - dst;
+       int dst, src, size;
+       Glyph *line;
 
-       term.dirty[term.c.y] = 1;
+       LIMIT(n, 0, term.col - term.c.x);
 
-       if(dst >= term.col) {
-               tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
-               return;
-       }
+       dst = term.c.x + n;
+       src = term.c.x;
+       size = term.col - dst;
+       line = term.line[term.c.y];
 
-       memmove(&term.line[term.c.y][dst], &term.line[term.c.y][src],
-                       size * sizeof(Glyph));
+       memmove(&line[dst], &line[src], size * sizeof(Glyph));
        tclearregion(src, term.c.y, dst - 1, term.c.y);
 }
 
@@ -2311,9 +2301,9 @@ techo(char *buf, int len) {
        for(; len > 0; buf++, len--) {
                char c = *buf;
 
-               if(c < '\x20') { /* control code */
+               if(c < 0x20 || c == 0177) { /* control code */
                        if(c != '\n' && c != '\r' && c != '\t') {
-                               c |= '\x40';
+                               c ^= '\x40';
                                tputc("^", 1);
                        }
                        tputc(&c, 1);
@@ -3076,7 +3066,7 @@ xinit(void) {
 
        xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
        XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
-                       PropModeReplace, (unsigned char *)&thispid, 1);
+                       PropModeReplace, (uchar *)&thispid, 1);
 
        xresettitle();
        XMapWindow(xw.dpy, xw.win);