Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
13 #define LENGTH(x) (sizeof(x) / sizeof((x)[0]))
14 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
15 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
18 void cmd(const char *cmdstr
, ...);
20 void movea(int x
, int y
);
21 void mover(int x
, int y
);
29 unsigned char data
[BUFSIZ
];
34 int cols
= 80, lines
= 25;
39 _Bool bold
, digit
, qmark
;
45 if(buf
.n
< LENGTH(buf
.data
))
48 buf
.s
= (buf
.s
+ 1) % LENGTH(buf
.data
);
49 buf
.data
[buf
.e
++] = c
;
50 buf
.e
%= LENGTH(buf
.data
);
54 cmd(const char *cmdstr
, ...) {
60 vfprintf(stdout
, cmdstr
, ap
);
75 movea(cx
+ x
, cy
+ y
);
83 memset(arg
, 0, LENGTH(arg
));
88 for(j
= 0; j
< LENGTH(arg
);) {
98 eprint("syntax error\n");
115 mover(0, j
? arg
[0] : 1);
118 mover(0, j
? -arg
[0] : -1);
121 mover(j
? arg
[0] : 1, 0);
124 mover(j
? -arg
[0] : -1, 0);
127 /* movel(j ? arg[0] : 1); */
130 /* movel(j ? -arg[0] : -1); */
134 movea(j
? arg
[0] : 1, cy
);
138 movea(arg
[1] ? arg
[1] : 1, arg
[0] ? arg
[0] : 1);
140 /* insline(j ? arg[0] : 1); */
143 /* delline(j ? arg[0] : 1); */
148 scroll(j
? arg
[0] : 1);
151 scroll(j
? -arg
[0] : -1);
154 movea(cx
, j
? arg
[0] : 1);
157 for(i
= 0; i
< j
; i
++) {
158 if(arg
[i
] >= 30 && arg
[i
] <= 37)
159 cmd("#%d", arg
[i
] - 30);
160 if(arg
[i
] >= 40 && arg
[i
] <= 47)
161 cmd("|%d", arg
[i
] - 40);
162 /* xterm bright colors */
163 if(arg
[i
] >= 90 && arg
[i
] <= 97)
164 cmd("#%d", arg
[i
] - 90);
165 if(arg
[i
] >= 100 && arg
[i
] <= 107)
166 cmd("|%d", arg
[i
] - 100);
189 cmd("s %d, %d", cx
, cy
+ l
);
194 static char *shell
= NULL
;
196 if(!shell
&& !(shell
= getenv("SHELL")))
201 eprint("error, cannot fork\n");
204 dup2(pts
, STDIN_FILENO
);
205 dup2(pts
, STDOUT_FILENO
);
206 dup2(pts
, STDERR_FILENO
);
208 putenv("TERM=vt102");
213 signal(SIGCHLD
, sigchld
);
221 if(waitpid(pid
, &ret
, 0) == -1)
222 eprintn("error, waiting for child failed");
224 exit(WEXITSTATUS(ret
));
233 c
= buf
.data
[buf
.s
++];
234 buf
.s
%= LENGTH(buf
.data
);
240 main(int argc
, char *argv
[]) {
241 if(argc
== 2 && !strcmp("-v", argv
[1]))
242 eprint("std-"VERSION
", © 2008 Matthias-Christian Ott\n");
244 eprint("usage: st [-v]\n");
247 fptm
= fdopen(ptm
, "r+");
249 eprintn("cannot open slave pty");