Remove one indentation level in getsel().

dev
noname 2014-04-27 15:40:23 +04:00 committed by Roberto E. Vargas Caballero
parent 6681af165b
commit 74962bf566
1 changed files with 48 additions and 49 deletions

97
st.c
View File

@ -922,60 +922,59 @@ getsel(void) {
int x, y, bufsize, size, i, ex; int x, y, bufsize, size, i, ex;
Glyph *gp, *last; Glyph *gp, *last;
if(sel.ob.x == -1) { if(sel.ob.x == -1)
str = NULL; return NULL;
} else {
bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ;
ptr = str = xmalloc(bufsize);
/* append every set & selected glyph to the selection */ bufsize = (term.col+1) * (sel.ne.y-sel.nb.y+1) * UTF_SIZ;
for(y = sel.nb.y; y < sel.ne.y + 1; y++) { ptr = str = xmalloc(bufsize);
gp = &term.line[y][0];
last = &gp[term.col-1];
while(last >= gp && !(selected(last - gp, y) && /* append every set & selected glyph to the selection */
strcmp(last->c, " ") != 0)) { for(y = sel.nb.y; y < sel.ne.y + 1; y++) {
--last; gp = &term.line[y][0];
} last = &gp[term.col-1];
for(x = 0; gp <= last; x++, ++gp) { while(last >= gp && !(selected(last - gp, y) &&
if(!selected(x, y) || (gp->mode & ATTR_WDUMMY)) strcmp(last->c, " ") != 0)) {
continue; --last;
}
size = utf8len(gp->c);
memcpy(ptr, gp->c, size); for(x = 0; gp <= last; x++, ++gp) {
ptr += size; if(!selected(x, y) || (gp->mode & ATTR_WDUMMY))
} continue;
/* size = utf8len(gp->c);
* Copy and pasting of line endings is inconsistent memcpy(ptr, gp->c, size);
* in the inconsistent terminal and GUI world. ptr += size;
* The best solution seems like to produce '\n' when }
* something is copied from st and convert '\n' to
* '\r', when something to be pasted is received by /*
* st. * Copy and pasting of line endings is inconsistent
* FIXME: Fix the computer world. * in the inconsistent terminal and GUI world.
*/ * The best solution seems like to produce '\n' when
if(y < sel.ne.y && x > 0 && !((gp-1)->mode & ATTR_WRAP)) * something is copied from st and convert '\n' to
*ptr++ = '\n'; * '\r', when something to be pasted is received by
* st.
/* * FIXME: Fix the computer world.
* If the last selected line expands in the selection */
* after the visible text '\n' is appended. if(y < sel.ne.y && x > 0 && !((gp-1)->mode & ATTR_WRAP))
*/ *ptr++ = '\n';
if(y == sel.ne.y) {
i = term.col; /*
while(--i > 0 && term.line[y][i].c[0] == ' ') * If the last selected line expands in the selection
/* nothing */; * after the visible text '\n' is appended.
ex = sel.ne.x; */
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x) if(y == sel.ne.y) {
ex = sel.nb.x; i = term.col;
if(i < ex) while(--i > 0 && term.line[y][i].c[0] == ' ')
*ptr++ = '\n'; /* nothing */;
} ex = sel.ne.x;
if(sel.nb.y == sel.ne.y && sel.ne.x < sel.nb.x)
ex = sel.nb.x;
if(i < ex)
*ptr++ = '\n';
} }
*ptr = 0;
} }
*ptr = 0;
return str; return str;
} }