diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-09 11:37:21 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-02-09 11:37:21 +0000 |
commit | d56e3ccf960a6773ea7939811728f1942cc493ac (patch) | |
tree | cca31e184ef73cada7b1786c5b47f8aacf6b672c | |
parent | 937b10f35dc9fb74220ffa8d3f8e98f07f732f79 (diff) | |
download | busybox-w32-d56e3ccf960a6773ea7939811728f1942cc493ac.tar.gz busybox-w32-d56e3ccf960a6773ea7939811728f1942cc493ac.tar.bz2 busybox-w32-d56e3ccf960a6773ea7939811728f1942cc493ac.zip |
microcom: split -d (delay) option away from -t
-rw-r--r-- | include/usage.h | 10 | ||||
-rw-r--r-- | miscutils/microcom.c | 38 |
2 files changed, 28 insertions, 20 deletions
diff --git a/include/usage.h b/include/usage.h index 98d3f3c96..37cefeab1 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2235,9 +2235,15 @@ USE_FEATURE_BRCTL_FANCY("\n" \ | |||
2235 | " n Disallow write access to your terminal" | 2235 | " n Disallow write access to your terminal" |
2236 | 2236 | ||
2237 | #define microcom_trivial_usage \ | 2237 | #define microcom_trivial_usage \ |
2238 | "[-s speed] tty-name" | 2238 | "[-d DELAY] [-t TIMEOUT] [-s SPEED] [-X] TTY" |
2239 | #define microcom_full_usage \ | 2239 | #define microcom_full_usage \ |
2240 | "" | 2240 | "Copy bytes for stdin to TTY and from TTY to stdout" \ |
2241 | "\n\nOptions:" \ | ||
2242 | "\n -d Wait up to DELAY ms for TTY output before sending every" \ | ||
2243 | "\n next byte to it" \ | ||
2244 | "\n -t Exit if both stdin and TTY are silent for TIMEOUT ms" \ | ||
2245 | "\n -s Set serial line to SPEED" | ||
2246 | "\n -X Disable special meaning of NUL and Ctrl-X from stdin" | ||
2241 | 2247 | ||
2242 | #define mkdir_trivial_usage \ | 2248 | #define mkdir_trivial_usage \ |
2243 | "[OPTION] DIRECTORY..." | 2249 | "[OPTION] DIRECTORY..." |
diff --git a/miscutils/microcom.c b/miscutils/microcom.c index fb5e9c868..52baaca51 100644 --- a/miscutils/microcom.c +++ b/miscutils/microcom.c | |||
@@ -51,22 +51,28 @@ int microcom_main(int argc, char **argv) | |||
51 | enum { | 51 | enum { |
52 | OPT_X = 1 << 0, // do not respect Ctrl-X, Ctrl-@ | 52 | OPT_X = 1 << 0, // do not respect Ctrl-X, Ctrl-@ |
53 | OPT_s = 1 << 1, // baudrate | 53 | OPT_s = 1 << 1, // baudrate |
54 | OPT_t = 1 << 2 // wait for device response, msecs | 54 | OPT_d = 1 << 2 // wait for device response, msecs |
55 | OPT_t = 1 << 3 // timeout, ms | ||
55 | }; | 56 | }; |
56 | speed_t speed = 9600; | 57 | speed_t speed = 9600; |
57 | int timeout = 100; // 0.1 sec timeout | 58 | int delay = -1; |
59 | int timeout = -1; | ||
58 | 60 | ||
59 | // fetch options | 61 | // fetch options |
60 | char *opt_s; | 62 | char *opt_s; |
61 | char *opt_t; | 63 | char *opt_t; |
62 | unsigned opts; | 64 | unsigned opts; |
63 | opt_complementary = "=1"; /* exactly one arg should be there */ | 65 | opt_complementary = "=1"; /* exactly one arg should be there */ |
64 | opts = getopt32(argv, "Xs:t:", &opt_s, &opt_t); | 66 | opts = getopt32(argv, "Xs:d:t:", &opt_s, &opt_d, &opt_t); |
67 | |||
65 | // apply options | 68 | // apply options |
66 | if (opts & OPT_s) | 69 | if (opts & OPT_s) |
67 | speed = xatoi_u(opt_s); | 70 | speed = xatoi_u(opt_s); |
71 | if (opts & OPT_d) | ||
72 | delay = xatoi_u(opt_d); | ||
68 | if (opts & OPT_t) | 73 | if (opts & OPT_t) |
69 | timeout = xatoi_u(opt_t); | 74 | timeout = xatoi_u(opt_t); |
75 | |||
70 | // argc -= optind; | 76 | // argc -= optind; |
71 | argv += optind; | 77 | argv += optind; |
72 | 78 | ||
@@ -106,13 +112,12 @@ int microcom_main(int argc, char **argv) | |||
106 | goto done; | 112 | goto done; |
107 | fcntl(sfd, F_SETFL, O_RDWR | O_NOCTTY); | 113 | fcntl(sfd, F_SETFL, O_RDWR | O_NOCTTY); |
108 | 114 | ||
109 | /* put stdin to "raw mode" (if stdin is a TTY), | 115 | // put stdin to "raw mode" (if stdin is a TTY), |
110 | handle one character at a time */ | 116 | // handle one character at a time |
111 | if (isatty(STDIN_FILENO)) { | 117 | if (isatty(STDIN_FILENO)) { |
112 | xget1(STDIN_FILENO, &tio, &tio0); | 118 | xget1(STDIN_FILENO, &tio, &tio0); |
113 | if (xset1(STDIN_FILENO, &tio, "stdin")) | 119 | if (xset1(STDIN_FILENO, &tio, "stdin")) |
114 | goto done; | 120 | goto done; |
115 | timeout = -1; // tty input? -> set infinite timeout for poll() | ||
116 | } | 121 | } |
117 | 122 | ||
118 | // same thing for modem | 123 | // same thing for modem |
@@ -136,16 +141,18 @@ int microcom_main(int argc, char **argv) | |||
136 | nfd = 2; | 141 | nfd = 2; |
137 | while (!signalled && safe_poll(pfd, nfd, timeout) > 0) { | 142 | while (!signalled && safe_poll(pfd, nfd, timeout) > 0) { |
138 | char c; | 143 | char c; |
139 | if (pfd[0].revents & POLLIN) { | 144 | if (pfd[0].revents) { |
145 | serial_ready: | ||
140 | // read from device -> write to stdout | 146 | // read from device -> write to stdout |
141 | if (safe_read(sfd, &c, 1) > 0) | 147 | if (safe_read(sfd, &c, 1) > 0) |
142 | write(STDOUT_FILENO, &c, 1); | 148 | write(STDOUT_FILENO, &c, 1); |
149 | // else { EOF/error - what to do? } | ||
143 | } | 150 | } |
144 | if (pfd[1].revents & POLLIN) { | 151 | if (pfd[1].revents) { |
152 | pfd[1].revents = 0; | ||
145 | // read from stdin -> write to device | 153 | // read from stdin -> write to device |
146 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { | 154 | if (safe_read(STDIN_FILENO, &c, 1) < 1) { |
147 | // skip polling stdin if we got EOF/error | 155 | // don't poll stdin anymore if we got EOF/error |
148 | pfd[1].revents = 0; | ||
149 | nfd--; | 156 | nfd--; |
150 | continue; | 157 | continue; |
151 | } | 158 | } |
@@ -161,20 +168,15 @@ int microcom_main(int argc, char **argv) | |||
161 | break; | 168 | break; |
162 | } | 169 | } |
163 | write(sfd, &c, 1); | 170 | write(sfd, &c, 1); |
164 | //// vda: this is suspicious! | 171 | if (delay >= 0 && safe_poll(pfd, 1, delay) > 0) |
165 | // without this we never get POLLIN on sfd | 172 | goto serial_ready; |
166 | // until piped stdin is drained | ||
167 | if (-1 != timeout) | ||
168 | safe_poll(pfd, 1, 1 /* 1 ms */); | ||
169 | } | 173 | } |
170 | } | 174 | } |
171 | /* usleep(10000); - let last chars leave serial line */ | ||
172 | 175 | ||
173 | tcsetattr(sfd, TCSAFLUSH, &tiosfd); | 176 | tcsetattr(sfd, TCSAFLUSH, &tiosfd); |
174 | 177 | ||
175 | restore0_and_done: | 178 | restore0_and_done: |
176 | // timeout == -1 -- stdin is a tty | 179 | if (isatty(STDIN_FILENO)) |
177 | if (-1 == timeout) | ||
178 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0); | 180 | tcsetattr(STDIN_FILENO, TCSAFLUSH, &tio0); |
179 | 181 | ||
180 | done: | 182 | done: |