Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/stty.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/coreutils/stty.c
r3232 r3621 33 33 34 34 #include "libbb.h" 35 #include "common_bufsiz.h" 35 36 36 37 #ifndef _POSIX_VDISABLE … … 247 248 /* Which member(s) of 'struct termios' a mode uses */ 248 249 enum { 249 /* Do NOT change the order or values, as mode_type_flag()250 * depends on them */251 250 control, input, output, local, combination 252 251 }; 252 static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode) 253 { 254 static const uint8_t tcflag_offsets[] ALIGN1 = { 255 offsetof(struct termios, c_cflag), /* control */ 256 offsetof(struct termios, c_iflag), /* input */ 257 offsetof(struct termios, c_oflag), /* output */ 258 offsetof(struct termios, c_lflag) /* local */ 259 }; 260 if (type <= local) { 261 return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]); 262 } 263 return NULL; 264 } 253 265 254 266 /* Flags for 'struct mode_info' */ … … 307 319 308 320 /* Mode names given on command line */ 309 static const char mode_name[] =321 static const char mode_name[] ALIGN1 = 310 322 MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 ) 311 323 MI_ENTRY("parity", combination, REV | OMIT, 0, 0 ) … … 670 682 671 683 /* Name given on command line */ 672 static const char control_name[] =684 static const char control_name[] ALIGN1 = 673 685 CI_ENTRY("intr", CINTR, VINTR ) 674 686 CI_ENTRY("quit", CQUIT, VQUIT ) … … 712 724 #define CI_ENTRY(n,s,o) { s, o }, 713 725 714 static const struct control_info control_info[] = {726 static const struct control_info control_info[] ALIGN2 = { 715 727 /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */ 716 728 CI_ENTRY("intr", CINTR, VINTR ) … … 765 777 char buf[10]; 766 778 } FIX_ALIASING; 767 #define G (*(struct globals*) &bb_common_bufsiz1)779 #define G (*(struct globals*)bb_common_bufsiz1) 768 780 #define INIT_G() do { \ 769 781 G.device_name = bb_msg_standard_input; \ 770 782 G.max_col = 80; \ 771 783 } while (0) 772 773 774 /* Return a string that is the printable representation of character CH */775 /* Adapted from 'cat' by Torbjorn Granlund */776 static const char *visible(unsigned ch)777 {778 char *bpout = G.buf;779 780 if (ch == _POSIX_VDISABLE)781 return "<undef>";782 783 if (ch >= 128) {784 ch -= 128;785 *bpout++ = 'M';786 *bpout++ = '-';787 }788 789 if (ch < 32) {790 *bpout++ = '^';791 *bpout++ = ch + 64;792 } else if (ch < 127) {793 *bpout++ = ch;794 } else {795 *bpout++ = '^';796 *bpout++ = '?';797 }798 799 *bpout = '\0';800 return G.buf;801 }802 803 static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)804 {805 static const uint8_t tcflag_offsets[] ALIGN1 = {806 offsetof(struct termios, c_cflag), /* control */807 offsetof(struct termios, c_iflag), /* input */808 offsetof(struct termios, c_oflag), /* output */809 offsetof(struct termios, c_lflag) /* local */810 };811 812 if (type <= local) {813 return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);814 }815 return NULL;816 }817 784 818 785 static void set_speed_or_die(enum speed_setting type, const char *arg, … … 1043 1010 1044 1011 for (i = 0; i != CIDX_min; ++i) { 1012 char ch; 1045 1013 /* If swtch is the same as susp, don't print both */ 1046 1014 #if VSWTCH == VSUSP … … 1056 1024 } 1057 1025 #endif 1058 wrapf("%s = %s;", nth_string(control_name, i), 1059 visible(mode->c_cc[control_info[i].offset])); 1026 ch = mode->c_cc[control_info[i].offset]; 1027 if (ch == _POSIX_VDISABLE) 1028 strcpy(G.buf, "<undef>"); 1029 else 1030 visible(ch, G.buf, 0); 1031 wrapf("%s = %s;", nth_string(control_name, i), G.buf); 1060 1032 } 1061 1033 #if VEOF == VMIN … … 1073 1045 } 1074 1046 1075 bitsp = mode_type_flag(mode_info[i].type, mode);1047 bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); 1076 1048 mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; 1077 1049 if ((*bitsp & mask) == mode_info[i].bits) { … … 1092 1064 { 1093 1065 int i; 1094 tcflag_t *bitsp;1095 1066 1096 1067 for (i = 0; i < NUM_control_info; ++i) { … … 1103 1074 1104 1075 for (i = 0; i < NUM_mode_info; ++i) { 1076 tcflag_t val; 1077 tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); 1078 1079 if (!bitsp) 1080 continue; 1081 val = *bitsp & ~((unsigned long)mode_info[i].mask); 1105 1082 if (mode_info[i].flags & SANE_SET) { 1106 bitsp = mode_type_flag(mode_info[i].type, mode); 1107 *bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask)) 1108 | mode_info[i].bits; 1109 } else if (mode_info[i].flags & SANE_UNSET) { 1110 bitsp = mode_type_flag(mode_info[i].type, mode); 1111 *bitsp = *bitsp & ~((unsigned long)mode_info[i].mask) 1112 & ~mode_info[i].bits; 1083 *bitsp = val | mode_info[i].bits; 1084 } else 1085 if (mode_info[i].flags & SANE_UNSET) { 1086 *bitsp = val & ~mode_info[i].bits; 1113 1087 } 1114 1088 } … … 1120 1094 tcflag_t *bitsp; 1121 1095 1122 bitsp = mode_type_flag(info->type, mode);1096 bitsp = get_ptr_to_tcflag(info->type, mode); 1123 1097 1124 1098 if (bitsp) { 1099 tcflag_t val = *bitsp & ~info->mask; 1125 1100 if (reversed) 1126 *bitsp = *bitsp & ~info->mask& ~info->bits;1101 *bitsp = val & ~info->bits; 1127 1102 else 1128 *bitsp = (*bitsp & ~info->mask)| info->bits;1103 *bitsp = val | info->bits; 1129 1104 return; 1130 1105 } 1131 1106 1132 /* Combinationmode */1107 /* !bitsp - it's a "combination" mode */ 1133 1108 if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) { 1134 1109 if (reversed) … … 1430 1405 1431 1406 if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { 1432 get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);1407 G.max_col = get_terminal_width(STDOUT_FILENO); 1433 1408 output_func(&mode, display_all); 1434 1409 return EXIT_SUCCESS; … … 1535 1510 1536 1511 if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { 1537 #if CIBAUD 1512 /* 1513 * I think the below chunk is not necessary on Linux. 1514 * If you are deleting it, also delete STTY_speed_was_set bit - 1515 * it is only ever checked here. 1516 */ 1517 #if 0 /* was "if CIBAUD" */ 1538 1518 /* SunOS 4.1.3 (at least) has the problem that after this sequence, 1539 1519 tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
Note:
See TracChangeset
for help on using the changeset viewer.