aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2017-10-12 22:25:49 -0500
committerDevin J. Pohly <djpohly@gmail.com>2018-02-25 21:53:24 -0600
commit69e32a61df15787c410a48eaa10a89240c36257d (patch)
treea8de7f88f5d712df627e9c0302ce7e77f2f208c2
parented132e11271d18a5d8aa163096bc6192c694bc47 (diff)
downloadst-patched-69e32a61df15787c410a48eaa10a89240c36257d.tar.bz2
st-patched-69e32a61df15787c410a48eaa10a89240c36257d.tar.xz
st-patched-69e32a61df15787c410a48eaa10a89240c36257d.zip
Move opt_* into same file as main()/run()
This commit is purely about reducing externs and LOC. If the main and run functions ever move elsewhere (which will probably make sense eventually), these should come along with them. Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
-rw-r--r--st.c50
-rw-r--r--st.h11
-rw-r--r--x.c12
3 files changed, 33 insertions, 40 deletions
diff --git a/st.c b/st.c
index 1a8fa1f..58f7941 100644
--- a/st.c
+++ b/st.c
@@ -48,7 +48,6 @@
48 48
49/* macros */ 49/* macros */
50#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) 50#define NUMMAXLEN(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1)
51#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
52#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177') 51#define ISCONTROLC0(c) (BETWEEN(c, 0, 0x1f) || (c) == '\177')
53#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) 52#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
54#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) 53#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
@@ -124,8 +123,8 @@ static void sendbreak(const Arg *);
124/* config.h for applying patches and the configuration. */ 123/* config.h for applying patches and the configuration. */
125#include "config.h" 124#include "config.h"
126 125
127static void execsh(void); 126static void execsh(char **);
128static void stty(void); 127static void stty(char **);
129static void sigchld(int); 128static void sigchld(int);
130 129
131static void csidump(void); 130static void csidump(void);
@@ -189,14 +188,6 @@ Term term;
189Selection sel; 188Selection sel;
190int cmdfd; 189int cmdfd;
191pid_t pid; 190pid_t pid;
192char **opt_cmd = NULL;
193char *opt_class = NULL;
194char *opt_embed = NULL;
195char *opt_font = NULL;
196char *opt_io = NULL;
197char *opt_line = NULL;
198char *opt_name = NULL;
199char *opt_title = NULL;
200int oldbutton = 3; /* button event on startup: 3 = release */ 191int oldbutton = 3; /* button event on startup: 3 = release */
201 192
202static CSIEscape csiescseq; 193static CSIEscape csiescseq;
@@ -634,9 +625,9 @@ die(const char *errstr, ...)
634} 625}
635 626
636void 627void
637execsh(void) 628execsh(char **args)
638{ 629{
639 char **args, *sh, *prog; 630 char *sh, *prog;
640 const struct passwd *pw; 631 const struct passwd *pw;
641 632
642 errno = 0; 633 errno = 0;
@@ -650,13 +641,13 @@ execsh(void)
650 if ((sh = getenv("SHELL")) == NULL) 641 if ((sh = getenv("SHELL")) == NULL)
651 sh = (pw->pw_shell[0]) ? pw->pw_shell : shell; 642 sh = (pw->pw_shell[0]) ? pw->pw_shell : shell;
652 643
653 if (opt_cmd) 644 if (args)
654 prog = opt_cmd[0]; 645 prog = args[0];
655 else if (utmp) 646 else if (utmp)
656 prog = utmp; 647 prog = utmp;
657 else 648 else
658 prog = sh; 649 prog = sh;
659 args = (opt_cmd) ? opt_cmd : (char *[]) {prog, NULL}; 650 DEFAULT(args, ((char *[]) {prog, NULL}));
660 651
661 unsetenv("COLUMNS"); 652 unsetenv("COLUMNS");
662 unsetenv("LINES"); 653 unsetenv("LINES");
@@ -697,7 +688,7 @@ sigchld(int a)
697 688
698 689
699void 690void
700stty(void) 691stty(char **args)
701{ 692{
702 char cmd[_POSIX_ARG_MAX], **p, *q, *s; 693 char cmd[_POSIX_ARG_MAX], **p, *q, *s;
703 size_t n, siz; 694 size_t n, siz;
@@ -707,7 +698,7 @@ stty(void)
707 memcpy(cmd, stty_args, n); 698 memcpy(cmd, stty_args, n);
708 q = cmd + n; 699 q = cmd + n;
709 siz = sizeof(cmd) - n; 700 siz = sizeof(cmd) - n;
710 for (p = opt_cmd; p && (s = *p); ++p) { 701 for (p = args; p && (s = *p); ++p) {
711 if ((n = strlen(s)) > siz-1) 702 if ((n = strlen(s)) > siz-1)
712 die("stty parameter length too long\n"); 703 die("stty parameter length too long\n");
713 *q++ = ' '; 704 *q++ = ' ';
@@ -721,26 +712,26 @@ stty(void)
721} 712}
722 713
723void 714void
724ttynew(void) 715ttynew(char *line, char *out, char **args)
725{ 716{
726 int m, s; 717 int m, s;
727 struct winsize w = {term.row, term.col, 0, 0}; 718 struct winsize w = {term.row, term.col, 0, 0};
728 719
729 if (opt_io) { 720 if (out) {
730 term.mode |= MODE_PRINT; 721 term.mode |= MODE_PRINT;
731 iofd = (!strcmp(opt_io, "-")) ? 722 iofd = (!strcmp(out, "-")) ?
732 1 : open(opt_io, O_WRONLY | O_CREAT, 0666); 723 1 : open(out, O_WRONLY | O_CREAT, 0666);
733 if (iofd < 0) { 724 if (iofd < 0) {
734 fprintf(stderr, "Error opening %s:%s\n", 725 fprintf(stderr, "Error opening %s:%s\n",
735 opt_io, strerror(errno)); 726 out, strerror(errno));
736 } 727 }
737 } 728 }
738 729
739 if (opt_line) { 730 if (line) {
740 if ((cmdfd = open(opt_line, O_RDWR)) < 0) 731 if ((cmdfd = open(line, O_RDWR)) < 0)
741 die("open line failed: %s\n", strerror(errno)); 732 die("open line failed: %s\n", strerror(errno));
742 dup2(cmdfd, 0); 733 dup2(cmdfd, 0);
743 stty(); 734 stty(args);
744 return; 735 return;
745 } 736 }
746 737
@@ -762,7 +753,7 @@ ttynew(void)
762 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); 753 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
763 close(s); 754 close(s);
764 close(m); 755 close(m);
765 execsh(); 756 execsh(args);
766 break; 757 break;
767 default: 758 default:
768 close(s); 759 close(s);
@@ -1942,8 +1933,7 @@ void
1942tprinter(char *s, size_t len) 1933tprinter(char *s, size_t len)
1943{ 1934{
1944 if (iofd != -1 && xwrite(iofd, s, len) < 0) { 1935 if (iofd != -1 && xwrite(iofd, s, len) < 0) {
1945 fprintf(stderr, "Error writing in %s:%s\n", 1936 perror("Error writing to output file");
1946 opt_io, strerror(errno));
1947 close(iofd); 1937 close(iofd);
1948 iofd = -1; 1938 iofd = -1;
1949 } 1939 }
@@ -2532,7 +2522,7 @@ tresize(int col, int row)
2532void 2522void
2533resettitle(void) 2523resettitle(void)
2534{ 2524{
2535 xsettitle(opt_title ? opt_title : "st"); 2525 xsettitle(NULL);
2536} 2526}
2537 2527
2538void 2528void
diff --git a/st.h b/st.h
index c255b7c..09473c2 100644
--- a/st.h
+++ b/st.h
@@ -9,6 +9,7 @@
9#define LEN(a) (sizeof(a) / sizeof(a)[0]) 9#define LEN(a) (sizeof(a) / sizeof(a)[0])
10#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b)) 10#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
11#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d)) 11#define DIVCEIL(n, d) (((n) + ((d) - 1)) / (d))
12#define DEFAULT(a, b) (a) = (a) ? (a) : (b)
12#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x) 13#define LIMIT(x, a, b) (x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)
13#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \ 14#define ATTRCMP(a, b) ((a).mode != (b).mode || (a).fg != (b).fg || \
14 (a).bg != (b).bg) 15 (a).bg != (b).bg)
@@ -194,7 +195,7 @@ void tnew(int, int);
194void tresize(int, int); 195void tresize(int, int);
195void tsetdirt(int, int); 196void tsetdirt(int, int);
196void tsetdirtattr(int); 197void tsetdirtattr(int);
197void ttynew(void); 198void ttynew(char *, char *, char **);
198size_t ttyread(void); 199size_t ttyread(void);
199void ttyresize(int, int); 200void ttyresize(int, int);
200void ttysend(char *, size_t); 201void ttysend(char *, size_t);
@@ -221,14 +222,6 @@ extern Term term;
221extern Selection sel; 222extern Selection sel;
222extern int cmdfd; 223extern int cmdfd;
223extern pid_t pid; 224extern pid_t pid;
224extern char **opt_cmd;
225extern char *opt_class;
226extern char *opt_embed;
227extern char *opt_font;
228extern char *opt_io;
229extern char *opt_line;
230extern char *opt_name;
231extern char *opt_title;
232extern int oldbutton; 225extern int oldbutton;
233 226
234/* config.h globals */ 227/* config.h globals */
diff --git a/x.c b/x.c
index 371a467..e267961 100644
--- a/x.c
+++ b/x.c
@@ -179,6 +179,15 @@ static char *usedfont = NULL;
179static double usedfontsize = 0; 179static double usedfontsize = 0;
180static double defaultfontsize = 0; 180static double defaultfontsize = 0;
181 181
182static char *opt_class = NULL;
183static char **opt_cmd = NULL;
184static char *opt_embed = NULL;
185static char *opt_font = NULL;
186static char *opt_io = NULL;
187static char *opt_line = NULL;
188static char *opt_name = NULL;
189static char *opt_title = NULL;
190
182void 191void
183zoom(const Arg *arg) 192zoom(const Arg *arg)
184{ 193{
@@ -1473,6 +1482,7 @@ void
1473xsettitle(char *p) 1482xsettitle(char *p)
1474{ 1483{
1475 XTextProperty prop; 1484 XTextProperty prop;
1485 DEFAULT(p, "st");
1476 1486
1477 Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle, 1487 Xutf8TextListToTextProperty(xw.dpy, &p, 1, XUTF8StringStyle,
1478 &prop); 1488 &prop);
@@ -1757,7 +1767,7 @@ run(void)
1757 } while (ev.type != MapNotify); 1767 } while (ev.type != MapNotify);
1758 1768
1759 cresize(w, h); 1769 cresize(w, h);
1760 ttynew(); 1770 ttynew(opt_line, opt_io, opt_cmd);
1761 ttyresize(win.tw, win.th); 1771 ttyresize(win.tw, win.th);
1762 1772
1763 clock_gettime(CLOCK_MONOTONIC, &last); 1773 clock_gettime(CLOCK_MONOTONIC, &last);