Welcome to the Builder Academy

Question strcpy problems after compiling on Mac resolved.

More
12 Apr 2023 01:45 #10311 by Barnes
// for anyone that may ever encounter this problem, I had to change the generic find to this in order to look at 2.mob or 2.obj

int generic_find(char *arg, bitvector_t bitvector, struct char_data *ch,
    struct char_data **tar_ch, struct obj_data **tar_obj) {
  int i, found, number;
  char name[MAX_INPUT_LENGTH + 1];
  char *pos = name;

  *tar_ch = NULL;
  *tar_obj = NULL;

  /* Copy arg to name with length check */
  strncpy(name, arg, MAX_INPUT_LENGTH);
  name[MAX_INPUT_LENGTH] = '\0';

  /* Skip leading spaces */
  while (isspace(*pos))
    pos++;

  /* Check if name is empty */
  if (*pos == '\0')
    return (0);

  /* Extract first word */
  one_argument(pos, pos);

  if (!(number = get_number(&pos)))
    return (0);

  if (IS_SET(bitvector, FIND_CHAR_ROOM)) { /* Find person in room */
    if ((*tar_ch = get_char_room_vis(ch, pos, &number)) != NULL)
      return (FIND_CHAR_ROOM);
  }

  if (IS_SET(bitvector, FIND_CHAR_WORLD)) {
    if ((*tar_ch = get_char_world_vis(ch, pos, &number)) != NULL)
      return (FIND_CHAR_WORLD);
  }

  if (IS_SET(bitvector, FIND_OBJ_EQUIP)) {
    for (found = FALSE, i = 0; i < NUM_WEARS && !found; i++)
      if (GET_EQ(ch, i) && isname(pos, GET_EQ(ch, i)->name) && --number == 0) {
        *tar_obj = GET_EQ(ch, i);
        found = TRUE;
      }
    if (found)
      return (FIND_OBJ_EQUIP);
  }

  if (IS_SET(bitvector, FIND_OBJ_INV)) {
    if ((*tar_obj = get_obj_in_list_vis(ch, pos, &number, ch->carrying)) != NULL)
      return (FIND_OBJ_INV);
  }

  if (IS_SET(bitvector, FIND_OBJ_ROOM)) {
    if ((*tar_obj = get_obj_in_list_vis(ch, pos, &number, world[IN_ROOM(ch)].contents)) != NULL)
      return (FIND_OBJ_ROOM);
  }

  if (IS_SET(bitvector, FIND_OBJ_WORLD)) {
    if ((*tar_obj = get_obj_vis(ch, pos, &number)))
      return (FIND_OBJ_WORLD);
  }

  return (0);
}


 
The following user(s) said Thank You: thomas

Please Log in or Create an account to join the conversation.

Time to create page: 0.198 seconds