Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff st/st.c Downloads/st-0.8.1/st.c
- 38d37
- < #define HISTSIZE 2000
- 46,51c45
- < #define ISDELIM(u) (u && wcschr(worddelimiters, u))
- < #define TLINE(y) ((y) < term.scr ? term.hist[((y) + term.histi - \
- < term.scr + HISTSIZE + 1) % HISTSIZE] : \
- < term.line[(y) - term.scr])
- <
- < #define TLINE_HIST(y) ((y) <= HISTSIZE-term.row+2 ? term.hist[(y)] : term.line[(y-HISTSIZE+term.row-3)])
- ---
- > #define ISDELIM(u) (utf8strchr(worddelimiters, u) != NULL)
- 130,132d123
- < Line hist[HISTSIZE]; /* history buffer */
- < int histi; /* history index */
- < int scr; /* scroll back */
- 200,201c191,192
- < static void tscrollup(int, int, int);
- < static void tscrolldown(int, int, int);
- ---
- > static void tscrollup(int, int);
- > static void tscrolldown(int, int);
- 225a217
- > static char *utf8strchr(char *, Rune);
- 267c259
- < void *p;
- ---
- > void *p = malloc(len);
- 269,270c261,262
- < if (!(p = malloc(len)))
- < die("malloc: %s\n", strerror(errno));
- ---
- > if (!p)
- > die("Out of memory\n");
- 279c271
- < die("realloc: %s\n", strerror(errno));
- ---
- > die("Out of memory\n");
- 288c280
- < die("strdup: %s\n", strerror(errno));
- ---
- > die("Out of memory\n");
- 351a344,360
- > char *
- > utf8strchr(char *s, Rune u)
- > {
- > Rune r;
- > size_t i, j, len;
- >
- > len = strlen(s);
- > for (i = 0, j = 0; i < len; i += j) {
- > if (!(j = utf8decode(&s[i], &r, len - i)))
- > break;
- > if (r == u)
- > return &(s[i]);
- > }
- >
- > return NULL;
- > }
- >
- 425c434
- < if (TLINE(y)[i - 1].mode & ATTR_WRAP)
- ---
- > if (term.line[y][i - 1].mode & ATTR_WRAP)
- 428,442c437
- < while (i > 0 && TLINE(y)[i - 1].u == ' ')
- < --i;
- <
- < return i;
- < }
- <
- < int
- < tlinehistlen(int y)
- < {
- < int i = term.col;
- <
- < if (TLINE_HIST(y)[i - 1].mode & ATTR_WRAP)
- < return i;
- <
- < while (i > 0 && TLINE_HIST(y)[i - 1].u == ' ')
- ---
- > while (i > 0 && term.line[y][i - 1].u == ' ')
- 454d448
- < sel.alt = IS_SET(MODE_ALTSCREEN);
- 482a477
- > sel.alt = IS_SET(MODE_ALTSCREEN);
- 488c483
- < if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY)
- ---
- > if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
- 551c546
- < prevgp = &TLINE(*y)[*x];
- ---
- > prevgp = &term.line[*y][*x];
- 566c561
- < if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
- ---
- > if (!(term.line[yt][xt].mode & ATTR_WRAP))
- 573c568
- < gp = &TLINE(newy)[newx];
- ---
- > gp = &term.line[newy][newx];
- 594c589
- < if (!(TLINE(*y-1)[term.col-1].mode
- ---
- > if (!(term.line[*y-1][term.col-1].mode
- 601c596
- < if (!(TLINE(*y)[term.col-1].mode
- ---
- > if (!(term.line[*y][term.col-1].mode
- 632c627
- < gp = &TLINE(y)[sel.nb.x];
- ---
- > gp = &term.line[y][sel.nb.x];
- 635c630
- < gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
- ---
- > gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
- 638c633
- < last = &TLINE(y)[MIN(lastx, linelen-1)];
- ---
- > last = &term.line[y][MIN(lastx, linelen-1)];
- 695c690
- < die("getpwuid: %s\n", strerror(errno));
- ---
- > die("getpwuid:%s\n", strerror(errno));
- 738c733
- < die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
- ---
- > die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
- 743,746c738,739
- < if (WIFEXITED(stat) && WEXITSTATUS(stat))
- < die("child exited with status %d\n", WEXITSTATUS(stat));
- < else if (WIFSIGNALED(stat))
- < die("child terminated due to signal %d\n", WTERMSIG(stat));
- ---
- > if (!WIFEXITED(stat) || WEXITSTATUS(stat))
- > die("child finished with error '%d'\n", stat);
- 791,792c784
- < die("open line '%s' failed: %s\n",
- < line, strerror(errno));
- ---
- > die("open line failed: %s\n", strerror(errno));
- 804c796
- < die("fork failed: %s\n", strerror(errno));
- ---
- > die("fork failed\n");
- 816,819d807
- < #ifdef __OpenBSD__
- < if (pledge("stdio getpw proc exec", NULL) == -1)
- < die("pledge\n");
- < #endif
- 823,826d810
- < #ifdef __OpenBSD__
- < if (pledge("stdio rpath tty proc", NULL) == -1)
- < die("pledge\n");
- < #endif
- 845c829
- < die("couldn't read from shell: %s\n", strerror(errno));
- ---
- > die("Couldn't read from shell: %s\n", strerror(errno));
- 861,863d844
- < Arg arg = (Arg) { .i = term.scr };
- <
- < kscrolldown(&arg);
- 1075,1108c1056
- < kscrolldown(const Arg* a)
- < {
- < int n = a->i;
- <
- < if (n < 0)
- < n = term.row + n;
- <
- < if (n > term.scr)
- < n = term.scr;
- <
- < if (term.scr > 0) {
- < term.scr -= n;
- < selscroll(0, -n);
- < tfulldirt();
- < }
- < }
- <
- < void
- < kscrollup(const Arg* a)
- < {
- < int n = a->i;
- <
- < if (n < 0)
- < n = term.row + n;
- <
- < if (term.scr <= HISTSIZE-n) {
- < term.scr += n;
- < selscroll(0, n);
- < tfulldirt();
- < }
- < }
- <
- < void
- < tscrolldown(int orig, int n, int copyhist)
- ---
- > tscrolldown(int orig, int n)
- 1115,1121d1062
- < if (copyhist) {
- < term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
- < temp = term.hist[term.histi];
- < term.hist[term.histi] = term.line[term.bot];
- < term.line[term.bot] = temp;
- < }
- <
- 1135c1076
- < tscrollup(int orig, int n, int copyhist)
- ---
- > tscrollup(int orig, int n)
- 1142,1151d1082
- < if (copyhist) {
- < term.histi = (term.histi + 1) % HISTSIZE;
- < temp = term.hist[term.histi];
- < term.hist[term.histi] = term.line[orig];
- < term.line[orig] = temp;
- < }
- <
- < if (term.scr > 0 && term.scr < HISTSIZE)
- < term.scr = MIN(term.scr + n, HISTSIZE-1);
- <
- 1200c1131
- < tscrollup(term.top, 1, 1);
- ---
- > tscrollup(term.top, 1);
- 1365c1296
- < tscrolldown(term.c.y, n, 0);
- ---
- > tscrolldown(term.c.y, n);
- 1372c1303
- < tscrollup(term.c.y, n, 0);
- ---
- > tscrollup(term.c.y, n);
- 1519,1520c1450
- < attr[i]);
- < csidump();
- ---
- > attr[i]), csidump();
- 1640d1569
- < break;
- 1803c1732
- < tscrollup(term.top, csiescseq.arg[0], 0);
- ---
- > tscrollup(term.top, csiescseq.arg[0]);
- 1807c1736
- < tscrolldown(term.top, csiescseq.arg[0], 0);
- ---
- > tscrolldown(term.top, csiescseq.arg[0]);
- 1912c1841
- < char *p = NULL, *dec;
- ---
- > char *p = NULL;
- 1929a1859,1860
- > char *dec;
- >
- 1947,1950c1878
- < if (par == 104 && narg <= 1)
- < return; /* color reset without parameter */
- < fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
- < j, p ? p : "(null)");
- ---
- > fprintf(stderr, "erresc: invalid color %s\n", p);
- 2048,2103d1975
- < externalpipe(const Arg *arg)
- < {
- < int to[2];
- < char buf[UTF_SIZ];
- < void (*oldsigpipe)(int);
- < Glyph *bp, *end;
- < int lastpos, n, newline;
- <
- < if (pipe(to) == -1)
- < return;
- <
- < switch (fork()) {
- < case -1:
- < close(to[0]);
- < close(to[1]);
- < return;
- < case 0:
- < dup2(to[0], STDIN_FILENO);
- < close(to[0]);
- < close(to[1]);
- < execvp(((char **)arg->v)[0], (char **)arg->v);
- < fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
- < perror("failed");
- < exit(0);
- < }
- <
- < close(to[0]);
- < /* ignore sigpipe for now, in case child exists early */
- < oldsigpipe = signal(SIGPIPE, SIG_IGN);
- < newline = 0;
- < /* modify externalpipe patch to pipe history too */
- < for (n = 0; n <= HISTSIZE + 2; n++) {
- < bp = TLINE_HIST(n);
- < lastpos = MIN(tlinehistlen(n) +1, term.col) - 1;
- < if (lastpos < 0)
- < break;
- < if (lastpos == 0)
- < continue;
- < end = &bp[lastpos + 1];
- < for (; bp < end; ++bp)
- < if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
- < break;
- < if ((newline = TLINE_HIST(n)[lastpos].mode & ATTR_WRAP))
- < continue;
- < if (xwrite(to[1], "\n", 1) < 0)
- < break;
- < newline = 0;
- < }
- < if (newline)
- < (void)xwrite(to[1], "\n", 1);
- < close(to[1]);
- < /* restore */
- < signal(SIGPIPE, oldsigpipe);
- < }
- <
- < void
- 2388c2260
- < tscrollup(term.top, 1, 1);
- ---
- > tscrollup(term.top, 1);
- 2401c2273
- < tscrolldown(term.top, 1, 1);
- ---
- > tscrolldown(term.top, 1);
- 2409c2281
- < case 'c': /* RIS -- Reset to initial state */
- ---
- > case 'c': /* RIS -- Reset to inital state */
- 2479a2352
- >
- 2619c2492
- < int i, j;
- ---
- > int i;
- 2656,2663d2528
- < for (i = 0; i < HISTSIZE; i++) {
- < term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
- < for (j = mincol; j < col; j++) {
- < term.hist[i][j] = term.c.attr;
- < term.hist[i][j].u = ' ';
- < }
- < }
- <
- 2721c2586
- < xdrawline(TLINE(y), x1, y, x2);
- ---
- > xdrawline(term.line[y], x1, y, x2);
- 2742,2744c2607,2608
- < if (term.scr == 0)
- < xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
- < term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
- ---
- > xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
- > term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
- 2747d2610
- < xximspot(term.ocx, term.ocy);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement