1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2014, Joyent, Inc. All rights reserved.
*/
/*
* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
* All Rights Reserved
*
*/
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <sys/types.h>
#include <termio.h>
#include <sys/stermio.h>
#include <sys/termiox.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#ifdef EUC
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stropts.h>
#include <sys/eucioctl.h>
#include <sys/csiioctl.h>
#include <sys/stream.h>
#include <sys/termios.h>
#include <sys/ldterm.h>
#include <getwidth.h>
#endif /* EUC */
#include "stty.h"
extern const char *not_supported[];
extern char *getenv();
extern void exit();
extern void perror();
extern int get_ttymode();
extern int set_ttymode();
static char *STTY = "stty: ";
static int pitt = 0;
static struct termios cb;
static struct termio ocb; /* for non-streams devices */
static struct stio stio;
static struct termiox termiox;
static struct winsize winsize, owinsize;
static int term;
#ifdef EUC
static struct eucioc kwp;
static eucwidth_t wp;
static ldterm_cs_data_user_t cswp; /* User side codeset width data */
static ldterm_cs_data_user_t kcswp; /* Kernel side codeset width data */
static int invalid_ldterm_dat_file;
#endif /* EUC */
static void prmodes();
static void pramodes();
static void pit(unsigned char what, char *itsname, char *sep);
static void delay(int m, char *s);
static void prspeed(char *c, int s);
static void prencode();
int
main(int argc, char *argv[])
{
int i;
int fd;
char *s_arg, *sttyparse(); /* s_arg: ptr to mode to be set */
#ifdef EUC
char *lc;
char tmps[PATH_MAX];
#endif /* EUC */
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
#ifdef EUC
lc = setlocale(LC_CTYPE, (const char *)NULL);
if (lc) {
sprintf(tmps, _LDTERM_DAT_PATH, lc);
fd = open(tmps, O_RDONLY, 0);
if (fd != -1) {
if (read(fd, (void *)&cswp, sizeof (cswp)) <
sizeof (cswp)) {
(void) fprintf(stderr, gettext(
"cannot read entire %s file\n"), tmps);
exit(2);
}
(void) close(fd);
/*
* If the ldterm.dat contains invalid data or
* the current locale name is too long, we clear
* the 'cswp' and flag the invalid ldterm.dat since
* we are not going to use the data.
*/
if (cswp.version > LDTERM_DATA_VERSION ||
cswp.codeset_type < LDTERM_CS_TYPE_MIN ||
cswp.codeset_type > LDTERM_CS_TYPE_MAX ||
strlen(lc) >= MAXNAMELEN ||
(cswp.codeset_type == LDTERM_CS_TYPE_EUC &&
cswp.csinfo_num > LDTERM_CS_TYPE_EUC_MAX_SUBCS) ||
(cswp.codeset_type == LDTERM_CS_TYPE_PCCS &&
(cswp.csinfo_num < LDTERM_CS_TYPE_PCCS_MIN_SUBCS ||
cswp.csinfo_num > LDTERM_CS_TYPE_PCCS_MAX_SUBCS))) {
(void) memset((void *)&cswp, 0, sizeof (cswp));
invalid_ldterm_dat_file = 1;
} else {
(void) strcpy(cswp.locale_name, lc);
}
}
}
getwidth(&wp);
#endif /* EUC */
if ((term = get_ttymode(0, &ocb, &cb, &stio, &termiox, &winsize
#ifdef EUC
/* */, &kwp, &kcswp
#endif /* EUC */
/* */)) < 0) {
perror(STTY);
exit(2);
}
owinsize = winsize;
if (argc == 1) {
prmodes();
exit(0);
}
if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
switch (argv[1][1]) {
case 'a':
pramodes();
return (0);
case 'g':
prencode();
return (0);
case '-':
prmodes(); /* stty -- */
return (0);
default:
(void) fprintf(stderr, gettext(
"usage: stty [-a| -g]\n"));
(void) fprintf(stderr, gettext(
" stty [modes]\n"));
return (2);
}
if ((argc == 3) && (argv[1][0] == '-') && (argv[1][2] == '\0') &&
(argv[2][0] == '-') && (argv[2][1] == '-') && (argv[2][2] == '\0'))
switch (argv[1][1]) {
case 'a':
pramodes();
return (0);
case 'g':
prencode();
return (0);
default:
(void) fprintf(stderr, gettext(
"usage: stty [-a| -g]\n"));
(void) fprintf(stderr, gettext(
" stty [modes]\n"));
return (2);
}
if ((argc >= 3) && (argv[1][0] == '-') && (argv[1][1] == '-') &&
(argv[1][2] == '\0')) {
/* ignore -- */
--argc;
++argv;
}
if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize
#ifdef EUC
/* */, &wp, &kwp, &cswp, &kcswp
#endif /* EUC */
/* */)) {
char *s = s_arg;
if (*s == '-') s++;
for (i = 0; not_supported[i]; i++) {
if (strcmp(not_supported[i], s) == 0) {
(void) fprintf(stderr,
gettext(
"mode not supported on this device: %s\n"),
s_arg);
exit(2);
}
}
(void) fprintf(stderr, gettext("unknown mode: %s\n"), s_arg);
return (2);
}
if (set_ttymode(0, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize
#ifdef EUC
/* */, &kwp, &kcswp, invalid_ldterm_dat_file
#endif /* EUC */
/* */) == -1) {
perror(STTY);
return (2);
}
return (0);
}
void
prmodes(void) /* print modes, no options, argc is 1 */
{
int m;
if (!(term & ASYNC)) {
m = stio.imode;
if (m & IUCLC)
(void) printf("iuclc ");
else
(void) printf("-iuclc ");
m = stio.omode;
if (m & OLCUC)
(void) printf("olcuc ");
else
(void) printf("-olcuc ");
if (m & TAB3)
(void) printf("tab3 ");
m = stio.lmode;
if (m & XCASE)
(void) printf("xcase ");
else
(void) printf("-xcase ");
if (m & STFLUSH)
(void) printf("stflush ");
else
(void) printf("-stflush ");
if (m & STWRAP)
(void) printf("stwrap ");
else
(void) printf("-stwrap ");
if (m & STAPPL)
(void) printf("stappl ");
else
(void) printf("-stappl ");
(void) printf("\n");
}
if (term & ASYNC) {
m = cb.c_cflag;
if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
cfgetispeed(&cb) != cfgetospeed(&cb)) {
prspeed("ispeed ", cfgetispeed(&cb));
prspeed("ospeed ", cfgetospeed(&cb));
} else
prspeed("speed ", cfgetospeed(&cb));
if (m&PARENB) {
if ((m&PAREXT) && (term & TERMIOS)) {
if (m&PARODD)
(void) printf("markp ");
else
(void) printf("spacep ");
} else {
if (m&PARODD)
(void) printf("oddp ");
else
(void) printf("evenp ");
}
} else
(void) printf("-parity ");
if (((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8)))
(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
if (m&CSTOPB)
(void) printf("cstopb ");
if (m&HUPCL)
(void) printf("hupcl ");
if (!(m&CREAD))
(void) printf("-cread ");
if (m&CLOCAL)
(void) printf("clocal ");
if (m&LOBLK)
(void) printf("loblk ");
(void) printf("\n");
if (ocb.c_line != 0)
(void) printf(gettext("line = %d; "), ocb.c_line);
if (term & WINDOW) {
(void) printf(gettext("rows = %d; columns = %d;"),
winsize.ws_row, winsize.ws_col);
(void) printf(gettext(
" ypixels = %d; xpixels = %d;\n"),
winsize.ws_ypixel, winsize.ws_xpixel);
}
if ((cb.c_lflag&ICANON) == 0)
(void) printf(gettext("min = %d; time = %d;\n"),
cb.c_cc[VMIN], cb.c_cc[VTIME]);
if (cb.c_cc[VINTR] != CINTR)
pit(cb.c_cc[VINTR], "intr", "; ");
if (cb.c_cc[VQUIT] != CQUIT)
pit(cb.c_cc[VQUIT], "quit", "; ");
if (cb.c_cc[VERASE] != CERASE)
pit(cb.c_cc[VERASE], "erase", "; ");
if (cb.c_cc[VKILL] != CKILL)
pit(cb.c_cc[VKILL], "kill", "; ");
if (cb.c_cc[VEOF] != CEOF)
pit(cb.c_cc[VEOF], "eof", "; ");
if (cb.c_cc[VEOL] != CNUL)
pit(cb.c_cc[VEOL], "eol", "; ");
if (cb.c_cc[VEOL2] != CNUL)
pit(cb.c_cc[VEOL2], "eol2", "; ");
if (cb.c_cc[VSWTCH] != CSWTCH)
pit(cb.c_cc[VSWTCH], "swtch", "; ");
if (term & TERMIOS) {
if (cb.c_cc[VSTART] != CSTART)
pit(cb.c_cc[VSTART], "start", "; ");
if (cb.c_cc[VSTOP] != CSTOP)
pit(cb.c_cc[VSTOP], "stop", "; ");
if (cb.c_cc[VSUSP] != CSUSP)
pit(cb.c_cc[VSUSP], "susp", "; ");
if (cb.c_cc[VDSUSP] != CDSUSP)
pit(cb.c_cc[VDSUSP], "dsusp", "; ");
if (cb.c_cc[VREPRINT] != CRPRNT)
pit(cb.c_cc[VREPRINT], "rprnt", "; ");
if (cb.c_cc[VDISCARD] != CFLUSH)
pit(cb.c_cc[VDISCARD], "flush", "; ");
if (cb.c_cc[VWERASE] != CWERASE)
pit(cb.c_cc[VWERASE], "werase", "; ");
if (cb.c_cc[VLNEXT] != CLNEXT)
pit(cb.c_cc[VLNEXT], "lnext", "; ");
if (cb.c_cc[VSTATUS] != CSTATUS)
pit(cb.c_cc[VSTATUS], "status", "; ");
}
if (pitt) (void) printf("\n");
m = cb.c_iflag;
if (m&IGNBRK)
(void) printf("ignbrk ");
else if (m&BRKINT)
(void) printf("brkint ");
if (!(m&INPCK))
(void) printf("-inpck ");
else if (m&IGNPAR)
(void) printf("ignpar ");
if (m&PARMRK)
(void) printf("parmrk ");
if (!(m&ISTRIP))
(void) printf("-istrip ");
if (m&INLCR)
(void) printf("inlcr ");
if (m&IGNCR)
(void) printf("igncr ");
if (m&ICRNL)
(void) printf("icrnl ");
if (m&IUCLC)
(void) printf("iuclc ");
if (!(m&IXON))
(void) printf("-ixon ");
else if (!(m&IXANY))
(void) printf("-ixany ");
if (m&IXOFF)
(void) printf("ixoff ");
if ((term & TERMIOS) && (m&IMAXBEL))
(void) printf("imaxbel ");
m = cb.c_oflag;
if (!(m&OPOST))
(void) printf("-opost ");
else {
if (m&OLCUC)
(void) printf("olcuc ");
if (m&ONLCR)
(void) printf("onlcr ");
if (m&OCRNL)
(void) printf("ocrnl ");
if (m&ONOCR)
(void) printf("onocr ");
if (m&ONLRET)
(void) printf("onlret ");
if (m&OFILL)
if (m&OFDEL)
(void) printf("del-fill ");
else
(void) printf("nul-fill ");
delay((m&CRDLY)/CR1, "cr");
delay((m&NLDLY)/NL1, "nl");
delay((m&TABDLY)/TAB1, "tab");
delay((m&BSDLY)/BS1, "bs");
delay((m&VTDLY)/VT1, "vt");
delay((m&FFDLY)/FF1, "ff");
}
(void) printf("\n");
m = cb.c_lflag;
if (!(m&ISIG))
(void) printf("-isig ");
if (!(m&ICANON))
(void) printf("-icanon ");
if (m&XCASE)
(void) printf("xcase ");
(void) printf("-echo "+((m&ECHO) != 0));
(void) printf("-echoe "+((m&ECHOE) != 0));
(void) printf("-echok "+((m&ECHOK) != 0));
if (m&ECHONL)
(void) printf("echonl ");
if (m&NOFLSH)
(void) printf("noflsh ");
if (m&TOSTOP)
(void) printf("tostop ");
if (m&ECHOCTL)
(void) printf("echoctl ");
if (m&ECHOPRT)
(void) printf("echoprt ");
if (m&ECHOKE)
(void) printf("echoke ");
if (m&DEFECHO)
(void) printf("defecho ");
if (m&FLUSHO)
(void) printf("flusho ");
if (m&PENDIN)
(void) printf("pendin ");
if (m&IEXTEN)
(void) printf("iexten ");
(void) printf("\n");
}
if (term & FLOW) {
m = termiox.x_hflag;
if (m & RTSXOFF)
(void) printf("rtsxoff ");
if (m & CTSXON)
(void) printf("ctsxon ");
if (m & DTRXOFF)
(void) printf("dtrxoff ");
if (m & CDXON)
(void) printf("cdxon ");
if (m & ISXOFF)
(void) printf("isxoff ");
m = termiox.x_cflag;
switch (m & XMTCLK) {
case XCIBRG: (void)printf("xcibrg ");
break;
case XCTSET: (void)printf("xctset ");
break;
case XCRSET: (void)printf("xcrset ");
}
switch (m & RCVCLK) {
case RCIBRG: (void)printf("rcibrg ");
break;
case RCTSET: (void)printf("rctset ");
break;
case RCRSET: (void)printf("rcrset ");
}
switch (m & TSETCLK) {
case TSETCOFF: (void)printf("tsetcoff ");
break;
case TSETCRBRG: (void)printf("tsetcrbrg ");
break;
case TSETCTBRG: (void)printf("tsetctbrg ");
break;
case TSETCTSET: (void)printf("tsetctset ");
break;
case TSETCRSET: (void)printf("tsetcrset ");
}
switch (m & RSETCLK) {
case RSETCOFF: (void)printf("rsetcoff ");
break;
case RSETCRBRG: (void)printf("rsetcrbrg ");
break;
case RSETCTBRG: (void)printf("rsetctbrg ");
break;
case RSETCTSET: (void)printf("rsetctset ");
break;
case RSETCRSET: (void)printf("rsetcrset ");
}
(void) printf("\n");
}
}
void
pramodes(void) /* print all modes, -a option */
{
int m;
m = cb.c_cflag;
if (term & ASYNC) {
if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
cfgetispeed(&cb) != cfgetospeed(&cb)) {
prspeed("ispeed ", cfgetispeed(&cb));
prspeed("ospeed ", cfgetospeed(&cb));
} else
prspeed("speed ", cfgetospeed(&cb));
if (!(term & TERMIOS))
(void) printf(gettext("line = %d; "), ocb.c_line);
(void) printf("\n");
if (term & WINDOW) {
(void) printf(gettext("rows = %d; columns = %d;"),
winsize.ws_row, winsize.ws_col);
(void) printf(gettext(
" ypixels = %d; xpixels = %d;\n"),
winsize.ws_ypixel, winsize.ws_xpixel);
}
#ifdef EUC
if ((term & CSIW) && kcswp.locale_name[0]) {
(void) printf("csdata %s\n", kcswp.locale_name);
} else {
(void) printf("csdata ?\n");
}
/*
* If kwp.eucw[0] is zero, it means the current codeset type
* in the ldterm is not EUC.
*/
if ((term & EUCW) && kwp.eucw[0]) {
(void) printf("eucw %d:%d:%d:%d, ", kwp.eucw[0],
kwp.eucw[1], kwp.eucw[2], kwp.eucw[3]);
(void) printf("scrw %d:%d:%d:%d\n", kwp.scrw[0],
kwp.scrw[1], kwp.scrw[2], kwp.scrw[3]);
} else
(void) printf("eucw ?, scrw ?\n");
#endif /* EUC */
if ((cb.c_lflag&ICANON) == 0)
(void) printf(gettext("min = %d; time = %d;\n"),
cb.c_cc[VMIN], cb.c_cc[VTIME]);
pit(cb.c_cc[VINTR], "intr", "; ");
pit(cb.c_cc[VQUIT], "quit", "; ");
pit(cb.c_cc[VERASE], "erase", "; ");
pit(cb.c_cc[VKILL], "kill", ";\n");
pit(cb.c_cc[VEOF], "eof", "; ");
pit(cb.c_cc[VEOL], "eol", "; ");
pit(cb.c_cc[VEOL2], "eol2", "; ");
pit(cb.c_cc[VSWTCH], "swtch", ";\n");
if (term & TERMIOS) {
pit(cb.c_cc[VSTART], "start", "; ");
pit(cb.c_cc[VSTOP], "stop", "; ");
pit(cb.c_cc[VSUSP], "susp", "; ");
pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
pit(cb.c_cc[VREPRINT], "rprnt", "; ");
pit(cb.c_cc[VDISCARD], "flush", "; ");
pit(cb.c_cc[VWERASE], "werase", "; ");
pit(cb.c_cc[VLNEXT], "lnext", ";\n");
pit(cb.c_cc[VSTATUS], "status", ";\n");
}
} else
pit((unsigned)stio.tab, "ctab", "\n");
m = cb.c_cflag;
(void) printf("-parenb "+((m&PARENB) != 0));
(void) printf("-parodd "+((m&PARODD) != 0));
(void) printf("cs%c ", '5'+(m&CSIZE)/CS6);
(void) printf("-cstopb "+((m&CSTOPB) != 0));
(void) printf("-hupcl "+((m&HUPCL) != 0));
(void) printf("-cread "+((m&CREAD) != 0));
(void) printf("-clocal "+((m&CLOCAL) != 0));
(void) printf("-loblk "+((m&LOBLK) != 0));
(void) printf("-crtscts "+((m&CRTSCTS) != 0));
(void) printf("-crtsxoff "+((m&CRTSXOFF) != 0));
if (term & TERMIOS)
(void) printf("-parext "+((m&PAREXT) != 0));
(void) printf("\n");
m = cb.c_iflag;
(void) printf("-ignbrk "+((m&IGNBRK) != 0));
(void) printf("-brkint "+((m&BRKINT) != 0));
(void) printf("-ignpar "+((m&IGNPAR) != 0));
(void) printf("-parmrk "+((m&PARMRK) != 0));
(void) printf("-inpck "+((m&INPCK) != 0));
(void) printf("-istrip "+((m&ISTRIP) != 0));
(void) printf("-inlcr "+((m&INLCR) != 0));
(void) printf("-igncr "+((m&IGNCR) != 0));
(void) printf("-icrnl "+((m&ICRNL) != 0));
(void) printf("-iuclc "+((m&IUCLC) != 0));
(void) printf("\n");
(void) printf("-ixon "+((m&IXON) != 0));
(void) printf("-ixany "+((m&IXANY) != 0));
(void) printf("-ixoff "+((m&IXOFF) != 0));
if (term & TERMIOS)
(void) printf("-imaxbel "+((m&IMAXBEL) != 0));
(void) printf("\n");
m = cb.c_lflag;
(void) printf("-isig "+((m&ISIG) != 0));
(void) printf("-icanon "+((m&ICANON) != 0));
(void) printf("-xcase "+((m&XCASE) != 0));
(void) printf("-echo "+((m&ECHO) != 0));
(void) printf("-echoe "+((m&ECHOE) != 0));
(void) printf("-echok "+((m&ECHOK) != 0));
(void) printf("-echonl "+((m&ECHONL) != 0));
(void) printf("-noflsh "+((m&NOFLSH) != 0));
if (term & TERMIOS) {
(void) printf("\n");
(void) printf("-tostop "+((m&TOSTOP) != 0));
(void) printf("-echoctl "+((m&ECHOCTL) != 0));
(void) printf("-echoprt "+((m&ECHOPRT) != 0));
(void) printf("-echoke "+((m&ECHOKE) != 0));
(void) printf("-defecho "+((m&DEFECHO) != 0));
(void) printf("-flusho "+((m&FLUSHO) != 0));
(void) printf("-pendin "+((m&PENDIN) != 0));
(void) printf("-iexten "+((m&IEXTEN) != 0));
}
if (!(term & ASYNC)) {
(void) printf("-stflush "+((m&STFLUSH) != 0));
(void) printf("-stwrap "+((m&STWRAP) != 0));
(void) printf("-stappl "+((m&STAPPL) != 0));
}
(void) printf("\n");
m = cb.c_oflag;
(void) printf("-opost "+((m&OPOST) != 0));
(void) printf("-olcuc "+((m&OLCUC) != 0));
(void) printf("-onlcr "+((m&ONLCR) != 0));
(void) printf("-ocrnl "+((m&OCRNL) != 0));
(void) printf("-onocr "+((m&ONOCR) != 0));
(void) printf("-onlret "+((m&ONLRET) != 0));
(void) printf("-ofill "+((m&OFILL) != 0));
(void) printf("-ofdel "+((m&OFDEL) != 0));
delay((m&CRDLY)/CR1, "cr");
delay((m&NLDLY)/NL1, "nl");
delay((m&TABDLY)/TAB1, "tab");
delay((m&BSDLY)/BS1, "bs");
delay((m&VTDLY)/VT1, "vt");
delay((m&FFDLY)/FF1, "ff");
(void) printf("\n");
if (term & FLOW) {
m = termiox.x_hflag;
(void) printf("-rtsxoff "+((m&RTSXOFF) != 0));
(void) printf("-ctsxon "+((m&CTSXON) != 0));
(void) printf("-dtrxoff "+((m&DTRXOFF) != 0));
(void) printf("-cdxon "+((m&CDXON) != 0));
(void) printf("-isxoff "+((m&ISXOFF) != 0));
m = termiox.x_cflag;
switch (m & XMTCLK) {
case XCIBRG: (void)printf("xcibrg ");
break;
case XCTSET: (void)printf("xctset ");
break;
case XCRSET: (void)printf("xcrset ");
}
switch (m & RCVCLK) {
case RCIBRG: (void)printf("rcibrg ");
break;
case RCTSET: (void)printf("rctset ");
break;
case RCRSET: (void)printf("rcrset ");
}
switch (m & TSETCLK) {
case TSETCOFF: (void)printf("tsetcoff ");
break;
case TSETCRBRG: (void)printf("tsetcrbrg ");
break;
case TSETCTBRG: (void)printf("tsetctbrg ");
break;
case TSETCTSET: (void)printf("tsetctset ");
break;
case TSETCRSET: (void)printf("tsetcrset ");
}
switch (m & RSETCLK) {
case RSETCOFF: (void)printf("rsetcoff ");
break;
case RSETCRBRG: (void)printf("rsetcrbrg ");
break;
case RSETCTBRG: (void)printf("rsetctbrg ");
break;
case RSETCTSET: (void)printf("rsetctset ");
break;
case RSETCRSET: (void)printf("rsetcrset ");
}
(void) printf("\n");
}
}
/* print function for prmodes() and pramodes() */
void
pit(unsigned char what, char *itsname, char *sep)
{
pitt++;
(void) printf("%s", itsname);
if ((term & TERMIOS) && what == _POSIX_VDISABLE ||
!(term & TERMIOS) && what == 0200) {
(void) printf(" = <undef>%s", sep);
return;
}
(void) printf(" = ");
if (what & 0200 && !isprint(what)) {
(void) printf("-");
what &= ~ 0200;
}
if (what == 0177) {
(void) printf("^?%s", sep);
return;
} else if (what < ' ') {
(void) printf("^");
what += '`';
if (what > 'z')
what -= 'a' -'A';
}
(void) printf("%c%s", what, sep);
}
void
delay(int m, char *s)
{
if (m)
(void) printf("%s%d ", s, m);
}
void
prspeed(char *c, int scode)
{
int sval = -1;
int i;
for (i = 0; speeds[i].string; i++) {
if (speeds[i].code == scode) {
sval = speeds[i].value;
break;
}
}
(void) printf("%s%d baud; ", c, sval);
}
/* print current settings for use with */
void
prencode(void) /* another stty cmd, used for -g option */
{
int i, last;
/*
* Although there are only 16 control chars defined as of April 1995,
* prencode() and encode() will not have to be changed if up to MAX_CC
* control chars are defined in the future. A maximum of MAX_CC rather
* than NCCS control chars are printed because the last control slot
* is unused. "stty -g" prints out a total of NUM_FIELDS fields
* (NUM_MODES modes + MAX_CC control chars). First print the input,
* output, control, and line discipline modes.
*/
(void) printf("%x:%x:%x:%x", cb.c_iflag, cb.c_oflag, cb.c_cflag,
cb.c_lflag);
/* Print the control character fields. */
if (term & TERMIOS)
last = MAX_CC;
else
last = NCC;
#ifdef EUC
if (term & CSIW) {
for (i = 0; i < MAX_CC; i++)
(void) printf(":%x", (i >= last) ? 0 : cb.c_cc[i]);
/*
* Print out ldterm_cs_data_user_t data fields for
* PSARC/1999/140 TCR2. This change introduces additional
* 44 fields that come from the ldterm_cs_data_user_t data
* structure.
*/
(void) printf(":%x:%x:%x:", kcswp.version, kcswp.codeset_type,
kcswp.csinfo_num);
if (*kcswp.locale_name == '\0') {
(void) printf("00");
} else {
for (i = 0; kcswp.locale_name[i] && i < MAXNAMELEN; i++)
(void) printf("%02x", kcswp.locale_name[i]);
}
for (i = 0; i < LDTERM_CS_MAX_CODESETS; i++)
(void) printf(":%x:%x:%x:%x",
kcswp.eucpc_data[i].byte_length,
kcswp.eucpc_data[i].screen_width,
kcswp.eucpc_data[i].msb_start,
kcswp.eucpc_data[i].msb_end);
} else {
#endif /* EUC */
for (i = 0; i < last; i++)
(void) printf(":%x", cb.c_cc[i]);
#ifdef EUC
}
#endif /* EUC */
(void) printf("\n");
}
|