int test_defaults(void *state) { size_t i; struct monster_base *mb = lookup_monster_base("giant"); int tval = tval_find_idx("sword"); /* Monster bases */ eq(process_pref_file_command("monster-base:giant:3:3"), 0); for (i = 0; i < z_info->r_max; i++) { monster_race *race = &r_info[i]; if (race->base != mb) continue; eq(monster_x_attr[race->ridx], 3); eq(monster_x_char[race->ridx], 3); } /* Object tvals */ eq(process_pref_file_command("object:sword:*:3:3"), 0); for (i = 0; i < z_info->k_max; i++) { struct object_kind *kind = &k_info[i]; if (kind->tval != tval) continue; eq(kind_x_attr[kind->kidx], 3); eq(kind_x_char[kind->kidx], 3); } /* Traps */ eq(process_pref_file_command("trap:*:*:3:3"), 0); for (i = 0; i < z_info->trap_max; i++) { int light_idx; for (light_idx = 0; light_idx < LIGHTING_MAX; light_idx++) { eq(trap_x_attr[light_idx][i], 3); eq(trap_x_attr[light_idx][i], 3); } } ok; }
/* * Ask for a "user pref line" and process it */ void do_cmd_pref(void) { char tmp[80]; /* Default */ my_strcpy(tmp, "", sizeof(tmp)); /* Ask for a "user pref command" */ if (!get_string("Pref: ", tmp, 80)) return; /* Process that pref command */ (void)process_pref_file_command(tmp); }
/* * Open the "user pref file" and parse it. */ static errr process_pref_file_aux(cptr name) { FILE *fp; char buf[1024]; char old[1024]; int line = -1; errr err = 0; bool bypass = FALSE; /* Open the file */ fp = my_fopen(name, "r"); /* No such file */ if (!fp) return (-1); /* Process the file */ while (0 == my_fgets(fp, buf, sizeof(buf))) { /* Count lines */ line++; /* Skip "empty" lines */ if (!buf[0]) continue; /* Skip "blank" lines */ if (isspace((unsigned char)buf[0])) continue; /* Skip comments */ if (buf[0] == '#') continue; /* Save a copy */ my_strcpy(old, buf, sizeof(old)); /* Process "?:<expr>" */ if ((buf[0] == '?') && (buf[1] == ':')) { char f; cptr v; char *s; /* Start */ s = buf + 2; /* Parse the expr */ v = process_pref_file_expr(&s, &f); /* Set flag */ bypass = (streq(v, "0") ? TRUE : FALSE); /* Continue */ continue; } /* Apply conditionals */ if (bypass) continue; /* Process "%:<file>" */ if (buf[0] == '%') { /* Process that file if allowed */ (void)process_pref_file(buf + 2); /* Continue */ continue; } /* Process the line */ err = process_pref_file_command(buf); /* Oops */ if (err) break; } /* Error */ if (err) { /* Print error message */ /* ToDo: Add better error messages */ msg_format("Error %d in line %d of file '%s'.", err, line, name); msg_format("Parsing '%s'", old); message_flush(); } /* Close the file */ my_fclose(fp); /* Result */ return (err); }