diff options
| author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2012-01-21 23:43:03 +0100 |
|---|---|---|
| committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2012-01-21 23:43:03 +0100 |
| commit | bcb7ec68c2780a65d0d362bafd3690b2a8f5473e (patch) | |
| tree | cc93a54493b7d5a175086a8b2ee20b9170ff2eb9 /st.c | |
| parent | df54ab040509829b4baec1673e4b158038ff983d (diff) | |
| download | st-bcb7ec68c2780a65d0d362bafd3690b2a8f5473e.tar.gz st-bcb7ec68c2780a65d0d362bafd3690b2a8f5473e.zip | |
cosmetic, whitespace, etc.
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 79 |
1 files changed, 42 insertions, 37 deletions
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <limits.h> | 6 | #include <limits.h> |
| 7 | #include <locale.h> | 7 | #include <locale.h> |
| 8 | #include <stdarg.h> | 8 | #include <stdarg.h> |
| 9 | #include <stdbool.h> | ||
| 9 | #include <stdio.h> | 10 | #include <stdio.h> |
| 10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| 11 | #include <string.h> | 12 | #include <string.h> |
| @@ -79,6 +80,10 @@ enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; | |||
| 79 | #undef B0 | 80 | #undef B0 |
| 80 | enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 }; | 81 | enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 }; |
| 81 | 82 | ||
| 83 | typedef unsigned char uchar; | ||
| 84 | typedef unsigned int uint; | ||
| 85 | typedef unsigned long ulong; | ||
| 86 | |||
| 82 | typedef struct { | 87 | typedef struct { |
| 83 | char c[UTF_SIZ]; /* character code */ | 88 | char c[UTF_SIZ]; /* character code */ |
| 84 | char mode; /* attribute flags */ | 89 | char mode; /* attribute flags */ |
| @@ -113,7 +118,7 @@ typedef struct { | |||
| 113 | int col; /* nb col */ | 118 | int col; /* nb col */ |
| 114 | Line* line; /* screen */ | 119 | Line* line; /* screen */ |
| 115 | Line* alt; /* alternate screen */ | 120 | Line* alt; /* alternate screen */ |
| 116 | char* dirty; /* dirtyness of lines */ | 121 | bool* dirty; /* dirtyness of lines */ |
| 117 | TCursor c; /* cursor */ | 122 | TCursor c; /* cursor */ |
| 118 | int top; /* top scroll limit */ | 123 | int top; /* top scroll limit */ |
| 119 | int bot; /* bottom scroll limit */ | 124 | int bot; /* bottom scroll limit */ |
| @@ -145,13 +150,13 @@ typedef struct { | |||
| 145 | 150 | ||
| 146 | typedef struct { | 151 | typedef struct { |
| 147 | KeySym k; | 152 | KeySym k; |
| 148 | unsigned int mask; | 153 | uint mask; |
| 149 | char s[ESC_BUF_SIZ]; | 154 | char s[ESC_BUF_SIZ]; |
| 150 | } Key; | 155 | } Key; |
| 151 | 156 | ||
| 152 | /* Drawing Context */ | 157 | /* Drawing Context */ |
| 153 | typedef struct { | 158 | typedef struct { |
| 154 | unsigned long col[256]; | 159 | ulong col[256]; |
| 155 | GC gc; | 160 | GC gc; |
| 156 | struct { | 161 | struct { |
| 157 | int ascent; | 162 | int ascent; |
| @@ -182,7 +187,7 @@ static void drawregion(int, int, int, int); | |||
| 182 | static void execsh(void); | 187 | static void execsh(void); |
| 183 | static void sigchld(int); | 188 | static void sigchld(int); |
| 184 | static void run(void); | 189 | static void run(void); |
| 185 | static int last_draw_too_old(void); | 190 | static bool last_draw_too_old(void); |
| 186 | 191 | ||
| 187 | static void csidump(void); | 192 | static void csidump(void); |
| 188 | static void csihandle(void); | 193 | static void csihandle(void); |
| @@ -229,7 +234,7 @@ static void xresize(int, int); | |||
| 229 | static void expose(XEvent *); | 234 | static void expose(XEvent *); |
| 230 | static void visibility(XEvent *); | 235 | static void visibility(XEvent *); |
| 231 | static void unmap(XEvent *); | 236 | static void unmap(XEvent *); |
| 232 | static char* kmap(KeySym, unsigned int); | 237 | static char* kmap(KeySym, uint); |
| 233 | static void kpress(XEvent *); | 238 | static void kpress(XEvent *); |
| 234 | static void cmessage(XEvent *); | 239 | static void cmessage(XEvent *); |
| 235 | static void resize(XEvent *); | 240 | static void resize(XEvent *); |
| @@ -241,7 +246,7 @@ static void selnotify(XEvent *); | |||
| 241 | static void selrequest(XEvent *); | 246 | static void selrequest(XEvent *); |
| 242 | 247 | ||
| 243 | static void selinit(void); | 248 | static void selinit(void); |
| 244 | static inline int selected(int, int); | 249 | static inline bool selected(int, int); |
| 245 | static void selcopy(void); | 250 | static void selcopy(void); |
| 246 | static void selpaste(); | 251 | static void selpaste(); |
| 247 | static void selscroll(int, int); | 252 | static void selscroll(int, int); |
| @@ -282,31 +287,31 @@ static char *opt_class = NULL; | |||
| 282 | 287 | ||
| 283 | int | 288 | int |
| 284 | utf8decode(char *s, long *u) { | 289 | utf8decode(char *s, long *u) { |
| 285 | unsigned char c; | 290 | uchar c; |
| 286 | int i, n, rtn; | 291 | int i, n, rtn; |
| 287 | 292 | ||
| 288 | rtn = 1; | 293 | rtn = 1; |
| 289 | c = *s; | 294 | c = *s; |
| 290 | if(~c&B7) { /* 0xxxxxxx */ | 295 | if(~c & B7) { /* 0xxxxxxx */ |
| 291 | *u = c; | 296 | *u = c; |
| 292 | return rtn; | 297 | return rtn; |
| 293 | } else if((c&(B7|B6|B5)) == (B7|B6)) { /* 110xxxxx */ | 298 | } else if((c & (B7|B6|B5)) == (B7|B6)) { /* 110xxxxx */ |
| 294 | *u = c&(B4|B3|B2|B1|B0); | 299 | *u = c&(B4|B3|B2|B1|B0); |
| 295 | n = 1; | 300 | n = 1; |
| 296 | } else if((c&(B7|B6|B5|B4)) == (B7|B6|B5)) { /* 1110xxxx */ | 301 | } else if((c & (B7|B6|B5|B4)) == (B7|B6|B5)) { /* 1110xxxx */ |
| 297 | *u = c&(B3|B2|B1|B0); | 302 | *u = c&(B3|B2|B1|B0); |
| 298 | n = 2; | 303 | n = 2; |
| 299 | } else if((c&(B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) { /* 11110xxx */ | 304 | } else if((c & (B7|B6|B5|B4|B3)) == (B7|B6|B5|B4)) { /* 11110xxx */ |
| 300 | *u = c&(B2|B1|B0); | 305 | *u = c & (B2|B1|B0); |
| 301 | n = 3; | 306 | n = 3; |
| 302 | } else | 307 | } else |
| 303 | goto invalid; | 308 | goto invalid; |
| 304 | for(i=n,++s; i>0; --i,++rtn,++s) { | 309 | for(i = n, ++s; i > 0; --i, ++rtn, ++s) { |
| 305 | c = *s; | 310 | c = *s; |
| 306 | if((c&(B7|B6)) != B7) /* 10xxxxxx */ | 311 | if((c & (B7|B6)) != B7) /* 10xxxxxx */ |
| 307 | goto invalid; | 312 | goto invalid; |
| 308 | *u <<= 6; | 313 | *u <<= 6; |
| 309 | *u |= c&(B5|B4|B3|B2|B1|B0); | 314 | *u |= c & (B5|B4|B3|B2|B1|B0); |
| 310 | } | 315 | } |
| 311 | if((n == 1 && *u < 0x80) || | 316 | if((n == 1 && *u < 0x80) || |
| 312 | (n == 2 && *u < 0x800) || | 317 | (n == 2 && *u < 0x800) || |
| @@ -321,11 +326,11 @@ invalid: | |||
| 321 | 326 | ||
| 322 | int | 327 | int |
| 323 | utf8encode(long *u, char *s) { | 328 | utf8encode(long *u, char *s) { |
| 324 | unsigned char *sp; | 329 | uchar *sp; |
| 325 | unsigned long uc; | 330 | ulong uc; |
| 326 | int i, n; | 331 | int i, n; |
| 327 | 332 | ||
| 328 | sp = (unsigned char*) s; | 333 | sp = (uchar*) s; |
| 329 | uc = *u; | 334 | uc = *u; |
| 330 | if(uc < 0x80) { | 335 | if(uc < 0x80) { |
| 331 | *sp = uc; /* 0xxxxxxx */ | 336 | *sp = uc; /* 0xxxxxxx */ |
| @@ -357,11 +362,11 @@ invalid: | |||
| 357 | UTF-8 otherwise return 0 */ | 362 | UTF-8 otherwise return 0 */ |
| 358 | int | 363 | int |
| 359 | isfullutf8(char *s, int b) { | 364 | isfullutf8(char *s, int b) { |
| 360 | unsigned char *c1, *c2, *c3; | 365 | uchar *c1, *c2, *c3; |
| 361 | 366 | ||
| 362 | c1 = (unsigned char *) s; | 367 | c1 = (uchar *) s; |
| 363 | c2 = (unsigned char *) ++s; | 368 | c2 = (uchar *) ++s; |
| 364 | c3 = (unsigned char *) ++s; | 369 | c3 = (uchar *) ++s; |
| 365 | if(b < 1) | 370 | if(b < 1) |
| 366 | return 0; | 371 | return 0; |
| 367 | else if((*c1&(B7|B6|B5)) == (B7|B6) && b == 1) | 372 | else if((*c1&(B7|B6|B5)) == (B7|B6) && b == 1) |
| @@ -381,7 +386,7 @@ isfullutf8(char *s, int b) { | |||
| 381 | 386 | ||
| 382 | int | 387 | int |
| 383 | utf8size(char *s) { | 388 | utf8size(char *s) { |
| 384 | unsigned char c = *s; | 389 | uchar c = *s; |
| 385 | 390 | ||
| 386 | if(~c&B7) | 391 | if(~c&B7) |
| 387 | return 1; | 392 | return 1; |
| @@ -405,7 +410,7 @@ selinit(void) { | |||
| 405 | sel.xtarget = XA_STRING; | 410 | sel.xtarget = XA_STRING; |
| 406 | } | 411 | } |
| 407 | 412 | ||
| 408 | static inline int | 413 | static inline bool |
| 409 | selected(int x, int y) { | 414 | selected(int x, int y) { |
| 410 | if(sel.ey == y && sel.by == y) { | 415 | if(sel.ey == y && sel.by == y) { |
| 411 | int bx = MIN(sel.bx, sel.ex); | 416 | int bx = MIN(sel.bx, sel.ex); |
| @@ -504,9 +509,9 @@ selcopy(void) { | |||
| 504 | 509 | ||
| 505 | void | 510 | void |
| 506 | selnotify(XEvent *e) { | 511 | selnotify(XEvent *e) { |
| 507 | unsigned long nitems, ofs, rem; | 512 | ulong nitems, ofs, rem; |
| 508 | int format; | 513 | int format; |
| 509 | unsigned char *data; | 514 | uchar *data; |
| 510 | Atom type; | 515 | Atom type; |
| 511 | 516 | ||
| 512 | ofs = 0; | 517 | ofs = 0; |
| @@ -550,12 +555,12 @@ selrequest(XEvent *e) { | |||
| 550 | Atom string = sel.xtarget; | 555 | Atom string = sel.xtarget; |
| 551 | XChangeProperty(xsre->display, xsre->requestor, xsre->property, | 556 | XChangeProperty(xsre->display, xsre->requestor, xsre->property, |
| 552 | XA_ATOM, 32, PropModeReplace, | 557 | XA_ATOM, 32, PropModeReplace, |
| 553 | (unsigned char *) &string, 1); | 558 | (uchar *) &string, 1); |
| 554 | xev.property = xsre->property; | 559 | xev.property = xsre->property; |
| 555 | } else if(xsre->target == sel.xtarget && sel.clip != NULL) { | 560 | } else if(xsre->target == sel.xtarget && sel.clip != NULL) { |
| 556 | XChangeProperty(xsre->display, xsre->requestor, xsre->property, | 561 | XChangeProperty(xsre->display, xsre->requestor, xsre->property, |
| 557 | xsre->target, 8, PropModeReplace, | 562 | xsre->target, 8, PropModeReplace, |
| 558 | (unsigned char *) sel.clip, strlen(sel.clip)); | 563 | (uchar *) sel.clip, strlen(sel.clip)); |
| 559 | xev.property = xsre->property; | 564 | xev.property = xsre->property; |
| 560 | } | 565 | } |
| 561 | 566 | ||
| @@ -636,7 +641,7 @@ bmotion(XEvent *e) { | |||
| 636 | if(oldey != sel.ey || oldex != sel.ex) { | 641 | if(oldey != sel.ey || oldex != sel.ex) { |
| 637 | int starty = MIN(oldey, sel.ey); | 642 | int starty = MIN(oldey, sel.ey); |
| 638 | int endy = MAX(oldey, sel.ey); | 643 | int endy = MAX(oldey, sel.ey); |
| 639 | for(int i=starty; i<=endy; i++) | 644 | for(int i = starty; i <= endy; i++) |
| 640 | term.dirty[i] = 1; | 645 | term.dirty[i] = 1; |
| 641 | draw(); | 646 | draw(); |
| 642 | } | 647 | } |
| @@ -1444,7 +1449,7 @@ tputc(char *c) { | |||
| 1444 | break; | 1449 | break; |
| 1445 | default: | 1450 | default: |
| 1446 | fprintf(stderr, "erresc: unknown sequence ESC 0x%02X '%c'\n", | 1451 | fprintf(stderr, "erresc: unknown sequence ESC 0x%02X '%c'\n", |
| 1447 | (unsigned char) ascii, isprint(ascii)?ascii:'.'); | 1452 | (uchar) ascii, isprint(ascii)?ascii:'.'); |
| 1448 | term.esc = 0; | 1453 | term.esc = 0; |
| 1449 | } | 1454 | } |
| 1450 | } | 1455 | } |
| @@ -1582,7 +1587,7 @@ void | |||
| 1582 | xloadcols(void) { | 1587 | xloadcols(void) { |
| 1583 | int i, r, g, b; | 1588 | int i, r, g, b; |
| 1584 | XColor color; | 1589 | XColor color; |
| 1585 | unsigned long white = WhitePixel(xw.dpy, xw.scr); | 1590 | ulong white = WhitePixel(xw.dpy, xw.scr); |
| 1586 | 1591 | ||
| 1587 | for(i = 0; i < LEN(colorname); i++) { | 1592 | for(i = 0; i < LEN(colorname); i++) { |
| 1588 | if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { | 1593 | if(!XAllocNamedColor(xw.dpy, xw.cmap, colorname[i], &color, &color)) { |
| @@ -1756,7 +1761,7 @@ xinit(void) { | |||
| 1756 | 1761 | ||
| 1757 | void | 1762 | void |
| 1758 | xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { | 1763 | xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { |
| 1759 | unsigned long xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp; | 1764 | ulong xfg = dc.col[base.fg], xbg = dc.col[base.bg], temp; |
| 1760 | int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw; | 1765 | int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw; |
| 1761 | int i; | 1766 | int i; |
| 1762 | 1767 | ||
| @@ -1776,7 +1781,7 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { | |||
| 1776 | 1781 | ||
| 1777 | if(base.mode & ATTR_GFX) { | 1782 | if(base.mode & ATTR_GFX) { |
| 1778 | for(i = 0; i < bytelen; i++) { | 1783 | for(i = 0; i < bytelen; i++) { |
| 1779 | char c = gfx[(unsigned int)s[i] % 256]; | 1784 | char c = gfx[(uint)s[i] % 256]; |
| 1780 | if(c) | 1785 | if(c) |
| 1781 | s[i] = c; | 1786 | s[i] = c; |
| 1782 | else if(s[i] > 0x5f) | 1787 | else if(s[i] > 0x5f) |
| @@ -1929,11 +1934,11 @@ focus(XEvent *ev) { | |||
| 1929 | } | 1934 | } |
| 1930 | 1935 | ||
| 1931 | char* | 1936 | char* |
| 1932 | kmap(KeySym k, unsigned int state) { | 1937 | kmap(KeySym k, uint state) { |
| 1933 | int i; | 1938 | int i; |
| 1934 | state &= ~Mod2Mask; | 1939 | state &= ~Mod2Mask; |
| 1935 | for(i = 0; i < LEN(key); i++) { | 1940 | for(i = 0; i < LEN(key); i++) { |
| 1936 | unsigned int mask = key[i].mask; | 1941 | uint mask = key[i].mask; |
| 1937 | if(key[i].k == k && ((state & mask) == mask || (mask == XK_NO_MOD && !state))) | 1942 | if(key[i].k == k && ((state & mask) == mask || (mask == XK_NO_MOD && !state))) |
| 1938 | return (char*)key[i].s; | 1943 | return (char*)key[i].s; |
| 1939 | } | 1944 | } |
| @@ -2024,7 +2029,7 @@ resize(XEvent *e) { | |||
| 2024 | xresize(col, row); | 2029 | xresize(col, row); |
| 2025 | } | 2030 | } |
| 2026 | 2031 | ||
| 2027 | int | 2032 | bool |
| 2028 | last_draw_too_old(void) { | 2033 | last_draw_too_old(void) { |
| 2029 | struct timeval now; | 2034 | struct timeval now; |
| 2030 | gettimeofday(&now, NULL); | 2035 | gettimeofday(&now, NULL); |
| @@ -2037,7 +2042,7 @@ run(void) { | |||
| 2037 | fd_set rfd; | 2042 | fd_set rfd; |
| 2038 | int xfd = XConnectionNumber(xw.dpy); | 2043 | int xfd = XConnectionNumber(xw.dpy); |
| 2039 | struct timeval timeout = {0}; | 2044 | struct timeval timeout = {0}; |
| 2040 | int stuff_to_print = 0; | 2045 | bool stuff_to_print = 0; |
| 2041 | 2046 | ||
| 2042 | for(;;) { | 2047 | for(;;) { |
| 2043 | FD_ZERO(&rfd); | 2048 | FD_ZERO(&rfd); |
