Changeset 896
- Timestamp:
- 05/11/08 23:07:10 (4 months ago)
- Files:
-
- trunk/src/init1.c (modified) (1 diff)
- trunk/src/obj-util.c (modified) (1 diff)
- trunk/src/object.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/init1.c
r893 r896 1690 1690 else if (buf[0] == 'I') 1691 1691 { 1692 char *tval_s, *sval_s, *pval_s; 1692 1693 int tval, sval, pval; 1693 1694 1694 /* Scan for the values */ 1695 if (3 != sscanf(buf+2, "%d:%d:%d", 1696 &tval, &sval, &pval)) return (PARSE_ERROR_GENERIC); 1695 /* Find the beginning of the tval field */ 1696 tval_s = strchr(buf, ':'); 1697 if (!tval_s) return PARSE_ERROR_MISSING_COLON; 1698 *tval_s++ = '\0'; 1699 if (!*tval_s) return PARSE_ERROR_MISSING_FIELD; 1700 1701 /* Now find the beginning of the sval field */ 1702 sval_s = strchr(tval_s, ':'); 1703 if (!sval_s) return PARSE_ERROR_MISSING_COLON; 1704 *sval_s++ = '\0'; 1705 if (!*sval_s) return PARSE_ERROR_MISSING_FIELD; 1706 1707 /* Now find the beginning of the pval field */ 1708 pval_s = strchr(sval_s, ':'); 1709 if (!pval_s) return PARSE_ERROR_MISSING_COLON; 1710 *pval_s++ = '\0'; 1711 if (!*pval_s) return PARSE_ERROR_MISSING_FIELD; 1712 1713 /* Now convert the tval into its numeric equivalent */ 1714 if (1 != sscanf(tval_s, "%d", &tval)) 1715 { 1716 tval = tval_find_idx(tval_s); 1717 if (tval == -1) return PARSE_ERROR_UNRECOGNISED_TVAL; 1718 } 1719 1720 /* Now find the sval */ 1721 if (1 != sscanf(sval_s, "%d", &sval)) 1722 { 1723 sval = lookup_sval(tval, sval_s); 1724 if (sval == -1) return PARSE_ERROR_UNRECOGNISED_SVAL; 1725 } 1726 1727 /* Now extract the pval */ 1728 if (1 != sscanf(pval_s, "%d", &pval)) 1729 return PARSE_ERROR_NOT_NUMBER; 1697 1730 1698 1731 /* Save the values */ trunk/src/obj-util.c
r895 r896 3473 3473 3474 3474 msg_format("No object (\"%s\",\"%s\")", tval_find_name(tval), name); 3475 return 0; 3475 return -1; 3476 } 3477 3478 /** 3479 * Return the numeric sval of the object kind with the given `tval` and name `name`. 3480 */ 3481 int lookup_sval(int tval, const char *name) 3482 { 3483 int k; 3484 3485 /* Look for it */ 3486 for (k = 1; k < z_info->k_max; k++) 3487 { 3488 object_kind *k_ptr = &k_info[k]; 3489 const char *nm = k_name + k_ptr->name; 3490 3491 if (*nm == '&' && *(nm+1)) 3492 nm += 2; 3493 3494 /* Found a match */ 3495 if (k_ptr->tval == tval && !strcmp(name, nm)) 3496 return k_ptr->sval; 3497 } 3498 3499 msg_format("No object (\"%s\",\"%s\")", tval_find_name(tval), name); 3500 return -1; 3476 3501 } 3477 3502 trunk/src/object.h
r889 r896 139 139 bool lookup_reverse(s16b k_idx, int *tval, int *sval); 140 140 int lookup_name(int tval, const char *name); 141 int lookup_sval(int tval, const char *name); 141 142 int tval_find_idx(const char *name); 142 143 const char *tval_find_name(int tval);
