SHARE
TWEET

Untitled

a guest Jun 27th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff st/st.c Downloads/st-0.8.1/st.c
  2.  
  3. 38d37
  4. < #define HISTSIZE      2000
  5. 46,51c45
  6. < #define ISDELIM(u)        (u && wcschr(worddelimiters, u))
  7. < #define TLINE(y)      ((y) < term.scr ? term.hist[((y) + term.histi - \
  8. <               term.scr + HISTSIZE + 1) % HISTSIZE] : \
  9. <               term.line[(y) - term.scr])
  10. <
  11. < #define TLINE_HIST(y)           ((y) <= HISTSIZE-term.row+2 ? term.hist[(y)] : term.line[(y-HISTSIZE+term.row-3)])
  12. ---
  13. > #define ISDELIM(u)        (utf8strchr(worddelimiters, u) != NULL)
  14. 130,132d123
  15. <   Line hist[HISTSIZE]; /* history buffer */
  16. <   int histi;    /* history index */
  17. <   int scr;      /* scroll back */
  18. 200,201c191,192
  19. < static void tscrollup(int, int, int);
  20. < static void tscrolldown(int, int, int);
  21. ---
  22. > static void tscrollup(int, int);
  23. > static void tscrolldown(int, int);
  24. 225a217
  25. > static char *utf8strchr(char *, Rune);
  26. 267c259
  27. <   void *p;
  28. ---
  29. >   void *p = malloc(len);
  30. 269,270c261,262
  31. <   if (!(p = malloc(len)))
  32. <       die("malloc: %s\n", strerror(errno));
  33. ---
  34. >   if (!p)
  35. >       die("Out of memory\n");
  36. 279c271
  37. <       die("realloc: %s\n", strerror(errno));
  38. ---
  39. >       die("Out of memory\n");
  40. 288c280
  41. <       die("strdup: %s\n", strerror(errno));
  42. ---
  43. >       die("Out of memory\n");
  44. 351a344,360
  45. > char *
  46. > utf8strchr(char *s, Rune u)
  47. > {
  48. >   Rune r;
  49. >   size_t i, j, len;
  50. >
  51. >   len = strlen(s);
  52. >   for (i = 0, j = 0; i < len; i += j) {
  53. >       if (!(j = utf8decode(&s[i], &r, len - i)))
  54. >           break;
  55. >       if (r == u)
  56. >           return &(s[i]);
  57. >   }
  58. >
  59. >   return NULL;
  60. > }
  61. >
  62. 425c434
  63. <   if (TLINE(y)[i - 1].mode & ATTR_WRAP)
  64. ---
  65. >   if (term.line[y][i - 1].mode & ATTR_WRAP)
  66. 428,442c437
  67. <   while (i > 0 && TLINE(y)[i - 1].u == ' ')
  68. <       --i;
  69. <
  70. <   return i;
  71. < }
  72. <
  73. < int
  74. < tlinehistlen(int y)
  75. < {
  76. <   int i = term.col;
  77. <
  78. <   if (TLINE_HIST(y)[i - 1].mode & ATTR_WRAP)
  79. <       return i;
  80. <
  81. <   while (i > 0 && TLINE_HIST(y)[i - 1].u == ' ')
  82. ---
  83. >   while (i > 0 && term.line[y][i - 1].u == ' ')
  84. 454d448
  85. <   sel.alt = IS_SET(MODE_ALTSCREEN);
  86. 482a477
  87. >   sel.alt = IS_SET(MODE_ALTSCREEN);
  88. 488c483
  89. <   if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type || sel.mode == SEL_EMPTY)
  90. ---
  91. >   if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
  92. 551c546
  93. <       prevgp = &TLINE(*y)[*x];
  94. ---
  95. >       prevgp = &term.line[*y][*x];
  96. 566c561
  97. <               if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
  98. ---
  99. >               if (!(term.line[yt][xt].mode & ATTR_WRAP))
  100. 573c568
  101. <           gp = &TLINE(newy)[newx];
  102. ---
  103. >           gp = &term.line[newy][newx];
  104. 594c589
  105. <               if (!(TLINE(*y-1)[term.col-1].mode
  106. ---
  107. >               if (!(term.line[*y-1][term.col-1].mode
  108. 601c596
  109. <               if (!(TLINE(*y)[term.col-1].mode
  110. ---
  111. >               if (!(term.line[*y][term.col-1].mode
  112. 632c627
  113. <           gp = &TLINE(y)[sel.nb.x];
  114. ---
  115. >           gp = &term.line[y][sel.nb.x];
  116. 635c630
  117. <           gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
  118. ---
  119. >           gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
  120. 638c633
  121. <       last = &TLINE(y)[MIN(lastx, linelen-1)];
  122. ---
  123. >       last = &term.line[y][MIN(lastx, linelen-1)];
  124. 695c690
  125. <           die("getpwuid: %s\n", strerror(errno));
  126. ---
  127. >           die("getpwuid:%s\n", strerror(errno));
  128. 738c733
  129. <       die("waiting for pid %hd failed: %s\n", pid, strerror(errno));
  130. ---
  131. >       die("Waiting for pid %hd failed: %s\n", pid, strerror(errno));
  132. 743,746c738,739
  133. <   if (WIFEXITED(stat) && WEXITSTATUS(stat))
  134. <       die("child exited with status %d\n", WEXITSTATUS(stat));
  135. <   else if (WIFSIGNALED(stat))
  136. <       die("child terminated due to signal %d\n", WTERMSIG(stat));
  137. ---
  138. >   if (!WIFEXITED(stat) || WEXITSTATUS(stat))
  139. >       die("child finished with error '%d'\n", stat);
  140. 791,792c784
  141. <           die("open line '%s' failed: %s\n",
  142. <               line, strerror(errno));
  143. ---
  144. >           die("open line failed: %s\n", strerror(errno));
  145. 804c796
  146. <       die("fork failed: %s\n", strerror(errno));
  147. ---
  148. >       die("fork failed\n");
  149. 816,819d807
  150. < #ifdef __OpenBSD__
  151. <       if (pledge("stdio getpw proc exec", NULL) == -1)
  152. <           die("pledge\n");
  153. < #endif
  154. 823,826d810
  155. < #ifdef __OpenBSD__
  156. <       if (pledge("stdio rpath tty proc", NULL) == -1)
  157. <           die("pledge\n");
  158. < #endif
  159. 845c829
  160. <       die("couldn't read from shell: %s\n", strerror(errno));
  161. ---
  162. >       die("Couldn't read from shell: %s\n", strerror(errno));
  163. 861,863d844
  164. <   Arg arg = (Arg) { .i = term.scr };
  165. <
  166. <   kscrolldown(&arg);
  167. 1075,1108c1056
  168. < kscrolldown(const Arg* a)
  169. < {
  170. <   int n = a->i;
  171. <
  172. <   if (n < 0)
  173. <       n = term.row + n;
  174. <
  175. <   if (n > term.scr)
  176. <       n = term.scr;
  177. <
  178. <   if (term.scr > 0) {
  179. <       term.scr -= n;
  180. <       selscroll(0, -n);
  181. <       tfulldirt();
  182. <   }
  183. < }
  184. <
  185. < void
  186. < kscrollup(const Arg* a)
  187. < {
  188. <   int n = a->i;
  189. <
  190. <   if (n < 0)
  191. <       n = term.row + n;
  192. <
  193. <   if (term.scr <= HISTSIZE-n) {
  194. <       term.scr += n;
  195. <       selscroll(0, n);
  196. <       tfulldirt();
  197. <   }
  198. < }
  199. <
  200. < void
  201. < tscrolldown(int orig, int n, int copyhist)
  202. ---
  203. > tscrolldown(int orig, int n)
  204. 1115,1121d1062
  205. <   if (copyhist) {
  206. <       term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
  207. <       temp = term.hist[term.histi];
  208. <       term.hist[term.histi] = term.line[term.bot];
  209. <       term.line[term.bot] = temp;
  210. <   }
  211. <
  212. 1135c1076
  213. < tscrollup(int orig, int n, int copyhist)
  214. ---
  215. > tscrollup(int orig, int n)
  216. 1142,1151d1082
  217. <   if (copyhist) {
  218. <       term.histi = (term.histi + 1) % HISTSIZE;
  219. <       temp = term.hist[term.histi];
  220. <       term.hist[term.histi] = term.line[orig];
  221. <       term.line[orig] = temp;
  222. <   }
  223. <
  224. <   if (term.scr > 0 && term.scr < HISTSIZE)
  225. <       term.scr = MIN(term.scr + n, HISTSIZE-1);
  226. <
  227. 1200c1131
  228. <       tscrollup(term.top, 1, 1);
  229. ---
  230. >       tscrollup(term.top, 1);
  231. 1365c1296
  232. <       tscrolldown(term.c.y, n, 0);
  233. ---
  234. >       tscrolldown(term.c.y, n);
  235. 1372c1303
  236. <       tscrollup(term.c.y, n, 0);
  237. ---
  238. >       tscrollup(term.c.y, n);
  239. 1519,1520c1450
  240. <                   attr[i]);
  241. <               csidump();
  242. ---
  243. >                   attr[i]), csidump();
  244. 1640d1569
  245. <               break;
  246. 1803c1732
  247. <       tscrollup(term.top, csiescseq.arg[0], 0);
  248. ---
  249. >       tscrollup(term.top, csiescseq.arg[0]);
  250. 1807c1736
  251. <       tscrolldown(term.top, csiescseq.arg[0], 0);
  252. ---
  253. >       tscrolldown(term.top, csiescseq.arg[0]);
  254. 1912c1841
  255. <   char *p = NULL, *dec;
  256. ---
  257. >   char *p = NULL;
  258. 1929a1859,1860
  259. >               char *dec;
  260. >
  261. 1947,1950c1878
  262. <               if (par == 104 && narg <= 1)
  263. <                   return; /* color reset without parameter */
  264. <               fprintf(stderr, "erresc: invalid color j=%d, p=%s\n",
  265. <                   j, p ? p : "(null)");
  266. ---
  267. >               fprintf(stderr, "erresc: invalid color %s\n", p);
  268. 2048,2103d1975
  269. < externalpipe(const Arg *arg)
  270. < {
  271. <   int to[2];
  272. <   char buf[UTF_SIZ];
  273. <   void (*oldsigpipe)(int);
  274. <   Glyph *bp, *end;
  275. <   int lastpos, n, newline;
  276. <
  277. <   if (pipe(to) == -1)
  278. <       return;
  279. <
  280. <   switch (fork()) {
  281. <   case -1:
  282. <       close(to[0]);
  283. <       close(to[1]);
  284. <       return;
  285. <   case 0:
  286. <       dup2(to[0], STDIN_FILENO);
  287. <       close(to[0]);
  288. <       close(to[1]);
  289. <       execvp(((char **)arg->v)[0], (char **)arg->v);
  290. <       fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
  291. <       perror("failed");
  292. <       exit(0);
  293. <   }
  294. <
  295. <   close(to[0]);
  296. <   /* ignore sigpipe for now, in case child exists early */
  297. <   oldsigpipe = signal(SIGPIPE, SIG_IGN);
  298. <   newline = 0;
  299. <   /* modify externalpipe patch to pipe history too      */
  300. <   for (n = 0; n <= HISTSIZE + 2; n++) {
  301. <       bp = TLINE_HIST(n);
  302. <       lastpos = MIN(tlinehistlen(n) +1, term.col) - 1;
  303. <       if (lastpos < 0)
  304. <           break;
  305. <       if (lastpos == 0)
  306. <           continue;
  307. <       end = &bp[lastpos + 1];
  308. <       for (; bp < end; ++bp)
  309. <           if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
  310. <               break;
  311. <       if ((newline = TLINE_HIST(n)[lastpos].mode & ATTR_WRAP))
  312. <           continue;
  313. <       if (xwrite(to[1], "\n", 1) < 0)
  314. <           break;
  315. <       newline = 0;
  316. <   }
  317. <   if (newline)
  318. <       (void)xwrite(to[1], "\n", 1);
  319. <   close(to[1]);
  320. <   /* restore */
  321. <   signal(SIGPIPE, oldsigpipe);
  322. < }
  323. <
  324. < void
  325. 2388c2260
  326. <           tscrollup(term.top, 1, 1);
  327. ---
  328. >           tscrollup(term.top, 1);
  329. 2401c2273
  330. <           tscrolldown(term.top, 1, 1);
  331. ---
  332. >           tscrolldown(term.top, 1);
  333. 2409c2281
  334. <   case 'c': /* RIS -- Reset to initial state */
  335. ---
  336. >   case 'c': /* RIS -- Reset to inital state */
  337. 2479a2352
  338. >
  339. 2619c2492
  340. <   int i, j;
  341. ---
  342. >   int i;
  343. 2656,2663d2528
  344. <   for (i = 0; i < HISTSIZE; i++) {
  345. <       term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
  346. <       for (j = mincol; j < col; j++) {
  347. <           term.hist[i][j] = term.c.attr;
  348. <           term.hist[i][j].u = ' ';
  349. <       }
  350. <   }
  351. <
  352. 2721c2586
  353. <       xdrawline(TLINE(y), x1, y, x2);
  354. ---
  355. >       xdrawline(term.line[y], x1, y, x2);
  356. 2742,2744c2607,2608
  357. <   if (term.scr == 0)
  358. <       xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
  359. <               term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
  360. ---
  361. >   xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
  362. >           term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
  363. 2747d2610
  364. <   xximspot(term.ocx, term.ocy);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top