static int parse_u8(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off, int offmask) { int res = -1; int argc = *argc_p; char **argv = *argv_p; __u32 key; __u32 mask; if (argc < 2) return -1; if (get_u32(&key, *argv, 0)) return -1; argc--; argv++; if (get_u32(&mask, *argv, 16)) return -1; argc--; argv++; if (key > 0xFF || mask > 0xFF) return -1; if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } res = pack_key8(sel, key, mask, off, offmask); *argc_p = argc; *argv_p = argv; return res; }
static int parse_ip_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off) { int res = -1; int argc = *argc_p; char **argv = *argv_p; inet_prefix addr; __u32 mask; int offmask = 0; if (argc < 1) return -1; if (get_prefix_1(&addr, *argv, AF_INET)) return -1; argc--; argv++; if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } mask = 0; if (addr.bitlen) mask = htonl(0xFFFFFFFF << (32 - addr.bitlen)); if (pack_key(sel, addr.data[0], mask, off, offmask) < 0) return -1; res = 0; *argc_p = argc; *argv_p = argv; return res; }
int envy_bios_parse_bit_P (struct envy_bios *bios, struct envy_bios_bit_entry *bit) { struct envy_bios_power *power = &bios->power; int idx = 0; power->bit = bit; while (!parse_at(bios, power, idx, -1, NULL)) idx++; envy_bios_parse_power_unk14(bios); envy_bios_parse_power_unk18(bios); envy_bios_parse_power_unk1c(bios); envy_bios_parse_power_unk24(bios); envy_bios_parse_power_sense(bios); envy_bios_parse_power_budget(bios); envy_bios_parse_power_boost(bios); envy_bios_parse_power_cstep(bios); envy_bios_parse_power_base_clock(bios); envy_bios_parse_power_unk3c(bios); envy_bios_parse_power_unk40(bios); envy_bios_parse_power_unk44(bios); envy_bios_parse_power_unk48(bios); envy_bios_parse_power_unk4c(bios); envy_bios_parse_power_unk50(bios); envy_bios_parse_power_unk54(bios); envy_bios_parse_power_fan(bios); envy_bios_parse_power_unk5c(bios); envy_bios_parse_power_unk60(bios); envy_bios_parse_power_unk64(bios); return 0; }
void list_skills(struct char_data *ch) { const char *overflow = "\r\n**OVERFLOW**\r\n"; int i, sortpos; size_t len = 0, nlen; char buf2[MAX_STRING_LENGTH]; len = snprintf(buf2, sizeof(buf2), "You have %d practice session%s remaining.\r\n" "You know of the following %ss:\r\n", GET_PRACTICES(ch), GET_PRACTICES(ch) == 1 ? "" : "s", SPLSKL(ch)); int cnt = 0; for (sortpos = 1; sortpos <= MAX_SKILLS; sortpos++) { i = spell_sort_info[sortpos]; if (GET_LEVEL(ch) >= spell_info[i].min_level[(int) GET_CLASS(ch)]) { cnt += 1; nlen = snprintf(buf2 + len, sizeof(buf2) - len, (cnt%2) ? "%-20s %s | " : "%-20s %s\r\n", spell_info[i].name, how_good(GET_SKILL(ch, i))); if (len + nlen >= sizeof(buf2) || nlen < 0) break; len += nlen; } } if (len >= sizeof(buf2)) strcpy(buf2 + sizeof(buf2) - strlen(overflow) - 1, overflow); /* strcpy: OK */ parse_at(buf2); page_string(ch->desc, buf2, TRUE); }
void loadDamageMessages(void) { FILE *fl; char chk[128]; int maxDam, painPercentage; struct damage_message_type *message; if(!(fl = fopen(COMBAT_FILE,"r"))) { log("SYSERR: Error reading combat message file %s: %s", COMBAT_FILE, strerror(errno)); exit(1); } // necessary for reloading if(damageMessageList != NULL) { free_list(damageMessageList); } damageMessageList = create_list(); while(!feof(fl)) { fgets(chk, 128, fl); while(!feof(fl) && (*chk == '\n' || *chk == '*')) fgets(chk, 128, fl); while(*chk == 'M') { fgets(chk, 128, fl); sscanf(chk, "%d %d\n", &maxDam, &painPercentage); CREATE(message, struct damage_message_type, 1); CREATE(message->msg, struct msg_type, 1); message->maxDamage = maxDam; message->painPercentage = painPercentage; message->msg->room_msg= strdup(fread_line(fl)); message->msg->attacker_msg = strdup(fread_line(fl)); message->msg->victim_msg = strdup(fread_line(fl)); parse_at(message->msg->attacker_msg); parse_at(message->msg->room_msg); parse_at(message->msg->victim_msg); add_to_list(message, damageMessageList); } } fclose(fl); log("Loaded %d damage messages", damageMessageList->iSize); }
static int conf_arg(int numargs, char **arg) { if (numargs < 2) return 0; /* CMDSCRIPT <scriptname> */ if (!strcmp(arg[0], "CMDSCRIPT")) { cmdscript = xstrdup(arg[1]); return 1; } /* PIPEFN <pipename> */ if (!strcmp(arg[0], "PIPEFN")) { pipefn = xstrdup(arg[1]); return 1; } /* LOCKFN <filename> */ if (!strcmp(arg[0], "LOCKFN")) { lockfn = xstrdup(arg[1]); return 1; } if (numargs < 5) return 0; /* AT <notifytype> <upsname> <command> <cmdarg1> [<cmdarg2>] */ if (!strcmp(arg[0], "AT")) { /* don't use arg[5] unless we have it... */ if (numargs > 5) parse_at(arg[1], arg[2], arg[3], arg[4], arg[5]); else parse_at(arg[1], arg[2], arg[3], arg[4], NULL); return 1; } return 0; }
static int parse_ip6_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off) { int res = -1; int argc = *argc_p; char **argv = *argv_p; int plen = 128; int i; inet_prefix addr; int offmask = 0; if (argc < 1) return -1; if (get_prefix_1(&addr, *argv, AF_INET6)) return -1; argc--; argv++; if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } plen = addr.bitlen; for (i = 0; i < plen; i += 32) { /* if (((i + 31) & ~0x1F) <= plen) { */ if (i + 31 <= plen) { res = pack_key(sel, addr.data[i / 32], 0xFFFFFFFF, off + 4 * (i / 32), offmask); if (res < 0) return -1; } else if (i < plen) { __u32 mask = htonl(0xFFFFFFFF << (32 - (plen - i))); res = pack_key(sel, addr.data[i / 32], mask, off + 4 * (i / 32), offmask); if (res < 0) return -1; } } res = 0; *argc_p = argc; *argv_p = argv; return res; }
static int nk_parse_u16(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off, int offmask , unsigned int type) { int res = -1; int argc = *argc_p; char **argv = *argv_p; __u32 key; __u32 mask; //fprintf(stderr, "test 1\n "); if (argc < 2) { //fprintf(stderr, "test 1-1\n "); return -1; } //fprintf(stderr, "test 2\n "); if (get_u32(&key, *argv, 0)) { //fprintf(stderr, "test 2-1\n "); return -1; } //fprintf(stderr, "off 1 = %x ", off); //fprintf(stderr, "key 1 = %x ", key); argc--; argv++; if (get_u32(&mask, *argv, 16)) return -1; //fprintf(stderr, "mask 1 = %x ", mask); argc--; argv++; if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } res = nk_pack_key16(sel, key, mask, off, offmask,type); *argc_p = argc; *argv_p = argv; return res; }
static int parse_port(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off, int offmask) { int res = -1; int argc = *argc_p; char **argv = *argv_p; __u32 start; __u32 end; if (argc < 2) return -1; if (get_u32(&start, *argv, 0)) return -1; argc--; argv++; if (get_u32(&end, *argv, 0)) return -1; argc--; argv++; #if 0 if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } #endif if (start > 0xFFFF || end > 0xFFFF) return -1; if ((off & 3) == 0) { start <<= 16; end <<= 16; } off &= ~3; start = htonl(start); end = htonl(end); res = pack_key(sel, start, end, off, offmask, 1); *argc_p = argc; *argv_p = argv; return res; }
int parse_arg(const char *arg,sh_operand_info *op, char *err_msg) // Parse arg and return a filled operand struct { int len,mode; if(arg[0] == 0) { op->type = 0; op->reg = 0; return 1; } if(*arg == '@') { arg++; return parse_at(arg,op, err_msg); } if(*arg == '#') { op->type = A_IMM; return 1; } len = parse_reg(arg,&mode,&(op->reg)); if(len) { op->type = mode; return 1; } else { op->type = A_BDISP12; return 1; } return 0; }
static int parse_ether_addr(int *argc_p, char ***argv_p, struct tc_u32_sel *sel, int off) { int res = -1; int argc = *argc_p; char **argv = *argv_p; __u8 addr[6]; int offmask = 0; int i; if (argc < 1) return -1; if (sscanf(*argv, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", addr + 0, addr + 1, addr + 2, addr + 3, addr + 4, addr + 5) != 6) { fprintf(stderr, "parse_ether_addr: improperly formed address '%s'\n", *argv); return -1; } argc--; argv++; if (argc > 0 && strcmp(argv[0], "at") == 0) { NEXT_ARG(); if (parse_at(&argc, &argv, &off, &offmask)) return -1; } for (i = 0; i < 6; i++) { res = pack_key8(sel, addr[i], 0xFF, off + i, offmask); if (res < 0) return -1; } *argc_p = argc; *argv_p = argv; return res; }
void envy_bios_print_bit_P (struct envy_bios *bios, FILE *out, unsigned mask) { struct envy_bios_power *power = &bios->power; const char *name; uint16_t addr; int ret = 0, i = 0; if (!power->bit || !(mask & ENVY_BIOS_PRINT_PERF)) return; fprintf(out, "BIT table 'P' at 0x%x, version %i\n", power->bit->offset, power->bit->version); for (i = 0; i < power->bit->t_len; i+=2) { ret = bios_u16(bios, power->bit->t_offset + i, &addr); if (!ret && addr) { name = "UNKNOWN"; ret = parse_at(bios, power, -1, i, &name); fprintf(out, "0x%02x: 0x%x => %s TABLE\n", i, addr, name); } } fprintf(out, "\n"); }