X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=st.c;h=0923cec886d30e4e6de4c3826a94f799a01e7e42;hb=55adf0aad1d5acf0b9a00e2a9f834cef8b61b3b3;hp=7ddce0cb5104ba2bce3a7aa5d298273d542f995b;hpb=7cb0d95509d1b2837e4fa7d131f497800b20d22c;p=st.git diff --git a/st.c b/st.c index 7ddce0c..0923cec 100644 --- a/st.c +++ b/st.c @@ -1,5 +1,4 @@ /* See LICENSE for licence details. */ -#define _XOPEN_SOURCE 600 #include #include #include @@ -796,7 +795,7 @@ selcopy(void) { } /* \n at the end of every selected line except for the last one */ if(is_selected && y < sel.e.y) - *ptr++ = '\n'; + *ptr++ = '\r'; } *ptr = 0; } @@ -1295,7 +1294,6 @@ tnewline(int first_col) { void csiparse(void) { - /* int noarg = 1; */ char *p = csiescseq.buf, *np; long int v; @@ -1305,24 +1303,21 @@ csiparse(void) { p++; } + csiescseq.buf[csiescseq.len] = '\0'; while(p < csiescseq.buf+csiescseq.len) { np = NULL; v = strtol(p, &np, 10); + if(np == p) + v = 0; if(v == LONG_MAX || v == LONG_MIN) v = -1; - csiescseq.arg[csiescseq.narg] = v; - if(np != NULL) - p = np; - - if(*p == ';' && csiescseq.narg+1 < ESC_ARG_SIZ) { - csiescseq.narg++, p++; - } else { - csiescseq.mode = *p; - csiescseq.narg++; - - return; - } + csiescseq.arg[csiescseq.narg++] = v; + p = np; + if(*p != ';' || csiescseq.narg == ESC_ARG_SIZ) + break; + p++; } + csiescseq.mode = *p; } /* for absolute user moves, when decom is set */ @@ -1930,17 +1925,12 @@ strhandle(void) { void strparse(void) { - char *p = strescseq.buf, *np, *sp; + char *p = strescseq.buf; strescseq.narg = 0; - np = strtok_r(strescseq.buf, ";", &sp); - while(p < strescseq.buf+strescseq.len && np != NULL) { - strescseq.args[strescseq.narg++] = p; - - np = strtok_r(NULL, ";", &sp); - if(np != NULL) - p = np; - } + strescseq.buf[strescseq.len] = '\0'; + while(p && strescseq.narg < STR_ARG_SIZ) + strescseq.args[strescseq.narg++] = strsep(&p, ";"); } void @@ -1951,7 +1941,9 @@ strdump(void) { printf("ESC%c", strescseq.type); for(i = 0; i < strescseq.len; i++) { c = strescseq.buf[i] & 0xff; - if(isprint(c)) { + if(c == '\0') { + return; + } else if(isprint(c)) { putchar(c); } else if(c == '\n') { printf("(\\n)"); @@ -2039,7 +2031,7 @@ tputc(char *c, int len) { strhandle(); break; default: - if(strescseq.len + len < sizeof(strescseq.buf)) { + if(strescseq.len + len < sizeof(strescseq.buf) - 1) { memmove(&strescseq.buf[strescseq.len], c, len); strescseq.len += len; } else { @@ -2115,7 +2107,8 @@ tputc(char *c, int len) { if(term.esc & ESC_CSI) { csiescseq.buf[csiescseq.len++] = ascii; if(BETWEEN(ascii, 0x40, 0x7E) - || csiescseq.len >= ESC_BUF_SIZ) { + || csiescseq.len >= \ + sizeof(csiescseq.buf)-1) { term.esc = 0; csiparse(); csihandle(); @@ -2500,7 +2493,7 @@ xloadfont(Font *f, FcPattern *pattern) { f->lbearing = 0; f->rbearing = f->match->max_advance_width; - f->height = f->match->height; + f->height = f->ascent + f->descent; f->width = f->lbearing + f->rbearing; return 0;