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>
23 /* Default settings, the Minix ones are defined in <termios.h> */
26 #define TCTRL_DEF (PARENB | CREAD | CS7)
30 #define TSPEED_DEF B1200
34 #define TINPUT_DEF (BRKINT | IGNPAR | ISTRIP | ICRNL)
38 #define TOUTPUT_DEF OPOST
42 #define TLOCAL_DEF (ISIG | IEXTEN | ICANON | ECHO | ECHOE)
46 #define TEOF_DEF '\4' /* ^D */
49 #ifdef _POSIX_VDISABLE
50 #define TEOL_DEF _POSIX_VDISABLE
56 #define TERASE_DEF '\10' /* ^H */
59 #define TINTR_DEF '\177' /* ^? */
62 #define TKILL_DEF '\25' /* ^U */
65 #define TQUIT_DEF '\34' /* ^\ */
68 #define TSUSP_DEF '\32' /* ^Z */
71 #define TSTART_DEF '\21' /* ^Q */
74 #define TSTOP_DEF '\23' /* ^S */
86 struct termios termios
;
87 int column
= 0, max_column
=80; /* Assume 80 character terminals. */
89 struct winsize winsize
;
93 #define PROTO(a) _ARGS(a)
98 void main
PROTO(( int argc
, char **argv
));
99 void report
PROTO(( int flags
));
100 int option
PROTO(( char *opt
, char *next
));
101 int match
PROTO(( char *s1
, char *s2
));
102 void prctl
PROTO(( int c
));
103 speed_t long2speed
PROTO(( long num
));
104 long speed2long
PROTO(( unsigned long speed
));
105 void print_flags
PROTO(( unsigned long flags
, unsigned long flag
,
106 unsigned long def
, char *string
, int all
));
107 void output
PROTO(( char *s
));
108 void do_print_char
PROTO(( unsigned chr
, unsigned def
, char *name
, int all
));
109 void do_print_num
PROTO(( unsigned num
, unsigned def
, char *name
, int all
));
110 void set_saved_settings
PROTO(( char *opt
));
111 void set_control
PROTO(( int option
, char *value
));
112 void set_min_tim
PROTO(( int option
, char *value
));
114 #define print_char(c,d,n,a) (do_print_char((unsigned)(c),(unsigned)(d),(n),(a)))
115 #define print_num(m,d,n,a) (do_print_num((unsigned)(m),(unsigned)(d),(n),(a)))
117 void main(argc
, argv
)
126 /* Stty with no arguments just reports on current status. */
127 if (tcgetattr(0, &termios
) == -1)
129 fprintf(stderr
, "%s: can't read ioctl parameters from stdin: %s\n",
130 prog_name
, strerror(errno
));
134 if (ioctl(0, TIOCGWINSZ
, &winsize
) == -1)
136 fprintf(stderr
, "%s: can't get screen size from stdin: %s\n",
137 prog_name
, strerror(errno
));
140 if (winsize
.ws_col
!= 0)
141 max_column
= winsize
.ws_col
;
146 if (!strcmp(argv
[1], "-a"))
148 else if (!strcmp(argv
[1], "-g"))
151 if (argc
== 1 || flags
) {
156 /* Process the options specified. */
157 for (k
= 1; k
< argc
; k
++)
158 k
+= option(argv
[k
], k
+1 < argc
? argv
[k
+1] : "");
161 if (ioctl(0, TIOCSWINSZ
, &winsize
) == -1)
163 fprintf(stderr
, "%s: can't set screen size to stdin: %s\n",
164 prog_name
, strerror(errno
));
168 if (tcsetattr(0, TCSANOW
, &termios
) == -1)
170 fprintf(stderr
, "%s: can't set terminal parameters to stdin: %s\n",
171 prog_name
, strerror(errno
));
183 tcflag_t c_cflag
, c_iflag
, c_oflag
, c_lflag
;
185 speed_t ispeed
, ospeed
;
188 { /* We have to write the termios structure in a encoded form
191 printf(":%x:%x:%x:%x:%x:%x", termios
.c_iflag
, termios
.c_oflag
,
192 termios
.c_cflag
, termios
.c_lflag
, cfgetispeed(&termios
),
193 cfgetospeed(&termios
));
194 for (i
= 0; i
<NCCS
; i
++)
195 printf(":%x", termios
.c_cc
[i
]);
202 /* Start with the baud rate. */
203 ispeed
= cfgetispeed(&termios
);
204 ospeed
= cfgetospeed(&termios
);
205 if (ispeed
!= ospeed
)
207 sprintf(line
, "ispeed %lu baud; ospeed %lu baud;",
208 speed2long(ispeed
), speed2long(ospeed
));
211 else if (all
|| ospeed
!= TSPEED_DEF
)
213 sprintf(line
, "speed %lu baud;", speed2long(ospeed
));
217 /* The control modes. */
219 c_cflag
= termios
.c_cflag
;
220 if (all
|| (c_cflag
& CSIZE
) != (TCTRL_DEF
& CSIZE
))
222 switch (c_cflag
& CSIZE
)
224 case CS5
: output("cs5"); break;
225 case CS6
: output("cs6"); break;
226 case CS7
: output("cs7"); break;
227 case CS8
: output("cs8"); break;
228 default: output("cs??"); break;
231 print_flags(c_cflag
, PARENB
, TCTRL_DEF
, "-parenb", all
);
232 print_flags(c_cflag
, PARODD
, TCTRL_DEF
, "-parodd", all
);
233 print_flags(c_cflag
, HUPCL
, TCTRL_DEF
, "-hupcl", all
);
234 print_flags(c_cflag
, CSTOPB
, TCTRL_DEF
, "-cstopb", all
);
235 print_flags(c_cflag
, CREAD
, TCTRL_DEF
, "-cread", all
);
236 print_flags(c_cflag
, CLOCAL
, TCTRL_DEF
, "-clocal", all
);
244 /* The input flags. */
246 c_iflag
= termios
.c_iflag
;
248 print_flags(c_iflag
, IGNBRK
, TINPUT_DEF
, "-ignbrk", all
);
249 print_flags(c_iflag
, BRKINT
, TINPUT_DEF
, "-brkint", all
);
250 print_flags(c_iflag
, IGNPAR
, TINPUT_DEF
, "-ignpar", all
);
251 print_flags(c_iflag
, PARMRK
, TINPUT_DEF
, "-parmrk", all
);
252 print_flags(c_iflag
, INPCK
, TINPUT_DEF
, "-inpck", all
);
253 print_flags(c_iflag
, ISTRIP
, TINPUT_DEF
, "-istrip", all
);
254 print_flags(c_iflag
, INLCR
, TINPUT_DEF
, "-inlcr", all
);
255 print_flags(c_iflag
, IGNCR
, TINPUT_DEF
, "-igncr", all
);
256 print_flags(c_iflag
, ICRNL
, TINPUT_DEF
, "-icrnl", all
);
257 print_flags(c_iflag
, IXON
, TINPUT_DEF
, "-ixon", all
);
258 print_flags(c_iflag
, IXOFF
, TINPUT_DEF
, "-ixoff", all
);
259 print_flags(c_iflag
, IXANY
, TINPUT_DEF
, "-ixany", all
);
267 /* The output flags. */
269 c_oflag
= termios
.c_oflag
;
271 print_flags(c_oflag
, OPOST
, TOUTPUT_DEF
, "-opost", all
);
273 print_flags(c_oflag
, ONLCR
, TOUTPUT_DEF
, "-onlcr", all
);
274 print_flags(c_oflag
, XTABS
, TOUTPUT_DEF
, "-xtabs", all
);
275 print_flags(c_oflag
, ONOEOT
, TOUTPUT_DEF
, "-onoeot", all
);
283 /* The local flags. */
285 c_lflag
= termios
.c_lflag
;
287 print_flags(c_lflag
, ISIG
, TLOCAL_DEF
, "-isig", all
);
288 print_flags(c_lflag
, ICANON
, TLOCAL_DEF
, "-icanon", all
);
289 print_flags(c_lflag
, IEXTEN
, TLOCAL_DEF
, "-iexten", all
);
290 print_flags(c_lflag
, ECHO
, TLOCAL_DEF
, "-echo", all
);
291 print_flags(c_lflag
, ECHOE
, TLOCAL_DEF
, "-echoe", all
);
292 print_flags(c_lflag
, ECHOK
, TLOCAL_DEF
, "-echok", all
);
293 print_flags(c_lflag
, ECHONL
, TLOCAL_DEF
, "-echonl", all
);
294 print_flags(c_lflag
, NOFLSH
, TLOCAL_DEF
, "-noflsh", all
);
296 print_flags(c_lflag
, TOSTOP
, TLOCAL_DEF
, "-tostop", all
);
299 print_flags(c_lflag
, LFLUSHO
, TLOCAL_DEF
, "-lflusho", all
);
308 /* The special control characters. */
310 print_char(termios
.c_cc
[VEOF
], TEOF_DEF
, "eof", all
);
311 print_char(termios
.c_cc
[VEOL
], TEOL_DEF
, "eol", all
);
312 print_char(termios
.c_cc
[VERASE
], TERASE_DEF
, "erase", all
);
313 print_char(termios
.c_cc
[VINTR
], TINTR_DEF
, "intr", all
);
314 print_char(termios
.c_cc
[VKILL
], TKILL_DEF
, "kill", all
);
315 print_char(termios
.c_cc
[VQUIT
], TQUIT_DEF
, "quit", all
);
316 print_char(termios
.c_cc
[VSUSP
], TSUSP_DEF
, "susp", all
);
317 print_char(termios
.c_cc
[VSTART
], TSTART_DEF
, "start", all
);
318 print_char(termios
.c_cc
[VSTOP
], TSTOP_DEF
, "stop", all
);
320 print_char(termios
.c_cc
[VREPRINT
], TREPRINT_DEF
, "rprnt", all
);
321 print_char(termios
.c_cc
[VLNEXT
], TLNEXT_DEF
, "lnext", all
);
322 print_char(termios
.c_cc
[VDISCARD
], TDISCARD_DEF
, "flush", all
);
324 print_num(termios
.c_cc
[VMIN
], TMIN_DEF
, "min", all
);
325 print_num(termios
.c_cc
[VTIME
], TTIME_DEF
, "time", all
);
334 if (all
|| winsize
.ws_row
!= 0 || winsize
.ws_col
!= 0)
336 sprintf(line
, "%d rows %d columns", winsize
.ws_row
,
341 if (all
|| winsize
.ws_ypixel
!= 0 || winsize
.ws_xpixel
!= 0)
343 sprintf(line
, "%d ypixels %d xpixels", winsize
.ws_ypixel
,
362 int option(opt
, next
)
369 /* The control options. */
371 if (match(opt
, "clocal")) {
372 termios
.c_cflag
|= CLOCAL
;
375 if (match(opt
, "-clocal")) {
376 termios
.c_cflag
&= ~CLOCAL
;
380 if (match(opt
, "cread")) {
381 termios
.c_cflag
|= CREAD
;
384 if (match(opt
, "-cread")) {
385 termios
.c_cflag
&= ~CREAD
;
389 if (match(opt
, "cs5")) {
390 termios
.c_cflag
&= ~CSIZE
;
391 termios
.c_cflag
|= CS5
;
394 if (match(opt
, "cs6")) {
395 termios
.c_cflag
&= ~CSIZE
;
396 termios
.c_cflag
|= CS6
;
399 if (match(opt
, "cs7")) {
400 termios
.c_cflag
&= ~CSIZE
;
401 termios
.c_cflag
|= CS7
;
404 if (match(opt
, "cs8")) {
405 termios
.c_cflag
&= ~CSIZE
;
406 termios
.c_cflag
|= CS8
;
410 if (match(opt
, "cstopb")) {
411 termios
.c_cflag
|= CSTOPB
;
414 if (match(opt
, "-cstopb")) {
415 termios
.c_cflag
&= ~CSTOPB
;
419 if (match(opt
, "hupcl") || match(opt
, "hup")) {
420 termios
.c_cflag
|= HUPCL
;
423 if (match(opt
, "-hupcl") || match(opt
, "-hup")) {
424 termios
.c_cflag
&= ~HUPCL
;
428 if (match(opt
, "parenb")) {
429 termios
.c_cflag
|= PARENB
;
432 if (match(opt
, "-parenb")) {
433 termios
.c_cflag
&= ~PARENB
;
437 if (match(opt
, "parodd")) {
438 termios
.c_cflag
|= PARODD
;
441 if (match(opt
, "-parodd")) {
442 termios
.c_cflag
&= ~PARODD
;
446 num
= strtol(opt
, &check
, 10);
447 if (check
[0] == '\0')
449 speed
= long2speed(num
);
450 if (speed
== (speed_t
)-1)
452 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
, opt
);
456 cfsetispeed(&termios
, speed
);
457 cfsetospeed(&termios
, speed
);
461 if (match(opt
, "ispeed")) {
462 num
= strtol(next
, &check
, 10);
465 speed
= long2speed(num
);
466 if (speed
== (speed_t
)-1)
468 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
,
472 cfsetispeed(&termios
, speed
);
477 fprintf(stderr
, "%s: invalid argument to ispeed: '%s'\n",
483 if (match(opt
, "ospeed")) {
484 num
= strtol(next
, &check
, 10);
487 speed
= long2speed(num
);
488 if (speed
== (speed_t
)-1)
490 fprintf(stderr
, "%s: illegal speed: '%s'\n", prog_name
,
494 cfsetospeed(&termios
, speed
);
499 fprintf(stderr
, "%s: invalid argument to ospeed: %s\n",
507 if (match(opt
, "brkint")) {
508 termios
.c_iflag
|= BRKINT
;
511 if (match(opt
, "-brkint")) {
512 termios
.c_iflag
&= ~BRKINT
;
516 if (match(opt
, "icrnl")) {
517 termios
.c_iflag
|= ICRNL
;
520 if (match(opt
, "-icrnl")) {
521 termios
.c_iflag
&= ~ICRNL
;
525 if (match(opt
, "ignbrk")) {
526 termios
.c_iflag
|= IGNBRK
;
529 if (match(opt
, "-ignbrk")) {
530 termios
.c_iflag
&= ~IGNBRK
;
534 if (match(opt
, "igncr")) {
535 termios
.c_iflag
|= IGNCR
;
538 if (match(opt
, "-igncr")) {
539 termios
.c_iflag
&= ~IGNCR
;
543 if (match(opt
, "ignpar")) {
544 termios
.c_iflag
|= IGNPAR
;
547 if (match(opt
, "-ignpar")) {
548 termios
.c_iflag
&= ~IGNPAR
;
552 if (match(opt
, "inlcr")) {
553 termios
.c_iflag
|= INLCR
;
556 if (match(opt
, "-inlcr")) {
557 termios
.c_iflag
&= ~INLCR
;
561 if (match(opt
, "inpck")) {
562 termios
.c_iflag
|= INPCK
;
565 if (match(opt
, "-inpck")) {
566 termios
.c_iflag
&= ~INPCK
;
570 if (match(opt
, "istrip")) {
571 termios
.c_iflag
|= ISTRIP
;
574 if (match(opt
, "-istrip")) {
575 termios
.c_iflag
&= ~ISTRIP
;
579 if (match(opt
, "ixoff")) {
580 termios
.c_iflag
|= IXOFF
;
583 if (match(opt
, "-ixoff")) {
584 termios
.c_iflag
&= ~IXOFF
;
588 if (match(opt
, "ixon")) {
589 termios
.c_iflag
|= IXON
;
592 if (match(opt
, "-ixon")) {
593 termios
.c_iflag
&= ~IXON
;
597 if (match(opt
, "parmrk")) {
598 termios
.c_iflag
|= PARMRK
;
601 if (match(opt
, "-parmrk")) {
602 termios
.c_iflag
&= ~PARMRK
;
606 if (match(opt
, "ixany")) {
607 termios
.c_iflag
|= IXANY
;
610 if (match(opt
, "-ixany")) {
611 termios
.c_iflag
&= ~IXANY
;
617 if (match(opt
, "opost")) {
618 termios
.c_oflag
|= OPOST
;
621 if (match(opt
, "-opost")) {
622 termios
.c_oflag
&= ~OPOST
;
626 if (match(opt
, "onlcr")) {
627 termios
.c_oflag
|= ONLCR
;
630 if (match(opt
, "-onlcr")) {
631 termios
.c_oflag
&= ~ONLCR
;
635 if (match(opt
, "xtabs")) {
636 termios
.c_oflag
|= XTABS
;
639 if (match(opt
, "-xtabs")) {
640 termios
.c_oflag
&= ~XTABS
;
644 if (match(opt
, "onoeot")) {
645 termios
.c_oflag
|= ONOEOT
;
648 if (match(opt
, "-onoeot")) {
649 termios
.c_oflag
&= ~ONOEOT
;
656 if (match(opt
, "echo")) {
657 termios
.c_lflag
|= ECHO
;
660 if (match(opt
, "-echo")) {
661 termios
.c_lflag
&= ~ECHO
;
665 if (match(opt
, "echoe")) {
666 termios
.c_lflag
|= ECHOE
;
669 if (match(opt
, "-echoe")) {
670 termios
.c_lflag
&= ~ECHOE
;
674 if (match(opt
, "echok")) {
675 termios
.c_lflag
|= ECHOK
;
678 if (match(opt
, "-echok")) {
679 termios
.c_lflag
&= ~ECHOK
;
683 if (match(opt
, "echonl")) {
684 termios
.c_lflag
|= ECHONL
;
687 if (match(opt
, "-echonl")) {
688 termios
.c_lflag
&= ~ECHONL
;
692 if (match(opt
, "icanon")) {
693 termios
.c_lflag
|= ICANON
;
696 if (match(opt
, "-icanon")) {
697 termios
.c_lflag
&= ~ICANON
;
701 if (match(opt
, "iexten")) {
702 termios
.c_lflag
|= IEXTEN
;
705 if (match(opt
, "-iexten")) {
706 termios
.c_lflag
&= ~IEXTEN
;
710 if (match(opt
, "isig")) {
711 termios
.c_lflag
|= ISIG
;
714 if (match(opt
, "-isig")) {
715 termios
.c_lflag
&= ~ISIG
;
719 if (match(opt
, "noflsh")) {
720 termios
.c_lflag
|= NOFLSH
;
723 if (match(opt
, "-noflsh")) {
724 termios
.c_lflag
&= ~NOFLSH
;
728 if (match(opt
, "tostop")) {
729 termios
.c_lflag
|= TOSTOP
;
732 if (match(opt
, "-tostop")) {
733 termios
.c_lflag
&= ~TOSTOP
;
738 if (match(opt
, "lflusho")) {
739 termios
.c_lflag
|= LFLUSHO
;
742 if (match(opt
, "-lflusho")) {
743 termios
.c_lflag
&= ~LFLUSHO
;
748 /* The special control characters. */
749 if (match(opt
, "eof")) {
750 set_control(VEOF
, next
);
754 if (match(opt
, "eol")) {
755 set_control(VEOL
, next
);
759 if (match(opt
, "erase")) {
760 set_control(VERASE
, next
);
764 if (match(opt
, "intr")) {
765 set_control(VINTR
, next
);
769 if (match(opt
, "kill")) {
770 set_control(VKILL
, next
);
774 if (match(opt
, "quit")) {
775 set_control(VQUIT
, next
);
779 if (match(opt
, "susp")) {
780 set_control(VSUSP
, next
);
784 if (match(opt
, "start")) {
785 set_control(VSTART
, next
);
789 if (match(opt
, "stop")) {
790 set_control(VSTOP
, next
);
794 if (match(opt
, "rprnt")) {
795 set_control(VREPRINT
, next
);
799 if (match(opt
, "lnext")) {
800 set_control(VLNEXT
, next
);
804 if (match(opt
, "flush")) {
805 set_control(VDISCARD
, next
);
810 if (match(opt
, "min")) {
811 set_min_tim(VMIN
, next
);
815 if (match(opt
, "time")) {
816 set_min_tim(VTIME
, next
);
823 set_saved_settings(opt
);
827 if (match(opt
, "cooked") || match(opt
, "raw")) {
828 int x
= opt
[0] == 'c' ? 1 : 0;
830 option(x
+ "-icrnl", ""); /* off in raw mode, on in cooked mode */
831 option(x
+ "-ixon", "");
832 option(x
+ "-opost", "");
833 option(x
+ "-onlcr", "");
834 option(x
+ "-isig", "");
835 option(x
+ "-icanon", "");
836 option(x
+ "-iexten", "");
837 option(x
+ "-echo", "");
841 if (match(opt
, "evenp") || match(opt
, "parity")) {
842 option("parenb", "");
844 option("-parodd", "");
848 if (match(opt
, "oddp")) {
849 option("parenb", "");
851 option("parodd", "");
855 if (match(opt
, "-parity") || match(opt
, "-evenp") || match(opt
, "-oddp")) {
856 option("-parenb", "");
861 if (match(opt
, "nl")) {
866 if (match(opt
, "-nl")) {
867 option("-icrnl", "");
868 option("-inlcr", "");
869 option("-igncr", "");
873 if (match(opt
, "ek")) {
874 termios
.c_cc
[VERASE
]= TERASE_DEF
;;
875 termios
.c_cc
[VKILL
]= TKILL_DEF
;;
879 if (match(opt
, "sane"))
881 /* Reset all terminal attributes to a sane state, except things like
882 * line speed and parity, because it can't be known what their sane
885 termios
.c_iflag
= (TINPUT_DEF
& ~(IGNPAR
|ISTRIP
|INPCK
))
886 | (termios
.c_iflag
& (IGNPAR
|ISTRIP
|INPCK
));
887 termios
.c_oflag
= (TOUTPUT_DEF
& ~(XTABS
))
888 | (termios
.c_oflag
& (XTABS
));
889 termios
.c_cflag
= (TCTRL_DEF
& ~(CLOCAL
|CSIZE
|CSTOPB
|PARENB
|PARODD
))
890 | (termios
.c_cflag
& (CLOCAL
|CSIZE
|CSTOPB
|PARENB
|PARODD
));
891 termios
.c_lflag
= (TLOCAL_DEF
& ~(ECHOE
|ECHOK
))
892 | (termios
.c_lflag
& (ECHOE
|ECHOK
));
893 if (termios
.c_lflag
& ICANON
) {
894 termios
.c_cc
[VMIN
]= TMIN_DEF
;
895 termios
.c_cc
[VTIME
]= TTIME_DEF
;
897 termios
.c_cc
[VEOF
]= TEOF_DEF
;
898 termios
.c_cc
[VEOL
]= TEOL_DEF
;
899 termios
.c_cc
[VERASE
]= TERASE_DEF
;
900 termios
.c_cc
[VINTR
]= TINTR_DEF
;
901 termios
.c_cc
[VKILL
]= TKILL_DEF
;
902 termios
.c_cc
[VQUIT
]= TQUIT_DEF
;
903 termios
.c_cc
[VSUSP
]= TSUSP_DEF
;
905 termios
.c_cc
[VREPRINT
]= TREPRINT_DEF
;
906 termios
.c_cc
[VLNEXT
]= TLNEXT_DEF
;
907 termios
.c_cc
[VDISCARD
]= TDISCARD_DEF
;
909 termios
.c_cc
[VSTART
]= TSTART_DEF
;
910 termios
.c_cc
[VSTOP
]= TSTOP_DEF
;
911 if (!(termios
.c_lflag
& ICANON
)) {
912 termios
.c_cc
[VMIN
]= TMIN_DEF
;
913 termios
.c_cc
[VTIME
]= TTIME_DEF
;
919 if (match(opt
, "cols"))
921 num
= strtol(next
, &check
, 0);
922 if (check
[0] != '\0')
924 fprintf(stderr
, "%s: illegal parameter to cols: '%s'\n",
932 if (match(opt
, "rows"))
934 num
= strtol(next
, &check
, 0);
935 if (check
[0] != '\0')
937 fprintf(stderr
, "%s: illegal parameter to rows: '%s'\n",
945 if (match(opt
, "xpixels"))
947 num
= strtol(next
, &check
, 0);
948 if (check
[0] != '\0')
950 fprintf(stderr
, "%s: illegal parameter to xpixels: '%s'\n",
954 winsize
.ws_xpixel
= num
;
958 if (match(opt
, "ypixels"))
960 num
= strtol(next
, &check
, 0);
961 if (check
[0] != '\0')
963 fprintf(stderr
, "%s: illegal parameter to ypixels: '%s'\n",
967 winsize
.ws_ypixel
= num
;
972 fprintf(stderr
, "%s: unknown mode: %s\n", prog_name
, opt
);
981 if (*s1
== 0 && *s2
== 0) return(1);
982 if (*s1
== 0 || *s2
== 0) return (0);
983 if (*s1
!= *s2
) return (0);
993 printf("^%c", 'A' + c
- 1);
1022 { B115200
, 115200 },
1024 { B230400
, 230400 },
1027 { B460800
, 460800 },
1030 { B921600
, 921600 },
1035 speed_t
long2speed(num
)
1040 for (sp
= s2s
; sp
< s2s
+ (sizeof(s2s
) / sizeof(s2s
[0])); sp
++) {
1041 if (sp
->ns
== num
) return sp
->ts
;
1046 long speed2long(speed
)
1047 unsigned long speed
;
1051 for (sp
= s2s
; sp
< s2s
+ (sizeof(s2s
) / sizeof(s2s
[0])); sp
++) {
1052 if (sp
->ts
== speed
) return sp
->ns
;
1057 void print_flags(flags
, flag
, def
, string
, all
)
1058 unsigned long flags
;
1064 if (!(flags
& flag
))
1066 if (all
|| (def
& flag
))
1071 if (all
|| !(def
& flag
))
1081 if (column
+ len
+ 3 >= max_column
)
1095 void do_print_char(chr
, def
, name
, all
)
1103 if (!all
&& chr
== def
)
1106 #ifdef _POSIX_VDISABLE
1107 if (chr
== _POSIX_VDISABLE
)
1108 sprintf(line
, "%s = <undef>", name
);
1112 sprintf(line
, "%s = ^%c", name
, chr
+ '@');
1113 else if (chr
== 127)
1114 sprintf(line
, "%s = ^?", name
);
1116 sprintf(line
, "%s = %c", name
, chr
);
1120 void do_print_num(num
, def
, name
, all
)
1128 if (!all
&& num
== def
)
1130 sprintf(line
, "%s = %u", name
, num
);
1134 void set_saved_settings(opt
)
1139 tcflag_t c_oflag
, c_cflag
, c_lflag
, c_iflag
;
1141 speed_t ispeed
, ospeed
;
1145 num
= strtol(check
+1, &check
, 16);
1146 if (check
[0] != ':')
1148 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1153 num
= strtol(check
+1, &check
, 16);
1154 if (check
[0] != ':')
1156 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1161 num
= strtol(check
+1, &check
, 16);
1162 if (check
[0] != ':')
1164 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1169 num
= strtol(check
+1, &check
, 16);
1170 if (check
[0] != ':')
1172 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1177 num
= strtol(check
+1, &check
, 16);
1178 if (check
[0] != ':')
1180 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1185 num
= strtol(check
+1, &check
, 16);
1186 if (check
[0] != ':')
1188 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1193 for(i
=0; i
<NCCS
; i
++)
1195 num
= strtol(check
+1, &check
, 16);
1196 if (check
[0] != ':')
1198 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1203 if (check
[1] != '\0')
1205 fprintf(stderr
, "error in saved settings '%s'\n", opt
);
1208 termios
.c_iflag
= c_iflag
;
1209 termios
.c_oflag
= c_oflag
;
1210 termios
.c_cflag
= c_cflag
;
1211 termios
.c_lflag
= c_lflag
;
1213 cfsetispeed(&termios
, ispeed
);
1214 cfsetospeed(&termios
, ospeed
);
1216 for(i
=0; i
<NCCS
; i
++)
1217 termios
.c_cc
[i
]= c_cc
[i
];
1220 void set_control(option
, value
)
1226 if (match(value
, "undef") || match(value
, "^-")) {
1227 #ifdef _POSIX_VDISABLE
1228 chr
= _POSIX_VDISABLE
;
1231 "stty: unable to set option to _POSIX_VDISABLE\n");
1234 } else if (match(value
, "^?"))
1236 else if (strlen(value
) == 2 && value
[0] == '^') {
1237 chr
= toupper(value
[1]) - '@';
1238 if (chr
< 0 || chr
>= 32) {
1239 fprintf(stderr
, "stty: illegal option value: '%s'\n",
1243 } else if (strlen(value
) == 1)
1246 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1250 assert(option
>= 0 && option
< NCCS
);
1251 termios
.c_cc
[option
]= chr
;
1254 void set_min_tim(option
, value
)
1261 num
= strtol(value
, &check
, 0);
1262 if (check
[0] != '\0') {
1263 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1267 if ((cc_t
)num
!= num
) {
1268 fprintf(stderr
, "stty: illegal option value: '%s'\n", value
);
1271 assert(option
>= 0 && option
< NCCS
);
1272 termios
.c_cc
[option
]= num
;
1276 * $PchId: stty.c,v 1.7 2001/05/02 15:04:42 philip Exp $