Esempio n. 1
0
/**
 * Get a binary file context for the given program / library path.
 */
static bfd_ctx_t *
bfd_util_get_bc(struct bfd_list **list, const char *path)
{
	struct bfd_list *item = *list;
	bfd_ctx_t bc, *bp;

	/*
	 * We're probably crashing, use simple data structures, and not a
	 * hash table / hash list here.  We're going to handle only a handful
	 * of modules, so linear lookups are perfectly OK.
	 */

	while (item != NULL) {
		if (0 == strcmp(path, item->path))
			return item->bc;
		item = item->next;
	}

	ZERO(&bc);

	if (!bfd_util_open(&bc, path))
		return NULL;

	bp = XCOPY(&bc);
	item = xmalloc(sizeof *item);
	item->bc = bp;
	item->path = xstrdup(path);

	/* Insert at head of list */

	item->next = *list;
	*list = item;

	return bp;
}
Esempio n. 2
0
/* Create a copy of orig_state */
CWGameState * 
cw_gamestate_copy(CWGameState *orig_state)
{
  int i, t;
  CWGameState *state = (CWGameState *) malloc(sizeof(CWGameState));

  state->event_count = orig_state->event_count;
  state->inning = orig_state->inning;
  state->batting_team = orig_state->batting_team;
  state->outs = orig_state->outs;
  state->inning_batters = orig_state->inning_batters;
  state->inning_score = orig_state->inning_score;

  for (t = 0; t <= 1; t++) {
    state->score[t] = orig_state->score[t];
    state->hits[t] = orig_state->hits[t];
    state->errors[t] = orig_state->errors[t];
    state->times_out[t] = orig_state->times_out[t];
    state->num_batters[t] = orig_state->num_batters[t];
    state->dh_slot[t] = orig_state->dh_slot[t];
  }

  state->is_leadoff = orig_state->is_leadoff;
  state->is_new_pa = orig_state->is_new_pa;
  state->ph_flag = orig_state->ph_flag;

  for (i = 0; i <= 3; i++) {
    strcpy(state->runners[i], orig_state->runners[i]);
    state->runner_src_event[i] = orig_state->runner_src_event[i];
    strcpy(state->pitchers[i], orig_state->pitchers[i]);
    strcpy(state->catchers[i], orig_state->catchers[i]);
  }

  XCOPY(state->removed_for_ph, orig_state->removed_for_ph);
  XCOPY(state->walk_pitcher, orig_state->walk_pitcher);
  XCOPY(state->strikeout_batter, orig_state->strikeout_batter);
  XCOPY(state->go_ahead_rbi, orig_state->go_ahead_rbi);

  for (i = 0; i <= 3; i++) {
    XCOPY(state->removed_for_pr[i], orig_state->removed_for_pr[i]);
  }

  for (t = 0; t <= 1; t++) {
    for (i = 0; i <= 9; i++) {
      XCOPY(state->lineups[i][t].player_id, 
	    orig_state->lineups[i][t].player_id);
      XCOPY(state->lineups[i][t].name, orig_state->lineups[i][t].name);
      XCOPY(state->fielders[i][t], orig_state->fielders[i][t]);
    }
  }

  state->batter_hand = orig_state->batter_hand;

  return state;
}