aboutsummaryrefslogtreecommitdiff
path: root/std.c
diff options
context:
space:
mode:
Diffstat (limited to 'std.c')
-rw-r--r--std.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/std.c b/std.c
index 84048e4..daf759e 100644
--- a/std.c
+++ b/std.c
@@ -3,6 +3,7 @@
3#include <sys/types.h> 3#include <sys/types.h>
4#include <sys/wait.h> 4#include <sys/wait.h>
5#include <ctype.h> 5#include <ctype.h>
6#include <err.h>
6#include <signal.h> 7#include <signal.h>
7#include <stdarg.h> 8#include <stdarg.h>
8#include <stdio.h> 9#include <stdio.h>
@@ -73,7 +74,7 @@ getch() {
73 if(rbuf.i++ >= rbuf.n) { 74 if(rbuf.i++ >= rbuf.n) {
74 rbuf.n = read(ptm, rbuf.data, LENGTH(rbuf.data)); 75 rbuf.n = read(ptm, rbuf.data, LENGTH(rbuf.data));
75 if(rbuf.n == -1) 76 if(rbuf.n == -1)
76 eprintn("error, cannot read from slave pty"); 77 err(EXIT_FAILURE, "cannot read from slave pty");
77 rbuf.i = 0; 78 rbuf.i = 0;
78 } 79 }
79 return rbuf.data[rbuf.i]; 80 return rbuf.data[rbuf.i];
@@ -113,7 +114,7 @@ parseesc(void) {
113 qmark = 1; 114 qmark = 1;
114 else if(c == ';') { 115 else if(c == ';') {
115 if(!digit) 116 if(!digit)
116 eprint("syntax error\n"); 117 errx(EXIT_FAILURE, "syntax error");
117 digit = 0; 118 digit = 0;
118 j++; 119 j++;
119 } 120 }
@@ -216,7 +217,7 @@ shell(void) {
216 pid = fork(); 217 pid = fork();
217 switch(pid) { 218 switch(pid) {
218 case -1: 219 case -1:
219 eprint("error, cannot fork\n"); 220 err(EXIT_FAILURE, "cannot fork");
220 case 0: 221 case 0:
221 setsid(); 222 setsid();
222 dup2(pts, STDIN_FILENO); 223 dup2(pts, STDIN_FILENO);
@@ -237,7 +238,7 @@ sigchld(int n) {
237 int ret; 238 int ret;
238 239
239 if(waitpid(pid, &ret, 0) == -1) 240 if(waitpid(pid, &ret, 0) == -1)
240 eprintn("error, waiting for child failed"); 241 err(EXIT_FAILURE, "waiting for child failed");
241 if(WIFEXITED(ret)) 242 if(WIFEXITED(ret))
242 exit(WEXITSTATUS(ret)); 243 exit(WEXITSTATUS(ret));
243 else 244 else
@@ -257,7 +258,7 @@ unbuffer(void) {
257void 258void
258ungetch(int c) { 259ungetch(int c) {
259 if(rbuf.i + 1 >= rbuf.n) 260 if(rbuf.i + 1 >= rbuf.n)
260 eprint("error, read buffer full\n"); 261 errx(EXIT_FAILURE, "read buffer full");
261 rbuf.data[rbuf.i++] = c; 262 rbuf.data[rbuf.i++] = c;
262} 263}
263 264
@@ -266,10 +267,14 @@ main(int argc, char *argv[]) {
266 fd_set rfds; 267 fd_set rfds;
267 int r; 268 int r;
268 269
269 if(argc == 2 && !strcmp("-v", argv[1])) 270 if(argc == 2 && !strcmp("-v", argv[1])) {
270 eprint("std-"VERSION", © 2008 Matthias-Christian Ott\n"); 271 fprintf(stderr, "std-"VERSION", © 2008 Matthias-Christian Ott\n");
271 else if(argc == 1) 272 exit(EXIT_SUCCESS);
272 eprint("usage: st [-v]\n"); 273 }
274 else if(argc == 1) {
275 fprintf(stderr, "usage: st [-v]\n");
276 exit(EXIT_FAILURE);
277 }
273 getpty(); 278 getpty();
274 shell(); 279 shell();
275 FD_ZERO(&rfds); 280 FD_ZERO(&rfds);
@@ -278,7 +283,7 @@ main(int argc, char *argv[]) {
278 for(;;) { 283 for(;;) {
279 r = select(ptm + 1, &rfds, NULL, NULL, NULL); 284 r = select(ptm + 1, &rfds, NULL, NULL, NULL);
280 if(r == -1) 285 if(r == -1)
281 eprintn("error, cannot select"); 286 err(EXIT_FAILURE, "cannot select");
282 if(FD_ISSET(ptm, &rfds)) { 287 if(FD_ISSET(ptm, &rfds)) {
283 do { 288 do {
284 c = getch(); 289 c = getch();