st-externalpipe-20181016-3be4cf1.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-externalpipe-20181016-3be4cf1.diff (1958B)
---
1 From c19e14bef38548e3984a0135f6466f77d56b8d77 Mon Sep 17 00:00:00 2001
2 From: Parker Ellertson <parkerellertson@airmail.cc>
3 Date: Tue, 16 Oct 2018 12:27:29 -0600
4 Subject: [PATCH] Applied externalpipe patch to current git version.
5
6 ---
7 st.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
8 st.h | 1 +
9 2 files changed, 54 insertions(+)
10
11 diff --git a/st.c b/st.c
12 index 46cf2da..2a34f83 100644
13 --- a/st.c
14 +++ b/st.c
15 @@ -1978,6 +1978,59 @@ tprinter(char *s, size_t len)
16 }
17 }
18
19 +void
20 +externalpipe(const Arg *arg)
21 +{
22 + int to[2];
23 + char buf[UTF_SIZ];
24 + void (*oldsigpipe)(int);
25 + Glyph *bp, *end;
26 + int lastpos, n, newline;
27 +
28 + if (pipe(to) == -1)
29 + return;
30 +
31 + switch (fork()) {
32 + case -1:
33 + close(to[0]);
34 + close(to[1]);
35 + return;
36 + case 0:
37 + dup2(to[0], STDIN_FILENO);
38 + close(to[0]);
39 + close(to[1]);
40 + execvp(((char **)arg->v)[0], (char **)arg->v);
41 + fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]);
42 + perror("failed");
43 + exit(0);
44 + }
45 +
46 + close(to[0]);
47 + /* ignore sigpipe for now, in case child exists early */
48 + oldsigpipe = signal(SIGPIPE, SIG_IGN);
49 + newline = 0;
50 + for (n = 0; n < term.row; n++) {
51 + bp = term.line[n];
52 + lastpos = MIN(tlinelen(n) + 1, term.col) - 1;
53 + if (lastpos < 0)
54 + break;
55 + end = &bp[lastpos + 1];
56 + for (; bp < end; ++bp)
57 + if (xwrite(to[1], buf, utf8encode(bp->u, buf)) < 0)
58 + break;
59 + if ((newline = term.line[n][lastpos].mode & ATTR_WRAP))
60 + continue;
61 + if (xwrite(to[1], "\n", 1) < 0)
62 + break;
63 + newline = 0;
64 + }
65 + if (newline)
66 + (void)xwrite(to[1], "\n", 1);
67 + close(to[1]);
68 + /* restore */
69 + signal(SIGPIPE, oldsigpipe);
70 +}
71 +
72 void
73 toggleprinter(const Arg *arg)
74 {
75 diff --git a/st.h b/st.h
76 index 38c61c4..fe56f49 100644
77 --- a/st.h
78 +++ b/st.h
79 @@ -83,6 +83,7 @@ void draw(void);
80 void printscreen(const Arg *);
81 void printsel(const Arg *);
82 void sendbreak(const Arg *);
83 +void externalpipe(const Arg *);
84 void toggleprinter(const Arg *);
85
86 int tattrset(int);
87 --
88 2.19.1
89