commit c65df186e2e2068371e8094971c26e7019fc292b
parent f096a78a1be52a6a6dc68b904e6598e4d6d29d59
Author: robert <robertrussell.72001@gmail.com>
Date: Fri, 31 Dec 2021 22:56:57 -0800
Trivial matters
- Break lines as if tab size was 4
- Make error messages more consistent
- Etc.
Diffstat:
| M | st.c | | | 160 | ++++++++++++++++++++++++++++++++----------------------------------------------- |
| M | st.h | | | 2 | -- |
| M | util.c | | | 3 | ++- |
| M | win.h | | | 2 | +- |
| M | x.c | | | 141 | ++++++++++++++++++++++++++++++++++++------------------------------------------- |
5 files changed, 132 insertions(+), 176 deletions(-)
diff --git a/st.c b/st.c
@@ -320,7 +320,7 @@ selected(int x, int y)
if (sel.type == SEL_RECTANGULAR)
return BETWEEN(y, sel.nb.y, sel.ne.y)
- && BETWEEN(x, sel.nb.x, sel.ne.x);
+ && BETWEEN(x, sel.nb.x, sel.ne.x);
return BETWEEN(y, sel.nb.y, sel.ne.y)
&& (y != sel.nb.y || x >= sel.nb.x)
@@ -468,9 +468,9 @@ execsh(char *cmd, char **args)
errno = 0;
if ((pw = getpwuid(getuid())) == NULL) {
if (errno)
- die("getpwuid: %s\n", strerror(errno));
+ die("getpwuid failed: %s\n", strerror(errno));
else
- die("who are you?\n");
+ die("who are you? (password file entry not found)\n");
}
if ((sh = getenv("SHELL")) == NULL)
@@ -551,7 +551,7 @@ stty(char **args)
}
*q = '\0';
if (system(cmd) != 0)
- perror("Couldn't call stty");
+ perror("failed to call stty");
}
int
@@ -561,24 +561,22 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
if (out) {
term.mode |= MODE_PRINT;
- iofd = (!strcmp(out, "-")) ?
- 1 : open(out, O_WRONLY | O_CREAT, 0666);
- if (iofd < 0) {
- fprintf(stderr, "Error opening %s:%s\n",
- out, strerror(errno));
- }
+ iofd = (!strcmp(out, "-")) ? 1 : open(out, O_WRONLY | O_CREAT, 0666);
+ if (iofd < 0)
+ fprintf(stderr, "open '%s' failed: %s\n", out, strerror(errno));
}
if (line) {
if ((cmdfd = open(line, O_RDWR)) < 0)
- die("open line '%s' failed: %s\n",
- line, strerror(errno));
+ die("open line '%s' failed: %s\n", line, strerror(errno));
dup2(cmdfd, 0);
stty(args);
return cmdfd;
}
- /* seems to work fine on linux, openbsd and freebsd */
+ /* openpty is BSD function, but it is implemented by glibc and
+ * musl on linux, so this should be ok. */
+ /* TODO: don't we essentially do a forkpty here? Let's use that instead */
if (openpty(&m, &s, NULL, NULL, NULL) < 0)
die("openpty failed: %s\n", strerror(errno));
@@ -598,14 +596,14 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
close(m);
#ifdef __OpenBSD__
if (pledge("stdio getpw proc exec", NULL) == -1)
- die("pledge\n");
+ die("pledge failed\n");
#endif
execsh(cmd, args);
break;
default:
#ifdef __OpenBSD__
if (pledge("stdio rpath tty proc", NULL) == -1)
- die("pledge\n");
+ die("pledge failed\n");
#endif
close(s);
cmdfd = m;
@@ -629,7 +627,7 @@ ttyread(void)
case 0:
exit(0);
case -1:
- die("couldn't read from shell: %s\n", strerror(errno));
+ die("read from shell failed: %s\n", strerror(errno));
default:
buflen += ret;
written = twrite(buf, buflen, 0);
@@ -676,9 +674,8 @@ ttywriteraw(const char *s, size_t n)
ssize_t r;
size_t lim = 256;
- /* Remember that we are using a pty, which might be a modem line.
- * Writing too much will clog the line. That's why we are doing this
- * dance.
+ /* Remember that we are using a pty, which might be a modem line. Writing
+ * too much will clog the line. That's why we are doing this dance.
* FIXME: Migrate the world to Plan 9. */
while (n > 0) {
FD_ZERO(&wfd);
@@ -699,9 +696,8 @@ ttywriteraw(const char *s, size_t n)
if ((r = write(cmdfd, s, (n < lim)? n : lim)) < 0)
goto write_error;
if (r < n) {
- /* We weren't able to write out everything.
- * This means the buffer is getting full
- * again. Empty it. */
+ /* We weren't able to write out everything. This means the
+ * buffer is getting full again. Empty it. */
if (n < lim)
lim = ttyread();
n -= r;
@@ -717,7 +713,7 @@ ttywriteraw(const char *s, size_t n)
return;
write_error:
- die("write error on tty: %s\n", strerror(errno));
+ die("write on tty failed: %s\n", strerror(errno));
}
void
@@ -730,7 +726,7 @@ ttyresize(int tw, int th)
w.ws_xpixel = tw;
w.ws_ypixel = th;
if (ioctl(cmdfd, TIOCSWINSZ, &w) < 0)
- fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
+ fprintf(stderr, "failed to set window size: %s\n", strerror(errno));
}
void
@@ -901,11 +897,10 @@ selscroll(int orig, int n)
sel.ob.y += n;
sel.oe.y += n;
if (sel.ob.y < term.top || sel.ob.y > term.bot ||
- sel.oe.y < term.top || sel.oe.y > term.bot) {
+ sel.oe.y < term.top || sel.oe.y > term.bot)
selclear();
- } else {
+ else
selnormalize();
- }
}
}
@@ -914,11 +909,10 @@ tnewline(int first_col)
{
int y = term.c.y;
- if (y == term.bot) {
+ if (y == term.bot)
tscrollup(term.top, 1);
- } else {
+ else
y++;
- }
tmoveto(first_col ? 0 : term.c.x, y);
}
@@ -992,7 +986,7 @@ tsetchar(Rune u, const Glyph *attr, int x, int y)
/* The table is proudly stolen from rxvt. */
if (term.trantbl[term.charset] == CS_GRAPHIC0 &&
- BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41])
+ BETWEEN(u, 0x41, 0x7e) && vt100_0[u - 0x41])
utf8dec(vt100_0[u - 0x41], &u, UTF_SIZ);
if (term.line[y][x].mode & ATTR_WIDE) {
@@ -1098,8 +1092,8 @@ tdefcolor(const int *attr, int *npar, int l)
case 2: /* direct color in RGB space */
if (*npar + 4 >= l) {
fprintf(stderr,
- "erresc(38): Incorrect number of parameters (%d)\n",
- *npar);
+ "erresc(38): Incorrect number of parameters (%d)\n",
+ *npar);
break;
}
r = attr[*npar + 2];
@@ -1107,16 +1101,15 @@ tdefcolor(const int *attr, int *npar, int l)
b = attr[*npar + 4];
*npar += 4;
if (!BETWEEN(r, 0, 255) || !BETWEEN(g, 0, 255) || !BETWEEN(b, 0, 255))
- fprintf(stderr, "erresc: bad rgb color (%u,%u,%u)\n",
- r, g, b);
+ fprintf(stderr, "erresc: bad rgb color (%u,%u,%u)\n", r, g, b);
else
idx = TRUECOLOR(r, g, b);
break;
case 5: /* indexed color */
if (*npar + 2 >= l) {
fprintf(stderr,
- "erresc(38): Incorrect number of parameters (%d)\n",
- *npar);
+ "erresc(38): Incorrect number of parameters (%d)\n",
+ *npar);
break;
}
*npar += 2;
@@ -1130,8 +1123,7 @@ tdefcolor(const int *attr, int *npar, int l)
case 3: /* direct color in CMY space */
case 4: /* direct color in CMYK space */
default:
- fprintf(stderr,
- "erresc(38): gfx attr %d unknown\n", attr[*npar]);
+ fprintf(stderr, "erresc(38): gfx attr %d unknown\n", attr[*npar]);
break;
}
@@ -1231,8 +1223,8 @@ tsetattr(const int *attr, int l)
term.c.attr.bg = attr[i] - 100 + 8;
} else {
fprintf(stderr,
- "erresc(default): gfx attr %d unknown\n",
- attr[i]);
+ "erresc(default): gfx attr %d unknown\n",
+ attr[i]);
csidump();
}
break;
@@ -1329,10 +1321,8 @@ tsetmode(int priv, int set, const int *args, int narg)
if (!allowaltscreen)
break;
alt = IS_SET(MODE_ALTSCREEN);
- if (alt) {
- tclearregion(0, 0, term.col-1,
- term.row-1);
- }
+ if (alt)
+ tclearregion(0, 0, term.col-1, term.row-1);
if (set ^ alt) /* set is always 1 or 0 */
tswapscreen();
if (*args != 1049)
@@ -1356,8 +1346,8 @@ tsetmode(int priv, int set, const int *args, int narg)
break;
default:
fprintf(stderr,
- "erresc: unknown private set/reset mode %d\n",
- *args);
+ "erresc: unknown private set/reset mode %d\n",
+ *args);
break;
}
} else {
@@ -1377,9 +1367,7 @@ tsetmode(int priv, int set, const int *args, int narg)
MODBIT(term.mode, set, MODE_CRLF);
break;
default:
- fprintf(stderr,
- "erresc: unknown set/reset mode %d\n",
- *args);
+ fprintf(stderr, "erresc: unknown set/reset mode %d\n", *args);
break;
}
}
@@ -1437,9 +1425,10 @@ csihandle(void)
break;
case 'b': /* REP -- if last char is printable print it <n> more times */
DEFAULT(csiescseq.arg[0], 1);
- if (term.lastc)
+ if (term.lastc) {
while (csiescseq.arg[0]-- > 0)
tputc(term.lastc);
+ }
break;
case 'C': /* CUF -- Cursor <n> Forward */
case 'a': /* HPR -- Cursor <n> Forward */
@@ -1489,10 +1478,8 @@ csihandle(void)
switch (csiescseq.arg[0]) {
case 0: /* below */
tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
- if (term.c.y < term.row-1) {
- tclearregion(0, term.c.y+1, term.col-1,
- term.row-1);
- }
+ if (term.c.y < term.row-1)
+ tclearregion(0, term.c.y+1, term.col-1, term.row-1);
break;
case 1: /* above */
if (term.c.y > 1)
@@ -1509,8 +1496,7 @@ csihandle(void)
case 'K': /* EL -- Clear line */
switch (csiescseq.arg[0]) {
case 0: /* right */
- tclearregion(term.c.x, term.c.y, term.col-1,
- term.c.y);
+ tclearregion(term.c.x, term.c.y, term.col-1, term.c.y);
break;
case 1: /* left */
tclearregion(0, term.c.y, term.c.x, term.c.y);
@@ -1607,17 +1593,16 @@ csidump(void)
fprintf(stderr, "ESC[");
for (i = 0; i < csiescseq.len; i++) {
c = csiescseq.buf[i] & 0xff;
- if (isprint(c)) {
+ if (isprint(c))
putc(c, stderr);
- } else if (c == '\n') {
+ else if (c == '\n')
fprintf(stderr, "(\\n)");
- } else if (c == '\r') {
+ else if (c == '\r')
fprintf(stderr, "(\\r)");
- } else if (c == 0x1b) {
+ else if (c == 0x1b)
fprintf(stderr, "(\\e)");
- } else {
+ else
fprintf(stderr, "(%02x)", c);
- }
}
putc('\n', stderr);
}
@@ -1679,8 +1664,7 @@ strhandle(void)
fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
j, p ? p : "(null)");
} else {
- /* TODO if defaultbg color is changed, borders
- * are dirty */
+ /* TODO if defaultbg color is changed, borders are dirty */
redraw();
}
return;
@@ -1848,11 +1832,10 @@ tdeftran(char ascii)
static int vcs[] = {CS_GRAPHIC0, CS_USA};
char *p;
- if ((p = strchr(cs, ascii)) == NULL) {
+ if ((p = strchr(cs, ascii)) == NULL)
fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii);
- } else {
+ else
term.trantbl[term.icharset] = vcs[p - cs];
- }
}
void
@@ -2021,11 +2004,10 @@ eschandle(uchar ascii)
term.esc |= ESC_ALTCHARSET;
return 0;
case 'D': /* IND -- Linefeed */
- if (term.c.y == term.bot) {
+ if (term.c.y == term.bot)
tscrollup(term.top, 1);
- } else {
+ else
tmoveto(term.c.x, term.c.y+1);
- }
break;
case 'E': /* NEL -- Next line */
tnewline(1); /* always go to first col */
@@ -2034,19 +2016,18 @@ eschandle(uchar ascii)
term.tabs[term.c.x] = 1;
break;
case 'M': /* RI -- Reverse index */
- if (term.c.y == term.top) {
+ if (term.c.y == term.top)
tscrolldown(term.top, 1);
- } else {
+ else
tmoveto(term.c.x, term.c.y-1);
- }
break;
case 'Z': /* DECID -- Identify Terminal */
ttywrite(vtiden, strlen(vtiden), 0);
break;
case 'c': /* RIS -- Reset to initial state */
treset();
- resettitle();
- xloadcols();
+ xsettitle(NULL);
+ xloadcolors();
break;
case '=': /* DECPAM -- Application keypad */
xsetmode(1, MODE_APPKEYPAD);
@@ -2066,7 +2047,7 @@ eschandle(uchar ascii)
break;
default:
fprintf(stderr, "erresc: unknown sequence ESC 0x%02X '%c'\n",
- (uchar) ascii, isprint(ascii)? ascii:'.');
+ (uchar) ascii, isprint(ascii)? ascii:'.');
break;
}
return 1;
@@ -2139,9 +2120,8 @@ check_control_code:
} else if (term.esc & ESC_START) {
if (term.esc & ESC_CSI) {
csiescseq.buf[csiescseq.len++] = u;
- if (BETWEEN(u, 0x40, 0x7E)
- || csiescseq.len >= \
- sizeof(csiescseq.buf)-1) {
+ if (BETWEEN(u, 0x40, 0x7E) ||
+ csiescseq.len >= sizeof(csiescseq.buf)-1) {
term.esc = 0;
csiparse();
csihandle();
@@ -2191,11 +2171,10 @@ check_control_code:
gp[1].mode = ATTR_WDUMMY;
}
}
- if (term.c.x+width < term.col) {
+ if (term.c.x+width < term.col)
tmoveto(term.c.x+width, term.c.y);
- } else {
+ else
term.c.state |= CURSOR_WRAPNEXT;
- }
}
int
@@ -2240,8 +2219,7 @@ tresize(int col, int row)
TCursor c;
if (col < 1 || row < 1) {
- fprintf(stderr,
- "tresize: error resizing to %dx%d\n", col, row);
+ fprintf(stderr, "tresize: error resizing to %dx%d\n", col, row);
return;
}
@@ -2298,12 +2276,10 @@ tresize(int col, int row)
/* Clearing both screens (it makes dirty all lines) */
c = term.c;
for (i = 0; i < 2; i++) {
- if (mincol < col && 0 < minrow) {
+ if (mincol < col && 0 < minrow)
tclearregion(mincol, 0, col - 1, minrow - 1);
- }
- if (0 < col && minrow < row) {
+ if (0 < col && minrow < row)
tclearregion(0, minrow, col - 1, row - 1);
- }
tswapscreen();
tcursor(CURSOR_LOAD);
}
@@ -2311,12 +2287,6 @@ tresize(int col, int row)
}
void
-resettitle(void)
-{
- xsettitle(NULL);
-}
-
-void
drawregion(int x1, int y1, int x2, int y2)
{
int y;
diff --git a/st.h b/st.h
@@ -65,8 +65,6 @@ size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
-void resettitle(void);
-
void selclear(void);
void selinit(void);
void selstart(int, int, int);
diff --git a/util.c b/util.c
@@ -129,9 +129,10 @@ utf8dec(const char *c, Rune *u, size_t clen)
Rune
utf8decbyte(char c, size_t *i)
{
- for (*i = 0; *i < LEN(utfmask); ++(*i))
+ for (*i = 0; *i < LEN(utfmask); ++(*i)) {
if (((uchar)c & utfmask[*i]) == utfbyte[*i])
return (uchar)c & ~utfmask[*i];
+ }
return 0;
}
diff --git a/win.h b/win.h
@@ -39,7 +39,7 @@ void xclipcopy(void);
void xdrawcursor(int, int, Glyph, int, int, Glyph);
void xdrawline(Line, int, int, int);
void xfinishdraw(void);
-void xloadcols(void);
+void xloadcolors(void);
int xsetcolorname(int, const char *);
void xseticontitle(char *);
void xsettitle(char *);
diff --git a/x.c b/x.c
@@ -167,8 +167,8 @@ static void (*handler[LASTEvent])(XEvent *) = {
* different in another window. */
/* [SelectionClear] = selclear_, */
[SelectionNotify] = selnotify,
-/* PropertyNotify is only turned on when there is some INCR transfer happening
- * for the selection retrieval. */
+ /* PropertyNotify is only turned on when there is some INCR transfer
+ * happening for the selection retrieval. */
[PropertyNotify] = propnotify,
[SelectionRequest] = selrequest,
};
@@ -477,7 +477,7 @@ selnotify(XEvent *e)
BUFSIZ/4, False, AnyPropertyType,
&type, &format, &nitems, &rem,
&data)) {
- fprintf(stderr, "Clipboard allocation failed\n");
+ fprintf(stderr, "clipboard allocation failed\n");
return;
}
@@ -574,8 +574,8 @@ selrequest(XEvent *e)
seltext = xsel.clipboard;
} else {
fprintf(stderr,
- "Unhandled clipboard selection 0x%lx\n",
- xsre->selection);
+ "unhandled clipboard selection 0x%lx\n",
+ xsre->selection);
return;
}
if (seltext != NULL) {
@@ -589,7 +589,7 @@ selrequest(XEvent *e)
/* all done, send a notification to the listener */
if (!XSendEvent(xsre->display, xsre->requestor, 1, 0, (XEvent *) &xev))
- fprintf(stderr, "Error sending SelectionNotify event\n");
+ fprintf(stderr, "error sending SelectionNotify event\n");
}
void
@@ -680,17 +680,17 @@ xloadcolor(int i, const char *name, Color *ncolor)
color.red = 0x0808 + 0x0a0a * (i - (6*6*6+16));
color.green = color.blue = color.red;
}
- return XftColorAllocValue(xw.dpy, xw.vis,
- xw.cmap, &color, ncolor);
- } else
+ return XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, ncolor);
+ } else {
name = colorname[i];
+ }
}
return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor);
}
void
-xloadcols(void)
+xloadcolors(void)
{
int i;
static int loaded;
@@ -707,13 +707,14 @@ xloadcols(void)
dc.col = xmalloc(dc.collen * sizeof(Color));
}
- for (i = 0; i < dc.collen; i++)
+ for (i = 0; i < dc.collen; i++) {
if (!xloadcolor(i, NULL, &dc.col[i])) {
if (colorname[i])
- die("could not allocate color '%s'\n", colorname[i]);
+ die("allocate color '%s' failed\n", colorname[i]);
else
- die("could not allocate color %d\n", i);
+ die("allocate color %d failed\n", i);
}
+ }
loaded = 1;
}
@@ -774,8 +775,7 @@ xhints(void)
sizeh->win_gravity = xgeommasktogravity(xw.gm);
}
- XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm,
- &class);
+ XSetWMProperties(xw.dpy, xw.win, NULL, NULL, NULL, 0, sizeh, &wm, &class);
XFree(sizeh);
}
@@ -803,9 +803,8 @@ xloadfont(Font *f, FcPattern *pattern)
XGlyphInfo extents;
int wantattr, haveattr;
- /* Manually configure instead of calling XftMatchFont
- * so that we can use the configured pattern for
- * "missing glyph" lookups. */
+ /* Manually configure instead of calling XftMatchFont so that we can use
+ * the configured pattern for "missing glyph" lookups. */
configured = FcPatternDuplicate(pattern);
if (!configured)
return 1;
@@ -875,12 +874,12 @@ xloadfonts(const char *fontstr, double fontsize)
pattern = FcNameParse((const FcChar8 *)fontstr);
if (!pattern)
- die("can't open font %s\n", fontstr);
+ die("open font '%s' failed\n", fontstr);
if (fontsize > 1) {
FcPatternDel(pattern, FC_PIXEL_SIZE);
FcPatternDel(pattern, FC_SIZE);
- FcPatternAddDouble(pattern, FC_PIXEL_SIZE, (double)fontsize);
+ FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontsize);
usedfontsize = fontsize;
} else {
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &fontval) ==
@@ -899,11 +898,10 @@ xloadfonts(const char *fontstr, double fontsize)
}
if (xloadfont(&dc.font, pattern))
- die("can't open font %s\n", fontstr);
+ die("open font '%s' failed\n", fontstr);
if (usedfontsize < 0) {
- FcPatternGetDouble(dc.font.match->pattern,
- FC_PIXEL_SIZE, 0, &fontval);
+ FcPatternGetDouble(dc.font.match->pattern, FC_PIXEL_SIZE, 0, &fontval);
usedfontsize = fontval;
if (fontsize == 0)
defaultfontsize = fontval;
@@ -916,17 +914,17 @@ xloadfonts(const char *fontstr, double fontsize)
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
if (xloadfont(&dc.ifont, pattern))
- die("can't open font %s\n", fontstr);
+ die("open font '%s' failed\n", fontstr);
FcPatternDel(pattern, FC_WEIGHT);
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
if (xloadfont(&dc.ibfont, pattern))
- die("can't open font %s\n", fontstr);
+ die("open font '%s' failed\n", fontstr);
FcPatternDel(pattern, FC_SLANT);
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
if (xloadfont(&dc.bfont, pattern))
- die("can't open font %s\n", fontstr);
+ die("open font '%s' failed\n", fontstr);
FcPatternDestroy(pattern);
}
@@ -964,21 +962,18 @@ ximopen(Display *dpy)
return 0;
if (XSetIMValues(xw.ime.xim, XNDestroyCallback, &imdestroy, NULL))
- fprintf(stderr, "XSetIMValues: "
- "Could not set XNDestroyCallback.\n");
+ fprintf(stderr, "XSetIMValues: failed to set XNDestroyCallback\n");
- xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation, &xw.ime.spot,
- NULL);
+ xw.ime.spotlist = XVaCreateNestedList(0, XNSpotLocation,
+ &xw.ime.spot, NULL);
if (xw.ime.xic == NULL) {
xw.ime.xic = XCreateIC(xw.ime.xim, XNInputStyle,
- XIMPreeditNothing | XIMStatusNothing,
- XNClientWindow, xw.win,
- XNDestroyCallback, &icdestroy,
- NULL);
+ XIMPreeditNothing | XIMStatusNothing, XNClientWindow, xw.win,
+ XNDestroyCallback, &icdestroy, NULL);
+ if (xw.ime.xic == NULL)
+ fprintf(stderr, "XCreateIC: failed to create input context\n");
}
- if (xw.ime.xic == NULL)
- fprintf(stderr, "XCreateIC: Could not create input context.\n");
return 1;
}
@@ -988,7 +983,7 @@ ximinstantiate(Display *dpy, XPointer client, XPointer call)
{
if (ximopen(dpy))
XUnregisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
- ximinstantiate, NULL);
+ ximinstantiate, NULL);
}
void
@@ -996,7 +991,7 @@ ximdestroy(XIM xim, XPointer client, XPointer call)
{
xw.ime.xim = NULL;
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
- ximinstantiate, NULL);
+ ximinstantiate, NULL);
XFree(xw.ime.spotlist);
}
@@ -1017,20 +1012,20 @@ xinit(int cols, int rows)
XColor xmousefg, xmousebg;
if (!(xw.dpy = XOpenDisplay(NULL)))
- die("can't open display\n");
+ die("open display failed\n");
xw.scr = XDefaultScreen(xw.dpy);
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
/* font */
if (!FcInit())
- die("could not init fontconfig.\n");
+ die("fontconfig init failed\n");
- usedfont = (opt_font == NULL)? font : opt_font;
+ usedfont = (opt_font == NULL) ? font : opt_font;
xloadfonts(usedfont, 0);
/* colors */
xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
- xloadcols();
+ xloadcolors();
/* adjust fixed window geometry */
win.w = 2 * borderpx + cols * win.cw;
@@ -1072,10 +1067,9 @@ xinit(int cols, int rows)
xw.draw = XftDrawCreate(xw.dpy, xw.buf, xw.vis, xw.cmap);
/* input methods */
- if (!ximopen(xw.dpy)) {
+ if (!ximopen(xw.dpy))
XRegisterIMInstantiateCallback(xw.dpy, NULL, NULL, NULL,
- ximinstantiate, NULL);
- }
+ ximinstantiate, NULL);
/* white cursor, black outline */
cursor = XCreateFontCursor(xw.dpy, mouseshape);
@@ -1106,7 +1100,7 @@ xinit(int cols, int rows)
PropModeReplace, (uchar *)&thispid, 1);
win.mode = MODE_NUMLOCK;
- resettitle();
+ xsettitle(NULL);
xhints();
XMapWindow(xw.dpy, xw.win);
XSync(xw.dpy, False);
@@ -1192,8 +1186,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
/* Nothing was found. Use fontconfig to find matching font. */
if (f >= frclen) {
if (!font->set)
- font->set = FcFontSort(0, font->pattern,
- 1, 0, &fcres);
+ font->set = FcFontSort(0, font->pattern, 1, 0, &fcres);
fcsets[0] = font->set;
/* Nothing was found in the cache. Now use
@@ -1226,7 +1219,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
fontpattern);
if (!frc[frclen].font)
die("XftFontOpenPattern failed seeking fallback font: %s\n",
- strerror(errno));
+ strerror(errno));
frc[frclen].flags = frcflags;
frc[frclen].unicodep = rune;
@@ -1303,8 +1296,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
colfg.green = ~fg->color.green;
colfg.blue = ~fg->color.blue;
colfg.alpha = fg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg,
- &revfg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colfg, &revfg);
fg = &revfg;
}
@@ -1315,8 +1307,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
colbg.green = ~bg->color.green;
colbg.blue = ~bg->color.blue;
colbg.alpha = bg->color.alpha;
- XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg,
- &revbg);
+ XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &colbg, &revbg);
bg = &revbg;
}
}
@@ -1344,13 +1335,12 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Intelligent cleaning up of the borders. */
if (x == 0) {
- xclear(0, (y == 0)? 0 : winy, borderpx,
- winy + win.ch +
- ((winy + win.ch >= borderpx + win.th)? win.h : 0));
+ xclear(0, (y == 0)? 0 : winy, borderpx, winy + win.ch +
+ ((winy + win.ch >= borderpx + win.th) ? win.h : 0));
}
if (winx + width >= borderpx + win.tw) {
- xclear(winx + width, (y == 0)? 0 : winy, win.w,
- ((winy + win.ch >= borderpx + win.th)? win.h : (winy + win.ch)));
+ xclear(winx + width, (y == 0)? 0 : winy, win.w, ((winy + win.ch >=
+ borderpx + win.th) ? win.h : (winy + win.ch)));
}
if (y == 0)
xclear(winx, 0, winx + width, borderpx);
@@ -1372,8 +1362,7 @@ xdrawglyphfontspecs(const XftGlyphFontSpec *specs, Glyph base, int len, int x, i
/* Render underline and strikethrough. */
if (base.mode & ATTR_UNDERLINE) {
- XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1,
- width, 1);
+ XftDrawRect(xw.draw, fg, winx, winy + dc.font.ascent + 1, width, 1);
}
if (base.mode & ATTR_STRUCK) {
@@ -1494,8 +1483,7 @@ xseticontitle(char *p)
XTextProperty prop;
DEFAULT(p, opt_title);
- Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
- &prop);
+ Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, &prop);
XSetWMIconName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmiconname);
XFree(prop.value);
@@ -1507,8 +1495,7 @@ xsettitle(char *p)
XTextProperty prop;
DEFAULT(p, opt_title);
- Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
- &prop);
+ Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, &prop);
XSetWMName(xw.dpy, xw.win, &prop);
XSetTextProperty(xw.dpy, xw.win, &prop, xw.netwmname);
XFree(prop.value);
@@ -1554,11 +1541,9 @@ xdrawline(Line line, int x1, int y1, int x2)
void
xfinishdraw(void)
{
- XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w,
- win.h, 0, 0);
+ XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, 0, 0, win.w, win.h, 0, 0);
XSetForeground(xw.dpy, dc.gc,
- dc.col[IS_SET(MODE_REVERSE)?
- defaultfg : defaultbg].pixel);
+ dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg].pixel);
}
void
@@ -1714,7 +1699,7 @@ void
kaction(XKeyEvent *e, int release)
{
uint state;
- char buf[64];
+ char buf[64]; /* big enough for CSI sequence */
size_t len;
KeySym sym;
Status status;
@@ -1736,8 +1721,7 @@ kaction(XKeyEvent *e, int release)
return;
/* 2. Modified UTF8-encoded unicode */
- if ((state&KMOD) > 0 && utf8dec(buf, &c, len) == len
- && c != UTF_INVALID)
+ if ((state&KMOD) > 0 && utf8dec(buf, &c, len) == len && c != UTF_INVALID)
len = csienc(buf, sizeof buf, state, c, SHFT, 'u');
/* 3. Default to directly sending composed string from the input method
@@ -1765,8 +1749,8 @@ krelease(XEvent *e)
void
cmessage(XEvent *e)
{
- /* See xembed specs
- * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
+ /* See xembed specs:
+ * http://standards.freedesktop.org/xembed-spec/xembed-spec-latest.html */
if (e->xclient.message_type == xw.xembed && e->xclient.format == 32) {
if (e->xclient.data.l[1] == XEMBED_FOCUS_IN) {
win.mode |= MODE_FOCUSED;
@@ -1862,8 +1846,8 @@ run(void)
trigger = now;
drawing = 1;
}
- timeout = (maxlatency - TIMEDIFF(now, trigger)) \
- / maxlatency * minlatency;
+ timeout = (maxlatency - TIMEDIFF(now, trigger)) /
+ maxlatency * minlatency;
if (timeout > 0)
continue; /* we have time, try to find idle */
}
@@ -1901,11 +1885,15 @@ usage(void)
" [stty_args ...]\n", argv0, argv0);
}
+/* TODO it is weird that main is in x.c and not st.c. Probably, the tty stuff
+ * should be in tty.c, the X stuff should be in win.c, and the "neutral"
+ * stuff (e.g., main) should be in st.c. */
int
main(int argc, char *argv[])
{
xw.l = xw.t = 0;
xw.isfixed = False;
+ /* TODO why is this here? Probably this belongs in xinit. */
xsetcursor(cursorshape);
ARGBEGIN {
@@ -1923,8 +1911,7 @@ main(int argc, char *argv[])
opt_font = EARGF(usage());
break;
case 'g':
- xw.gm = XParseGeometry(EARGF(usage()),
- &xw.l, &xw.t, &cols, &rows);
+ xw.gm = XParseGeometry(EARGF(usage()), &xw.l, &xw.t, &cols, &rows);
break;
case 'i':
xw.isfixed = 1;