---
st.c | 63 ++++++++++++++++++++++++------------------------------------
1 file changed, 25 insertions(+), 38 deletions(-)
diff --git a/st.c b/st.c
index 9c34a5b..e0e8e65 100644
--- a/st.c
+++ b/st.c
@@ -235,10 +235,9 @@ ssize_t
xwrite(int fd, const char *s, size_t len)
{
size_t aux = len;
- ssize_t r;
while (len > 0) {
- r = write(fd, s, len);
+ ssize_t r = write(fd, s, len);
if (r < 0)
return r;
len -= r;
@@ -528,9 +527,8 @@ selected(int x, int y)
void
selsnap(int *x, int *y, int direction)
{
- int newx, newy, xt, yt;
- int delim, prevdelim;
- Glyph *gp, *prevgp;
+ Glyph *prevgp = &term.line[*y][*x];
+ int prevdelim = ISDELIM(prevgp->u);
switch (sel.snap) {
case SNAP_WORD:
@@ -538,12 +536,11 @@ selsnap(int *x, int *y, int direction)
* Snap around if the word wraps around at the end or
* beginning of a line.
*/
- prevgp = &term.line[*y][*x];
- prevdelim = ISDELIM(prevgp->u);
for (;;) {
- newx = *x + direction;
- newy = *y;
+ int newx = *x + direction;
+ int newy = *y;
if (!BETWEEN(newx, 0, term.col - 1)) {
+ int xt, yt;
newy += direction;
newx = (newx + term.col) % term.col;
if (!BETWEEN(newy, 0, term.row - 1))
@@ -560,8 +557,8 @@ selsnap(int *x, int *y, int direction)
if (newx >= tlinelen(newy))
break;
- gp = &term.line[newy][newx];
- delim = ISDELIM(gp->u);
+ Glyph *gp = &term.line[newy][newx];
+ int delim = ISDELIM(gp->u);
if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
|| (delim && gp->u != prevgp->u)))
break;
@@ -602,8 +599,7 @@ char *
getsel(void)
{
char *str, *ptr;
- int y, bufsize, lastx, linelen;
- Glyph *gp, *last;
+ int y, bufsize;
if (sel.ob.x == -1)
return NULL;
@@ -613,6 +609,9 @@ getsel(void)
/* append every set & selected glyph to the selection */
for (y = sel.nb.y; y <= sel.ne.y; y++) {
+ int lastx, linelen;
+ Glyph *gp, *last;
+
if ((linelen = tlinelen(y)) == 0) {
*ptr++ = '\n';
continue;
@@ -1142,8 +1141,7 @@ tnewline(int first_col)
void
csiparse(void)
{
- char *p = csiescseq.buf, *np;
- long int v;
+ char *p = csiescseq.buf;
csiescseq.narg = 0;
if (*p == '?') {
@@ -1153,8 +1151,8 @@ csiparse(void)
csiescseq.buf[csiescseq.len] = '\0';
while (p < csiescseq.buf+csiescseq.len) {
- np = NULL;
- v = strtol(p, &np, 10);
+ char *np = NULL;
+ long int v = strtol(p, &np, 10);
if (np == p)
v = 0;
if (v == LONG_MAX || v == LONG_MIN)
@@ -1462,12 +1460,10 @@ tsetattr(int *attr, int l)
void
tsetscroll(int t, int b)
{
- int temp;
-
LIMIT(t, 0, term.row-1);
LIMIT(b, 0, term.row-1);
if (t > b) {
- temp = t;
+ int temp = t;
t = b;
b = temp;
}
@@ -1813,12 +1809,9 @@ csihandle(void)
void
csidump(void)
{
- int i;
- uint c;
-
fprintf(stderr, "ESC[");
- for (i = 0; i < csiescseq.len; i++) {
- c = csiescseq.buf[i] & 0xff;
+ for (int i = 0; i < csiescseq.len; i++) {
+ uint c = csiescseq.buf[i] & 0xff;
if (isprint(c)) {
putc(c, stderr);
} else if (c == '\n') {
@@ -1908,7 +1901,6 @@ strhandle(void)
void
strparse(void)
{
- int c;
char *p = strescseq.buf;
strescseq.narg = 0;
@@ -1918,6 +1910,7 @@ strparse(void)
return;
while (strescseq.narg < STR_ARG_SIZ) {
+ int c;
strescseq.args[strescseq.narg++] = p;
while ((c = *p) != ';' && c != '\0')
++p;
@@ -1930,12 +1923,9 @@ strparse(void)
void
strdump(void)
{
- int i;
- uint c;
-
fprintf(stderr, "ESC%c", strescseq.type);
- for (i = 0; i < strescseq.len; i++) {
- c = strescseq.buf[i] & 0xff;
+ for (int i = 0; i < strescseq.len; i++) {
+ uint c = strescseq.buf[i] & 0xff;
if (c == '\0') {
putc('\n', stderr);
return;
@@ -2009,12 +1999,12 @@ tdumpsel(void)
void
tdumpline(int n)
{
- char buf[UTF_SIZ];
Glyph *bp, *end;
bp = &term.line[n][0];
end = &bp[MIN(tlinelen(n), term.col) - 1];
if (bp != end || bp->u != ' ') {
+ char buf[UTF_SIZ];
for ( ;bp <= end; ++bp)
tprinter(buf, utf8encode(bp->u, buf));
}
@@ -2073,11 +2063,9 @@ tdeftran(char ascii)
void
tdectest(char c)
{
- int x, y;
-
if (c == '8') { /* DEC screen alignment test. */
- for (x = 0; x < term.col; ++x) {
- for (y = 0; y < term.row; ++y)
+ for (int x = 0; x < term.col; ++x) {
+ for (int y = 0; y < term.row; ++y)
tsetchar('E', &term.c.attr, x, y);
}
}
@@ -2475,7 +2463,6 @@ tresize(int col, int row)
int i;
int minrow = MIN(row, term.row);
int mincol = MIN(col, term.col);
- int *bp;
TCursor c;
if (col < 1 || row < 1) {
@@ -2521,7 +2508,7 @@ tresize(int col, int row)
term.alt[i] = xmalloc(col * sizeof(Glyph));
}
if (col > term.col) {
- bp = term.tabs + term.col;
+ int *bp = term.tabs + term.col;
memset(bp, 0, sizeof(*term.tabs) * (col - term.col));
while (--bp > term.tabs && !*bp)
--
2.20.1