|
Lines 66-73
Link Here
|
| 66 |
FILE *fscript; |
66 |
FILE *fscript; |
| 67 |
int master, slave; |
67 |
int master, slave; |
| 68 |
int child; |
68 |
int child; |
| 69 |
char *fname; |
69 |
const char *fname; |
| 70 |
int qflg; |
70 |
int Aflg, qflg; |
| 71 |
|
71 |
|
| 72 |
struct termios tt; |
72 |
struct termios tt; |
| 73 |
|
73 |
|
|
Lines 76-81
Link Here
|
| 76 |
void doshell __P((char **)); |
76 |
void doshell __P((char **)); |
| 77 |
void fail __P((void)); |
77 |
void fail __P((void)); |
| 78 |
void finish __P((void)); |
78 |
void finish __P((void)); |
|
|
79 |
void log_write __P((const char *, int)); |
| 79 |
static void usage __P((void)); |
80 |
static void usage __P((void)); |
| 80 |
|
81 |
|
| 81 |
int |
82 |
int |
|
Lines 95-105
Link Here
|
| 95 |
int flushtime = 30; |
96 |
int flushtime = 30; |
| 96 |
|
97 |
|
| 97 |
aflg = kflg = 0; |
98 |
aflg = kflg = 0; |
| 98 |
while ((ch = getopt(argc, argv, "aqkt:")) != -1) |
99 |
while ((ch = getopt(argc, argv, "aAqkt:")) != -1) |
| 99 |
switch(ch) { |
100 |
switch(ch) { |
| 100 |
case 'a': |
101 |
case 'a': |
| 101 |
aflg = 1; |
102 |
aflg = 1; |
| 102 |
break; |
103 |
break; |
|
|
104 |
case 'A': |
| 105 |
Aflg = 1; |
| 106 |
break; |
| 103 |
case 'q': |
107 |
case 'q': |
| 104 |
qflg = 1; |
108 |
qflg = 1; |
| 105 |
break; |
109 |
break; |
|
Lines 177-183
Link Here
|
| 177 |
(void)write(master, ibuf, cc); |
181 |
(void)write(master, ibuf, cc); |
| 178 |
if (kflg && tcgetattr(master, &stt) >= 0 && |
182 |
if (kflg && tcgetattr(master, &stt) >= 0 && |
| 179 |
((stt.c_lflag & ECHO) == 0)) { |
183 |
((stt.c_lflag & ECHO) == 0)) { |
| 180 |
(void)fwrite(ibuf, 1, cc, fscript); |
184 |
log_write(ibuf, cc); |
| 181 |
} |
185 |
} |
| 182 |
} |
186 |
} |
| 183 |
} |
187 |
} |
|
Lines 186-192
Link Here
|
| 186 |
if (cc <= 0) |
190 |
if (cc <= 0) |
| 187 |
break; |
191 |
break; |
| 188 |
(void)write(STDOUT_FILENO, obuf, cc); |
192 |
(void)write(STDOUT_FILENO, obuf, cc); |
| 189 |
(void)fwrite(obuf, 1, cc, fscript); |
193 |
log_write(obuf, cc); |
| 190 |
} |
194 |
} |
| 191 |
tvec = time(0); |
195 |
tvec = time(0); |
| 192 |
if (tvec - start >= flushtime) { |
196 |
if (tvec - start >= flushtime) { |
|
Lines 202-208
Link Here
|
| 202 |
usage() |
206 |
usage() |
| 203 |
{ |
207 |
{ |
| 204 |
(void)fprintf(stderr, |
208 |
(void)fprintf(stderr, |
| 205 |
"usage: script [-a] [-q] [-k] [-t time] [file] [command]\n"); |
209 |
"usage: script [-a] [-A] [-q] [-k] [-t time] [file] [command]\n"); |
| 206 |
exit(1); |
210 |
exit(1); |
| 207 |
} |
211 |
} |
| 208 |
|
212 |
|
|
Lines 232-238
Link Here
|
| 232 |
doshell(av) |
236 |
doshell(av) |
| 233 |
char **av; |
237 |
char **av; |
| 234 |
{ |
238 |
{ |
| 235 |
char *shell; |
239 |
const char *shell; |
| 236 |
|
240 |
|
| 237 |
shell = getenv("SHELL"); |
241 |
shell = getenv("SHELL"); |
| 238 |
if (shell == NULL) |
242 |
if (shell == NULL) |
|
Lines 273-276
Link Here
|
| 273 |
(void)fclose(fscript); |
277 |
(void)fclose(fscript); |
| 274 |
(void)close(master); |
278 |
(void)close(master); |
| 275 |
exit(eno); |
279 |
exit(eno); |
|
|
280 |
} |
| 281 |
|
| 282 |
void |
| 283 |
log_write(const char *buf, int size) |
| 284 |
{ |
| 285 |
int off, i; |
| 286 |
|
| 287 |
if (!Aflg) { |
| 288 |
(void)fwrite(buf, 1, size, fscript); |
| 289 |
return; |
| 290 |
} |
| 291 |
off = 0; |
| 292 |
do { |
| 293 |
i = 0; |
| 294 |
while ((off + i < size) && (buf[off + i] != '\r')) |
| 295 |
i++; |
| 296 |
if (i > 0) |
| 297 |
(void)fwrite(buf + off, 1, i, fscript); |
| 298 |
off += i + 1; |
| 299 |
} while (off < size); |
| 276 |
} |
300 |
} |