Whitespace fixes and small changes in brelease(): code for selecting
word is no longer executed when you triple-click.
diff -r 2a6ed7b26469 st.c
--- a/st.c      Fri Apr 22 00:42:58 2011 +0200
+++ b/st.c      Sat Apr 23 15:36:45 2011 +0400
@@ -363,11 +363,11 @@
 utf8size(char *s) {
        unsigned char c = *s;
 
-       if (~c&B7)
+       if(~c&B7)
                return 1;
-       else if ((c&(B7|B6|B5)) == (B7|B6))
+       else if((c&(B7|B6|B5)) == (B7|B6))
                return 2;
-       else if ((c&(B7|B6|B5|B4)) == (B7|B6|B5))
+       else if((c&(B7|B6|B5|B4)) == (B7|B6|B5))
                return 3;
        else
                return 4;
@@ -523,20 +523,25 @@
 void
 brelease(XEvent *e) {
        int b;
+
        sel.mode = 0;
        getbuttoninfo(e, &b, &sel.ex, &sel.ey);
-       
        if(sel.bx == sel.ex && sel.by == sel.ey) {
                sel.bx = -1;
                if(b == 2)
                        selpaste();
-
                else if(b == 1) {
-                       /* double click to select word */
                        struct timeval now;
                        gettimeofday(&now, NULL);
 
-                       if(TIMEDIFFERENCE(now, sel.tclick1) <= 
DOUBLECLICK_TIMEOUT) {
+                       if(TIMEDIFFERENCE(now, sel.tclick2) <= 
TRIPLECLICK_TIMEOUT) {
+                               /* triple click on the line */
+                               sel.b.x = sel.bx = 0;
+                               sel.e.x = sel.ex = term.col;
+                               sel.b.y = sel.e.y = sel.ey;
+                               selcopy();
+                       } else if(TIMEDIFFERENCE(now, sel.tclick1) <= 
DOUBLECLICK_TIMEOUT) {
+                               /* double click to select word */
                                sel.bx = sel.ex;
                                while(term.line[sel.ey][sel.bx-1].state & 
GLYPH_SET && 
                                          term.line[sel.ey][sel.bx-1].c[0] != ' 
') sel.bx--;
@@ -547,19 +552,9 @@
                                sel.b.y = sel.e.y = sel.ey;
                                selcopy();
                        }
-
-                       /* triple click on the line */
-                       if(TIMEDIFFERENCE(now, sel.tclick2) <= 
TRIPLECLICK_TIMEOUT) {
-                               sel.b.x = sel.bx = 0;
-                               sel.e.x = sel.ex = term.col;
-                               sel.b.y = sel.e.y = sel.ey;
-                               selcopy();
-                       }
                }
-       } else {
-               if(b == 1) 
-                       selcopy();
-       }
+       } else if(b == 1) 
+               selcopy();
        memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval));
        gettimeofday(&sel.tclick1, NULL);
        draw();
@@ -605,7 +600,7 @@
 void 
 sigchld(int a) {
        int stat = 0;
-       if(waitpid(pid, &stat, 0) < 0)
+       if(waitpid(pid, &stat, 0) == -1)
                die("Waiting for pid %hd failed: %s\n", pid, SERRNO);
        if(WIFEXITED(stat))
                exit(WEXITSTATUS(stat));
@@ -619,7 +614,7 @@
        
        /* seems to work fine on linux, openbsd and freebsd */
        struct winsize w = {term.row, term.col, 0, 0};
-       if(openpty(&m, &s, NULL, NULL, &w) < 0)
+       if(openpty(&m, &s, NULL, NULL, &w) == -1)
                die("openpty failed: %s\n", SERRNO);
 
        switch(pid = fork()) {
@@ -631,7 +626,7 @@
                dup2(s, STDIN_FILENO);
                dup2(s, STDOUT_FILENO);
                dup2(s, STDERR_FILENO);
-               if(ioctl(s, TIOCSCTTY, NULL) < 0)
+               if(ioctl(s, TIOCSCTTY, NULL) == -1)
                        die("ioctl TIOCSCTTY failed: %s\n", SERRNO);
                close(s);
                close(m);
@@ -663,7 +658,7 @@
        int ret;
 
        /* append read bytes to unprocessed bytes */
-       if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
+       if((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) == -1)
                die("Couldn't read from shell: %s\n", SERRNO);
 
        /* process every complete utf8 char */
@@ -698,7 +693,7 @@
        w.ws_row = term.row;
        w.ws_col = term.col;
        w.ws_xpixel = w.ws_ypixel = 0;
-       if(ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
+       if(ioctl(cmdfd, TIOCSWINSZ, &w) == -1)
                fprintf(stderr, "Couldn't set window size: %s\n", SERRNO);
 }
 
@@ -921,9 +916,9 @@
                        term.c.attr.mode &= ~ATTR_REVERSE;       
                        break;
                case 38:
-                       if (i + 2 < l && attr[i + 1] == 5) {
+                       if(i + 2 < l && attr[i + 1] == 5) {
                                i += 2;
-                               if (BETWEEN(attr[i], 0, 255))
+                               if(BETWEEN(attr[i], 0, 255))
                                        term.c.attr.fg = attr[i];
                                else
                                        fprintf(stderr, "erresc: bad fgcolor 
%d\n", attr[i]);
@@ -935,9 +930,9 @@
                        term.c.attr.fg = DefaultFG;
                        break;
                case 48:
-                       if (i + 2 < l && attr[i + 1] == 5) {
+                       if(i + 2 < l && attr[i + 1] == 5) {
                                i += 2;
-                               if (BETWEEN(attr[i], 0, 255))
+                               if(BETWEEN(attr[i], 0, 255))
                                        term.c.attr.bg = attr[i];
                                else
                                        fprintf(stderr, "erresc: bad bgcolor 
%d\n", attr[i]);
@@ -1045,7 +1040,6 @@
                        break;
                case 2: /* all */
                        tclearregion(0, 0, term.col-1, term.row-1);
-                       break;
                default:
                        goto unknown;
                }
@@ -1245,9 +1239,8 @@
                                term.esc = 0;
                                term.title[term.titlelen] = '\0';
                                XStoreName(xw.dpy, xw.win, term.title);
-                       } else {
+                       } else
                                term.title[term.titlelen++] = ascii;
-                       }
                } else if(term.esc & ESC_ALTCHARSET) {
                        switch(ascii) {
                        case '0': /* Line drawing crap */
@@ -1348,7 +1341,6 @@
                                tmoveto(term.c.x+1, term.c.y);
                        else
                                term.c.state |= CURSOR_WRAPNEXT;
-                       break;
                }
        }
 }
@@ -1447,7 +1439,7 @@
        unsigned long white = WhitePixel(xw.dpy, xw.scr);
 
        for(i = 0; i < 16; i++) {
-               if (!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, 
&color)) {
+               if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, 
&color)) {
                        dc.col[i] = white;
                        fprintf(stderr, "Could not allocate color '%s'\n", 
colorname[i]);
                } else
@@ -1461,7 +1453,7 @@
                                color.red = r == 0 ? 0 : 0x3737 + 0x2828 * r;
                                color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
                                color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
-                               if (!XAllocColor(xw.dpy, xw.cmap, &color)) {
+                               if(!XAllocColor(xw.dpy, xw.cmap, &color)) {
                                        dc.col[i] = white;
                                        fprintf(stderr, "Could not allocate 
color %d\n", i);
                                } else
@@ -1471,7 +1463,7 @@
 
        for(r = 0; r < 24; r++, i++) {
                color.red = color.green = color.blue = 0x0808 + 0x0a0a * r;
-               if (!XAllocColor(xw.dpy, xw.cmap, &color)) {
+               if(!XAllocColor(xw.dpy, xw.cmap, &color)) {
                        dc.col[i] = white;
                        fprintf(stderr, "Could not allocate color %d\n", i);
                } else
@@ -1488,8 +1480,7 @@
 }
 
 void
-xhints(void)
-{
+xhints(void) {
        XClassHint class = {opt_class ? opt_class : TNAME, TNAME};
        XWMHints wm = {.flags = InputHint, .input = 1};
        XSizeHints size = {
@@ -1505,8 +1496,7 @@
 }
 
 XFontSet
-xinitfont(char *fontstr)
-{
+xinitfont(char *fontstr) {
        XFontSet set;
        char *def, **missing;
        int n;
@@ -1522,8 +1512,7 @@
 }
 
 void
-xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short 
*rbearing)
-{
+xgetfontinfo(XFontSet set, int *ascent, int *descent, short *lbearing, short 
*rbearing) {
        XFontStruct **xfonts;
        char **font_names;
        int i, n;
@@ -1540,8 +1529,7 @@
 }
 
 void
-initfonts(char *fontstr, char *bfontstr)
-{
+initfonts(char *fontstr, char *bfontstr) {
        if((dc.font.set = xinitfont(fontstr)) == NULL ||
           (dc.bfont.set = xinitfont(bfontstr)) == NULL)
                die("Can't load font %s\n", dc.font.set ? BOLDFONT : FONT);
@@ -1705,7 +1693,6 @@
        XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, 
BORDER, BORDER);
        XFlush(xw.dpy);
 }
-
 #else
 /* optimized drawing routine */
 void 
@@ -1752,7 +1739,6 @@
        xdrawcursor();
        XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, 
BORDER, BORDER);
 }
-
 #endif
 
 void
@@ -1889,7 +1875,7 @@
                FD_ZERO(&rfd);
                FD_SET(cmdfd, &rfd);
                FD_SET(xfd, &rfd);
-               if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) < 0) {
+               if(select(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, NULL) == -1) {
                        if(errno == EINTR)
                                continue;
                        die("select failed: %s\n", SERRNO);
@@ -1900,7 +1886,7 @@
                }
                while(XPending(xw.dpy)) {
                        XNextEvent(xw.dpy, &ev);
-                       if (XFilterEvent(&ev, xw.win))
+                       if(XFilterEvent(&ev, xw.win))
                                continue;
                        if(handler[ev.type])
                                (handler[ev.type])(&ev);

Reply via email to