X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=b604f0e71185d9896ec7f97a00c745a62f532a24;hb=62756fdb4945a80f4a53e6d354d5d93f51035517;hp=97e1800d5196f160d777d0a06acdd7cdf213a59c;hpb=684f0a0729442e18115f71bc594a159725418ce8;p=st.git diff --git a/st.c b/st.c index 97e1800..b604f0e 100644 --- a/st.c +++ b/st.c @@ -62,26 +62,28 @@ char *argv0; #define XK_SWITCH_MOD (1<<13) /* macros */ -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define MAX(a, b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a) / sizeof(a)[0]) -#define DEFAULT(a, b) (a) = (a) ? (a) : (b) -#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) -#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') -#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) -#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) -#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL) -#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) -#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || (a).bg != (b).bg) -#define IS_SET(flag) ((term.mode & (flag)) != 0) -#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + (t1.tv_nsec-t2.tv_nsec)/1E6) -#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) - -#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) -#define IS_TRUECOL(x) (1 << 24 & (x)) -#define TRUERED(x) (((x) & 0xff0000) >> 8) -#define TRUEGREEN(x) (((x) & 0xff00)) -#define TRUEBLUE(x) (((x) & 0xff) << 8) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define MAX(a, b) ((a) < (b) ? (b) : (a)) +#define LEN(a) (sizeof(a) / sizeof(a)[0]) +#define DEFAULT(a, b) (a) = (a) ? (a) : (b) +#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) +#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') +#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) +#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) +#define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL) +#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) +#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ + (a).bg != (b).bg) +#define IS_SET(flag) ((term.mode & (flag)) != 0) +#define TIMEDIFF(t1, t2) ((t1.tv_sec-t2.tv_sec)*1000 + \ + (t1.tv_nsec-t2.tv_nsec)/1E6) +#define MODBIT(x, set, bit) ((set) ? ((x) |= (bit)) : ((x) &= ~(bit))) + +#define TRUECOLOR(r,g,b) (1 << 24 | (r) << 16 | (g) << 8 | (b)) +#define IS_TRUECOL(x) (1 << 24 & (x)) +#define TRUERED(x) (((x) & 0xff0000) >> 8) +#define TRUEGREEN(x) (((x) & 0xff00)) +#define TRUEBLUE(x) (((x) & 0xff) << 8) enum glyph_attribute { @@ -567,6 +569,7 @@ xwrite(int fd, const char *s, size_t len) len -= r; s += r; } + return aux; } @@ -620,6 +623,7 @@ utf8decode(char *c, Rune *u, size_t clen) return 0; *u = udecoded; utf8validate(u, len); + return len; } @@ -629,6 +633,7 @@ utf8decodebyte(char c, size_t *i) for (*i = 0; *i < LEN(utfmask); ++(*i)) if (((uchar)c & utfmask[*i]) == utfbyte[*i]) return (uchar)c & ~utfmask[*i]; + return 0; } @@ -640,11 +645,13 @@ utf8encode(Rune u, char *c) len = utf8validate(&u, 0); if (len > UTF_SIZ) return 0; + for (i = len - 1; i != 0; --i) { c[i] = utf8encodebyte(u, 0); u >>= 6; } c[0] = utf8encodebyte(u, len); + return len; } @@ -667,6 +674,7 @@ utf8strchr(char *s, Rune u) if (r == u) return &(s[i]); } + return NULL; } @@ -677,6 +685,7 @@ utf8validate(Rune *u, size_t i) *u = UTF_INVALID; for (i = 1; *u > utfmax[i]; ++i) ; + return i; } @@ -1320,9 +1329,8 @@ execsh(void) die("who are you?\n"); } - if (!(sh = getenv("SHELL"))) { + if ((sh = getenv("SHELL")) == NULL) sh = (pw->pw_shell[0]) ? pw->pw_shell : shell; - } if (opt_cmd) prog = opt_cmd[0]; @@ -3125,6 +3133,7 @@ xloadcolor(int i, const char *name, Color *ncolor) } else name = colorname[i]; } + return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); } @@ -3164,6 +3173,7 @@ xsetcolorname(int x, const char *name) XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); dc.col[x] = ncolor; + return 0; } @@ -3233,6 +3243,7 @@ xgeommasktogravity(int mask) case YNegative: return SouthWestGravity; } + return SouthEastGravity; } @@ -4148,9 +4159,9 @@ run(void) do { XNextEvent(xw.dpy, &ev); /* - * XFilterEvent is required to be called after you using XOpenIM, - * this is not unnecessary.It does not only filter the key event, - * but some clientmessage for input method as well. + * This XFilterEvent call is required because of XOpenIM. It + * does filter out the key event and some client message for + * the input method too. */ if (XFilterEvent(&ev, None)) continue;