aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--st.c79
1 files changed, 42 insertions, 37 deletions
diff --git a/st.c b/st.c
index f56667b..b1db093 100644
--- a/st.c
+++ b/st.c
@@ -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
80enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 }; 81enum { B0=1, B1=2, B2=4, B3=8, B4=16, B5=32, B6=64, B7=128 };
81 82
83typedef unsigned char uchar;
84typedef unsigned int uint;
85typedef unsigned long ulong;
86
82typedef struct { 87typedef 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
146typedef struct { 151typedef 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 */
153typedef struct { 158typedef 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);
182static void execsh(void); 187static void execsh(void);
183static void sigchld(int); 188static void sigchld(int);
184static void run(void); 189static void run(void);
185static int last_draw_too_old(void); 190static bool last_draw_too_old(void);
186 191
187static void csidump(void); 192static void csidump(void);
188static void csihandle(void); 193static void csihandle(void);
@@ -229,7 +234,7 @@ static void xresize(int, int);
229static void expose(XEvent *); 234static void expose(XEvent *);
230static void visibility(XEvent *); 235static void visibility(XEvent *);
231static void unmap(XEvent *); 236static void unmap(XEvent *);
232static char* kmap(KeySym, unsigned int); 237static char* kmap(KeySym, uint);
233static void kpress(XEvent *); 238static void kpress(XEvent *);
234static void cmessage(XEvent *); 239static void cmessage(XEvent *);
235static void resize(XEvent *); 240static void resize(XEvent *);
@@ -241,7 +246,7 @@ static void selnotify(XEvent *);
241static void selrequest(XEvent *); 246static void selrequest(XEvent *);
242 247
243static void selinit(void); 248static void selinit(void);
244static inline int selected(int, int); 249static inline bool selected(int, int);
245static void selcopy(void); 250static void selcopy(void);
246static void selpaste(); 251static void selpaste();
247static void selscroll(int, int); 252static void selscroll(int, int);
@@ -282,31 +287,31 @@ static char *opt_class = NULL;
282 287
283int 288int
284utf8decode(char *s, long *u) { 289utf8decode(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
322int 327int
323utf8encode(long *u, char *s) { 328utf8encode(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 */
358int 363int
359isfullutf8(char *s, int b) { 364isfullutf8(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
382int 387int
383utf8size(char *s) { 388utf8size(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
408static inline int 413static inline bool
409selected(int x, int y) { 414selected(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
505void 510void
506selnotify(XEvent *e) { 511selnotify(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
1582xloadcols(void) { 1587xloadcols(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
1757void 1762void
1758xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { 1763xdraws(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
1931char* 1936char*
1932kmap(KeySym k, unsigned int state) { 1937kmap(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
2027int 2032bool
2028last_draw_too_old(void) { 2033last_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);