st-externalpipe-0.7.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-externalpipe-0.7.diff (2228B)
---
1 diff --git a/st.c b/st.c
2 index 2594c65..ecd9bdc 100644
3 --- a/st.c
4 +++ b/st.c
5 @@ -329,6 +329,7 @@ static void clipcopy(const Arg *);
6 static void clippaste(const Arg *);
7 static void numlock(const Arg *);
8 static void selpaste(const Arg *);
9 +static void externalpipe(const Arg *);
10 static void xzoom(const Arg *);
11 static void xzoomabs(const Arg *);
12 static void xzoomreset(const Arg *);
13 @@ -337,6 +338,9 @@ static void printscreen(const Arg *) ;
14 static void toggleprinter(const Arg *);
15 static void sendbreak(const Arg *);
16
17 +/* variables used in config.h */
18 +static char winid[64];
19 +
20 /* Config.h for applying patches and the configuration. */
21 #include "config.h"
22
23 @@ -2922,6 +2926,59 @@ eschandle(uchar ascii)
24 }
25
26 void
27 +externalpipe(const Arg *arg)
28 +{
29 + int to[2];
30 + char buf[UTF_SIZ];
31 + void (*oldsigpipe)(int);
32 + Glyph *bp, *end;
33 + int lastpos, n, newline;
34 +
35 + if (pipe(to) == -1)
36 + return;
37 +
38 + switch (fork()) {
39 + case -1:
40 + close(to[0]);
41 + close(to[1]);
42 + return;
43 + case 0:
44 + dup2(to[0], STDIN_FILENO);
45 + close(to[0]);
46 + close(to[1]);
47 + execvp(((char **)arg->v)[0], (char **)arg->v);
48 + fprintf(stderr, "st: execvp %s ", ((char **)arg->v)[0]);
49 + perror("failed");
50 + exit(0);
51 + }
52 +
53 + close(to[0]);
54 + /* ignore sigpipe for now, in case child exits early */
55 + oldsigpipe = signal(SIGPIPE, SIG_IGN);
56 + newline = 0;
57 + for (n = 0; n < term.row; n++) {
58 + bp = term.line[n];
59 + lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
60 + if (lastpos < 0)
61 + break;
62 + end = &bp[lastpos + 1];
63 + for (; bp < end; ++bp)
64 + if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
65 + break;
66 + if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
67 + continue;
68 + if (xwrite(to[1], "\n", 1) < 0)
69 + break;
70 + newline = 0;
71 + }
72 + if (newline)
73 + (void)xwrite(to[1], "\n", 1);
74 + close(to[1]);
75 + /* restore */
76 + signal(SIGPIPE, oldsigpipe);
77 +}
78 +
79 +void
80 tputc(Rune u)
81 {
82 char c[UTF_SIZ];
83 @@ -3479,6 +3536,7 @@ xinit(void)
84 xw.w, xw.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
85 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
86 | CWEventMask | CWColormap, &xw.attrs);
87 + snprintf(winid, LEN(winid), "%lu", (unsigned long)xw.win);
88
89 memset(&gcvalues, 0, sizeof(gcvalues));
90 gcvalues.graphics_exposures = False;