static enum parser_error parse_prefs_m(struct parser *p) { int a, msg_index; const char *attr; const char *type; struct prefs_data *d = parser_priv(p); assert(d != NULL); if (d->bypass) return PARSE_ERROR_NONE; type = parser_getsym(p, "type"); attr = parser_getsym(p, "attr"); msg_index = message_lookup_by_name(type); if (msg_index < 0) return PARSE_ERROR_GENERIC; if (strlen(attr) > 1) a = color_text_to_attr(attr); else a = color_char_to_attr(attr[0]); if (a < 0) return PARSE_ERROR_INVALID_COLOR; message_color_define(msg_index, (byte)a); return PARSE_ERROR_NONE; }
static enum parser_error parse_prefs_m(struct parser *p) { int a, type; const char *attr; struct prefs_data *d = parser_priv(p); assert(d != NULL); if (d->bypass) return PARSE_ERROR_NONE; type = parser_getint(p, "type"); attr = parser_getsym(p, "attr"); if (strlen(attr) > 1) a = color_text_to_attr(attr); else a = color_char_to_attr(attr[0]); if (a < 0) return PARSE_ERROR_INVALID_COLOR; message_color_define((u16b) type, (byte) a); return PARSE_ERROR_NONE; }
static enum parser_error parse_r_c(struct parser *p) { struct monster_race *r = parser_priv(p); const char *color; int attr; if (!r) return PARSE_ERROR_MISSING_RECORD_HEADER; color = parser_getsym(p, "color"); if (strlen(color) > 1) attr = color_text_to_attr(color); else attr = color_char_to_attr(color[0]); if (attr < 0) return PARSE_ERROR_INVALID_COLOR; r->d_attr = attr; return PARSE_ERROR_NONE; }
/* * Parse a sub-file of the "extra info" (format shown below) * * Each "action" line has an "action symbol" in the first column, * followed by a colon, followed by some command specific info, * usually in the form of "tokens" separated by colons or slashes. * * Blank lines, lines starting with white space, and lines starting * with pound signs ("#") are ignored (as comments). * * Note the use of "tokenize()" to allow the use of both colons and * slashes as delimeters, while still allowing final tokens which * may contain any characters including "delimiters". * * Note the use of "strtol()" to allow all "integers" to be encoded * in decimal, hexidecimal, or octal form. * * Note that "monster zero" is used for the "player" attr/char, "object * zero" will be used for the "stack" attr/char, and "feature zero" is * used for the "nothing" attr/char. * * Specify the attr/char values for "monsters" by race index. * R:<num>:<a>/<c> * * Specify the attr/char values for "objects" by kind index. * K:<num>:<a>/<c> * * Specify the attr/char values for "features" by feature index. * F:<num>:<a>/<c> * * Specify the attr/char values for "special" things. * S:<num>:<a>/<c> * * Specify the attribute values for inventory "objects" by kind tval. * E:<tv>:<a> * * Define a macro action, given an encoded macro action. * A:<str> * * Create a macro, given an encoded macro trigger. * P:<str> * * Create a keymap, given an encoded keymap trigger. * C:<num>:<str> * * Turn an option off, given its name. * X:<str> * * Turn an option on, given its name. * Y:<str> * * Turn a window flag on or off, given a window, flag, and value. * W:<win>:<flag>:<value> * * Specify visual information, given an index, and some data. * V:<num>:<kv>:<rv>:<gv>:<bv> * * Specify colors for message-types. * M:<type>:<attr> * * Specify the attr/char values for "flavors" by flavors index. * L:<num>:<a>/<c> */ errr process_pref_file_command(char *buf) { long i; char *zz[16]; /* Skip "empty" lines */ if (!buf[0]) return (0); /* Skip "blank" lines */ if (isspace((unsigned char)buf[0])) return (0); /* Skip comments */ if (buf[0] == '#') return (0); /* Paranoia */ /* if (strlen(buf) >= 1024) return (1); */ /* Require "?:*" format */ if (buf[1] != ':') return (1); /* * Hookifying this. * Designate certain types of preference lines that are called out * to the user. * */ #ifndef AVT_HOOKIFY_PREFS /* Process "R:<num>:<a>/<c>" -- attr/char for monster races */ if (buf[0] == 'R') { if (tokenize(buf+2, 3, zz) == 3) { monster_race *r_ptr; i = strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); if ((i < 0) || (i >= (long)z_info->r_max)) return (1); r_ptr = &r_info[i]; if (n1) r_ptr->x_attr = (byte)n1; if (n2) r_ptr->x_char = (char)n2; return (0); } } /* Process "K:<num>:<a>/<c>" -- attr/char for object kinds */ else if (buf[0] == 'K') { if (tokenize(buf+2, 3, zz) == 3) { object_kind *k_ptr; i = strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); if ((i < 0) || (i >= (long)z_info->k_max)) return (1); k_ptr = &k_info[i]; if (n1) k_ptr->x_attr = (byte)n1; if (n2) k_ptr->x_char = (char)n2; return (0); } } /* Process "F:<num>:<a>/<c>" -- attr/char for terrain features */ else if (buf[0] == 'F') { if (tokenize(buf+2, 3, zz) == 3) { feature_type *f_ptr; i = strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); if ((i < 0) || (i >= (long)z_info->f_max)) return (1); f_ptr = &f_info[i]; if (n1) f_ptr->x_attr = (byte)n1; if (n2) f_ptr->x_char = (char)n2; return (0); } } /* Process "L:<num>:<a>/<c>" -- attr/char for flavors */ else if (buf[0] == 'L') { if (tokenize(buf+2, 3, zz) == 3) { flavor_type *flavor_ptr; i = strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); if ((i < 0) || (i >= (long)z_info->flavor_max)) return (1); flavor_ptr = &flavor_info[i]; if (n1) flavor_ptr->x_attr = (byte)n1; if (n2) flavor_ptr->x_char = (char)n2; return (0); } } /* Process "S:<num>:<a>/<c>" -- attr/char for special things */ else if (buf[0] == 'S') { if (tokenize(buf+2, 3, zz) == 3) { i = strtol(zz[0], NULL, 0); n1 = strtol(zz[1], NULL, 0); n2 = strtol(zz[2], NULL, 0); if ((i < 0) || (i >= (long)N_ELEMENTS(misc_to_attr))) return (1); misc_to_attr[i] = (byte)n1; misc_to_char[i] = (char)n2; return (0); } } /* Process "E:<tv>:<a>" -- attribute for inventory objects */ else if (buf[0] == 'E') { if (tokenize(buf+2, 2, zz) == 2) { i = strtol(zz[0], NULL, 0) % 128; n1 = strtol(zz[1], NULL, 0); if ((i < 0) || (i >= (long)N_ELEMENTS(tval_to_attr))) return (1); if (n1) tval_to_attr[i] = (byte)n1; return (0); } } else #endif /* AVT_HOOKIFY_PREFS */ /* Process "A:<str>" -- save an "action" for later */ if (buf[0] == 'A') { text_to_ascii(macro_buffer, sizeof(macro_buffer), buf+2); return (0); } /* Process "P:<str>" -- create macro */ #ifdef AVT_USE_MACROS else if (buf[0] == 'P') { char tmp[1024]; text_to_ascii(tmp, sizeof(tmp), buf+2); macro_add(tmp, macro_buffer); return (0); } else #endif /* Process "C:<num>:<str>" -- create keymap */ if (buf[0] == 'C') { long mode; char tmp[1024]; if (tokenize(buf+2, 2, zz) != 2) return (1); mode = strtol(zz[0], NULL, 0); if ((mode < 0) || (mode >= KEYMAP_MODES)) return (1); text_to_ascii(tmp, sizeof(tmp), zz[1]); if (!tmp[0] || tmp[1]) return (1); i = (long)tmp[0]; string_free(keymap_act[mode][i]); keymap_act[mode][i] = string_make(macro_buffer); return (0); } /* Process "V:<num>:<kv>:<rv>:<gv>:<bv>" -- visual info */ else if (buf[0] == 'V') { if (tokenize(buf+2, 5, zz) == 5) { i = strtol(zz[0], NULL, 0); if ((i < 0) || (i >= 256)) return (1); angband_color_table[i][0] = (byte)strtol(zz[1], NULL, 0); angband_color_table[i][1] = (byte)strtol(zz[2], NULL, 0); angband_color_table[i][2] = (byte)strtol(zz[3], NULL, 0); angband_color_table[i][3] = (byte)strtol(zz[4], NULL, 0); return (0); } } /* Process "X:<str>" -- turn option off */ else if (buf[0] == 'X') { /* Check non-adult options */ for (i = 0; i < OPT_ADULT; i++) { #ifndef AVT_HOOKIFY_OPTIONS if (option_text[i] && streq(option_text[i], buf + 2)) { op_ptr->opt[i] = FALSE; return (0); } #endif } } /* Process "Y:<str>" -- turn option on */ else if (buf[0] == 'Y') { /* Check non-adult options */ for (i = 0; i < OPT_ADULT; i++) { #ifndef AVT_HOOKIFY_OPTIONS if (option_text[i] && streq(option_text[i], buf + 2)) { op_ptr->opt[i] = TRUE; return (0); } #endif } } /* Process "W:<win>:<flag>:<value>" -- window flags */ else if (buf[0] == 'W') { long win, flag, value; if (tokenize(buf + 2, 3, zz) == 3) { win = strtol(zz[0], NULL, 0); flag = strtol(zz[1], NULL, 0); value = strtol(zz[2], NULL, 0); /* Ignore illegal windows */ /* Hack -- Ignore the main window */ if ((win <= 0) || (win >= ANGBAND_TERM_MAX)) return (1); /* Ignore illegal flags */ if ((flag < 0) || (flag >= 32)) return (1); #ifndef AVT_HOOKIFY_WINDOW_FLAGS /* Require a real flag */ if (window_flag_desc[flag]) { if (value) { /* Turn flag on */ op_ptr->window_flag[win] |= (1L << flag); } else { /* Turn flag off */ op_ptr->window_flag[win] &= ~(1L << flag); } } #endif /* Success */ return (0); } } /* Process "M:<type>:<attr>" -- colors for message-types */ else if (buf[0] == 'M') { if (tokenize(buf+2, 2, zz) == 2) { long type = strtol(zz[0], NULL, 0); int color = color_char_to_attr(zz[1][0]); /* Ignore illegal color */ if (color < 0) return (1); /* Store the color */ return (message_color_define((u16b)type, (byte)color)); } } #ifdef AVT_HOOKIFY_PREFS else { /* Handle any hooked prefs. Warn on anything that we can't handle. */ return 0; } #endif /* Failure */ return (1); }
/* * Initialize the "f_info" array, by parsing an ascii "template" file */ errr parse_f_info(char *buf, header *head) { int i; char *s; /* Current entry */ static feature_type *f_ptr = NULL; /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { /* Find the colon before the name */ s = strchr(buf+2, ':'); /* Verify that colon */ if (!s) return (PARSE_ERROR_GENERIC); /* Nuke the colon, advance to the name */ *s++ = '\0'; /* Paranoia -- require a name */ if (!*s) return (PARSE_ERROR_GENERIC); /* Get the index */ i = atoi(buf+2); /* Verify information */ if (i <= error_idx) return (PARSE_ERROR_NON_SEQUENTIAL_RECORDS); /* Verify information */ if (i >= head->info_num) return (PARSE_ERROR_TOO_MANY_ENTRIES); /* Save the index */ error_idx = i; /* Point at the "info" */ f_ptr = (feature_type*)head->info_ptr + i; /* Store the name */ if (!(f_ptr->name = add_name(head, s))) return (PARSE_ERROR_OUT_OF_MEMORY); /* Default "mimic" */ f_ptr->mimic = i; } /* Process 'M' for "Mimic" (one line only) */ else if (buf[0] == 'M') { int mimic; /* There better be a current f_ptr */ if (!f_ptr) return (PARSE_ERROR_MISSING_RECORD_HEADER); /* Scan for the values */ if (1 != sscanf(buf+2, "%d", &mimic)) return (PARSE_ERROR_GENERIC); /* Save the values */ f_ptr->mimic = mimic; } /* Process 'G' for "Graphics" (one line only) */ else if (buf[0] == 'G') { char d_char; int d_attr; /* There better be a current f_ptr */ if (!f_ptr) return (PARSE_ERROR_MISSING_RECORD_HEADER); /* Paranoia */ if (!buf[2]) return (PARSE_ERROR_GENERIC); if (!buf[3]) return (PARSE_ERROR_GENERIC); if (!buf[4]) return (PARSE_ERROR_GENERIC); /* Extract d_char */ d_char = buf[2]; /* If we have a longer string than expected ... */ if (buf[5]) { /* Advance "buf" on by 4 */ buf += 4; /* Extract the colour */ d_attr = color_text_to_attr(buf); } else { /* Extract the attr */ d_attr = color_char_to_attr(buf[4]); } /* Paranoia */ if (d_attr < 0) return (PARSE_ERROR_GENERIC); /* Save the values */ f_ptr->d_attr = d_attr; f_ptr->d_char = d_char; } else { /* Oops */ return (PARSE_ERROR_UNDEFINED_DIRECTIVE); } /* Success */ return (0); }