diff options
-rw-r--r-- | st.c | 50 | ||||
-rw-r--r-- | st.h | 11 | ||||
-rw-r--r-- | x.c | 12 |
3 files changed, 33 insertions, 40 deletions
@@ -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 | ||
127 | static void execsh(void); | 126 | static void execsh(char **); |
128 | static void stty(void); | 127 | static void stty(char **); |
129 | static void sigchld(int); | 128 | static void sigchld(int); |
130 | 129 | ||
131 | static void csidump(void); | 130 | static void csidump(void); |
@@ -189,14 +188,6 @@ Term term; | |||
189 | Selection sel; | 188 | Selection sel; |
190 | int cmdfd; | 189 | int cmdfd; |
191 | pid_t pid; | 190 | pid_t pid; |
192 | char **opt_cmd = NULL; | ||
193 | char *opt_class = NULL; | ||
194 | char *opt_embed = NULL; | ||
195 | char *opt_font = NULL; | ||
196 | char *opt_io = NULL; | ||
197 | char *opt_line = NULL; | ||
198 | char *opt_name = NULL; | ||
199 | char *opt_title = NULL; | ||
200 | int oldbutton = 3; /* button event on startup: 3 = release */ | 191 | int oldbutton = 3; /* button event on startup: 3 = release */ |
201 | 192 | ||
202 | static CSIEscape csiescseq; | 193 | static CSIEscape csiescseq; |
@@ -634,9 +625,9 @@ die(const char *errstr, ...) | |||
634 | } | 625 | } |
635 | 626 | ||
636 | void | 627 | void |
637 | execsh(void) | 628 | execsh(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 | ||
699 | void | 690 | void |
700 | stty(void) | 691 | stty(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 | ||
723 | void | 714 | void |
724 | ttynew(void) | 715 | ttynew(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 | |||
1942 | tprinter(char *s, size_t len) | 1933 | tprinter(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) | |||
2532 | void | 2522 | void |
2533 | resettitle(void) | 2523 | resettitle(void) |
2534 | { | 2524 | { |
2535 | xsettitle(opt_title ? opt_title : "st"); | 2525 | xsettitle(NULL); |
2536 | } | 2526 | } |
2537 | 2527 | ||
2538 | void | 2528 | void |
@@ -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); | |||
194 | void tresize(int, int); | 195 | void tresize(int, int); |
195 | void tsetdirt(int, int); | 196 | void tsetdirt(int, int); |
196 | void tsetdirtattr(int); | 197 | void tsetdirtattr(int); |
197 | void ttynew(void); | 198 | void ttynew(char *, char *, char **); |
198 | size_t ttyread(void); | 199 | size_t ttyread(void); |
199 | void ttyresize(int, int); | 200 | void ttyresize(int, int); |
200 | void ttysend(char *, size_t); | 201 | void ttysend(char *, size_t); |
@@ -221,14 +222,6 @@ extern Term term; | |||
221 | extern Selection sel; | 222 | extern Selection sel; |
222 | extern int cmdfd; | 223 | extern int cmdfd; |
223 | extern pid_t pid; | 224 | extern pid_t pid; |
224 | extern char **opt_cmd; | ||
225 | extern char *opt_class; | ||
226 | extern char *opt_embed; | ||
227 | extern char *opt_font; | ||
228 | extern char *opt_io; | ||
229 | extern char *opt_line; | ||
230 | extern char *opt_name; | ||
231 | extern char *opt_title; | ||
232 | extern int oldbutton; | 225 | extern int oldbutton; |
233 | 226 | ||
234 | /* config.h globals */ | 227 | /* config.h globals */ |
@@ -179,6 +179,15 @@ static char *usedfont = NULL; | |||
179 | static double usedfontsize = 0; | 179 | static double usedfontsize = 0; |
180 | static double defaultfontsize = 0; | 180 | static double defaultfontsize = 0; |
181 | 181 | ||
182 | static char *opt_class = NULL; | ||
183 | static char **opt_cmd = NULL; | ||
184 | static char *opt_embed = NULL; | ||
185 | static char *opt_font = NULL; | ||
186 | static char *opt_io = NULL; | ||
187 | static char *opt_line = NULL; | ||
188 | static char *opt_name = NULL; | ||
189 | static char *opt_title = NULL; | ||
190 | |||
182 | void | 191 | void |
183 | zoom(const Arg *arg) | 192 | zoom(const Arg *arg) |
184 | { | 193 | { |
@@ -1473,6 +1482,7 @@ void | |||
1473 | xsettitle(char *p) | 1482 | xsettitle(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); |