diff options
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 50 |
1 files changed, 20 insertions, 30 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 |