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 <[email protected]>
* 4: value of shell in /etc/passwd
* 5: value of shell in config.h
*/
* 4: value of shell in /etc/passwd
* 5: value of shell in config.h
*/
-char *shell = "/bin/sh";
+static char *shell = "/bin/sh";
char *utmp = NULL;
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
char *utmp = NULL;
char *stty_args = "stty raw pass8 nl -echo -iexten -cstopb 38400";
int narg; /* nb of args */
} STREscape;
int narg; /* nb of args */
} STREscape;
-
-static void execsh(char **);
+static void execsh(char *, char **);
static void stty(char **);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
static void stty(char **);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
static ssize_t xwrite(int, const char *, size_t);
/* Globals */
static ssize_t xwrite(int, const char *, size_t);
/* Globals */
-int cmdfd;
-pid_t pid;
-int oldbutton = 3; /* button event on startup: 3 = release */
-
static Term term;
static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
static int iofd = 1;
static Term term;
static Selection sel;
static CSIEscape csiescseq;
static STREscape strescseq;
static int iofd = 1;
+static int cmdfd;
+static pid_t pid;
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
static uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0};
static uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8};
+execsh(char *cmd, char **args)
{
char *sh, *prog;
const struct passwd *pw;
{
char *sh, *prog;
const struct passwd *pw;
}
if ((sh = getenv("SHELL")) == NULL)
}
if ((sh = getenv("SHELL")) == NULL)
- sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
+ sh = (pw->pw_shell[0]) ? pw->pw_shell : cmd;
if (args)
prog = args[0];
if (args)
prog = args[0];
perror("Couldn't call stty");
}
perror("Couldn't call stty");
}
-void
-ttynew(char *line, char *out, char **args)
+int
+ttynew(char *line, char *cmd, char *out, char **args)
die("open line failed: %s\n", strerror(errno));
dup2(cmdfd, 0);
stty(args);
die("open line failed: %s\n", strerror(errno));
dup2(cmdfd, 0);
stty(args);
}
/* seems to work fine on linux, openbsd and freebsd */
}
/* seems to work fine on linux, openbsd and freebsd */
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
close(s);
close(m);
break;
default:
close(s);
break;
default:
close(s);
signal(SIGCHLD, sigchld);
break;
}
signal(SIGCHLD, sigchld);
break;
}
fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
}
fprintf(stderr, "Couldn't set window size: %s\n", strerror(errno));
}
+void
+ttyhangup()
+{
+ /* Send SIGHUP to shell */
+ kill(pid, SIGHUP);
+}
+
void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
void tnew(int, int);
void tresize(int, int);
void tsetdirtattr(int);
-void ttynew(char *, char *, char **);
+void ttyhangup(void);
+int ttynew(char *, char *, char *, char **);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
size_t ttyread(void);
void ttyresize(int, int);
void ttywrite(const char *, size_t, int);
void *xrealloc(void *, size_t);
char *xstrdup(char *);
void *xrealloc(void *, size_t);
char *xstrdup(char *);
-/* Globals */
-extern int cmdfd;
-extern pid_t pid;
-extern int oldbutton;
-
extern char *utmp;
extern char *stty_args;
extern char *vtiden;
extern char *utmp;
extern char *stty_args;
extern char *vtiden;
static char *opt_name = NULL;
static char *opt_title = NULL;
static char *opt_name = NULL;
static char *opt_title = NULL;
+static int oldbutton = 3; /* button event on startup: 3 = release */
+
void
clipcopy(const Arg *dummy)
{
void
clipcopy(const Arg *dummy)
{
win.mode &= ~MODE_FOCUSED;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
win.mode &= ~MODE_FOCUSED;
}
} else if (e->xclient.data.l[0] == xw.wmdeletewin) {
- /* Send SIGHUP to shell */
- kill(pid, SIGHUP);
int w = win.w, h = win.h;
fd_set rfd;
int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
int w = win.w, h = win.h;
fd_set rfd;
int xfd = XConnectionNumber(xw.dpy), xev, blinkset = 0, dodraw = 0;
struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
long deltatime;
struct timespec drawtimeout, *tv = NULL, now, last, lastblink;
long deltatime;
}
} while (ev.type != MapNotify);
}
} while (ev.type != MapNotify);
- ttynew(opt_line, opt_io, opt_cmd);
+ ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
cresize(w, h);
clock_gettime(CLOCK_MONOTONIC, &last);
cresize(w, h);
clock_gettime(CLOCK_MONOTONIC, &last);
for (xev = actionfps;;) {
FD_ZERO(&rfd);
for (xev = actionfps;;) {
FD_ZERO(&rfd);
- if (pselect(MAX(xfd, cmdfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
+ if (pselect(MAX(xfd, ttyfd)+1, &rfd, NULL, NULL, tv, NULL) < 0) {
if (errno == EINTR)
continue;
die("select failed: %s\n", strerror(errno));
}
if (errno == EINTR)
continue;
die("select failed: %s\n", strerror(errno));
}
- if (FD_ISSET(cmdfd, &rfd)) {
+ if (FD_ISSET(ttyfd, &rfd)) {
ttyread();
if (blinktimeout) {
blinkset = tattrset(ATTR_BLINK);
ttyread();
if (blinktimeout) {
blinkset = tattrset(ATTR_BLINK);
if (xev && !FD_ISSET(xfd, &rfd))
xev--;
if (xev && !FD_ISSET(xfd, &rfd))
xev--;
- if (!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+ if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
if (blinkset) {
if (TIMEDIFF(now, lastblink) \
> blinktimeout) {
if (blinkset) {
if (TIMEDIFF(now, lastblink) \
> blinktimeout) {