X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=b148401a1693cde21d15566577258ac7d7abb791;hb=93661042a2a0cf6f3655360f5c52215c684a4211;hp=8b65450a38da1430fd95c8c6438a5f98afe6b232;hpb=6fd887077e29efd789499e06193314d7abdcac38;p=st.git diff --git a/st.c b/st.c index 8b65450..b148401 100644 --- a/st.c +++ b/st.c @@ -180,7 +180,6 @@ typedef unsigned short ushort; typedef XftDraw *Draw; typedef XftColor Color; -typedef Colormap Colormap; typedef struct { char c[UTF_SIZ]; /* character code */ @@ -703,6 +702,9 @@ selected(int x, int y) { void selsnap(int mode, int *x, int *y, int direction) { + int newx, newy, xt, yt; + Glyph *gp; + switch(mode) { case SNAP_WORD: /* @@ -710,36 +712,31 @@ selsnap(int mode, int *x, int *y, int direction) { * beginning of a line. */ for(;;) { - if(direction < 0 && *x <= 0) { - if(*y > 0 && term.line[*y - 1][term.col-1].mode - & ATTR_WRAP) { - *y -= 1; - *x = term.col-1; - } else { + newx = *x + direction; + newy = *y; + if(!BETWEEN(newx, 0, term.col - 1)) { + newy += direction; + newx = (newx + term.col) % term.col; + if (!BETWEEN(newy, 0, term.row - 1)) break; - } - } - if(direction > 0 && *x >= term.col-1) { - if(*y < term.row-1 && term.line[*y][*x].mode - & ATTR_WRAP) { - *y += 1; - *x = 0; - } else { + + if(direction > 0) + yt = *y, xt = *x; + else + yt = newy, xt = newx; + if(!(term.line[yt][xt].mode & ATTR_WRAP)) break; - } } - if(term.line[*y][*x+direction].mode & ATTR_WDUMMY) { - *x += direction; - continue; - } + if (newx >= tlinelen(newy)) + break; - if(*x >= tlinelen(*y) || strchr(worddelimiters, - term.line[*y][*x+direction].c[0])) { + gp = &term.line[newy][newx]; + if (!(gp->mode & ATTR_WDUMMY) && strchr(worddelimiters, gp->c[0])) break; - } - *x += direction; + *x = newx; + *y = newy; } break; case SNAP_LINE: @@ -2318,19 +2315,14 @@ techo(char *buf, int len) { void tdeftran(char ascii) { - char c, (*bp)[2]; - static char tbl[][2] = { - {'0', CS_GRAPHIC0}, {'B', CS_USA}, - {0, 0} - }; - - for (bp = &tbl[0]; (c = (*bp)[0]) && c != ascii; ++bp) - /* nothing */; + static char cs[] = "0B"; + static int vcs[] = {CS_GRAPHIC0, CS_USA}; + char *p; - if (c == 0) + if((p = strchr(cs, ascii)) == NULL) fprintf(stderr, "esc unhandled charset: ESC ( %c\n", ascii); else - term.trantbl[term.icharset] = (*bp)[1]; + term.trantbl[term.icharset] = vcs[p - cs]; } void