static int sfq_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) { int ok=0; struct tc_sfq_qopt opt; memset(&opt, 0, sizeof(opt)); while (argc > 0) { if (strcmp(*argv, "quantum") == 0) { NEXT_ARG(); if (get_size(&opt.quantum, *argv)) { fprintf(stderr, "Illegal \"limit\"\n"); return -1; } ok++; } else if (strcmp(*argv, "perturb") == 0) { NEXT_ARG(); if (get_integer(&opt.perturb_period, *argv, 0)) { fprintf(stderr, "Illegal \"perturb\"\n"); return -1; } ok++; } else if (strcmp(*argv, "limit") == 0) { NEXT_ARG(); if (get_u32(&opt.limit, *argv, 0)) { fprintf(stderr, "Illegal \"limit\"\n"); return -1; } if (opt.limit < 2) { fprintf(stderr, "Illegal \"limit\", must be > 1\n"); return -1; } ok++; } else if (strcmp(*argv, "help") == 0) { explain(); return -1; } else { fprintf(stderr, "What is \"%s\"?\n", *argv); explain(); return -1; } argc--; argv++; } if (ok) addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); return 0; }
cellpoint apply_proc(cellpoint arglst) { int len; args_push(arglst); len = get_integer(list_len()); if (len < 2){ printf("Error: the procedure \"apply\" expects at least 2 arguments.\n"); error_handler(); } check_arg_type("apply", "first", car(arglst), PROCEDURE_T); args_push(a_false); args_push(combine_args(cdr(arglst))); args_push(car(arglst)); return apply(); }
static int get_index(const char **tbl, char *name) { int i, index; /* check for integer index passed in instead of name */ if (get_integer(&index, name, 10) == 0) for (i = 0; tbl[i]; i++) if (i == index) return i; for (i = 0; tbl[i]; i++) if (strcmp(tbl[i], name) == 0) return i; return -1; }
CharacterClass &pickClass() { int i, choice; while (true) { std::cout << "Please pick a class by entering a number:" << std::endl << std::endl; i = 1; for (auto &c : character_classes) { std::cout << i << ": " << c << std::endl; ++i; } std::cout << std::endl << ">"; choice = get_integer(); if (choice > 0 && ((size_t) choice) <= character_classes.size()) { return character_classes[choice - 1]; } } }
static void smt_eval_mk_bv_repeat(tstack_t *stack, stack_elem_t *f, uint32_t n) { int32_t i; bvlogic_buffer_t *b; i = get_integer(stack, f); b = tstack_get_bvlbuffer(stack); bvl_set_elem(stack, b, f+1); // check for overflow or for i <= 0 if (! yices_check_bvrepeat(b, i)) { report_yices_error(stack); } bvlogic_buffer_repeat_concat(b, i); tstack_pop_frame(stack); set_bvlogic_result(stack, b); }
static void smt_eval_mk_bv_rotate_right(tstack_t *stack, stack_elem_t *f, uint32_t n) { int32_t index; bvlogic_buffer_t *b; index = get_integer(stack, f); b = tstack_get_bvlbuffer(stack); bvl_set_elem(stack, b, f+1); if (! yices_check_bitshift(b, index)) { report_yices_error(stack); } // we known 0 <= index <= bitsize of b if (index < bvlogic_buffer_bitsize(b)) { bvlogic_buffer_rotate_right(b, index); } tstack_pop_frame(stack); set_bvlogic_result(stack, b); }
int get_prefix_1(inet_prefix *dst, char *arg, int family) { int err; unsigned plen; char *slash; memset(dst, 0, sizeof(*dst)); if (strcmp(arg, "default") == 0 || strcmp(arg, "any") == 0) { if (family == AF_DECnet) return -1; dst->family = family; dst->bytelen = 0; dst->bitlen = 0; return 0; } slash = strchr(arg, '/'); if (slash) *slash = 0; err = get_addr_1(dst, arg, family); if (err == 0) { switch(dst->family) { case AF_INET6: dst->bitlen = 128; break; case AF_DECnet: dst->bitlen = 16; break; default: case AF_INET: dst->bitlen = 32; } if (slash) { if (get_integer(&plen, slash+1, 0) || plen > dst->bitlen) { err = -1; goto done; } dst->bitlen = plen; } } done: if (slash) *slash = '/'; return err; }
//one arg: arglst cellpoint vector(void) { int len, i=0; args_push(args_ref(1)); len = get_integer(list_len()); reg = make_vector(len, NIL); stack_push(&vars_stack, args_ref(1)); while (is_false(is_null(stack_top(&vars_stack)))){ vector_set(reg, i, car(stack_top(&vars_stack))); ++i; stack_push(&vars_stack, cdr(stack_pop(&vars_stack))); } stack_pop(&vars_stack); args_pop(1); return reg; }
const Race *pickRace() { int i, choice; while (true) { std::cout << "Please pick a race by entering a number:" << std::endl << std::endl; i = 1; for (auto &r : character_races) { std::cout << i << ": " << r << std::endl; ++i; } std::cout << std::endl << ">"; choice = get_integer(); if (choice > 0 && ((size_t) choice) <= character_races.size()) { return &character_races[choice - 1]; } std::cout << "No such race available." << std::endl; } }
static int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type) { int argc = *argc_p; char **argv = *argv_p; if (argc <= 0) return -1; if (type == TINT) return get_integer((int *)val, *argv, 0); if (type == TU32) return get_u32(val, *argv, 0); if (type == TIPV4) { inet_prefix addr; if (get_prefix_1(&addr, *argv, AF_INET)) return -1; *val = addr.data[0]; return 0; } if (type == TIPV6) { inet_prefix addr; if (get_prefix_1(&addr, *argv, AF_INET6)) return -1; memcpy(val, addr.data, addr.bytelen); return 0; } if (type == TMAC) { #define MAC_ALEN 6 int ret = ll_addr_a2n((char *)val, MAC_ALEN, *argv); if (ret == MAC_ALEN) return 0; } return -1; }
static ssize_t b43_attr_interfmode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct b43_wldev *wldev = dev_to_b43_wldev(dev); int err; int mode; if (!capable(CAP_NET_ADMIN)) return -EPERM; mode = get_integer(buf, count); switch (mode) { case 0: mode = B43_INTERFMODE_NONE; break; case 1: mode = B43_INTERFMODE_NONWLAN; break; case 2: mode = B43_INTERFMODE_MANUALWLAN; break; case 3: mode = B43_INTERFMODE_AUTOWLAN; break; default: return -EINVAL; } mutex_lock(&wldev->wl->mutex); if (wldev->phy.ops->interf_mitigation) { err = wldev->phy.ops->interf_mitigation(wldev, mode); if (err) { b43err(wldev->wl, "Interference Mitigation not " "supported by device\n"); } } else err = -ENOSYS; mmiowb(); mutex_unlock(&wldev->wl->mutex); return err ? err : count; }
static ssize_t bcm43xx_attr_interfmode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct bcm43xx_wldev *wldev = dev_to_bcm43xx_wldev(dev); unsigned long flags; int err; int mode; if (!capable(CAP_NET_ADMIN)) return -EPERM; mode = get_integer(buf, count); switch (mode) { case 0: mode = BCM43xx_INTERFMODE_NONE; break; case 1: mode = BCM43xx_INTERFMODE_NONWLAN; break; case 2: mode = BCM43xx_INTERFMODE_MANUALWLAN; break; case 3: mode = BCM43xx_INTERFMODE_AUTOWLAN; break; default: return -EINVAL; } mutex_lock(&wldev->wl->mutex); spin_lock_irqsave(&wldev->wl->irq_lock, flags); err = bcm43xx_radio_set_interference_mitigation(wldev, mode); if (err) { printk(KERN_ERR PFX "Interference Mitigation not " "supported by device\n"); } mmiowb(); spin_unlock_irqrestore(&wldev->wl->irq_lock, flags); mutex_unlock(&wldev->wl->mutex); return err ? err : count; }
static ssize_t bcm43xx_attr_interfmode_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct bcm43xx_private *bcm = dev_to_bcm(dev); unsigned long flags; int err; int mode; if (!capable(CAP_NET_ADMIN)) return -EPERM; mode = get_integer(buf, count); switch (mode) { case 0: mode = BCM43xx_RADIO_INTERFMODE_NONE; break; case 1: mode = BCM43xx_RADIO_INTERFMODE_NONWLAN; break; case 2: mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN; break; case 3: mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN; break; default: return -EINVAL; } bcm43xx_lock_mmio(bcm, flags); assert(bcm->initialized); err = bcm43xx_radio_set_interference_mitigation(bcm, mode); if (err) { printk(KERN_ERR PFX "Interference Mitigation not " "supported by device\n"); } bcm43xx_unlock_mmio(bcm, flags); return err ? err : count; }
void tabs_widget_rep::handle_repaint (repaint_event ev) { (void) ev; renderer ren= ev->win; layout_default (ren, 0, 0, w, h); if (h1 == 0 || h2 == 0 || N(xs) == 0) return; int l= N(a)-1, focus= 0; a[l] << get_integer ("switch", focus); color pastel= layout_pastel (ren); color dark= layout_dark (ren); SI fx1= xs[focus] - PIXEL; SI fx2= xs[focus+1] - PIXEL; SI top= h1 + h2 + 2*PIXEL; SI lim= xs[N(xs)-1]; ren->set_pencil (pencil (pastel, PIXEL)); if (focus > 0) ren->line (0, h1, fx1, h1); ren->line (fx2, h1, w, h1); ren->set_pencil (pencil (dark, PIXEL)); if (focus > 0) ren->line (0, h1 + PIXEL, fx1, h1 + PIXEL); ren->line (fx2, h1 + PIXEL, w, h1 + PIXEL); ren->set_pencil (pencil (dark, PIXEL)); ren->line (0, top, lim - PIXEL, top); for (int i=0; i<l; i++) { ren->set_pencil (pencil (pastel, PIXEL)); ren->line (xs[i], h1+2*PIXEL, xs[i], top - PIXEL); ren->set_pencil (pencil (dark, PIXEL)); ren->line (xs[i+1]-PIXEL, h1+2*PIXEL, xs[i+1]-PIXEL, top - PIXEL); } ren->set_pencil (pencil (pastel, PIXEL)); ren->line (0, 0, 0, h1); ren->set_pencil (pencil (dark, PIXEL)); ren->line (0, 0, w, 0); ren->line (w-PIXEL, 0, w-PIXEL, h1); }
/* * Data is ready to be read. */ static void data_ready(void) { static char buf[1024]; static int buf_full; char *ptr; int x; /* Determine number of bytes to read */ if (buf_full < 8) { /* Read 8 bytes for header */ x = 8; } else { /* Skip to message size portion of header */ ptr = buf + 4; x = get_integer(&ptr); } /* Check for overly long message */ if (x > 1024) { /* Error */ printf("Received too long message!\n"); exit(1); } /* Try to read enough bytes */ x = read(0, buf + buf_full, x - buf_full); /* Check for error */ if (x <= 0) { /* Check for try again error */ if (x < 0 && errno == EAGAIN) return; /* Check for server disconnect */ if (x == 0) exit(0); /* Print error */ perror("read"); exit(1); } /* Add to amount read */ buf_full += x; /* Check for complete message header */ if (buf_full >= 8) { /* Skip to length portion of header */ ptr = buf + 4; x = get_integer(&ptr); /* Check for too-small message */ if (x < 8) { /* Print error */ printf("Got too small message!\n"); exit(1); } /* Check for complete message */ if (buf_full == x) { /* Handle message at next opportunity */ message_read(buf); /* Clear buffer */ buf_full = 0; } } }
/* ptr points to the start of the format_spec, end points just past its end. fills in format with the parsed information. returns 1 on success, 0 on failure. if failure, sets the exception */ static int parse_internal_render_format_spec(PyObject *format_spec, Py_ssize_t start, Py_ssize_t end, InternalFormatSpec *format, char default_type, char default_align) { Py_ssize_t pos = start; /* end-pos is used throughout this code to specify the length of the input string */ #define READ_spec(index) PyUnicode_READ_CHAR(format_spec, index) Py_ssize_t consumed; int align_specified = 0; int fill_char_specified = 0; format->fill_char = ' '; format->align = default_align; format->alternate = 0; format->sign = '\0'; format->width = -1; format->thousands_separators = 0; format->precision = -1; format->type = default_type; /* If the second char is an alignment token, then parse the fill char */ if (end-pos >= 2 && is_alignment_token(READ_spec(pos+1))) { format->align = READ_spec(pos+1); format->fill_char = READ_spec(pos); fill_char_specified = 1; align_specified = 1; pos += 2; } else if (end-pos >= 1 && is_alignment_token(READ_spec(pos))) { format->align = READ_spec(pos); align_specified = 1; ++pos; } /* Parse the various sign options */ if (end-pos >= 1 && is_sign_element(READ_spec(pos))) { format->sign = READ_spec(pos); ++pos; } /* If the next character is #, we're in alternate mode. This only applies to integers. */ if (end-pos >= 1 && READ_spec(pos) == '#') { format->alternate = 1; ++pos; } /* The special case for 0-padding (backwards compat) */ if (!fill_char_specified && end-pos >= 1 && READ_spec(pos) == '0') { format->fill_char = '0'; if (!align_specified) { format->align = '='; } ++pos; } consumed = get_integer(format_spec, &pos, end, &format->width); if (consumed == -1) /* Overflow error. Exception already set. */ return 0; /* If consumed is 0, we didn't consume any characters for the width. In that case, reset the width to -1, because get_integer() will have set it to zero. -1 is how we record that the width wasn't specified. */ if (consumed == 0) format->width = -1; /* Comma signifies add thousands separators */ if (end-pos && READ_spec(pos) == ',') { format->thousands_separators = 1; ++pos; } /* Parse field precision */ if (end-pos && READ_spec(pos) == '.') { ++pos; consumed = get_integer(format_spec, &pos, end, &format->precision); if (consumed == -1) /* Overflow error. Exception already set. */ return 0; /* Not having a precision after a dot is an error. */ if (consumed == 0) { PyErr_Format(PyExc_ValueError, "Format specifier missing precision"); return 0; } } /* Finally, parse the type field. */ if (end-pos > 1) { /* More than one char remain, invalid format specifier. */ PyErr_Format(PyExc_ValueError, "Invalid format specifier"); return 0; } if (end-pos == 1) { format->type = READ_spec(pos); ++pos; } /* Do as much validating as we can, just by looking at the format specifier. Do not take into account what type of formatting we're doing (int, float, string). */ if (format->thousands_separators) { switch (format->type) { case 'd': case 'e': case 'f': case 'g': case 'E': case 'G': case '%': case 'F': case '\0': /* These are allowed. See PEP 378.*/ break; default: invalid_comma_type(format->type); return 0; } } assert (format->align <= 127); assert (format->sign <= 127); return 1; }
static int do_set(int argc, char **argv) { char *dev = NULL; __u32 mask = 0; __u32 flags = 0; int qlen = -1; int mtu = -1; char *newaddr = NULL; char *newbrd = NULL; struct ifreq ifr0, ifr1; char *newname = NULL; int htype, halen; while (argc > 0) { if (strcmp(*argv, "up") == 0) { mask |= IFF_UP; flags |= IFF_UP; } else if (strcmp(*argv, "down") == 0) { mask |= IFF_UP; flags &= ~IFF_UP; } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); newname = *argv; } else if (strcmp(*argv, "mtu") == 0) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); if (get_integer(&mtu, *argv, 0)) invarg("Invalid \"mtu\" value\n", *argv); } else if (strcmp(*argv, "multicast") == 0) { NEXT_ARG(); mask |= IFF_MULTICAST; if (strcmp(*argv, "on") == 0) { flags |= IFF_MULTICAST; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_MULTICAST; } else return on_off("multicast"); } else if (strcmp(*argv, "arp") == 0) { NEXT_ARG(); mask |= IFF_NOARP; if (strcmp(*argv, "on") == 0) { flags &= ~IFF_NOARP; } else if (strcmp(*argv, "off") == 0) { flags |= IFF_NOARP; } else return on_off("noarp"); } else if (strcmp(*argv, "addr") == 0) { NEXT_ARG(); newaddr = *argv; } else { if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); } if (dev) duparg2("dev", *argv); dev = *argv; } argc--; argv++; } if (!dev) { bb_error_msg("Not enough of information: \"dev\" argument is required."); exit(-1); } if (newaddr || newbrd) { halen = get_address(dev, &htype); if (halen < 0) return -1; if (newaddr) { if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0) return -1; } if (newbrd) { if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0) return -1; } } if (newname && strcmp(dev, newname)) { if (do_changename(dev, newname) < 0) return -1; dev = newname; } if (qlen != -1) { if (set_qlen(dev, qlen) < 0) return -1; } if (mtu != -1) { if (set_mtu(dev, mtu) < 0) return -1; } if (newaddr || newbrd) { if (newbrd) { if (set_address(&ifr1, 1) < 0) return -1; } if (newaddr) { if (set_address(&ifr0, 0) < 0) return -1; } } if (mask) return do_chflags(dev, flags, mask); return 0; }
/** * \brief Converts this savegame v1 into a savegame v2. * \param savegame_v2 The savegame to fill. */ void SavegameConverterV1::convert_to_v2(Savegame& savegame_v2) { // 1. Built-in values. savegame_v2.set_string(Savegame::KEY_STARTING_POINT, get_string(STARTING_POINT)); if (!get_string(STARTING_MAP).empty()) { savegame_v2.set_string(Savegame::KEY_STARTING_MAP, get_string(STARTING_MAP)); } else { // Older v1 savegames used integers to identify maps. std::ostringstream oss; oss << get_integer(STARTING_MAP_INT); savegame_v2.set_string(Savegame::KEY_STARTING_MAP, oss.str()); } savegame_v2.set_integer(Savegame::KEY_CURRENT_LIFE, get_integer(CURRENT_LIFE)); savegame_v2.set_integer(Savegame::KEY_CURRENT_MONEY, get_integer(CURRENT_MONEY)); savegame_v2.set_integer(Savegame::KEY_CURRENT_MAGIC, get_integer(CURRENT_MAGIC)); savegame_v2.set_integer(Savegame::KEY_MAX_LIFE, get_integer(MAX_LIFE)); savegame_v2.set_integer(Savegame::KEY_MAX_MONEY, get_integer(MAX_MONEY)); savegame_v2.set_integer(Savegame::KEY_MAX_MAGIC, get_integer(MAX_MAGIC)); savegame_v2.set_string(Savegame::KEY_ITEM_SLOT_1, get_string(ITEM_SLOT_0)); savegame_v2.set_string(Savegame::KEY_ITEM_SLOT_2, get_string(ITEM_SLOT_1)); savegame_v2.set_string(Savegame::KEY_KEYBOARD_ACTION, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_ACTION_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_ATTACK, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_SWORD_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_ITEM_1, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_ITEM_1_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_ITEM_2, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_ITEM_2_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_PAUSE, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_PAUSE_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_RIGHT, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_RIGHT_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_UP, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_UP_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_LEFT, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_LEFT_KEY)))); savegame_v2.set_string(Savegame::KEY_KEYBOARD_DOWN, InputEvent::get_keyboard_key_name( InputEvent::KeyboardKey(get_integer(KEYBOARD_DOWN_KEY)))); savegame_v2.set_string(Savegame::KEY_JOYPAD_ACTION, get_string(JOYPAD_ACTION_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_ATTACK, get_string(JOYPAD_SWORD_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_ITEM_1, get_string(JOYPAD_ITEM_1_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_ITEM_2, get_string(JOYPAD_ITEM_2_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_PAUSE, get_string(JOYPAD_PAUSE_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_RIGHT, get_string(JOYPAD_RIGHT_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_UP, get_string(JOYPAD_UP_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_LEFT, get_string(JOYPAD_LEFT_KEY)); savegame_v2.set_string(Savegame::KEY_JOYPAD_DOWN, get_string(JOYPAD_DOWN_KEY)); savegame_v2.set_integer(Savegame::KEY_ABILITY_RESISTANCE, get_integer(ABILITY_TUNIC)); savegame_v2.set_integer(Savegame::KEY_ABILITY_SWORD, get_integer(ABILITY_SWORD)); savegame_v2.set_integer(Savegame::KEY_ABILITY_SHIELD, get_integer(ABILITY_SHIELD)); savegame_v2.set_integer(Savegame::KEY_ABILITY_LIFT, get_integer(ABILITY_LIFT)); savegame_v2.set_integer(Savegame::KEY_ABILITY_SWIM, get_integer(ABILITY_SWIM)); savegame_v2.set_integer(Savegame::KEY_ABILITY_SWORD_KNOWLEDGE, get_integer(ABILITY_SWORD_KNOWLEDGE)); savegame_v2.set_integer(Savegame::KEY_ABILITY_DETECT_WEAK_WALLS, get_integer(ABILITY_DETECT_WEAK_WALLS)); savegame_v2.set_integer(Savegame::KEY_ABILITY_GET_BACK_FROM_DEATH, get_integer(ABILITY_GET_BACK_FROM_DEATH)); savegame_v2.set_integer(Savegame::KEY_ABILITY_RUN, get_integer(ABILITY_RUN)); // 2. Values that used to be built-in in v1 and become pure data in v2. savegame_v2.set_string("player_name", get_string(PLAYER_NAME)); savegame_v2.set_integer("pause_last_submenu", get_integer(PAUSE_LAST_SUBMENU) + 1); savegame_v2.set_integer("pause_inventory_last_item_index", get_integer(INVENTORY_LAST_ITEM_INDEX) + 1); for (int i = 0; i < 40; i++) { int index = 200 + i * 10; std::ostringstream oss; oss << "dungeon_" << (i + 1); const std::string& dungeon_number = oss.str(); // Dungeon finished (integer replaced by a boolean). if (get_integer(index) > 0) { savegame_v2.set_boolean(dungeon_number + "_finished", true); } // Got the map? (integer replaced by a boolean). ++index; if (get_integer(index) > 0) { savegame_v2.set_boolean(dungeon_number + "_map", true); } // Got the compass? (integer replaced by a boolean). ++index; if (get_integer(index) > 0) { savegame_v2.set_boolean(dungeon_number + "_compass", true); } // Got the big key? (integer replaced by a boolean). ++index; if (get_integer(index) > 0) { savegame_v2.set_boolean(dungeon_number + "_big_key", true); } // Got the boss key? (integer replaced by a boolean). ++index; if (get_integer(index) > 0) { savegame_v2.set_boolean(dungeon_number + "_boss_key", true); } // Number of small keys. ++index; int nb_small_keys = get_integer(index); if (nb_small_keys > 0) { savegame_v2.set_integer(dungeon_number + "_small_keys", nb_small_keys); } } // 3. Custom values. int i; for (i = 32; i < 64; i++) { const std::string& value = get_string(i); if (!value.empty()) { std::ostringstream oss; oss << "s" << i; savegame_v2.set_string(oss.str(), value); } } for (i = 1024; i < 2048; i++) { int value = get_integer(i); if (value != 0) { std::ostringstream oss; oss << "i" << i; savegame_v2.set_integer(oss.str(), value); } } for (i = 0; i < 32768; i++) { bool value = get_boolean(i); if (value) { std::ostringstream oss; oss << "b" << i; savegame_v2.set_boolean(oss.str(), value); } } }
/* ** 'restore_retparm' is called when a 'return parameter' block is found on the ** stack. It saves the value currently in the parameter at the address stored as ** the return parameter address and then returns the local variable to its ** correct value */ void restore_retparm(int32 parmcount) { stack_retparm *p; int32 vartype, intvalue; float64 floatvalue; basicstring stringvalue; p = basicvars.stacktop.retparmsp; /* Not needed, but the code is unreadable otherwise */ #ifdef DEBUG if (basicvars.debug_flags.stack) fprintf(stderr, "Restoring RETURN variable at %p from %p, return dest=%p\n", p->savedetails.address.intaddr, p, p->retdetails.address.intaddr); #endif basicvars.stacktop.retparmsp++; switch (p->savedetails.typeinfo & PARMTYPEMASK) { /* Fetch value from local variable and restore local var */ case VAR_INTWORD: /* Integer variable */ intvalue = *p->savedetails.address.intaddr; /* Fetch current value of local variable */ *p->savedetails.address.intaddr = p->value.savedint; /* Restore local variable to its old value */ vartype = VAR_INTWORD; break; case VAR_FLOAT: /* Floating point variable */ floatvalue = *p->savedetails.address.floataddr; *p->savedetails.address.floataddr = p->value.savedfloat; vartype = VAR_FLOAT; break; case VAR_STRINGDOL: /* String variable */ stringvalue = *p->savedetails.address.straddr; *p->savedetails.address.straddr = p->value.savedstring; vartype = VAR_STRINGDOL; break; case VAR_INTBYTEPTR: /* Indirect byte integer variable */ intvalue = basicvars.offbase[p->savedetails.address.offset]; basicvars.offbase[p->savedetails.address.offset] = p->value.savedint; vartype = VAR_INTWORD; break; case VAR_INTWORDPTR: /* Indirect word integer variable */ intvalue = get_integer(p->savedetails.address.offset); store_integer(p->savedetails.address.offset, p->value.savedint); vartype = VAR_INTWORD; break; case VAR_FLOATPTR: /* Indirect floating point variable */ floatvalue = get_float(p->savedetails.address.offset); store_float(p->savedetails.address.offset, p->value.savedfloat); vartype = VAR_FLOAT; break; case VAR_DOLSTRPTR: /* Indirect string variable */ intvalue = stringvalue.stringlen = get_stringlen(p->savedetails.address.offset); stringvalue.stringaddr = alloc_string(intvalue); if (intvalue>0) memmove(stringvalue.stringaddr, &basicvars.offbase[p->savedetails.address.offset], intvalue); memmove(&basicvars.offbase[p->savedetails.address.offset], p->value.savedstring.stringaddr, p->value.savedstring.stringlen); free_string(p->value.savedstring); /* Discard saved copy of original '$ string' */ vartype = VAR_DOLSTRPTR; break; case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY: /* Array - Do nothing */ break; default: error(ERR_BROKEN, __LINE__, "stack"); } /* Now restore the next parameter */ parmcount--; if (parmcount>0) { /* There are still some parameters to do */ if (basicvars.stacktop.intsp->itemtype==STACK_LOCAL) restore(parmcount); else { /* Must be a return parameter */ restore_retparm(parmcount); } } /* Now we can store the returned value in original variable */ switch (p->retdetails.typeinfo) { case VAR_INTWORD: *p->retdetails.address.intaddr = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue); break; case VAR_FLOAT: *p->retdetails.address.floataddr = vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue; break; case VAR_STRINGDOL: free_string(*p->retdetails.address.straddr); *p->retdetails.address.straddr = stringvalue; break; case VAR_INTBYTEPTR: basicvars.offbase[p->retdetails.address.offset] = vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue); break; case VAR_INTWORDPTR: store_integer(p->retdetails.address.offset, vartype==VAR_INTWORD ? intvalue : TOINT(floatvalue)); break; case VAR_FLOATPTR: store_float(p->retdetails.address.offset, vartype==VAR_INTWORD ? TOFLOAT(intvalue) : floatvalue); break; case VAR_DOLSTRPTR: if (stringvalue.stringlen>0) memmove(&basicvars.offbase[p->retdetails.address.offset], stringvalue.stringaddr, stringvalue.stringlen); if (vartype==VAR_STRINGDOL) { /* Local var was a normal string variable */ basicvars.offbase[p->retdetails.address.offset+stringvalue.stringlen] = CR; /* So add a 'CR' at the end of the string */ } free_string(stringvalue); break; case VAR_INTARRAY: case VAR_FLOATARRAY: case VAR_STRARRAY: /* 'RETURN' dest is array - Do nothing */ break; default: error(ERR_BROKEN, __LINE__, "stack"); } }
/** * \copydoc LuaData::export_to_lua */ bool EntityData::export_to_lua(std::ostream& out) const { // Entity type. out << get_type_name() << "{\n"; // Name. if (has_name()) { out << " name = \"" << escape_string(get_name()) << "\",\n"; } // Position on the map. out << " layer = " << get_layer() << ",\n" << " x = " << get_xy().x << ",\n" << " y = " << get_xy().y << ",\n"; // Properties specific to a type of entity. const EntityTypeDescription& type_description = entity_type_descriptions.at(get_type()); for (const EntityFieldDescription& field_description : type_description) { const std::string& key = field_description.key; const bool optional = field_description.optional == OptionalFlag::OPTIONAL; switch (field_description.default_value.value_type) { case EntityFieldType::STRING: { const std::string& value = get_string(key); const std::string& default_value = field_description.default_value.string_value; if (optional && value == default_value) { // No need to write the value. continue; } out << " " << key << " = \"" << escape_string(value) << "\",\n"; break; } case EntityFieldType::INTEGER: { int value = get_integer(key); int default_value = field_description.default_value.int_value; if (optional && value == default_value) { // No need to write the value. continue; } out << " " << key << " = " << value << ",\n"; break; } case EntityFieldType::BOOLEAN: { bool value = get_boolean(key); bool default_value = field_description.default_value.int_value != 0; if (optional && value == default_value) { // No need to write the value. continue; } out << " " << key << " = " << (value ? "true" : "false") << ",\n"; break; } case EntityFieldType::NIL: Debug::die("Nil entity field"); break; } } out << "}\n\n"; return true; }
static int do_set(int argc, char **argv) { char *dev = NULL; __u32 mask = 0; __u32 flags = 0; int qlen = -1; int mtu = -1; char *newaddr = NULL; char *newbrd = NULL; struct ifreq ifr0, ifr1; char *newname = NULL; int htype, halen; while (argc > 0) { if (strcmp(*argv, "up") == 0) { mask |= IFF_UP; flags |= IFF_UP; } else if (strcmp(*argv, "down") == 0) { mask |= IFF_UP; flags &= ~IFF_UP; } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); newname = *argv; } else if (matches(*argv, "address") == 0) { NEXT_ARG(); newaddr = *argv; } else if (matches(*argv, "broadcast") == 0 || strcmp(*argv, "brd") == 0) { NEXT_ARG(); newbrd = *argv; } else if (matches(*argv, "txqueuelen") == 0 || strcmp(*argv, "qlen") == 0 || matches(*argv, "txqlen") == 0) { NEXT_ARG(); if (qlen != -1) duparg("txqueuelen", *argv); if (get_integer(&qlen, *argv, 0)) invarg("Invalid \"txqueuelen\" value\n", *argv); } else if (strcmp(*argv, "mtu") == 0) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); if (get_integer(&mtu, *argv, 0)) invarg("Invalid \"mtu\" value\n", *argv); } else if (strcmp(*argv, "multicast") == 0) { NEXT_ARG(); mask |= IFF_MULTICAST; if (strcmp(*argv, "on") == 0) { flags |= IFF_MULTICAST; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_MULTICAST; } else return on_off("multicast", *argv); } else if (strcmp(*argv, "allmulticast") == 0) { NEXT_ARG(); mask |= IFF_ALLMULTI; if (strcmp(*argv, "on") == 0) { flags |= IFF_ALLMULTI; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_ALLMULTI; } else return on_off("allmulticast", *argv); } else if (strcmp(*argv, "promisc") == 0) { NEXT_ARG(); mask |= IFF_PROMISC; if (strcmp(*argv, "on") == 0) { flags |= IFF_PROMISC; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_PROMISC; } else return on_off("promisc", *argv); } else if (strcmp(*argv, "trailers") == 0) { NEXT_ARG(); mask |= IFF_NOTRAILERS; if (strcmp(*argv, "off") == 0) { flags |= IFF_NOTRAILERS; } else if (strcmp(*argv, "on") == 0) { flags &= ~IFF_NOTRAILERS; } else return on_off("trailers", *argv); } else if (strcmp(*argv, "arp") == 0) { NEXT_ARG(); mask |= IFF_NOARP; if (strcmp(*argv, "on") == 0) { flags &= ~IFF_NOARP; } else if (strcmp(*argv, "off") == 0) { flags |= IFF_NOARP; } else return on_off("noarp", *argv); } else if (matches(*argv, "dynamic") == 0) { NEXT_ARG(); mask |= IFF_DYNAMIC; if (strcmp(*argv, "on") == 0) { flags |= IFF_DYNAMIC; } else if (strcmp(*argv, "off") == 0) { flags &= ~IFF_DYNAMIC; } else return on_off("dynamic", *argv); } else { if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); } if (matches(*argv, "help") == 0) usage(); if (dev) duparg2("dev", *argv); dev = *argv; } argc--; argv++; } if (!dev) { fprintf(stderr, "Not enough of information: \"dev\" argument is required.\n"); exit(-1); } if (newaddr || newbrd) { halen = get_address(dev, &htype); if (halen < 0) return -1; if (newaddr) { if (parse_address(dev, htype, halen, newaddr, &ifr0) < 0) return -1; } if (newbrd) { if (parse_address(dev, htype, halen, newbrd, &ifr1) < 0) return -1; } } if (newname && strcmp(dev, newname)) { if (strlen(newname) == 0) invarg("\"\" is not a valid device identifier\n", "name"); if (do_changename(dev, newname) < 0) return -1; dev = newname; } if (qlen != -1) { if (set_qlen(dev, qlen) < 0) return -1; } if (mtu != -1) { if (set_mtu(dev, mtu) < 0) return -1; } if (newaddr || newbrd) { if (newbrd) { if (set_address(&ifr1, 1) < 0) return -1; } if (newaddr) { if (set_address(&ifr0, 0) < 0) return -1; } } if (mask) return do_chflags(dev, flags, mask); return 0; }
void show_host_modem_test(uint8_t level, uint16_t vid, uint16_t pid, uint32_t duration) { uint8_t retval; set_defaults(&modem); modem.duration = duration; while (1) { retval = usb_ts_show_menu(level, "Modem Test Parameters", " 1) Execute Data Stress Test: <%s>\n" " 2) Execute Modem Control Endpoint Test: <%s>\n" " 3) Use random transmit length: <%s>\n" " 4) Use random transmit delay: <%s> ms\n" " 5) Use vendor specific interface: <%s>\n" "10) Loop data: <%s>\n" "13) Set test duration: <%d> seconds\n" "20) Reset parameters\n" "30) Start test (VID=0x%04x, PID=0x%04x)\n" "40) Select another device\n" " x) Return to previous menu \n", (modem.data_stress_test ? "YES" : "NO"), (modem.control_ep_test ? "YES" : "NO"), (modem.random_tx_length ? "YES" : "NO"), (modem.random_tx_delay ? "16" : "0"), (modem.use_vendor_specific ? "YES" : "NO"), (modem.loop_data ? "YES" : "NO"), (int)(modem.duration), (int)vid, (int)pid); switch (retval) { case 0: break; case 1: modem.data_stress_test ^= 1; break; case 2: modem.control_ep_test ^= 1; break; case 3: modem.random_tx_length ^= 1; break; case 4: modem.random_tx_delay ^= 1; break; case 5: modem.use_vendor_specific ^= 1; modem.control_ep_test = 0; break; case 10: modem.loop_data ^= 1; break; case 13: modem.duration = get_integer(); break; case 20: set_defaults(&modem); break; case 30: exec_host_modem_test(&modem, vid, pid); break; case 40: show_host_device_selection(level + 1, &vid, &pid); break; default: return; } } }
int get_addr_and_pi(int *argc_p, char ***argv_p, inet_prefix * addr, struct tc_rsvp_pinfo *pinfo, int dir, int family) { int argc = *argc_p; char **argv = *argv_p; char *p = strchr(*argv, '/'); struct tc_rsvp_gpi *pi = dir ? &pinfo->dpi : &pinfo->spi; if (p) { __u16 tmp; if (get_u16(&tmp, p+1, 0)) return -1; if (dir == 0) { /* Source port: u16 at offset 0 */ pi->key = htonl(((__u32)tmp)<<16); pi->mask = htonl(0xFFFF0000); } else { /* Destination port: u16 at offset 2 */ pi->key = htonl(((__u32)tmp)); pi->mask = htonl(0x0000FFFF); } pi->offset = 0; *p = 0; } if (get_addr_1(addr, *argv, family)) return -1; if (p) *p = '/'; argc--; argv++; if (pi->mask || argc <= 0) goto done; if (strcmp(*argv, "spi/ah") == 0 || strcmp(*argv, "gpi/ah") == 0) { __u32 gpi; NEXT_ARG(); if (get_u32(&gpi, *argv, 0)) return -1; pi->mask = htonl(0xFFFFFFFF); pi->key = htonl(gpi); pi->offset = 4; if (pinfo->protocol == 0) pinfo->protocol = IPPROTO_AH; argc--; argv++; } else if (strcmp(*argv, "spi/esp") == 0 || strcmp(*argv, "gpi/esp") == 0) { __u32 gpi; NEXT_ARG(); if (get_u32(&gpi, *argv, 0)) return -1; pi->mask = htonl(0xFFFFFFFF); pi->key = htonl(gpi); pi->offset = 0; if (pinfo->protocol == 0) pinfo->protocol = IPPROTO_ESP; argc--; argv++; } else if (strcmp(*argv, "flowlabel") == 0) { __u32 flabel; NEXT_ARG(); if (get_u32(&flabel, *argv, 0)) return -1; if (family != AF_INET6) return -1; pi->mask = htonl(0x000FFFFF); pi->key = htonl(flabel) & pi->mask; pi->offset = -40; argc--; argv++; } else if (strcmp(*argv, "u32") == 0 || strcmp(*argv, "u16") == 0 || strcmp(*argv, "u8") == 0) { int sz = 1; __u32 tmp; __u32 mask = 0xff; if (strcmp(*argv, "u32") == 0) { sz = 4; mask = 0xffff; } else if (strcmp(*argv, "u16") == 0) { mask = 0xffffffff; sz = 2; } NEXT_ARG(); if (get_u32(&tmp, *argv, 0)) return -1; argc--; argv++; if (strcmp(*argv, "mask") == 0) { NEXT_ARG(); if (get_u32(&mask, *argv, 16)) return -1; argc--; argv++; } if (strcmp(*argv, "at") == 0) { NEXT_ARG(); if (get_integer(&pi->offset, *argv, 0)) return -1; argc--; argv++; } if (sz == 1) { if ((pi->offset & 3) == 0) { mask <<= 24; tmp <<= 24; } else if ((pi->offset & 3) == 1) { mask <<= 16; tmp <<= 16; } else if ((pi->offset & 3) == 3) { mask <<= 8; tmp <<= 8; } } else if (sz == 2) { if ((pi->offset & 3) == 0) { mask <<= 16; tmp <<= 16; } } pi->offset &= ~3; pi->mask = htonl(mask); pi->key = htonl(tmp) & pi->mask; } done: *argc_p = argc; *argv_p = argv; return 0; }
static int parse_offset(int *argc_p, char ***argv_p, struct m_pedit_sel *sel, struct m_pedit_key *tkey) { int off; __u32 len, retain; int argc = *argc_p; char **argv = *argv_p; int res = -1; if (argc <= 0) return -1; if (get_integer(&off, *argv, 0)) return -1; tkey->off = off; argc--; argv++; if (argc <= 0) return -1; if (matches(*argv, "u32") == 0) { len = 4; retain = 0xFFFFFFFF; goto done; } if (matches(*argv, "u16") == 0) { len = 2; retain = 0xffff; goto done; } if (matches(*argv, "u8") == 0) { len = 1; retain = 0xff; goto done; } return -1; done: NEXT_ARG(); /* [at <someval> offmask <maskval> shift <shiftval>] */ if (matches(*argv, "at") == 0) { __u32 atv = 0, offmask = 0x0, shift = 0; NEXT_ARG(); if (get_u32(&atv, *argv, 0)) return -1; tkey->at = atv; NEXT_ARG(); if (get_u32(&offmask, *argv, 16)) return -1; tkey->offmask = offmask; NEXT_ARG(); if (get_u32(&shift, *argv, 0)) return -1; tkey->shift = shift; NEXT_ARG(); } res = parse_cmd(&argc, &argv, len, TU32, retain, sel, tkey); *argc_p = argc; *argv_p = argv; return res; }
int read_xdatcar(FILE *fp, int *p_num_frames, atom *p_molecule, int num_atoms, coord_flags *p_fix_flags, int *p_iconf, int *p_is_fract, int *p_is_cart ) { int ichar[LINESIZ]; int iatom,idummy; int skip, lower_case=FALSE; int error, good_line; char *p_key; char *tok; /* assume xdatcar file is just a read after atoms have been sorted out */ /* On first call the number of frames is assumed to be negative */ printf("Trying to read XDATCAR file format\n"); if (*p_num_frames < 0) { /*** Skip title line ****/ skip = TRUE; tok= tok_get(fp, skip, lower_case); printf("Read: %s\n", tok); /*** Skip the integer and the lattice vectors ****/ idummy = get_integer( fp, skip, &error ); printf("The integer = %d\n",idummy); /*** Jump lines to set up for first frame read next time in here ***/ skip=TRUE; tok= tok_get(fp, skip, lower_case); printf("TOK: %s\n",tok); tok= tok_get(fp, skip, lower_case); printf("TOK: %s\n",tok); tok= tok_get(fp, skip, lower_case); printf("TOK: %s\n",tok); tok= tok_get(fp, skip, lower_case); printf("TOK: %s\n",tok); tok= tok_get(fp, skip, lower_case); printf("TOK: %s\n",tok); return 0; } else { printf("Back in read_xdatcar to get another frame\n"); /*** Should be left with a line to skip between frames ***/ /*** If this moves to end of file we can stop.... ***/ skip=TRUE; tok= tok_get(fp, skip, lower_case); printf("TOK: %s",tok); if (strcmp(tok, END_OF_INPUT) == 0) return FALSE; skip=FALSE; tok= tok_get(fp, skip, lower_case); printf(" TOK: %s",tok); if (strcmp(tok, "Direct")) { printf("This is a direct lattice fractional coordinates.\n"); *p_is_fract=TRUE; *p_is_cart=FALSE; } else { printf("This is a direct lattice fractional coordinates.\n"); *p_is_cart=TRUE; *p_is_fract=FALSE; } tok= tok_get(fp, skip, lower_case); printf(" TOK: %s\n",tok); *p_iconf= atoi(tok); printf("XDATCAR says configuration %d\n", *p_iconf); /**** Must already have number of frames and am now just reading one in ****/ skip = TRUE; /**** First skip blank line ***/ /* while (!(tok= tok_get(fp, skip, lower_case))); */ /* fscanf(fp,"\n"); */ /* printf("TOK: %s\n",tok); */ for (iatom=0; iatom < num_atoms; iatom++) { good_line = read_atom_data_vasp( fp, p_molecule, &idummy, p_fix_flags ); printf("Read: %10.6f %10.6f %10.6f good= %d\n", p_molecule->x, p_molecule->y, p_molecule->z, good_line); p_molecule++; } printf("Frame read so off back to main.....\n"); } return good_line; }
main() { const char *device = "/dev/spidev1.0"; fd = open(device, O_RDWR); int4 i; int4 status; float f; char *verb, *qual; int4 iverb; char host_name[80]; int4 port; char table_name[80]; char *theString; printf (" \n"); TERM_BLUE_COLOR; printf (" ***************************************************** \n"); printf (" ***************************************************** \n"); printf (" ** ** \n"); printf (" ** Welcome to CRISTAL: ** \n"); printf (" ** ContRol In Sum-Trigger ALgorithm ** \n"); printf (" ** ** \n"); printf (" ** by: Jezabel R. Garcia ** \n"); printf (" ** ** \n"); printf (" ***************************************************** \n"); printf (" ***************************************************** \n"); TERM_RESET_COLOR; printf (" \n"); // signal(SIGINT, myinterrupt); signal(SIGPIPE,brokenpipe); signal(SIGTERM,myabort); signal(SIGBUS,mybuserror); theString=(char *)malloc(sizeof(char)*256); STInfo.hostname[0]=(char*)malloc(sizeof(char)*80); STInfo.hostname[1]=(char*)malloc(sizeof(char)*80); /* * Set the initial values for status/times */ time(&STInfo.startime);// mirar los usos del tiempo time(&STInfo.writetime);// STInfo.istatus=ST_STATUS_BUSY; STInfo.threshold_control_flag=0; //by default off STInfo.Global_Target_rate = 500; //Hz STInfo.telescope=1; STInfo.temp_control=0; STInfo.total_time=3600; STInfo.time_interval=900; //initializes the BBmenu package menu_init(); //allow simulate_input() AllowInput=1; define_file("cristal_define.uic"); simulate_input("@cristal_init"); AllowInput=0; /* * Launch threads for service programs */ // usleep(100);//DBG STInfo.exit = False; printf("init threads \n"); STInfo.monexit=true; //monitoring thread not running //SERVER THREAD (para oir a cc) pthread_attr_init(&serv_attr); pthread_create(&serv_tid, &serv_attr, (void * (*)(void *)) server_thread, NULL); printf("server_thread initiated \n"); //CLIENT THREAD ( para hablar a cc) pthread_attr_init(&client_attr); pthread_create(&client_tid, &client_attr, (void * (*)(void *)) client_thread, NULL); printf("client_thread initiated \n"); //Add a Thread for L3 //Report thread pthread_attr_init(&Report_attr); pthread_create(&Report_tid, &Report_attr, (void * (*)(void *)) Report_thread, NULL); printf("Report_thread initiated \n"); while(True) { verb=action_menu( "ST_Main_Menu", &iverb); if(interrupted==True) { interrupted=False; flush_buffers(); } ////////////////////// if(strcmp(verb,"STOP!")==0) { transfer(0xA4, 0, 0, 0); printf("Stopping gloabl triggers."); } ////////////////////// if(strcmp(verb,"START")==0) { transfer(0xA3, 0, 0, 0); printf("Starting gloabl triggers."); } ////////////////////// if(strcmp(verb,"SETTARGETRATE")==0) { get_integer("Enter Global Target Trigger Rate", &STInfo.Global_Target_rate, 0, 0); } ////////////////////// if(strcmp(verb,"MONSTOP!")==0) //monitoring stop { STInfo.monexit=true; //stop monitpring thread } ////////////////////// if(strcmp(verb,"MONSTART")==0) //monitoring start { pthread_attr_init(&STmon_attr); pthread_create(&STmon_tid, &STmon_attr, (void * (*)(void *)) STmon_thread, NULL); //STInfo.monexit=0; // keep monitoring threat running } ////////////////////// if(strcmp(verb,"REPORT")==0) { error_logger(__FILE__,ERINFO,"Reports ON!"); if(!timer_on)start_timer(imon_sec); } ////////////////////// if(strcmp(verb,"REP!")==0) { stop_timer(); error_logger(__FILE__,ERINFO,"Reports OFF"); } ////////////////////// if(strcmp(verb,"LOCK!")==0) { //switch to remote control error_logger(__FILE__,ERINFO,"Readout ready to be engaged!"); set_async(True);//aqui es cuando cierra la conexion, usando getsring STInfo.lock_mode=True; } ////////////////////// if(strcmp(verb,"ULOCK")==0) { // if(client_conn) { // client_close(); client_conn=False; } error_logger(__FILE__,ERINFO,"Readout disengaged from CC"); set_async(False); STInfo.lock_mode=False; } ////////////////////// if(strcmp(verb,"HOSTNAME")==0) { int ihost; for(ihost=0;ihost<2;ihost++) { get_text("Enter Host Name",(char *)STInfo.hostname[ihost]); printf(" DBG HOSTNAME, %s", STInfo.hostname[ihost]); //if(STInfo.debug==True) // printf("Host Name defined: %s\n", STInfo.hostname[ihost]); } } ////////////////////// if(strcmp(verb,"HOSTNO")==0) { int ihost; for(ihost=0;ihost<2;ihost++) { get_integer("Enter Host Port Number",&STInfo.hostno[ihost],0,0); // if(STInfo.debug==True) printf("Host Port Number defined: %ld\n", STInfo.hostno[ihost]); } } ////////////////////// if(strcmp(verb,"CRISTAL")==0) { printf("\n"); TERM_PURPLE_COLOR; printf("CIRSTAL:Control in Sum-Trigger Algorithm\n"); printf("Author: Jezabel R. Garcia\n"); TERM_RESET_COLOR; printf("This progam was developed following the concept of MIR .\n"); printf("(by Riccardo Paoeletti and Daniel Mazin)\n"); printf("The Mir space station was built by connecting\n"); printf("several modules, each launched into orbit separately\n"); printf("One of the main module of the Mir was Cristal\n"); printf("that performed the astronomical observations and \n"); printf("extended the scientific possibilities of Mir.\n"); printf (" \n"); } ////////////////////// if(strcmp(verb,"TELESCOPE")==0) { get_integer("Who I am?",&STInfo.telescope,1,2); printf("This cristal version is running on M%i\n", STInfo.telescope); } ////////////////////// if(strcmp(verb,"PORTNO")==0) { get_integer("Enter Local Port Number",&STInfo.portno,0,0); // if(STInfo.debug==True) printf("Local Port Number defined: %ld\n", STInfo.portno); } ////////////////////// if(strcmp(verb,"TOOLS")==0) tools_menu(); ////////////////////// if(strcmp(verb,"DUMMY")==0) dummy_menu(); ////////////////////// if(strcmp(verb,"ASTRO")==0) astro_menu(); ////////////////////// if(strcmp(verb,"CLIP")==0) clip_menu(); ////////////////////// if(strcmp(verb,"SUM")==0) sum_menu(); ////////////////////// if(strcmp(verb,"POWER")==0) power_menu(); ////////////////////// if(strcmp(verb,"MESSAGE")==0) { get_text("Enter command", theString); puts(theString); error_logger(__FILE__,ERINFO, theString); } ////////////////////// if(strcmp(verb,"TIME_READ")==0) { int data4=0; get_hexadecimal("time? ",(long unsigned int*) &data4,0,0); int secs=15-data4&0xF; int sect=15-(data4>>4)&0x7; int mins=15-(data4>>7)&0xF; int mint=15-(data4>>11)&0x7; int hout=15-(data4>>14)&0x2; int hour=15-(data4>>16)&0xF; int tickWrong=(data4>>24)&0xFF; int tickRight = 0; int tickc = 0; for (tickc=0;tickc<8;tickc++) { tickRight += ((tickWrong>>(7-tickc))&0x1)*pow(2,tickc); // printf(" right %x wrong %x \n ",tickRight, (tickWrong>>(7-tickc))&0x1); } int tick = tickRight; //super second: // printf("R %X ",data4&0x0000FFFF); //super sub second: printf(" %X ",(data4&0xFFFF0000)>>16); //subsecond: get_hexadecimal("time? ",(long unsigned int*)&data4,0,0); printf("time: %d.%d h %d%d m %d%d %lf %d\n ",hout,hour,mint,mins,sect,secs,1.677721600-(data4&0x00007FFF)*51200e-9, tickRight); } ////////////////////// if(strcmp(verb,"SYSTEM")==0) { get_text("Enter command", theString); system(theString); } /////////////////////: if(strcmp(verb,"READY")==0) { STInfo.istatus=ST_STATUS_BUSY; TERM_BLUE_COLOR; printf (" ***************************************************** \n"); printf (" ***************************************************** \n"); printf (" ** ** \n"); printf (" ** CRISTAL IS NOW READY TO OPERATE ** \n"); printf (" ** ** \n"); printf (" ** ENJOY IT! ** \n"); printf (" ** ** \n"); printf (" ***************************************************** \n"); printf (" ***************************************************** \n"); TERM_RESET_COLOR; printf (" \n"); printf ("Press ? for more info. \n"); } if(strcmp(verb,"EXIT")==0) { stop_timer(); break; } usleep(250); }
krb5_error_code KRB5_CALLCONV krb5_init_context_profile(profile_t profile, krb5_flags flags, krb5_context *context_out) { krb5_context ctx = 0; krb5_error_code retval; struct { krb5_timestamp now; krb5_int32 now_usec; long pid; } seed_data; krb5_data seed; int tmp; char *plugin_dir = NULL; /* Verify some assumptions. If the assumptions hold and the compiler is optimizing, this should result in no code being executed. If we're guessing "unsigned long long" instead of using uint64_t, the possibility does exist that we're wrong. */ { uint64_t i64; assert(sizeof(i64) == 8); i64 = 0, i64--, i64 >>= 62; assert(i64 == 3); i64 = 1, i64 <<= 31, i64 <<= 31, i64 <<= 1; assert(i64 != 0); i64 <<= 1; assert(i64 == 0); } retval = krb5int_initialize_library(); if (retval) return retval; #if (defined(_WIN32)) /* * Load the krbcc32.dll if necessary. We do this here so that * we know to use API: later on during initialization. * The context being NULL is ok. */ krb5_win_ccdll_load(ctx); /* * krb5_vercheck() is defined in win_glue.c, and this is * where we handle the timebomb and version server checks. */ retval = krb5_vercheck(); if (retval) return retval; #endif *context_out = NULL; ctx = calloc(1, sizeof(struct _krb5_context)); if (!ctx) return ENOMEM; ctx->magic = KV5M_CONTEXT; ctx->profile_secure = (flags & KRB5_INIT_CONTEXT_SECURE) != 0; retval = k5_os_init_context(ctx, profile, flags); if (retval) goto cleanup; ctx->trace_callback = NULL; #ifndef DISABLE_TRACING if (!ctx->profile_secure) k5_init_trace(ctx); #endif retval = get_boolean(ctx, KRB5_CONF_ALLOW_WEAK_CRYPTO, 0, &tmp); if (retval) goto cleanup; ctx->allow_weak_crypto = tmp; retval = get_boolean(ctx, KRB5_CONF_IGNORE_ACCEPTOR_HOSTNAME, 0, &tmp); if (retval) goto cleanup; ctx->ignore_acceptor_hostname = tmp; retval = get_tristate(ctx, KRB5_CONF_DNS_CANONICALIZE_HOSTNAME, "fallback", CANONHOST_FALLBACK, 1, &tmp); if (retval) goto cleanup; ctx->dns_canonicalize_hostname = tmp; /* initialize the prng (not well, but passable) */ if ((retval = krb5_c_random_os_entropy( ctx, 0, NULL)) !=0) goto cleanup; if ((retval = krb5_crypto_us_timeofday(&seed_data.now, &seed_data.now_usec))) goto cleanup; seed_data.pid = getpid (); seed.length = sizeof(seed_data); seed.data = (char *) &seed_data; if ((retval = krb5_c_random_add_entropy(ctx, KRB5_C_RANDSOURCE_TIMING, &seed))) goto cleanup; ctx->default_realm = 0; get_integer(ctx, KRB5_CONF_CLOCKSKEW, DEFAULT_CLOCKSKEW, &tmp); ctx->clockskew = tmp; /* DCE 1.1 and below only support CKSUMTYPE_RSA_MD4 (2) */ /* DCE add kdc_req_checksum_type = 2 to krb5.conf */ get_integer(ctx, KRB5_CONF_KDC_REQ_CHECKSUM_TYPE, CKSUMTYPE_RSA_MD5, &tmp); ctx->kdc_req_sumtype = tmp; get_integer(ctx, KRB5_CONF_AP_REQ_CHECKSUM_TYPE, 0, &tmp); ctx->default_ap_req_sumtype = tmp; get_integer(ctx, KRB5_CONF_SAFE_CHECKSUM_TYPE, CKSUMTYPE_RSA_MD5_DES, &tmp); ctx->default_safe_sumtype = tmp; get_integer(ctx, KRB5_CONF_KDC_DEFAULT_OPTIONS, KDC_OPT_RENEWABLE_OK, &tmp); ctx->kdc_default_options = tmp; #define DEFAULT_KDC_TIMESYNC 1 get_integer(ctx, KRB5_CONF_KDC_TIMESYNC, DEFAULT_KDC_TIMESYNC, &tmp); ctx->library_options = tmp ? KRB5_LIBOPT_SYNC_KDCTIME : 0; retval = profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS, KRB5_CONF_PLUGIN_BASE_DIR, 0, DEFAULT_PLUGIN_BASE_DIR, &plugin_dir); if (!retval) retval = k5_expand_path_tokens(ctx, plugin_dir, &ctx->plugin_base_dir); if (retval) { TRACE_PROFILE_ERR(ctx, KRB5_CONF_PLUGIN_BASE_DIR, KRB5_CONF_LIBDEFAULTS, retval); goto cleanup; } /* * We use a default file credentials cache of 3. See * lib/krb5/krb/ccache/file/fcc.h for a description of the * credentials cache types. * * Note: DCE 1.0.3a only supports a cache type of 1 * DCE 1.1 supports a cache type of 2. */ #define DEFAULT_CCACHE_TYPE 4 get_integer(ctx, KRB5_CONF_CCACHE_TYPE, DEFAULT_CCACHE_TYPE, &tmp); ctx->fcc_default_format = tmp + 0x0500; ctx->prompt_types = 0; ctx->use_conf_ktypes = 0; ctx->udp_pref_limit = -1; /* It's OK if this fails */ (void)profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS, KRB5_CONF_ERR_FMT, NULL, NULL, &ctx->err_fmt); *context_out = ctx; ctx = NULL; cleanup: profile_release_string(plugin_dir); krb5_free_context(ctx); return retval; }
static int amixer_control(t_amixer *x, int argc, t_atom *argv, int roflag) { int err; snd_ctl_t *handle; snd_ctl_elem_info_t *info; snd_ctl_elem_id_t *id; snd_ctl_elem_value_t *control; char *ptr; unsigned int idx, count; long tmp; snd_ctl_elem_type_t type; snd_ctl_elem_info_alloca(&info); snd_ctl_elem_id_alloca(&id); snd_ctl_elem_value_alloca(&control); if (argc < 1) { error("Specify a full control identifier: [[iface=<iface>,][name='name',][index=<index>,][device=<device>,][subdevice=<subdevice>]]|[numid=<numid>]\n"); return -EINVAL; } if(A_FLOAT==argv->a_type){ snd_ctl_elem_id_set_numid(id, atom_getint(argv)); if(0) { error("Wrong control identifier: %d\n", atom_getint(argv)); return -EINVAL; } } else { if (parse_control_id(atom_getsymbol(argv)->s_name, id)) { error("Wrong control identifier: %s\n", atom_getsymbol(argv)->s_name); return -EINVAL; } } if ((err = snd_ctl_open(&handle, x->card, 0)) < 0) { error("Control %s open error: %s\n", x->card, snd_strerror(err)); return err; } snd_ctl_elem_info_set_id(info, id); if ((err = snd_ctl_elem_info(handle, info)) < 0) { error("Control %s cinfo error: %s\n", x->card, snd_strerror(err)); return err; } snd_ctl_elem_info_get_id(info, id); /* FIXME: Remove it when hctl find works ok !!! */ type = snd_ctl_elem_info_get_type(info); count = snd_ctl_elem_info_get_count(info); snd_ctl_elem_value_set_id(control, id); if (!roflag) { t_float atom_float = atom_getfloat(argv+1); int atom_isfloat = (A_FLOAT==(argv+1)->a_type); post("now setting"); ptr = atom_getsymbol(argv+1)->s_name; for (idx = 0; idx < count && idx < 128 && ptr && *ptr; idx++) { switch (type) { case SND_CTL_ELEM_TYPE_BOOLEAN: tmp = 0; if(atom_isfloat){ tmp=(atom_float>0)?1:0; } else if (!strncasecmp(ptr, "on", 2) || !strncasecmp(ptr, "up", 2)) { tmp = 1; ptr += 2; } else if (!strncasecmp(ptr, "yes", 3)) { tmp = 1; ptr += 3; } else if (!strncasecmp(ptr, "toggle", 6)) { tmp = snd_ctl_elem_value_get_boolean(control, idx); tmp = tmp > 0 ? 0 : 1; ptr += 6; } else if (isdigit(*ptr)) { tmp = atoi(ptr) > 0 ? 1 : 0; while (isdigit(*ptr)) ptr++; } else { while (*ptr && *ptr != ',') ptr++; } snd_ctl_elem_value_set_boolean(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_INTEGER: tmp = atom_isfloat?((int)atom_float):get_integer(&ptr, snd_ctl_elem_info_get_min(info), snd_ctl_elem_info_get_max(info)); snd_ctl_elem_value_set_integer(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_INTEGER64: tmp = atom_isfloat?((int)atom_float):get_integer64(&ptr, snd_ctl_elem_info_get_min64(info), snd_ctl_elem_info_get_max64(info)); snd_ctl_elem_value_set_integer64(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_ENUMERATED: tmp = atom_isfloat?((int)atom_float):get_integer(&ptr, 0, snd_ctl_elem_info_get_items(info) - 1); snd_ctl_elem_value_set_enumerated(control, idx, tmp); break; case SND_CTL_ELEM_TYPE_BYTES: tmp = atom_isfloat?((int)atom_float):get_integer(&ptr, 0, 255); snd_ctl_elem_value_set_byte(control, idx, tmp); break; default: break; } if (!strchr(atom_getsymbol(argv+1)->s_name, ',')) ptr = atom_getsymbol(argv+1)->s_name; else if (*ptr == ',') ptr++; } if ((err = snd_ctl_elem_write(handle, control)) < 0) { error("Control %s element write error: %s\n", x->card, snd_strerror(err)); return err; } } snd_ctl_close(handle); if (1) { snd_hctl_t *hctl; snd_hctl_elem_t *elem; if ((err = snd_hctl_open(&hctl, x->card, 0)) < 0) { error("Control %s open error: %s\n", x->card, snd_strerror(err)); return err; } if ((err = snd_hctl_load(hctl)) < 0) { error("Control %s load error: %s\n", x->card, snd_strerror(err)); return err; } elem = snd_hctl_find_elem(hctl, id); if (elem) show_control(x->card, " ", elem, LEVEL_BASIC | LEVEL_ID); else printf("Could not find the specified element\n"); snd_hctl_close(hctl); } }
static int intl_ctl(ErlDrvData drv_data, unsigned int command, char *buf, int len, char **rbuf, int rlen) { void* d = (void*)drv_data; char* aptr = buf; int alen = len; char* str1; char* str2; char* str3; int int1; int int2; unsigned int uint1; switch(command) { case INTL_GETTEXT: /* arguments: string msgid */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(gettext(str1), rbuf, rlen); case INTL_NGETTEXT: /* arguments: string msgid, string msgid_plural, int n */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr, &alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(ngettext(str1,str2,uint1), rbuf, rlen); case INTL_DGETTEXT: /* arguments: string domain, string msgid */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dgettext(str1,str2), rbuf, rlen); case INTL_DNGETTEXT: /* arguments: string domain, string msgid, string msgid_plural, integer n */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str3) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr, &alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dngettext(str1,str2,str3,uint1), rbuf, rlen); case INTL_DCGETTEXT: /* arguments: string domain, string msgid, int category */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dcgettext(str1,str2,int1),rbuf,rlen); case INTL_DCNGETTEXT: /* arguments: string domain, string msgid, strinf msgid_plural, unsigned n, int category */ if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str3) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_uinteger(&aptr,&alen, &uint1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(dcngettext(str1,str2,str3,uint1,int1),rbuf,rlen); case INTL_TEXTDOMAIN: /* arguments: string domainname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(textdomain(str1), rbuf, rlen); case INTL_BINDTEXTDOMAIN: /* arguments: string domainname, string dirname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(bindtextdomain(str1,str2), rbuf, rlen); case INTL_BIND_TEXTDOMAIN_CODESET: /* arguments: string domainname, string dirname */ if (len == 0) return ret_string(textdomain(NULL), rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str2) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(bind_textdomain_codeset(str1,str2), rbuf, rlen); case INTL_SETLOCALE: if (get_integer(&aptr,&alen, &int1) < 0) return ret_code(EINVAL, rbuf, rlen); if ((int1 = get_category(int1)) < 0) return ret_code(EINVAL, rbuf, rlen); if (get_string(&aptr, &alen, &str1) < 0) return ret_code(EINVAL, rbuf, rlen); return ret_string(setlocale(int1,str1), rbuf, rlen); } return -1; }
int iplink_parse(int argc, char **argv, struct iplink_req *req, char **name, char **type, char **link, char **dev, int *group, int *index) { int ret, len; char abuf[32]; int qlen = -1; int mtu = -1; int netns = -1; int vf = -1; int numtxqueues = -1; int numrxqueues = -1; int dev_index = 0; *group = -1; ret = argc; while (argc > 0) { if (strcmp(*argv, "up") == 0) { req->i.ifi_change |= IFF_UP; req->i.ifi_flags |= IFF_UP; } else if (strcmp(*argv, "down") == 0) { req->i.ifi_change |= IFF_UP; req->i.ifi_flags &= ~IFF_UP; } else if (strcmp(*argv, "name") == 0) { NEXT_ARG(); *name = *argv; } else if (strcmp(*argv, "index") == 0) { NEXT_ARG(); *index = atoi(*argv); } else if (matches(*argv, "link") == 0) { NEXT_ARG(); *link = *argv; } else if (matches(*argv, "address") == 0) { NEXT_ARG(); len = ll_addr_a2n(abuf, sizeof(abuf), *argv); if (len < 0) return -1; addattr_l(&req->n, sizeof(*req), IFLA_ADDRESS, abuf, len); } else if (matches(*argv, "broadcast") == 0 || strcmp(*argv, "brd") == 0) { NEXT_ARG(); len = ll_addr_a2n(abuf, sizeof(abuf), *argv); if (len < 0) return -1; addattr_l(&req->n, sizeof(*req), IFLA_BROADCAST, abuf, len); } else if (matches(*argv, "txqueuelen") == 0 || strcmp(*argv, "qlen") == 0 || matches(*argv, "txqlen") == 0) { NEXT_ARG(); if (qlen != -1) duparg("txqueuelen", *argv); if (get_integer(&qlen, *argv, 0)) invarg("Invalid \"txqueuelen\" value\n", *argv); addattr_l(&req->n, sizeof(*req), IFLA_TXQLEN, &qlen, 4); } else if (strcmp(*argv, "mtu") == 0) { NEXT_ARG(); if (mtu != -1) duparg("mtu", *argv); if (get_integer(&mtu, *argv, 0)) invarg("Invalid \"mtu\" value\n", *argv); addattr_l(&req->n, sizeof(*req), IFLA_MTU, &mtu, 4); } else if (strcmp(*argv, "netns") == 0) { NEXT_ARG(); if (netns != -1) duparg("netns", *argv); if ((netns = get_netns_fd(*argv)) >= 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_FD, &netns, 4); else if (get_integer(&netns, *argv, 0) == 0) addattr_l(&req->n, sizeof(*req), IFLA_NET_NS_PID, &netns, 4); else invarg("Invalid \"netns\" value\n", *argv); } else if (strcmp(*argv, "multicast") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_MULTICAST; if (strcmp(*argv, "on") == 0) { req->i.ifi_flags |= IFF_MULTICAST; } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags &= ~IFF_MULTICAST; } else return on_off("multicast", *argv); } else if (strcmp(*argv, "allmulticast") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_ALLMULTI; if (strcmp(*argv, "on") == 0) { req->i.ifi_flags |= IFF_ALLMULTI; } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags &= ~IFF_ALLMULTI; } else return on_off("allmulticast", *argv); } else if (strcmp(*argv, "promisc") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_PROMISC; if (strcmp(*argv, "on") == 0) { req->i.ifi_flags |= IFF_PROMISC; } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags &= ~IFF_PROMISC; } else return on_off("promisc", *argv); } else if (strcmp(*argv, "trailers") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_NOTRAILERS; if (strcmp(*argv, "off") == 0) { req->i.ifi_flags |= IFF_NOTRAILERS; } else if (strcmp(*argv, "on") == 0) { req->i.ifi_flags &= ~IFF_NOTRAILERS; } else return on_off("trailers", *argv); } else if (strcmp(*argv, "arp") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_NOARP; if (strcmp(*argv, "on") == 0) { req->i.ifi_flags &= ~IFF_NOARP; } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags |= IFF_NOARP; } else return on_off("noarp", *argv); } else if (strcmp(*argv, "vf") == 0) { struct rtattr *vflist; NEXT_ARG(); if (get_integer(&vf, *argv, 0)) { invarg("Invalid \"vf\" value\n", *argv); } vflist = addattr_nest(&req->n, sizeof(*req), IFLA_VFINFO_LIST); if (dev_index == 0) missarg("dev"); len = iplink_parse_vf(vf, &argc, &argv, req, dev_index); if (len < 0) return -1; addattr_nest_end(&req->n, vflist); } else if (matches(*argv, "master") == 0) { int ifindex; NEXT_ARG(); ifindex = ll_name_to_index(*argv); if (!ifindex) invarg("Device does not exist\n", *argv); addattr_l(&req->n, sizeof(*req), IFLA_MASTER, &ifindex, 4); } else if (matches(*argv, "nomaster") == 0) { int ifindex = 0; addattr_l(&req->n, sizeof(*req), IFLA_MASTER, &ifindex, 4); } else if (matches(*argv, "dynamic") == 0) { NEXT_ARG(); req->i.ifi_change |= IFF_DYNAMIC; if (strcmp(*argv, "on") == 0) { req->i.ifi_flags |= IFF_DYNAMIC; } else if (strcmp(*argv, "off") == 0) { req->i.ifi_flags &= ~IFF_DYNAMIC; } else return on_off("dynamic", *argv); } else if (matches(*argv, "type") == 0) { NEXT_ARG(); *type = *argv; argc--; argv++; break; } else if (matches(*argv, "alias") == 0) { NEXT_ARG(); addattr_l(&req->n, sizeof(*req), IFLA_IFALIAS, *argv, strlen(*argv)); argc--; argv++; break; } else if (strcmp(*argv, "group") == 0) { NEXT_ARG(); if (*group != -1) duparg("group", *argv); if (rtnl_group_a2n(group, *argv)) invarg("Invalid \"group\" value\n", *argv); } else if (strcmp(*argv, "mode") == 0) { int mode; NEXT_ARG(); mode = get_link_mode(*argv); if (mode < 0) invarg("Invalid link mode\n", *argv); addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode); } else if (strcmp(*argv, "state") == 0) { int state; NEXT_ARG(); state = get_operstate(*argv); if (state < 0) invarg("Invalid operstate\n", *argv); addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state); } else if (matches(*argv, "numtxqueues") == 0) { NEXT_ARG(); if (numtxqueues != -1) duparg("numtxqueues", *argv); if (get_integer(&numtxqueues, *argv, 0)) invarg("Invalid \"numtxqueues\" value\n", *argv); addattr_l(&req->n, sizeof(*req), IFLA_NUM_TX_QUEUES, &numtxqueues, 4); } else if (matches(*argv, "numrxqueues") == 0) { NEXT_ARG(); if (numrxqueues != -1) duparg("numrxqueues", *argv); if (get_integer(&numrxqueues, *argv, 0)) invarg("Invalid \"numrxqueues\" value\n", *argv); addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES, &numrxqueues, 4); } else { if (strcmp(*argv, "dev") == 0) { NEXT_ARG(); } if (matches(*argv, "help") == 0) usage(); if (*dev) duparg2("dev", *argv); *dev = *argv; dev_index = ll_name_to_index(*dev); if (dev_index == 0) invarg("Unknown device", *argv); } argc--; argv++; } return ret - argc; }