aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2018-02-24 16:16:12 -0600
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:56:26 -0600
commit30683c70ab62fd37b5921cf72077b9aef2cb842e (patch)
treef81bf19a9cf62cd9ac97c4c7e4eab6a4cc131c89
parenta3beb626d2dae9d4d0883c7c8cb6ba58b0609105 (diff)
downloadst-patched-30683c70ab62fd37b5921cf72077b9aef2cb842e.tar.bz2
st-patched-30683c70ab62fd37b5921cf72077b9aef2cb842e.tar.xz
st-patched-30683c70ab62fd37b5921cf72077b9aef2cb842e.zip
Limit usage of extern to config.h globals
Prefer passing arguments to declaring external global variables. The only remaining usage of extern is for config.h variables which are needed in st.c instead of x.c (where it is now included). Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
-rw-r--r--config.def.h2
-rw-r--r--st.c29
-rw-r--r--st.h9
-rw-r--r--x.c16
4 files changed, 29 insertions, 27 deletions
diff --git a/config.def.h b/config.def.h
index 616616a..82b1b09 100644
--- a/config.def.h
+++ b/config.def.h
@@ -16,7 +16,7 @@ static int borderpx = 2;
16 * 4: value of shell in /etc/passwd 16 * 4: value of shell in /etc/passwd
17 * 5: value of shell in config.h 17 * 5: value of shell in config.h
18 */ 18 */
19char *shell = "/bin/sh"; 19static char *shell = "/bin/sh";
20char *utmp = NULL; 20char *utmp = NULL;
21char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400"; 21char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
22 22
diff --git a/st.c b/st.c
index da832ed..ce32cc0 100644
--- a/st.c
+++ b/st.c
@@ -136,8 +136,7 @@ typedef struct {
136 int narg; /* nb of args */ 136 int narg; /* nb of args */
137} STREscape; 137} STREscape;
138 138
139 139static void execsh(char *, char **);
140static void execsh(char **);
141static void stty(char **); 140static void stty(char **);
142static void sigchld(int); 141static void sigchld(int);
143static void ttywriteraw(const char *, size_t); 142static void ttywriteraw(const char *, size_t);
@@ -201,15 +200,13 @@ static char *base64dec(const char *);
201static ssize_t xwrite(int, const char *, size_t); 200static ssize_t xwrite(int, const char *, size_t);
202 201
203/* Globals */ 202/* Globals */
204int cmdfd;
205pid_t pid;
206int oldbutton = 3; /* button event on startup: 3 = release */
207
208static Term term; 203static Term term;
209static Selection sel; 204static Selection sel;
210static CSIEscape csiescseq; 205static CSIEscape csiescseq;
211static STREscape strescseq; 206static STREscape strescseq;
212static int iofd = 1; 207static int iofd = 1;
208static int cmdfd;
209static pid_t pid;
213 210
214static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; 211static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
215static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; 212static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
@@ -659,7 +656,7 @@ die(const char *errstr, ...)
659} 656}
660 657
661void 658void
662execsh(char **args) 659execsh(char *cmd, char **args)
663{ 660{
664 char *sh, *prog; 661 char *sh, *prog;
665 const struct passwd *pw; 662 const struct passwd *pw;
@@ -673,7 +670,7 @@ execsh(char **args)
673 } 670 }
674 671
675 if ((sh = getenv("SHELL")) == NULL) 672 if ((sh = getenv("SHELL")) == NULL)
676 sh = (pw->pw_shell[0]) ? pw->pw_shell : shell; 673 sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
677 674
678 if (args) 675 if (args)
679 prog = args[0]; 676 prog = args[0];
@@ -745,8 +742,8 @@ stty(char **args)
745 perror("Couldn't call stty"); 742 perror("Couldn't call stty");
746} 743}
747 744
748void 745int
749ttynew(char *line, char *out, char **args) 746ttynew(char *line, char *cmd, char *out, char **args)
750{ 747{
751 int m, s; 748 int m, s;
752 749
@@ -765,7 +762,7 @@ ttynew(char *line, char *out, char **args)
765 die("open line failed: %s\n", strerror(errno)); 762 die("open line failed: %s\n", strerror(errno));
766 dup2(cmdfd, 0); 763 dup2(cmdfd, 0);
767 stty(args); 764 stty(args);
768 return; 765 return cmdfd;
769 } 766 }
770 767
771 /* seems to work fine on linux, openbsd and freebsd */ 768 /* seems to work fine on linux, openbsd and freebsd */
@@ -786,7 +783,7 @@ ttynew(char *line, char *out, char **args)
786 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); 783 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
787 close(s); 784 close(s);
788 close(m); 785 close(m);
789 execsh(args); 786 execsh(cmd, args);
790 break; 787 break;
791 default: 788 default:
792 close(s); 789 close(s);
@@ -794,6 +791,7 @@ ttynew(char *line, char *out, char **args)
794 signal(SIGCHLD, sigchld); 791 signal(SIGCHLD, sigchld);
795 break; 792 break;
796 } 793 }
794 return cmdfd;
797} 795}
798 796
799size_t 797size_t
@@ -916,6 +914,13 @@ ttyresize(int tw, int th)
916 fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno)); 914 fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
917} 915}
918 916
917void
918ttyhangup()
919{
920 /* Send SIGHUP to shell */
921 kill(pid, SIGHUP);
922}
923
919int 924int
920tattrset(int attr) 925tattrset(int attr)
921{ 926{
diff --git a/st.h b/st.h
index b5bc1b5..0a7472b 100644
--- a/st.h
+++ b/st.h
@@ -125,7 +125,8 @@ int tattrset(int);
125void tnew(int, int); 125void tnew(int, int);
126void tresize(int, int); 126void tresize(int, int);
127void tsetdirtattr(int); 127void tsetdirtattr(int);
128void ttynew(char *, char *, char **); 128void ttyhangup(void);
129int ttynew(char *, char *, char *, char **);
129size_t ttyread(void); 130size_t ttyread(void);
130void ttyresize(int, int); 131void ttyresize(int, int);
131void ttywrite(const char *, size_t, int); 132void ttywrite(const char *, size_t, int);
@@ -147,13 +148,7 @@ void *xmalloc(size_t);
147void *xrealloc(void *, size_t); 148void *xrealloc(void *, size_t);
148char *xstrdup(char *); 149char *xstrdup(char *);
149 150
150/* Globals */
151extern int cmdfd;
152extern pid_t pid;
153extern int oldbutton;
154
155/* config.h globals */ 151/* config.h globals */
156extern char *shell;
157extern char *utmp; 152extern char *utmp;
158extern char *stty_args; 153extern char *stty_args;
159extern char *vtiden; 154extern char *vtiden;
diff --git a/x.c b/x.c
index 873ff08..970d6dd 100644
--- a/x.c
+++ b/x.c
@@ -227,6 +227,8 @@ static char *opt_line = NULL;
227static char *opt_name = NULL; 227static char *opt_name = NULL;
228static char *opt_title = NULL; 228static char *opt_title = NULL;
229 229
230static int oldbutton = 3; /* button event on startup: 3 = release */
231
230void 232void
231clipcopy(const Arg *dummy) 233clipcopy(const Arg *dummy)
232{ 234{
@@ -1733,8 +1735,7 @@ cmessage(XEvent *e)
1733 win.mode &= ~MODE_FOCUSED; 1735 win.mode &= ~MODE_FOCUSED;
1734 } 1736 }
1735 } else if (e->xclient.data.l[0] == xw.wmdeletewin) { 1737 } else if (e->xclient.data.l[0] == xw.wmdeletewin) {
1736 /* Send SIGHUP to shell */ 1738 ttyhangup();
1737 kill(pid, SIGHUP);
1738 exit(0); 1739 exit(0);
1739 } 1740 }
1740} 1741}
@@ -1755,6 +1756,7 @@ run(void)
1755 int w = win.w, h = win.h; 1756 int w = win.w, h = win.h;
1756 fd_set rfd; 1757 fd_set rfd;
1757 int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0; 1758 int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
1759 int ttyfd;
1758 struct timespec drawtimeout, *tv = NULL, now, last, lastblink; 1760 struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
1759 long deltatime; 1761 long deltatime;
1760 1762
@@ -1774,7 +1776,7 @@ run(void)
1774 } 1776 }
1775 } while (ev.type != MapNotify); 1777 } while (ev.type != MapNotify);
1776 1778
1777 ttynew(opt_line, opt_io, opt_cmd); 1779 ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
1778 cresize(w, h); 1780 cresize(w, h);
1779 1781
1780 clock_gettime(CLOCK_MONOTONIC, &last); 1782 clock_gettime(CLOCK_MONOTONIC, &last);
@@ -1782,15 +1784,15 @@ run(void)
1782 1784
1783 for (xev = actionfps;;) { 1785 for (xev = actionfps;;) {
1784 FD_ZERO(&rfd); 1786 FD_ZERO(&rfd);
1785 FD_SET(cmdfd, &rfd); 1787 FD_SET(ttyfd, &rfd);
1786 FD_SET(xfd, &rfd); 1788 FD_SET(xfd, &rfd);
1787 1789
1788 if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) { 1790 if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
1789 if (errno == EINTR) 1791 if (errno == EINTR)
1790 continue; 1792 continue;
1791 die("select failed: %s\n", strerror(errno)); 1793 die("select failed: %s\n", strerror(errno));
1792 } 1794 }
1793 if (FD_ISSET(cmdfd, &rfd)) { 1795 if (FD_ISSET(ttyfd, &rfd)) {
1794 ttyread(); 1796 ttyread();
1795 if (blinktimeout) { 1797 if (blinktimeout) {
1796 blinkset = tattrset(ATTR_BLINK); 1798 blinkset = tattrset(ATTR_BLINK);
@@ -1834,7 +1836,7 @@ run(void)
1834 1836
1835 if (xev && !FD_ISSET(xfd, &rfd)) 1837 if (xev && !FD_ISSET(xfd, &rfd))
1836 xev--; 1838 xev--;
1837 if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) { 1839 if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
1838 if (blinkset) { 1840 if (blinkset) {
1839 if (TIMEDIFF(now, lastblink) \ 1841 if (TIMEDIFF(now, lastblink) \
1840 > blinktimeout) { 1842 > blinktimeout) {