aboutsummaryrefslogtreecommitdiff
path: root/st.c
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 /st.c
parenta3beb626d2dae9d4d0883c7c8cb6ba58b0609105 (diff)
downloadst-30683c70ab62fd37b5921cf72077b9aef2cb842e.tar.gz
st-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>
Diffstat (limited to 'st.c')
-rw-r--r--st.c29
1 files changed, 17 insertions, 12 deletions
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{