From a46c1fbcb1b7df32c678af8f0bbfda801d6142dc Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Thu, 27 Sep 2007 11:18:58 +0000 Subject: * Reimplemented mmo_char_fromsql using sql statements. (fixes bugreport:93) * Fixed buildin_gethominfo not being included in the script engine. (bugreport:124) * homunculus_evolution -> homevolution in script_commands.txt. * Deleted item DEFAULT from item_db.txt and regenerated item_db.sql. (bugreport:103) * Skip empty lines and give more feedback (for invalid lines) when reading item_db.txt/item_db2.txt. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11311 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/itemdb.c | 81 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 30 deletions(-) (limited to 'src/map/itemdb.c') diff --git a/src/map/itemdb.c b/src/map/itemdb.c index 101738989..f6cdf6b3f 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -742,10 +742,10 @@ static bool itemdb_parse_dbrow(char** str, char* source, int line) if (id->slot > MAX_SLOTS) { - ShowWarning("itemdb_parse_dbrow: Item %d (%s) specifies %d slots, but the server only supports up to %d\n", nameid, id->jname, id->slot, MAX_SLOTS); + ShowWarning("itemdb_parse_dbrow: Item %d (%s) specifies %d slots, but the server only supports up to %d. Using %d slots.\n", nameid, id->jname, id->slot, MAX_SLOTS, MAX_SLOTS); id->slot = MAX_SLOTS; } - + itemdb_jobid2mapid(id->class_base, (unsigned int)strtoul(str[11],NULL,0)); id->class_upper = atoi(str[12]); id->sex = atoi(str[13]); @@ -812,58 +812,79 @@ static int itemdb_readdb(void) // process rows one by one while(fgets(line, sizeof(line), fp)) { - char *str[32], *p, *np; + char *str[32], *p; int i; lines++; if(line[0] == '/' && line[1] == '/') continue; memset(str, 0, sizeof(str)); - for(i = 0, np = p = line; i < 19 && p; i++) + + p = line; + while( ISSPACE(*p) ) + ++p; + if( *p == '\0' ) + continue;// empty line + for( i = 0; i < 19; ++i ) { str[i] = p; - if ((p = strchr(p,',')) != NULL) { - *p++ = '\0'; np = p; - } + p = strchr(p,','); + if( p == NULL ) + break;// comma not found + *p = '\0'; + ++p; } - if( i < 19 ) + if( p == NULL ) { - ShowWarning("itemdb_readdb: Insufficient columns in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); + ShowError("itemdb_readdb: Insufficient columns in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); continue; } - if((p=strchr(np,'{')) == NULL) + // Script + if( *p != '{' ) + { + ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); continue; - str[19] = p; //Script - np = strchr(p,'}'); - while (np && np[1] && np[1] != ',') - np = strchr(np+1,'}'); //Jump close brackets until the next field is found. - if (!np || !np[1]) { - continue; //Couldn't find the end of the script field. } - np[1] = '\0'; //Set end of script - np += 2; //Skip to next field + str[19] = p; + p = strstr(p+1,"},"); + if( p == NULL ) + { + ShowError("itemdb_readdb: Invalid format (Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); + continue; + } + p[1] = '\0'; + p += 2; - if(!np || (p=strchr(np,'{'))==NULL) + // OnEquip_Script + if( *p != '{' ) + { + ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); continue; - str[20] = p; //Equip Script - np = strchr(p,'}'); - while (np && np[1] && np[1] != ',') - np = strchr(np+1,'}'); //Jump close brackets until the next field is found. - if (!np || !np[1]) { - continue; //Couldn't find the end of the script field. } - np[1] = '\0'; //Set end of script - np += 2; //Skip comma, to next field + str[20] = p; + p = strstr(p+1,"},"); + if( p == NULL ) + { + ShowError("itemdb_readdb: Invalid format (OnEquip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); + continue; + } + p[1] = '\0'; + p += 2; - if(!np || (p=strchr(np,'{'))==NULL) + // OnUnequip_Script (last column) + if( *p != '{' ) + { + ShowError("itemdb_readdb: Invalid format (OnUnequip_Script column) in line %d of \"%s\" (item with id %d), skipping.\n", lines, path, atoi(str[0])); continue; - str[21] = p; //Unequip script, last column. + } + str[21] = p; + if (!itemdb_parse_dbrow(str, path, lines)) continue; - + count++; } -- cgit v1.2.3-70-g09d2