1 /* stty - set terminal mode Author: Andy Tanenbaum */
4 Adapted to POSIX 1003.2 by Philip Homburg.
19 #include <sys/types.h>
20 #include <sys/ioctl.h>
26 /* Default settings, the Minix ones are defined in <termios.h> */
29 #define TCTRL_DEF (PARENB | CREAD | CS7)
33 #define TSPEED_DEF B1200
37 #define TINPUT_DEF (BRKINT | IGNPAR | ISTRIP | ICRNL)
41 #define TOUTPUT_DEF OPOST
45 #define TLOCAL_DEF (ISIG | IEXTEN | ICANON | ECHO | ECHOE)
49 #define TEOF_DEF '\4' /* ^D */
52 #ifdef _POSIX_VDISABLE
53 #define TEOL_DEF _POSIX_VDISABLE
59 #define TERASE_DEF '\10' /* ^H */
62 #define TINTR_DEF '\177' /* ^? */
65 #define TKILL_DEF '\25' /* ^U */
68 #define TQUIT_DEF '\34' /* ^\ */
71 #define TSUSP_DEF '\32' /* ^Z */
74 #define TSTART_DEF '\21' /* ^Q */
77 #define TSTOP_DEF '\23' /* ^S */
89 struct termios termios
;
90 int column
= 0, max_column
=80; /* Assume 80 character terminals. */
92 struct winsize winsize
;
97 int main
PROTO(( int argc
, char **argv
));
98 void report
PROTO(( int flags
));
99 int option
PROTO(( char *opt
, char *next
));
100 int match
PROTO(( char *s1
, char *s2
));
101 void prctl
PROTO(( int c
));
102 speed_t long2speed
PROTO(( long num
));
103 long speed2long
PROTO(( unsigned long speed
));
104 void print_flags
PROTO(( unsigned long flags
, unsigned long flag
,
105 unsigned long def
, char *string
, int all
));
106 void output
PROTO(( char *s
));
107 void do_print_char
PROTO(( unsigned chr
, unsigned def
, char *name
, int all
));
108 void do_print_num
PROTO(( unsigned num
, unsigned def
, char *name
, int all
));
109 void set_saved_settings
PROTO(( char *opt
));
110 void set_control
PROTO(( int option
, char *value
));
111 void set_min_tim
PROTO(( int option
, char *value
));
113 #define print_char(c,d,n,a) (do_print_char((unsigned)(c),(unsigned)(d),(n),(a)))
114 #define print_num(m,d,n,a) (do_print_num((unsigned)(m),(unsigned)(d),(n),(a)))
125 /* Stty with no arguments just reports on current status. */
126 if (tcgetattr(0, &termios
) == -1)
128 fprintf(stderr
, "%s: can't read ioctl parameters from stdin: %s\n",
129 prog_name
, strerror(errno
));
133 if (ioctl(0, TIOCGWINSZ
, &winsize
) == -1)
135 fprintf(stderr
, "%s: can't get screen size from stdin: %s\n",
136 prog_name
, strerror(errno
));
139 if (winsize
.ws_col
!= 0)
140 max_column
= winsize
.ws_col
;
145 if (!strcmp(argv
[1], "-a"))
147 else if (!strcmp(argv
[1], "-g"))
150 if (argc
== 1 || flags
) {
155 /* Process the options specified. */
156 for (k
= 1; k
< argc
; k
++)
157 k
+= option(argv
[k
], k
+1 < argc
? argv
[k
+1] : "");
160 if (ioctl(0, TIOCSWINSZ
, &winsize
) == -1)
162 fprintf(stderr
, "%s: can't set screen size to stdin: %s\n",
163 prog_name
, strerror(errno
));
167 if (tcsetattr(0, TCSANOW
, &termios
) == -1)
169 fprintf(stderr
, "%s: can't set terminal parameters to stdin: %s\n",
170 prog_name
, strerror(errno
));
182 tcflag_t c_cflag
, c_iflag
, c_oflag
, c_lflag
;
184 speed_t ispeed
, ospeed
;
187 { /* We have to write the termios structure in a encoded form
190 printf(":%x:%x:%x:%x:%x:%x", termios
.c_iflag
, termios
.c_oflag
,
191 termios
.c_cflag
, termios
.c_lflag
, cfgetispeed(&termios
),
192 cfgetospeed(&termios
));
193 for (i
= 0; i
<NCCS
; i
++)
194 printf(":%x", termios
.c_cc
[i
]);
201 /* Start with the baud rate. */
202 ispeed
= cfgetispeed(&termios
);
203 ospeed
= cfgetospeed(&termios
);
204 if (ispeed
!= ospeed
)
206 sprintf(line
, "ispeed %lu baud; ospeed %lu baud;",
207 speed2long(ispeed
), speed2long(ospeed
));
210 else if (all
|| ospeed
!= TSPEED_DEF
)
212 sprintf(line
, "speed %lu baud;", speed2long(ospeed
));
216 /* The control modes. */
218 c_cflag
= termios
.c_cflag
;
219 if (all
|| (c_cflag
& CSIZE
) != (TCTRL_DEF
& CSIZE
))
221 switch (c_cflag
& CSIZE
)
223 case CS5
: output("cs5"); break;
224 case CS6
: output("cs6"); break;
225 case CS7
: output("cs7"); break;
226 case CS8
: output("cs8"); break;
227 default: output("cs??"); break;
230 print_flags(c_cflag
, PARENB
, TCTRL_DEF
, "-parenb", all
);
231 print_flags(c_cflag
, PARODD
, TCTRL_DEF
, "-parodd", all
);
232 print_flags(c_cflag
, HUPCL
, TCTRL_DEF
, "-hupcl", all
);
233 print_flags(c_cflag
, CSTOPB
, TCTRL_DEF
, "-cstopb", all
);
234 print_flags(c_cflag
, CREAD
, TCTRL_DEF
, "-cread", all
);
235 print_flags(c_cflag
, CLOCAL
, TCTRL_DEF
, "-clocal", all
);
243 /* The input flags. */
245 c_iflag
= termios
.c_iflag
;
247 print_flags(c_iflag
, IGNBRK
, TINPUT_DEF
, "-ignbrk", all
);
248 print_flags(c_iflag
, BRKINT
, TINPUT_DEF
, "-brkint", all
);
249 print_flags(c_iflag
, IGNPAR
, TINPUT_DEF
, "-ignpar", all
);
250 print_flags(c_iflag
, PARMRK
, TINPUT_DEF
, "-parmrk", all
);
251 print_flags(c_iflag
, INPCK
, TINPUT_DEF
, "-inpck", all
);
252 print_flags(c_iflag
, ISTRIP
, TINPUT_DEF
, "-istrip", all
);
253 print_flags(c_iflag
, INLCR
, TINPUT_DEF
, "-inlcr", all
);
254 print_flags(c_iflag
, IGNCR
, TINPUT_DEF
, "-igncr", all
);
255 print_flags(c_iflag
, ICRNL
, TINPUT_DEF
, "-icrnl", all
);
256 print_flags(c_iflag
, IXON
, TINPUT_DEF
, "-ixon", all
);
257 print_flags(c_iflag
, IXOFF
, TINPUT_DEF
, "-ixoff", all
);
258 print_flags(c_iflag
, IXANY
, TINPUT_DEF
, "-ixany", all
);
266 /* The output flags. */
268 c_oflag
= termios
.c_oflag
;
270 print_flags(c_oflag
, OPOST
, TOUTPUT_DEF
, "-opost", all
);
272 print_flags(c_oflag
, ONLCR
, TOUTPUT_DEF
, "-onlcr", all
);
273 print_flags(c_oflag
, XTABS
, TOUTPUT_DEF
, "-xtabs", all
);
274 print_flags(c_oflag
, ONOEOT
, TOUTPUT_DEF
, "-onoeot", all
);
282 /* The local flags. */
284 c_lflag
= termios
.c_lflag
;
286 print_flags(c_lflag
, ISIG
, TLOCAL_DEF
, "-isig", all
);
287 print_flags(c_lflag
, ICANON
, TLOCAL_DEF
, "-icanon", all
);
288 print_flags(c_lflag
, IEXTEN
, TLOCAL_DEF
, "-iexten", all
);
289 print_flags(c_lflag
, ECHO
, TLOCAL_DEF
, "-echo", all
);
290 print_flags(c_lflag
, ECHOE
, TLOCAL_DEF
, "-echoe", all
);
291 print_flags(c_lflag
, ECHOK
, TLOCAL_DEF
, "-echok", all
);
292 print_flags(c_lflag
, ECHONL
, TLOCAL_DEF
, "-echonl", all
);
293 print_flags(c_lflag
, NOFLSH
, TLOCAL_DEF
, "-noflsh", all
);
295 print_flags(c_lflag
, TOSTOP
, TLOCAL_DEF
, "-tostop", all
);
298 print_flags(c_lflag
, LFLUSHO
, TLOCAL_DEF
, "-lflusho", all
);
307 /* The special control characters. */
309 print_char(termios
.c_cc
[VEOF
], TEOF_DEF
, "eof", all
);
310 print_char(termios
.c_cc
[VEOL
], TEOL_DEF
, "eol", all
);
311 print_char(termios
.c_cc
[VERASE
], TERASE_DEF
, "erase", all
);
312 print_char(termios
.c_cc
[VINTR
], TINTR_DEF
, "intr", all
);
313 print_char(termios
.c_cc
[VKILL
], TKILL_DEF
, "kill", all
);
314 print_char(termios
.c_cc
[VQUIT
], TQUIT_DEF
, "quit", all
);
315 print_char(termios
.c_cc
[VSUSP
], TSUSP_DEF
, "susp", all
);
316 print_char(termios
.c_cc
[VSTART
], TSTART_DEF
, "start", all
);
317 print_char(termios
.c_cc
[VSTOP
], TSTOP_DEF
, "stop", all
);
319 print_char(termios
.c_cc
[VREPRINT
], TREPRINT_DEF
, "rprnt", all
);
320 print_char(termios
.c_cc
[VLNEXT
], TLNEXT_DEF
, "lnext", all
);
321 print_char(termios
.c_cc
[VDISCARD
], TDISCARD_DEF
, "flush", all
);
323 print_num(termios
.c_cc
[VMIN
], TMIN_DEF
, "min", all
);
324 print_num(termios
.c_cc
[VTIME
], TTIME_DEF
, "time", all
);
333 if (all
|| winsize
.ws_row
!= 0 || winsize
.ws_col
!= 0)
335 sprintf(line
, "%d rows %d columns", winsize
.ws_row
,
340 if (all
|| winsize
.ws_ypixel
!= 0 || winsize
.ws_xpixel
!= 0)
342 sprintf(line
, "%d ypixels %d xpixels", winsize
.ws_ypixel
,
361 int option(opt
, next
)
368 /* The control options. */
370 if (match(opt
, "clocal")) {
371 termios
.c_cflag
|= CLOCAL
;
374 if (match(opt
, "-clocal")) {
375 termios
.c_cflag
&= ~CLOCAL
;
379 if (match(opt
, "cread")) {
380 termios
.c_cflag
|= CREAD
;
383 if (match(opt
, "-cread")) {
384 termios
.c_cflag
&= ~CREAD
;
388 if (match(opt
, "cs5")) {
389 termios
.c_cflag
&= ~CSIZE
;
390 termios
.c_cflag
|= CS5
;
393 if (match(opt
, "cs6")) {
394 termios
.c_cflag
&= ~CSIZE
;
395 termios
.c_cflag
|= CS6
;
398 if (match(opt
, "cs7")) {
399 termios
.c_cflag
&= ~CSIZE
;
400 termios
.c_cflag
|= CS7
;
403 if (match(opt
, "cs8")) {
404 termios
.c_cflag
&= ~CSIZE
;
405 termios
.c_cflag
|= CS8
;
409 if (match(opt
, "cstopb")) {
410 termios
.c_cflag
|= CSTOPB
;
413 if (match(opt
, "-cstopb")) {
414 termios
.c_cflag
&= ~CSTOPB
;
418 if (match(opt
, "hupcl") || match(opt
, "hup")) {
419 termios
.c_cflag
|= HUPCL
;
422 if (match(opt
, "-hupcl") || match(opt
, "-hup")) {
423 termios
.c_cflag
&= ~HUPCL
;
427 if (match(opt
, "parenb")) {
428 termios
.c_cflag
|= PARENB
;
431 if (match(opt
, "-parenb")) {
432 termios
.c_cflag
&= ~PARENB
;
436 if (match(opt
, "parodd")) {
437 termios
.c_cflag
|= PARODD
;
440 if (match(opt
, "-parodd")) {
441 termios
.c_cflag
&= ~PARODD
;
445 num
= strtol(opt
, &check
, 10);
446 if (check
[0] == '\0')
448 speed
= long2speed(num
);
449 if (speed
== (speed_t
)-1)
451 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
, opt
);
455 cfsetispeed(&termios
, speed
);
456 cfsetospeed(&termios
, speed
);
460 if (match(opt
, "ispeed")) {
461 num
= strtol(next
, &check
, 10);
464 speed
= long2speed(num
);
465 if (speed
== (speed_t
)-1)
467 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
,
471 cfsetispeed(&termios
, speed
);
476 fprintf(stderr
, "%s: invalid argument to ispeed: '%s'\n",
482 if (match(opt
, "ospeed")) {
483 num
= strtol(next
, &check
, 10);
486 speed
= long2speed(num
);
487 if (speed
== (speed_t
)-1)
489 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
,
493 cfsetospeed(&termios
, speed
);
498 fprintf(stderr
, "%s: invalid argument to ospeed: %s\n",
506 if (match(opt
, "brkint")) {
507 termios
.c_iflag
|= BRKINT
;
510 if (match(opt
, "-brkint")) {
511 termios
.c_iflag
&= ~BRKINT
;
515 if (match(opt
, "icrnl")) {
516 termios
.c_iflag
|= ICRNL
;
519 if (match(opt
, "-icrnl")) {
520 termios
.c_iflag
&= ~ICRNL
;
524 if (match(opt
, "ignbrk")) {
525 termios
.c_iflag
|= IGNBRK
;
528 if (match(opt
, "-ignbrk")) {
529 termios
.c_iflag
&= ~IGNBRK
;
533 if (match(opt
, "igncr")) {
534 termios
.c_iflag
|= IGNCR
;
537 if (match(opt
, "-igncr")) {
538 termios
.c_iflag
&= ~IGNCR
;
542 if (match(opt
, "ignpar")) {
543 termios
.c_iflag
|= IGNPAR
;
546 if (match(opt
, "-ignpar")) {
547 termios
.c_iflag
&= ~IGNPAR
;
551 if (match(opt
, "inlcr")) {
552 termios
.c_iflag
|= INLCR
;
555 if (match(opt
, "-inlcr")) {
556 termios
.c_iflag
&= ~INLCR
;
560 if (match(opt
, "inpck")) {
561 termios
.c_iflag
|= INPCK
;
564 if (match(opt
, "-inpck")) {
565 termios
.c_iflag
&= ~INPCK
;
569 if (match(opt
, "istrip")) {
570 termios
.c_iflag
|= ISTRIP
;
573 if (match(opt
, "-istrip")) {
574 termios
.c_iflag
&= ~ISTRIP
;
578 if (match(opt
, "ixoff")) {
579 termios
.c_iflag
|= IXOFF
;
582 if (match(opt
, "-ixoff")) {
583 termios
.c_iflag
&= ~IXOFF
;
587 if (match(opt
, "ixon")) {
588 termios
.c_iflag
|= IXON
;
591 if (match(opt
, "-ixon")) {
592 termios
.c_iflag
&= ~IXON
;
596 if (match(opt
, "parmrk")) {
597 termios
.c_iflag
|= PARMRK
;
600 if (match(opt
, "-parmrk")) {
601 termios
.c_iflag
&= ~PARMRK
;
605 if (match(opt
, "ixany")) {
606 termios
.c_iflag
|= IXANY
;
609 if (match(opt
, "-ixany")) {
610 termios
.c_iflag
&= ~IXANY
;
616 if (match(opt
, "opost")) {
617 termios
.c_oflag
|= OPOST
;
620 if (match(opt
, "-opost")) {
621 termios
.c_oflag
&= ~OPOST
;
625 if (match(opt
, "onlcr")) {
626 termios
.c_oflag
|= ONLCR
;
629 if (match(opt
, "-onlcr")) {
630 termios
.c_oflag
&= ~ONLCR
;
634 if (match(opt
, "xtabs")) {
635 termios
.c_oflag
|= XTABS
;
638 if (match(opt
, "-xtabs")) {
639 termios
.c_oflag
&= ~XTABS
;
643 if (match(opt
, "onoeot")) {
644 termios
.c_oflag
|= ONOEOT
;
647 if (match(opt
, "-onoeot")) {
648 termios
.c_oflag
&= ~ONOEOT
;
655 if (match(opt
, "echo")) {
656 termios
.c_lflag
|= ECHO
;
659 if (match(opt
, "-echo")) {
660 termios
.c_lflag
&= ~ECHO
;
664 if (match(opt
, "echoe")) {
665 termios
.c_lflag
|= ECHOE
;
668 if (match(opt
, "-echoe")) {
669 termios
.c_lflag
&= ~ECHOE
;
673 if (match(opt
, "echok")) {
674 termios
.c_lflag
|= ECHOK
;
677 if (match(opt
, "-echok")) {
678 termios
.c_lflag
&= ~ECHOK
;
682 if (match(opt
, "echonl")) {
683 termios
.c_lflag
|= ECHONL
;
686 if (match(opt
, "-echonl")) {
687 termios
.c_lflag
&= ~ECHONL
;
691 if (match(opt
, "icanon")) {
692 termios
.c_lflag
|= ICANON
;
695 if (match(opt
, "-icanon")) {
696 termios
.c_lflag
&= ~ICANON
;
700 if (match(opt
, "iexten")) {
701 termios
.c_lflag
|= IEXTEN
;
704 if (match(opt
, "-iexten")) {
705 termios
.c_lflag
&= ~IEXTEN
;
709 if (match(opt
, "isig")) {
710 termios
.c_lflag
|= ISIG
;
713 if (match(opt
, "-isig")) {
714 termios
.c_lflag
&= ~ISIG
;
718 if (match(opt
, "noflsh")) {
719 termios
.c_lflag
|= NOFLSH
;
722 if (match(opt
, "-noflsh")) {
723 termios
.c_lflag
&= ~NOFLSH
;
727 if (match(opt
, "tostop")) {
728 termios
.c_lflag
|= TOSTOP
;
731 if (match(opt
, "-tostop")) {
732 termios
.c_lflag
&= ~TOSTOP
;
737 if (match(opt
, "lflusho")) {
738 termios
.c_lflag
|= LFLUSHO
;
741 if (match(opt
, "-lflusho")) {
742 termios
.c_lflag
&= ~LFLUSHO
;
747 /* The special control characters. */
748 if (match(opt
, "eof")) {
749 set_control(VEOF
, next
);
753 if (match(opt
, "eol")) {
754 set_control(VEOL
, next
);
758 if (match(opt
, "erase")) {
759 set_control(VERASE
, next
);
763 if (match(opt
, "intr")) {
764 set_control(VINTR
, next
);
768 if (match(opt
, "kill")) {
769 set_control(VKILL
, next
);
773 if (match(opt
, "quit")) {
774 set_control(VQUIT
, next
);
778 if (match(opt
, "susp")) {
779 set_control(VSUSP
, next
);
783 if (match(opt
, "start")) {
784 set_control(VSTART
, next
);
788 if (match(opt
, "stop")) {
789 set_control(VSTOP
, next
);
793 if (match(opt
, "rprnt")) {
794 set_control(VREPRINT
, next
);
798 if (match(opt
, "lnext")) {
799 set_control(VLNEXT
, next
);
803 if (match(opt
, "flush")) {
804 set_control(VDISCARD
, next
);
809 if (match(opt
, "min")) {
810 set_min_tim(VMIN
, next
);
814 if (match(opt
, "time")) {
815 set_min_tim(VTIME
, next
);
822 set_saved_settings(opt
);
826 if (match(opt
, "cooked") || match(opt
, "raw")) {
827 int x
= opt
[0] == 'c' ? 1 : 0;
829 option(x
+ "-icrnl", ""); /* off in raw mode, on in cooked mode */
830 option(x
+ "-ixon", "");
831 option(x
+ "-opost", "");
832 option(x
+ "-onlcr", "");
833 option(x
+ "-isig", "");
834 option(x
+ "-icanon", "");
835 option(x
+ "-iexten", "");
836 option(x
+ "-echo", "");
840 if (match(opt
, "evenp") || match(opt
, "parity")) {
841 option("parenb", "");
843 option("-parodd", "");
847 if (match(opt
, "oddp")) {
848 option("parenb", "");
850 option("parodd", "");
854 if (match(opt
, "-parity") || match(opt
, "-evenp") || match(opt
, "-oddp")) {
855 option("-parenb", "");
860 if (match(opt
, "nl")) {
865 if (match(opt
, "-nl")) {
866 option("-icrnl", "");
867 option("-inlcr", "");
868 option("-igncr", "");
872 if (match(opt
, "ek")) {
873 termios
.c_cc
[VERASE
]= TERASE_DEF
;;
874 termios
.c_cc
[VKILL
]= TKILL_DEF
;;
878 if (match(opt
, "sane"))
880 /* Reset all terminal attributes to a sane state, except things like
881 * line speed and parity, because it can't be known what their sane
884 termios
.c_iflag
= (TINPUT_DEF
& ~(IGNPAR
|ISTRIP
|INPCK
))
885 | (termios
.c_iflag
& (IGNPAR
|ISTRIP
|INPCK
));
886 termios
.c_oflag
= (TOUTPUT_DEF
& ~(XTABS
))
887 | (termios
.c_oflag
& (XTABS
));
888 termios
.c_cflag
= (TCTRL_DEF
& ~(CLOCAL
|CSIZE
|CSTOPB
|PARENB
|PARODD
))
889 | (termios
.c_cflag
& (CLOCAL
|CSIZE
|CSTOPB
|PARENB
|PARODD
));
890 termios
.c_lflag
= (TLOCAL_DEF
& ~(ECHOE
|ECHOK
))
891 | (termios
.c_lflag
& (ECHOE
|ECHOK
));
892 if (termios
.c_lflag
& ICANON
) {
893 termios
.c_cc
[VMIN
]= TMIN_DEF
;
894 termios
.c_cc
[VTIME
]= TTIME_DEF
;
896 termios
.c_cc
[VEOF
]= TEOF_DEF
;
897 termios
.c_cc
[VEOL
]= TEOL_DEF
;
898 termios
.c_cc
[VERASE
]= TERASE_DEF
;
899 termios
.c_cc
[VINTR
]= TINTR_DEF
;
900 termios
.c_cc
[VKILL
]= TKILL_DEF
;
901 termios
.c_cc
[VQUIT
]= TQUIT_DEF
;
902 termios
.c_cc
[VSUSP
]= TSUSP_DEF
;
904 termios
.c_cc
[VREPRINT
]= TREPRINT_DEF
;
905 termios
.c_cc
[VLNEXT
]= TLNEXT_DEF
;
906 termios
.c_cc
[VDISCARD
]= TDISCARD_DEF
;
908 termios
.c_cc
[VSTART
]= TSTART_DEF
;
909 termios
.c_cc
[VSTOP
]= TSTOP_DEF
;
910 if (!(termios
.c_lflag
& ICANON
)) {
911 termios
.c_cc
[VMIN
]= TMIN_DEF
;
912 termios
.c_cc
[VTIME
]= TTIME_DEF
;
918 if (match(opt
, "cols"))
920 num
= strtol(next
, &check
, 0);
921 if (check
[0] != '\0')
923 fprintf(stderr
, "%s: illegal parameter to cols: '%s'\n",
931 if (match(opt
, "rows"))
933 num
= strtol(next
, &check
, 0);
934 if (check
[0] != '\0')
936 fprintf(stderr
, "%s: illegal parameter to rows: '%s'\n",
944 if (match(opt
, "xpixels"))
946 num
= strtol(next
, &check
, 0);
947 if (check
[0] != '\0')
949 fprintf(stderr
, "%s: illegal parameter to xpixels: '%s'\n",
953 winsize
.ws_xpixel
= num
;
957 if (match(opt
, "ypixels"))
959 num
= strtol(next
, &check
, 0);
960 if (check
[0] != '\0')
962 fprintf(stderr
, "%s: illegal parameter to ypixels: '%s'\n",
966 winsize
.ws_ypixel
= num
;
971 fprintf(stderr
, "%s: unknown mode: %s\n", prog_name
, opt
);
980 if (*s1
== 0 && *s2
== 0) return(1);
981 if (*s1
== 0 || *s2
== 0) return (0);
982 if (*s1
!= *s2
) return (0);
992 printf("^%c", 'A' + c
- 1);
1021 { B115200
, 115200 },
1023 { B230400
, 230400 },
1026 { B460800
, 460800 },
1029 { B921600
, 921600 },
1034 speed_t
long2speed(num
)
1039 for (sp
= s2s
; sp
< s2s
+ (sizeof(s2s
) / sizeof(s2s
[0])); sp
++) {
1040 if (sp
->ns
== num
) return sp
->ts
;
1045 long speed2long(speed
)
1046 unsigned long speed
;
1050 for (sp
= s2s
; sp
< s2s
+ (sizeof(s2s
) / sizeof(s2s
[0])); sp
++) {
1051 if (sp
->ts
== speed
) return sp
->ns
;
1056 void print_flags(flags
, flag
, def
, string
, all
)
1057 unsigned long flags
;
1063 if (!(flags
& flag
))
1065 if (all
|| (def
& flag
))
1070 if (all
|| !(def
& flag
))
1080 if (column
+ len
+ 3 >= max_column
)
1094 void do_print_char(chr
, def
, name
, all
)
1102 if (!all
&& chr
== def
)
1105 #ifdef _POSIX_VDISABLE
1106 if (chr
== _POSIX_VDISABLE
)
1107 sprintf(line
, "%s = <undef>", name
);
1111 sprintf(line
, "%s = ^%c", name
, chr
+ '@');
1112 else if (chr
== 127)
1113 sprintf(line
, "%s = ^?", name
);
1115 sprintf(line
, "%s = %c", name
, chr
);
1119 void do_print_num(num
, def
, name
, all
)
1127 if (!all
&& num
== def
)
1129 sprintf(line
, "%s = %u", name
, num
);
1133 void set_saved_settings(opt
)
1138 tcflag_t c_oflag
, c_cflag
, c_lflag
, c_iflag
;
1140 speed_t ispeed
, ospeed
;
1144 num
= strtol(check
+1, &check
, 16);
1145 if (check
[0] != ':')
1147 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1152 num
= strtol(check
+1, &check
, 16);
1153 if (check
[0] != ':')
1155 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1160 num
= strtol(check
+1, &check
, 16);
1161 if (check
[0] != ':')
1163 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1168 num
= strtol(check
+1, &check
, 16);
1169 if (check
[0] != ':')
1171 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1176 num
= strtol(check
+1, &check
, 16);
1177 if (check
[0] != ':')
1179 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1184 num
= strtol(check
+1, &check
, 16);
1185 if (check
[0] != ':')
1187 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1192 for(i
=0; i
<NCCS
; i
++)
1194 num
= strtol(check
+1, &check
, 16);
1195 if (check
[0] != ':')
1197 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1202 if (check
[1] != '\0')
1204 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1207 termios
.c_iflag
= c_iflag
;
1208 termios
.c_oflag
= c_oflag
;
1209 termios
.c_cflag
= c_cflag
;
1210 termios
.c_lflag
= c_lflag
;
1212 cfsetispeed(&termios
, ispeed
);
1213 cfsetospeed(&termios
, ospeed
);
1215 for(i
=0; i
<NCCS
; i
++)
1216 termios
.c_cc
[i
]= c_cc
[i
];
1219 void set_control(option
, value
)
1225 if (match(value
, "undef") || match(value
, "^-")) {
1226 #ifdef _POSIX_VDISABLE
1227 chr
= _POSIX_VDISABLE
;
1230 "stty: unable to set option to _POSIX_VDISABLE\n");
1233 } else if (match(value
, "^?"))
1235 else if (strlen(value
) == 2 && value
[0] == '^') {
1236 chr
= toupper(value
[1]) - '@';
1237 if (chr
< 0 || chr
>= 32) {
1238 fprintf(stderr
, "stty: illegal option value: '%s'\n",
1242 } else if (strlen(value
) == 1)
1245 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1249 assert(option
>= 0 && option
< NCCS
);
1250 termios
.c_cc
[option
]= chr
;
1253 void set_min_tim(option
, value
)
1260 num
= strtol(value
, &check
, 0);
1261 if (check
[0] != '\0') {
1262 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1266 if ((cc_t
)num
!= num
) {
1267 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1270 assert(option
>= 0 && option
< NCCS
);
1271 termios
.c_cc
[option
]= num
;
1275 * $PchId: stty.c,v 1.7 2001/05/02 15:04:42 philip Exp $