static const char *get_spd(int flags, enum print_mode mode) { int idx; switch (flags & ASYNC_SPD_MASK) { case ASYNC_SPD_HI: idx = CMD_SPD_HI; break; case ASYNC_SPD_VHI: idx = CMD_SPD_VHI; break; case ASYNC_SPD_SHI: idx = CMD_SPD_SHI; break; case ASYNC_SPD_WARP: idx = CMD_SPD_WARP; break; case ASYNC_SPD_CUST: idx = CMD_SPD_CUST; break; default: if (mode < PRINT_FEDBACK) return NULL; idx = CMD_SPD_NORMAL; } return nth_string(commands, idx); }
static const char *uart_type(int type) { if (type > MAX_SERIAL_TYPE) return "undefined"; return nth_string(serial_types, type); }
const char* FAST_FUNC ll_proto_n2a(unsigned short id, char *buf, int len) { unsigned i; id = ntohs(id); for (i = 0; i < ARRAY_SIZE(llproto_ids); i++) { if (llproto_ids[i] == id) return nth_string(llproto_names, i); } snprintf(buf, len, "[%u]", id); return buf; }
static void print_serial_flags(int serial_flags, enum print_mode mode, const char *prefix, const char *postfix) { int i; const char *spd, *pr; pr = prefix; spd = get_spd(serial_flags, mode); if (spd) print_flag(&pr, spd); for (i = CMD_FLAG_FIRST; i <= CMD_FLAG_LAST; i++) { if ((serial_flags & setbits[i]) && (mode > PRINT_SUMMARY || !cmd_noprint(i)) ) { print_flag(&pr, nth_string(commands, i)); } } puts(pr == prefix ? "" : postfix); }
static void vlan_parse_opt(char **argv, struct nlmsghdr *n, unsigned int size) { static const char keywords[] ALIGN1 = "id\0" "protocol\0" "reorder_hdr\0" "gvrp\0" "mvrp\0" "loose_binding\0" ; static const char protocols[] ALIGN1 = "802.1q\0" "802.1ad\0" ; static const char str_on_off[] ALIGN1 = "on\0" "off\0" ; enum { ARG_id = 0, ARG_reorder_hdr, ARG_gvrp, ARG_mvrp, ARG_loose_binding, ARG_protocol, }; enum { PROTO_8021Q = 0, PROTO_8021AD, }; enum { PARM_on = 0, PARM_off }; int arg; uint16_t id, proto; struct ifla_vlan_flags flags = {}; while (*argv) { arg = index_in_substrings(keywords, *argv); if (arg < 0) invarg(*argv, "type vlan"); NEXT_ARG(); if (arg == ARG_id) { id = get_u16(*argv, "id"); addattr_l(n, size, IFLA_VLAN_ID, &id, sizeof(id)); } else if (arg == ARG_protocol) { arg = index_in_substrings(protocols, *argv); if (arg == PROTO_8021Q) proto = ETH_P_8021Q; else if (arg == PROTO_8021AD) proto = ETH_P_8021AD; else bb_error_msg_and_die("unknown VLAN encapsulation protocol '%s'", *argv); addattr_l(n, size, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto)); } else { int param = index_in_strings(str_on_off, *argv); if (param < 0) die_must_be_on_off(nth_string(keywords, arg)); if (arg == ARG_reorder_hdr) { flags.mask |= VLAN_FLAG_REORDER_HDR; flags.flags &= ~VLAN_FLAG_REORDER_HDR; if (param == PARM_on) flags.flags |= VLAN_FLAG_REORDER_HDR; } else if (arg == ARG_gvrp) { flags.mask |= VLAN_FLAG_GVRP; flags.flags &= ~VLAN_FLAG_GVRP; if (param == PARM_on) flags.flags |= VLAN_FLAG_GVRP; } else if (arg == ARG_mvrp) { flags.mask |= VLAN_FLAG_MVRP; flags.flags &= ~VLAN_FLAG_MVRP; if (param == PARM_on) flags.flags |= VLAN_FLAG_MVRP; } else { /*if (arg == ARG_loose_binding) */ flags.mask |= VLAN_FLAG_LOOSE_BINDING; flags.flags &= ~VLAN_FLAG_LOOSE_BINDING; if (param == PARM_on) flags.flags |= VLAN_FLAG_LOOSE_BINDING; } } argv++; } if (flags.mask) addattr_l(n, size, IFLA_VLAN_FLAGS, &flags, sizeof(flags)); }
static void do_display(const struct termios *mode, int all) { int i; tcflag_t *bitsp; unsigned long mask; int prev_type = control; display_speed(mode, 1); if (all) display_window_size(1); #ifdef __linux__ wrapf("line = %u;\n", mode->c_line); #else newline(); #endif for (i = 0; i != CIDX_min; ++i) { char ch; /* If swtch is the same as susp, don't print both */ #if VSWTCH == VSUSP if (i == CIDX_swtch) continue; #endif /* If eof uses the same slot as min, only print whichever applies */ #if VEOF == VMIN if (!(mode->c_lflag & ICANON) && (i == CIDX_eof || i == CIDX_eol) ) { continue; } #endif ch = mode->c_cc[control_info[i].offset]; if (ch == _POSIX_VDISABLE) strcpy(G.buf, "<undef>"); else visible(ch, G.buf, 0); wrapf("%s = %s;", nth_string(control_name, i), G.buf); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) #endif wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); newline(); for (i = 0; i < NUM_mode_info; ++i) { if (mode_info[i].flags & OMIT) continue; if (mode_info[i].type != prev_type) { newline(); prev_type = mode_info[i].type; } bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; if ((*bitsp & mask) == mode_info[i].bits) { if (all || (mode_info[i].flags & SANE_UNSET)) wrapf("-%s"+1, nth_string(mode_name, i)); } else { if ((all && mode_info[i].flags & REV) || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) ) { wrapf("-%s", nth_string(mode_name, i)); } } } newline(); }
int adjtimex_main(int argc UNUSED_PARAM, char **argv) { enum { OPT_quiet = 0x1 }; unsigned opt; char *opt_o, *opt_f, *opt_p, *opt_t; struct timex txc; int i, ret; const char *descript; opt_complementary = "=0"; /* no valid non-option parameters */ opt = getopt32(argv, "qo:f:p:t:", &opt_o, &opt_f, &opt_p, &opt_t); txc.modes = 0; //if (opt & 0x1) // -q if (opt & 0x2) { // -o txc.offset = xatol(opt_o); txc.modes |= ADJ_OFFSET_SINGLESHOT; } if (opt & 0x4) { // -f txc.freq = xatol(opt_f); txc.modes |= ADJ_FREQUENCY; } if (opt & 0x8) { // -p txc.constant = xatol(opt_p); txc.modes |= ADJ_TIMECONST; } if (opt & 0x10) { // -t txc.tick = xatol(opt_t); txc.modes |= ADJ_TICK; } ret = adjtimex(&txc); if (ret < 0) { bb_perror_nomsg_and_die(); } if (!(opt & OPT_quiet)) { int sep; const char *name; printf( " mode: %d\n" "-o offset: %ld\n" "-f frequency: %ld\n" " maxerror: %ld\n" " esterror: %ld\n" " status: %d (", txc.modes, txc.offset, txc.freq, txc.maxerror, txc.esterror, txc.status); /* representative output of next code fragment: "PLL | PPSTIME" */ name = statlist_name; sep = 0; for (i = 0; statlist_bit[i]; i++) { if (txc.status & statlist_bit[i]) { if (sep) fputs(" | ", stdout); fputs(name, stdout); sep = 1; } name += strlen(name) + 1; } descript = "error"; if (ret <= 5) descript = nth_string(ret_code_descript, ret); printf(")\n" "-p timeconstant: %ld\n" " precision: %ld\n" " tolerance: %ld\n" "-t tick: %ld\n" " time.tv_sec: %ld\n" " time.tv_usec: %ld\n" " return value: %d (%s)\n", txc.constant, txc.precision, txc.tolerance, txc.tick, (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript); } return 0; }
int adjtimex_main(int argc UNUSED_PARAM, char **argv) { enum { OPT_quiet = 0x1 }; unsigned opt; char *opt_o, *opt_f, *opt_p, *opt_t; struct timex txc; int ret; const char *descript; memset(&txc, 0, sizeof(txc)); opt = getopt32(argv, "^" "qo:f:p:t:" "\0" "=0"/*no valid non-option args*/, &opt_o, &opt_f, &opt_p, &opt_t ); //if (opt & 0x1) // -q if (opt & 0x2) { // -o txc.offset = xatol(opt_o); txc.modes |= ADJ_OFFSET_SINGLESHOT; } if (opt & 0x4) { // -f txc.freq = xatol(opt_f); txc.modes |= ADJ_FREQUENCY; } if (opt & 0x8) { // -p txc.constant = xatol(opt_p); txc.modes |= ADJ_TIMECONST; } if (opt & 0x10) { // -t txc.tick = xatol(opt_t); txc.modes |= ADJ_TICK; } /* It's NOFORK applet because the code is very simple: * just some printf. No opens, no allocs. * If you need to make it more complex, feel free to downgrade to NOEXEC */ ret = adjtimex(&txc); if (ret < 0) bb_perror_nomsg_and_die(); if (!(opt & OPT_quiet)) { const char *sep; const char *name; int i; printf( " mode: %d\n" "-o offset: %ld us\n" "-f freq.adjust: %ld (65536 = 1ppm)\n" " maxerror: %ld\n" " esterror: %ld\n" " status: %d (", txc.modes, txc.offset, txc.freq, txc.maxerror, txc.esterror, txc.status ); /* representative output of next code fragment: * "PLL | PPSTIME" */ name = statlist_name; sep = ""; for (i = 0; statlist_bit[i]; i++) { if (txc.status & statlist_bit[i]) { printf("%s%s", sep, name); sep = " | "; } name += strlen(name) + 1; } descript = "error"; if (ret <= 5) descript = nth_string(ret_code_descript, ret); printf(")\n" "-p timeconstant: %ld\n" " precision: %ld us\n" " tolerance: %ld\n" "-t tick: %ld us\n" " time.tv_sec: %ld\n" " time.tv_usec: %ld\n" " return value: %d (%s)\n", txc.constant, txc.precision, txc.tolerance, txc.tick, (long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript ); } return 0; }