// ------------------------------------------------------------------------------------------------------ int ObjectSelectNextinSegment(void) { //update_due_to_new_segment(); //Assert(Cur_object_seg == Cursegp); const vsegptr_t objsegp = Cursegp; if (Cur_object_index == object_none) { Cur_object_index = objsegp->objects; } else { if (Objects[Cur_object_index].segnum != Cursegp) Cur_object_index = objsegp->objects; } //Debug: make sure current object is in current segment objnum_t id; for (id=objsegp->objects;(id != Cur_object_index) && (id != object_none);id=Objects[id].next); Assert(id == Cur_object_index); //should have found object // Select the next object, wrapping back to start if we are at the end of the linked list for this segment. if (id != object_none) Cur_object_index = get_next_object(objsegp,Cur_object_index); Update_flags |= UF_WORLD_CHANGED; return 1; }
/* * Hack -- determine if a given location is "interesting" */ static bool target_set_interactive_accept(int y, int x) { object_type *o_ptr; /* Player grids are always interesting */ if (cave_m_idx[y][x] < 0) return (TRUE); /* Handle hallucination */ if (p_ptr->timed[TMD_IMAGE]) return (FALSE); /* Visible monsters */ if (cave_m_idx[y][x] > 0) { monster_type *m_ptr = &mon_list[cave_m_idx[y][x]]; /* Visible monsters */ if (m_ptr->ml) return (TRUE); } /* Scan all objects in the grid */ for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Memorized object */ if (o_ptr->marked) return (TRUE); } /* Interesting memorized features */ /* Ignore unknown features */ if (!(cave_info[y][x] & (CAVE_MARK))) return (FALSE); /* Find interesting effects */ if (cave_x_idx[y][x] > 0) { /* Get the first effect */ u16b x_idx = cave_x_idx[y][x]; /* Scan the effects on that grid */ while (x_idx) { /* Get the effect data */ effect_type *x_ptr = &x_list[x_idx]; /* Point to the next effect */ x_idx = x_ptr->next_x_idx; /* Ignore hidden effects */ if (!(x_ptr->x_f_idx) || (x_ptr->x_flags & (EF1_HIDDEN))) continue; /* We have an interesting effect */ return (TRUE); } } /* Check grid type with dungeon capabilities */ return ((*dun_cap->can_target_feature)(cave_feat[y][x])); }
READ_ALN* get_read_aln(hashtable ht,char*read_name) { ulong key=hashit(read_name); READ_ALN* r=(READ_ALN*)get_object(ht,key); while (r!=NULL) { // confirm that hdr are equal if (!strcmp(read_name,r->name)) break; r=(READ_ALN*)get_next_object(ht,key); } return r; }
inline static INDEX_ENTRY* lookup_header(hashtable index,char *hdr) { // lookup hdr in index long key=hashit(hdr); INDEX_ENTRY* e=(INDEX_ENTRY*)get_object(index,key); while (e!=NULL) { // confirm that hdr are equal if ( !strcmp(hdr,e->hdr)) break; e=(INDEX_ENTRY*)get_next_object(index,key); } return e; }
//returns the number of the next object in a segment, skipping the player int get_next_object(segment *seg,int id) { if (id==-1 || (id=Objects[id].next)==-1) return get_first_object(seg); if (id == (ConsoleObject-Objects)) return get_next_object(seg,id); return id; }
static INDEX_ENTRY* lookup_header(hashtable sn_index,char *hdr) { // lookup hdr in sn_index ulong key=hashit(hdr); //printf("looking for %s: key=%lu\n",hdr,key); INDEX_ENTRY* e=(INDEX_ENTRY*)get_object(sn_index,key); while (e!=NULL) { // confirm that hdr are equal if ( !strcmp(hdr,e->hdr)) break; e=(INDEX_ENTRY*)get_next_object(sn_index,key); } return e; }
/* ** Update the objects quantity in stuff. */ int stuff(t_player *p, char *data) { int i; i = 1; p->need_to_look_stuff = UPDATE_STUFF_TIME; if (strlen(data) < 1 || data[0] != '{' || data[strlen(data) - 1] != '}') return (1); while (data[i] && data[i] != '}') i += get_next_object(p, data + i, 0); return (1); }
/* * Hack -- determine if a given location is "interesting" */ static bool target_set_interactive_accept(int y, int x) { object_type *o_ptr; /* Player grids are always interesting */ if (cave->m_idx[y][x] < 0) return (TRUE); /* Handle hallucination */ if (p_ptr->timed[TMD_IMAGE]) return (FALSE); /* Visible monsters */ if (cave->m_idx[y][x] > 0) { monster_type *m_ptr = cave_monster_at(cave, y, x); /* Visible monsters */ if (m_ptr->ml && !m_ptr->unaware) return (TRUE); } /* Scan all objects in the grid */ for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Memorized object */ if (o_ptr->marked && !squelch_item_ok(o_ptr)) return (TRUE); } /* Interesting memorized features */ if (cave->info[y][x] & (CAVE_MARK) && !cave_isboring(cave, y, x)) return (TRUE); /* Nope */ return (FALSE); }
/* * Hack -- determine if a given location is "interesting" */ static bool target_set_interactive_accept(int y, int x) { object_type *o_ptr; /* Player grids are always interesting */ if (cave_m_idx[y][x] < 0) return (TRUE); /* Handle hallucination */ if (p_ptr->timed[TMD_IMAGE]) return (FALSE); /* Visible monsters */ if (cave_m_idx[y][x] > 0) { monster_type *m_ptr = &mon_list[cave_m_idx[y][x]]; /* Visible monsters */ if (m_ptr->ml) return (TRUE); } /* Scan all objects in the grid */ for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Memorized object */ if (o_ptr->marked && !squelch_hide_item(o_ptr)) return (TRUE); } /* Interesting memorized features */ if (cave_info[y][x] & (CAVE_MARK)) { /* Notice glyphs */ if (cave_feat[y][x] == FEAT_GLYPH) return (TRUE); /* Notice doors */ if (cave_feat[y][x] == FEAT_OPEN) return (TRUE); if (cave_feat[y][x] == FEAT_BROKEN) return (TRUE); /* Notice stairs */ if (cave_feat[y][x] == FEAT_LESS) return (TRUE); if (cave_feat[y][x] == FEAT_MORE) return (TRUE); /* Notice shops */ if ((cave_feat[y][x] >= FEAT_SHOP_HEAD) && (cave_feat[y][x] <= FEAT_SHOP_TAIL)) return (TRUE); /* Notice traps */ if ((cave_feat[y][x] >= FEAT_TRAP_HEAD) && (cave_feat[y][x] <= FEAT_TRAP_TAIL)) return (TRUE); /* Notice doors */ if ((cave_feat[y][x] >= FEAT_DOOR_HEAD) && (cave_feat[y][x] <= FEAT_DOOR_TAIL)) return (TRUE); /* Notice rubble */ if (cave_feat[y][x] == FEAT_RUBBLE) return (TRUE); /* Notice veins with treasure */ if (cave_feat[y][x] == FEAT_MAGMA_K) return (TRUE); if (cave_feat[y][x] == FEAT_QUARTZ_K) return (TRUE); } /* Nope */ return (FALSE); }
/* * Search for hidden things. Returns true if a search was attempted, returns * false when the player has a 0% chance of finding anything. Prints messages * for negative confirmation when verbose mode is requested. */ bool search(bool verbose) { int py = p_ptr->py; int px = p_ptr->px; int y, x, chance; bool found = FALSE; object_type *o_ptr; /* Start with base search ability */ chance = p_ptr->state.skills[SKILL_SEARCH]; /* Penalize various conditions */ if (p_ptr->timed[TMD_BLIND] || no_light()) chance = chance / 10; if (p_ptr->timed[TMD_CONFUSED] || p_ptr->timed[TMD_IMAGE]) chance = chance / 10; /* Prevent fruitless searches */ if (chance <= 0) { if (verbose) { msg("You can't make out your surroundings well enough to search."); /* Cancel repeat */ disturb(p_ptr, 0, 0); } return FALSE; } /* Search the nearby grids, which are always in bounds */ for (y = (py - 1); y <= (py + 1); y++) { for (x = (px - 1); x <= (px + 1); x++) { /* Sometimes, notice things */ if (randint0(100) < chance) { /* Invisible trap */ if (cave->feat[y][x] == FEAT_INVIS) { found = TRUE; /* Pick a trap */ pick_trap(y, x); /* Message */ msg("You have found a trap."); /* Disturb */ disturb(p_ptr, 0, 0); } /* Secret door */ if (cave->feat[y][x] == FEAT_SECRET) { found = TRUE; /* Message */ msg("You have found a secret door."); /* Pick a door */ place_closed_door(cave, y, x); /* Disturb */ disturb(p_ptr, 0, 0); } /* Scan all objects in the grid */ for (o_ptr = get_first_object(y, x); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Skip non-chests */ if (o_ptr->tval != TV_CHEST) continue; /* Skip disarmed chests */ if (o_ptr->pval[DEFAULT_PVAL] <= 0) continue; /* Skip non-trapped chests */ if (!chest_traps[o_ptr->pval[DEFAULT_PVAL]]) continue; /* Identify once */ if (!object_is_known(o_ptr)) { found = TRUE; /* Message */ msg("You have discovered a trap on the chest!"); /* Know the trap */ object_notice_everything(o_ptr); /* Notice it */ disturb(p_ptr, 0, 0); } } } } } if (verbose && !found) { if (chance >= 100) msg("There are no secrets here."); else msg("You found nothing."); } return TRUE; }
/* * Use an object the right way. * * There may be a BIG problem with any "effect" that can cause "changes" * to the inventory. For example, a "scroll of recharging" can cause * a wand/staff to "disappear", moving the inventory up. Luckily, the * scrolls all appear BEFORE the staffs/wands, so this is not a problem. * But, for example, a "staff of recharging" could cause MAJOR problems. * In such a case, it will be best to either (1) "postpone" the effect * until the end of the function, or (2) "change" the effect, say, into * giving a staff "negative" charges, or "turning a staff into a stick". * It seems as though a "rod of recharging" might in fact cause problems. * The basic problem is that the act of recharging (and destroying) an * item causes the inducer of that action to "move", causing "o_ptr" to * no longer point at the correct item, with horrifying results. */ void do_cmd_use(cmd_code code, cmd_arg args[]) { int item = args[0].item; object_type *o_ptr = object_from_item_idx(item); int effect; bool ident = FALSE, used = FALSE; bool was_aware = object_flavor_is_aware(o_ptr); int dir = 5; int px = p_ptr->px, py = p_ptr->py; int snd, boost, level; use_type use; int items_allowed = 0; /* Determine how this item is used. */ if (obj_is_rod(o_ptr)) { if (!obj_can_zap(o_ptr)) { msg_print("That rod is still charging."); return; } use = USE_TIMEOUT; snd = MSG_ZAP_ROD; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_wand(o_ptr)) { if (!obj_has_charges(o_ptr)) { msg_print("That wand has no charges."); return; } use = USE_CHARGE; snd = MSG_ZAP_ROD; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_staff(o_ptr)) { if (!obj_has_charges(o_ptr)) { msg_print("That staff has no charges."); return; } use = USE_CHARGE; snd = MSG_USE_STAFF; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_food(o_ptr)) { use = USE_SINGLE; snd = MSG_EAT; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_potion(o_ptr)) { use = USE_SINGLE; snd = MSG_QUAFF; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_scroll(o_ptr)) { /* Check player can use scroll */ if (!player_can_read()) return; use = USE_SINGLE; snd = MSG_GENERIC; items_allowed = USE_INVEN | USE_FLOOR; } else if (obj_is_activatable(o_ptr)) { if (!obj_can_activate(o_ptr)) { msg_print("That item is still charging."); return; } use = USE_TIMEOUT; snd = MSG_ACT_ARTIFACT; items_allowed = USE_EQUIP; } else { msg_print("The item cannot be used at the moment"); } /* Check if item is within player's reach. */ if (items_allowed == 0 || !item_is_available(item, NULL, items_allowed)) { msg_print("You cannot use that item from its current location."); return; } /* track the object used */ track_object(item); /* Figure out effect to use */ effect = object_effect(o_ptr); /* If the item requires a direction, get one (allow cancelling) */ if (obj_needs_aim(o_ptr)) dir = args[1].direction; /* Check for use if necessary, and execute the effect */ if ((use != USE_CHARGE && use != USE_TIMEOUT) || check_devices(o_ptr)) { /* Special message for artifacts */ if (artifact_p(o_ptr)) { message(snd, 0, "You activate it."); if (a_info[o_ptr->name1].effect_msg) activation_message(o_ptr, a_info[o_ptr->name1].effect_msg); level = a_info[o_ptr->name1].level; } else { /* Make a noise! */ sound(snd); level = k_info[o_ptr->k_idx].level; } /* A bit of a hack to make ID work better. -- Check for "obvious" effects beforehand. */ if (effect_obvious(effect)) object_flavor_aware(o_ptr); /* Boost damage effects if skill > difficulty */ boost = p_ptr->state.skills[SKILL_DEVICE] - level; if (boost < 0) boost = 0; /* Do effect */ used = effect_do(effect, &ident, was_aware, dir, beam_chance(o_ptr->tval), boost); /* Quit if the item wasn't used and no knowledge was gained */ if (!used && (was_aware || !ident)) return; } /* If the item is a null pointer or has been wiped, be done now */ if (!o_ptr || o_ptr->k_idx <= 1) return; if (ident) object_notice_effect(o_ptr); /* Food feeds the player */ if (o_ptr->tval == TV_FOOD || o_ptr->tval == TV_POTION) (void)set_food(p_ptr->food + o_ptr->pval); /* Use the turn */ p_ptr->energy_use = 100; /* Mark as tried and redisplay */ p_ptr->notice |= (PN_COMBINE | PN_REORDER); p_ptr->redraw |= (PR_INVEN | PR_EQUIP | PR_OBJECT); /* * If the player becomes aware of the item's function, then mark it as * aware and reward the player with some experience. Otherwise, mark * it as "tried". */ if (ident && !was_aware) { /* Object level */ int lev = k_info[o_ptr->k_idx].level; object_flavor_aware(o_ptr); if (o_ptr->tval == TV_ROD) object_notice_everything(o_ptr); gain_exp((lev + (p_ptr->lev / 2)) / p_ptr->lev); p_ptr->notice |= PN_SQUELCH; } else if (used) { object_flavor_tried(o_ptr); } /* If there are no more of the item left, then we're done. */ if (!o_ptr->number) return; /* Chargeables act differently to single-used items when not used up */ if (used && use == USE_CHARGE) { /* Use a single charge */ o_ptr->pval--; /* Describe charges */ if (item >= 0) inven_item_charges(item); else floor_item_charges(0 - item); } else if (used && use == USE_TIMEOUT) { /* Artifacts use their own special field */ if (o_ptr->name1) { const artifact_type *a_ptr = &a_info[o_ptr->name1]; o_ptr->timeout = randcalc(a_ptr->time, 0, RANDOMISE); } else { const object_kind *k_ptr = &k_info[o_ptr->k_idx]; o_ptr->timeout += randcalc(k_ptr->time, 0, RANDOMISE); } } else if (used && use == USE_SINGLE) { /* Destroy a potion in the pack */ if (item >= 0) { inven_item_increase(item, -1); inven_item_describe(item); inven_item_optimize(item); } /* Destroy a potion on the floor */ else { floor_item_increase(0 - item, -1); floor_item_describe(0 - item); floor_item_optimize(0 - item); } } /* Hack to make Glyph of Warding work properly */ if (cave_feat[py][px] == FEAT_GLYPH) { /* Shift any objects to further away */ for (o_ptr = get_first_object(py, px); o_ptr; o_ptr = get_next_object(o_ptr)) { drop_near(o_ptr, 0, py, px, FALSE); } /* Delete the "moved" objects from their original position */ delete_object(py, px); } }
/* * Update the current "run" path * * Return TRUE if the running should be stopped */ static bool run_test(void) { int py = p_ptr->py; int px = p_ptr->px; int prev_dir; int new_dir; int check_dir = 0; int row, col; int i, max, inv; int option, option2; /* No options yet */ option = 0; option2 = 0; /* Where we came from */ prev_dir = p_ptr->run_old_dir; /* Range of newly adjacent grids */ max = (prev_dir & 0x01) + 1; /* Look at every newly adjacent square. */ for (i = -max; i <= max; i++) { object_type *o_ptr; /* New direction */ new_dir = cycle[chome[prev_dir] + i]; /* New location */ row = py + ddy[new_dir]; col = px + ddx[new_dir]; /* Visible monsters abort running */ if (cave_m_idx[row][col] > 0) { monster_type *m_ptr = &mon_list[cave_m_idx[row][col]]; /* Visible monster */ if (m_ptr->ml) return (TRUE); } /* Visible objects abort running */ for (o_ptr = get_first_object(row, col); o_ptr; o_ptr = get_next_object(o_ptr)) { /* Visible object */ if (o_ptr->marked && !squelch_hide_item(o_ptr)) return (TRUE); } /* Assume unknown */ inv = TRUE; /* Check memorized grids */ if (cave_info[row][col] & (CAVE_MARK)) { bool notice = TRUE; /* Examine the terrain */ switch (cave_feat[row][col]) { /* Floors */ case FEAT_FLOOR: /* Invis traps */ case FEAT_INVIS: /* Secret doors */ case FEAT_SECRET: /* Normal veins */ case FEAT_MAGMA: case FEAT_QUARTZ: /* Hidden treasure */ case FEAT_MAGMA_H: case FEAT_QUARTZ_H: /* Walls */ case FEAT_WALL_EXTRA: case FEAT_WALL_INNER: case FEAT_WALL_OUTER: case FEAT_WALL_SOLID: case FEAT_PERM_EXTRA: case FEAT_PERM_INNER: case FEAT_PERM_OUTER: case FEAT_PERM_SOLID: { /* Ignore */ notice = FALSE; /* Done */ break; } } /* Interesting feature */ if (notice) return (TRUE); /* The grid is "visible" */ inv = FALSE; } /* Analyze unknown grids and floors */ if (inv || cave_floor_bold(row, col)) { /* Looking for open area */ if (p_ptr->run_open_area) { /* Nothing */ } /* The first new direction. */ else if (!option) { option = new_dir; } /* Three new directions. Stop running. */ else if (option2) { return (TRUE); } /* Two non-adjacent new directions. Stop running. */ else if (option != cycle[chome[prev_dir] + i - 1]) { return (TRUE); } /* Two new (adjacent) directions (case 1) */ else if (new_dir & 0x01) { check_dir = cycle[chome[prev_dir] + i - 2]; option2 = new_dir; } /* Two new (adjacent) directions (case 2) */ else { check_dir = cycle[chome[prev_dir] + i + 1]; option2 = option; option = new_dir; } } /* Obstacle, while looking for open area */ else { if (p_ptr->run_open_area) { if (i < 0) { /* Break to the right */ p_ptr->run_break_right = TRUE; } else if (i > 0) { /* Break to the left */ p_ptr->run_break_left = TRUE; } } } } /* Look at every soon to be newly adjacent square. */ for (i = -max; i <= max; i++) { /* New direction */ new_dir = cycle[chome[prev_dir] + i]; /* New location */ row = py + ddy[prev_dir] + ddy[new_dir]; col = px + ddx[prev_dir] + ddx[new_dir]; /* HACK: Ugh. Sometimes we come up with illegal bounds. This will * treat the symptom but not the disease. */ if (row >= DUNGEON_HGT || col >= DUNGEON_WID) continue; if (row < 0 || col < 0) continue; /* Visible monsters abort running */ if (cave_m_idx[row][col] > 0) { monster_type *m_ptr = &mon_list[cave_m_idx[row][col]]; /* Visible monster */ if (m_ptr->ml) return (TRUE); } } /* Looking for open area */ if (p_ptr->run_open_area) { /* Hack -- look again */ for (i = -max; i < 0; i++) { new_dir = cycle[chome[prev_dir] + i]; row = py + ddy[new_dir]; col = px + ddx[new_dir]; /* Unknown grid or non-wall */ /* Was: cave_floor_bold(row, col) */ if (!(cave_info[row][col] & (CAVE_MARK)) || (cave_feat[row][col] < FEAT_SECRET)) { /* Looking to break right */ if (p_ptr->run_break_right) { return (TRUE); } } /* Obstacle */ else { /* Looking to break left */ if (p_ptr->run_break_left) { return (TRUE); } } } /* Hack -- look again */ for (i = max; i > 0; i--) { new_dir = cycle[chome[prev_dir] + i]; row = py + ddy[new_dir]; col = px + ddx[new_dir]; /* Unknown grid or non-wall */ /* Was: cave_floor_bold(row, col) */ if (!(cave_info[row][col] & (CAVE_MARK)) || (cave_feat[row][col] < FEAT_SECRET)) { /* Looking to break left */ if (p_ptr->run_break_left) { return (TRUE); } } /* Obstacle */ else { /* Looking to break right */ if (p_ptr->run_break_right) { return (TRUE); } } } } /* Not looking for open area */ else { /* No options */ if (!option) { return (TRUE); } /* One option */ else if (!option2) { /* Primary option */ p_ptr->run_cur_dir = option; /* No other options */ p_ptr->run_old_dir = option; } /* Two options, examining corners */ else { /* Primary option */ p_ptr->run_cur_dir = option; /* Hack -- allow curving */ p_ptr->run_old_dir = option2; } } /* About to hit a known wall, stop */ if (see_wall(p_ptr->run_cur_dir, py, px)) { return (TRUE); } /* Failure */ return (FALSE); }
BOOL pdhservice_translate(LPSTR object, LPSTR counter, LPSTR instance, BOOL is_english, LPSTR *new_object, LPSTR *new_counter, LPSTR *new_instance) { #if 0 #define DEBUG_SHOW_NAME #endif BOOL instance_found = FALSE; BOOL counter_found = FALSE; BOOL object_found = FALSE; PPERF_DATA_BLOCK perf_data = NULL; DWORD buffer_size = TOTALBYTES; pdhservice_container *container1; pdhservice_container *container2; DENTER("pdhservice_translate"); if (is_english) { container1 = &container_english; container2 = &container_system_lang; } else { container1 = &container_system_lang; container2 = &container_english; } // Allocate the buffer for the performance data. perf_data = (PPERF_DATA_BLOCK) malloc(buffer_size); if (perf_data != NULL) { PPERF_OBJECT_TYPE perf_object; DWORD i; while (RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, (LPBYTE) perf_data, &buffer_size) == ERROR_MORE_DATA) { /* * Increase buffer until it is big enough */ buffer_size += BYTEINCREMENT; perf_data = (PPERF_DATA_BLOCK) realloc(perf_data, buffer_size); } /* * Process all objects */ perf_object = get_first_object(perf_data); for(i = 0; !object_found && i < perf_data->NumObjectTypes; i++) { PPERF_COUNTER_DEFINITION perf_counter; #ifdef DEBUG_SHOW_NAME printf("\nO %ld: %s\n", perf_object->ObjectNameTitleIndex, container1->names_array[perf_object->ObjectNameTitleIndex]); fflush(stdout); #endif if (lstrcmp(container1->names_array[perf_object->ObjectNameTitleIndex], object) == 0) { *new_object = container2->names_array[perf_object->ObjectNameTitleIndex]; object_found = TRUE; } perf_counter = get_first_counter(perf_object); if (perf_object->NumInstances > 0) { int k; /* * Process all instances */ PPERF_INSTANCE_DEFINITION perf_instance = get_first_instance(perf_object); for (k = 0; !instance_found && k < perf_object->NumInstances; k++) { PPERF_COUNTER_DEFINITION perf_curinst; DWORD j; WCHAR wide_string[1024]; #ifdef DEBUG_SHOW_NAME printf( "\n\tI %S: \n", (char *)((PBYTE)perf_instance + perf_instance->NameOffset)); fflush(stdout); #endif /* The instance seems to be stored as multibyte string !? */ mbstowcs(wide_string, instance, sizeof(wide_string)/sizeof(WCHAR)); if (object_found && wcscmp((wchar_t *)((PBYTE)perf_instance + perf_instance->NameOffset), wide_string) == 0) { *new_instance = instance; instance_found = TRUE; } else if (object_found && lstrcmp("*", instance) == 0) { *new_instance = "*"; instance_found = TRUE; } perf_curinst = perf_counter; // Retrieve all counters. for (j = 0; !counter_found && j < perf_object->NumCounters; j++) { #ifdef DEBUG_SHOW_NAME printf("\t\tC %ld: %s\n", perf_curinst->CounterNameTitleIndex, container1->names_array[perf_curinst->CounterNameTitleIndex]); fflush(stdout); #endif if (instance_found && lstrcmp(container1->names_array[perf_curinst->CounterNameTitleIndex], counter) == 0) { *new_counter = container2->names_array[perf_curinst->CounterNameTitleIndex]; counter_found = TRUE; } perf_curinst = get_next_counter(perf_curinst); } perf_instance = get_next_instance(perf_instance); } } else { WORD j; PPERF_COUNTER_BLOCK counter_block = (PPERF_COUNTER_BLOCK) ((PBYTE)perf_object + perf_object->DefinitionLength ); for (j = 0; !counter_found && j < perf_object->NumCounters; j++) { // Display the counter by index and name. #ifdef DEBUG_SHOW_NAME printf("\tC %ld: %s\n", perf_counter->CounterNameTitleIndex, container1->names_array[perf_counter->CounterNameTitleIndex] != NULL ? container1->names_array[perf_counter->CounterNameTitleIndex] : "NULL"); fflush(stdout); #endif if (object_found && lstrcmp(container1->names_array[perf_counter->CounterNameTitleIndex], counter) == 0) { *new_counter = container2->names_array[perf_counter->CounterNameTitleIndex]; counter_found = TRUE; } // Get the next counter. perf_counter = get_next_counter(perf_counter); } } // Get the next object type. perf_object = get_next_object(perf_object); } free(perf_data); perf_data = NULL; } DEXIT; return counter_found && object_found; }
/* * This is the entry point for generation statistics. */ static void stats_collect_level(void) { static bool first = TRUE; size_t i, x, y; memset(o_count, 0, sizeof(o_count)); memset(gold_count, 0, sizeof(gold_count)); mon_gold = 0.0; mon_drop = 0.0; results_reset(); result_add("level", format("%d", p_ptr->depth)); for (i = 0; i < TRIES; i++) { generate_cave(); /* Get stats on objects */ for (y = 1; y < DUNGEON_HGT - 1; y++) { for (x = 1; x < DUNGEON_WID - 1; x++) { const object_type *obj = get_first_object(y, x); if (obj) do { if (obj->tval == TV_GOLD) gold_count[i] += obj->pval; else o_count[i]++; } while ((obj = get_next_object(obj))); } } /* Get stats on monsters */ for (y = 1; y < DUNGEON_HGT - 1; y++) { for (x = 1; x < DUNGEON_WID - 1; x++) { if (cave_m_idx[y][x]) stats_monster(&mon_list[cave_m_idx[y][x]]); } } } stats_print_o(); stats_print_m(); if (first) { /* printf("level,mon-drops"); */ results_print_csv_titles(); first = FALSE; } /* results_print_csv_pair("level", "mon-drops"); */ results_print_csv(); do_cmd_redraw(); }
void snmp_input(u_char *pkt, int len){ u_char *snmppacket; int snmplen; SNMPObject so, ver, comm, pdu; SNMPObject reqid, errst, errin, vl, vb, oid, vo; SNMPObject result; u_char *ebuf; char *strp; int rlen, vlen, i, j=0, k; int errorstat=0, errorindex=0; u_long val; ebuf = resbuf + sizeof(resbuf) - 1; snmppacket = pkt + sizeof(struct ip) + sizeof(struct udphdr); snmplen = len - sizeof(struct ip) - sizeof(struct udphdr); DEBUG3( "snmp snmppkt = %lx, len = %lu, snmplen = %lu\n", snmppacket, len, snmplen); so = get_next_object(snmppacket, snmplen); if( so.type != (TAG_SEQ | TYPE_COMPOUND)){ DEBUG1( "so.type = %x\n", so.type); goto error_discard; } ver = get_next_object( so.p, so.len ); if( ver.type != TAG_INTEGER || ver.i != 0 ){ DEBUG1( "ver.type = %x\n", ver.type); goto error_discard; } comm = get_next_object( ver.next, so.len - ver.len ); if( comm.type != TAG_OCTETSTRING ){ DEBUG1( "comm.type = %x\n", comm.type); goto error_discard; } /* verify .... */ pdu = get_next_object( comm.next, so.len - ver.len - comm.len ); switch (pdu.type) { case PDU_GETREQUEST: case PDU_GETNEXT: case PDU_SETREQUEST: break; default: DEBUG1( "pdu.type = %x\n", pdu.type); goto error_discard; } rlen = pdu.len; reqid = get_next_object(pdu.p, rlen); if( reqid.type != TAG_INTEGER ){ DEBUG1( "reqid.type = %x\n", reqid.type); goto error_discard; } rlen -= reqid.tlen; errst = get_next_object( reqid.next, rlen ); if( errst.type != TAG_INTEGER ){ DEBUG1( "errst.type = %x\n", errst.type); goto error_discard; } rlen -= errst.tlen; errin = get_next_object( errst.next, rlen ); if( errin.type != TAG_INTEGER ){ DEBUG1( "errin.type = %x\n", errin.type); goto error_discard; } rlen -= errin.tlen; vl = get_next_object( errin.next, rlen ); if( vl.type != (TAG_SEQ | TYPE_COMPOUND)){ DEBUG1( "vl.type = %x\n", vl.type); goto error_discard; } vb = get_next_object( vl.p, vl.len ); if( vb.type != (TAG_SEQ | TYPE_COMPOUND)){ DEBUG1( "vb.type = %x\n", vb.type); goto error_discard; } do { oid = get_next_object( vb.p, vb.len ); if( oid.type != TAG_OID ){ DEBUG1( "oid.type = %x\n", oid.type); goto error_discard; } vo = get_next_object( oid.next, vb.len - oid.len ); if( vo.type == TAG_ERROR ){ DEBUG1( "vo.type = %x\n", vo.type); goto error_discard; } /* look for oid in our table */ for(i=0; mib[i].len; i++){ if( oid.len != mib[i].len ) continue; for(k=0; k<oid.len; k++){ if( oid.p[k] != mib[i].oid[k] ) break; } if( k == oid.len ) break; } if( !mib[i].len ){ /* not found report the error */ errorstat = ERRSTAT_NOSUCHNAME; }else{ if( pdu.type == PDU_GETNEXT ){ /* go to the next item */ i++; if( !mib[i].len ) /* there is nothing next - report an error */ errorstat = ERRSTAT_NOSUCHNAME; } } if( pdu.type == PDU_SETREQUEST ){ if( !( mib[i].tag & WRITABLE) ){ /* read-only variable */ errorstat = ERRSTAT_READONLY; } /* XXX set it */ }else{ /* get request */ if( !( mib[i].tag & READABLE) ){ /* write-only variable */ errorstat = ERRSTAT_GENERR; } /* get and encode our result */ /* note: we fill our buffer from the right and work back */ vlen = 0; switch (mib[i].tag & ~WRITABLE ) { case IT_STRING|READABLE: strp = (char*)mib[i].val; vlen = strlen( strp ); goto str_comn; case IT_OID|READABLE: /* val is ptr to {len, encoded_oid} */ strp = (char*)mib[i].val; vlen = *strp++; str_comn: /* copy data */ j += putstr(ebuf-j, strp, vlen, mib[i].otag, sizeof(resbuf)-j); break; case IT_CONST|READABLE: val = *(u_long*)&mib[i].val; goto int_comn; case IT_INT|READABLE: val = *(u_short*)(mib[i].val); goto int_comn; case IT_INT4|READABLE: val = *(u_long*)(mib[i].val); goto int_comn; case IT_INT1|READABLE: val = *(u_char*)(mib[i].val); int_comn: j += putint(ebuf-j, val, mib[i].otag, sizeof(resbuf)-j); break; default: /* if we have an error of some sort */ j += putint(ebuf-j, 0, TAG_INTEGER, sizeof(resbuf)-j); break; } } /* copy oid */ j += putstr(ebuf-j, (char*)mib[i].oid, mib[i].len, TAG_OID, sizeof(resbuf)-j); /* output the vb seq */ j += putlen( ebuf-j, j, sizeof(resbuf)-j); ebuf[-j++] = TYPE_COMPOUND | TAG_SEQ; /* handle multi-item requests */ /* get the next request */ rlen -= vb.tlen; vb = get_next_object( vb.next, rlen ); }while( rlen > 0 && vb.type == (TAG_SEQ | TYPE_COMPOUND)); /* output the vl seq */ j += putlen( ebuf-j, j, sizeof(resbuf)-j); ebuf[-j++] = TYPE_COMPOUND | TAG_SEQ; /* errstat, errindex, reqid */ j += putint(ebuf-j, errorindex, TAG_INTEGER, sizeof(resbuf)-j); j += putint(ebuf-j, errorstat, TAG_INTEGER, sizeof(resbuf)-j); j += putint(ebuf-j, reqid.i, TAG_INTEGER, sizeof(resbuf)-j); /* length and pdu_response */ j += putlen( ebuf-j, j, sizeof(resbuf)-j); ebuf[-j++] = PDU_GETRESPONSE; /* community */ bcopy((char*)ver.next, (char*)(ebuf-j-comm.tlen+1), comm.tlen); j += comm.tlen; /* version */ j += putint( ebuf-j, 0, TAG_INTEGER, sizeof(resbuf)-j); /* seq */ j += putlen( ebuf-j, j, sizeof(resbuf)-j); ebuf[-j++] = TYPE_COMPOUND | TAG_SEQ; /* whewwww!!! */ snmp_output(pkt, ebuf, j); return; error_discard: /* the SNMP packet was corrupt/invalid/wrong version/wrong community/... */ /* as per RFC1157, 4.1, we discard and perform no further action */ return; }