diff options
author | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-11-28 20:11:54 +0000 |
---|---|---|
committer | skotlex <skotlex@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-11-28 20:11:54 +0000 |
commit | 84b9be5ace46f9848ce664e1896c4b4c9bf58889 (patch) | |
tree | d9c87180e74f77a53726520818c2fa1eb35f1d8c /src | |
parent | 1aabb60a820129e5abc2aa12e7e8e78badf4b83e (diff) | |
download | hercules-84b9be5ace46f9848ce664e1896c4b4c9bf58889.tar.gz hercules-84b9be5ace46f9848ce664e1896c4b4c9bf58889.tar.bz2 hercules-84b9be5ace46f9848ce664e1896c4b4c9bf58889.tar.xz hercules-84b9be5ace46f9848ce664e1896c4b4c9bf58889.zip |
- Increased line buffer size when parsing scripts. Helps when trying to define pretty big shops.
- Applied The Ultra Mage's patch to use strict npc header formatting parsing. Updated the relevant stock scripts/mapflags that didn't conform to the standard.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9352 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src')
-rw-r--r-- | src/map/npc.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index 44b73d8f5..236f0a7e0 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2616,7 +2616,7 @@ static int npc_parse_mapcell (char *w1, char *w2, char *w3, char *w4) void npc_parsesrcfile (char *name)
{
int m, lines = 0;
- char line[1024];
+ char line[2048];
FILE *fp = fopen (name,"r");
if (fp == NULL) {
@@ -2626,33 +2626,34 @@ void npc_parsesrcfile (char *name) current_file = name;
while (fgets(line, sizeof(line) - 1, fp)) {
- char w1[1024], w2[1024], w3[1024], w4[1024], mapname[1024];
- int i, j, w4pos, count;
+ char w1[2048], w2[2048], w3[2048], w4[2048], mapname[2048];
+ int i, w4pos, count;
lines++;
if (line[0] == '/' && line[1] == '/')
continue;
- // 不要なスペースやタブの連続は詰める
- for (i = j = 0; line[i]; i++) {
- if (line[i]==' ') {
- if (!((line[i+1] && (isspace((unsigned char)line[i+1]) || line[i+1]==',')) ||
- (j && line[j-1]==',')))
- line[j++]=' ';
- } else if (line[i]=='\t') {
- if (!(j && line[j-1]=='\t'))
- line[j++]='\t';
- } else
- line[j++]=line[i];
- }
- line[j] = '\0'; //Forget to terminate the string. From [jA 1091]
+
+ if (!sscanf(line, " %n", &i) && i == strlen(line)) // just whitespace
+ continue;
+
// 最初はタブ区切りでチェックしてみて、ダメならスペース区切りで確認
w1[0] = w2[0] = w3[0] = w4[0] = '\0'; //It's best to initialize values
//to prevent passing previously parsed values to the parsers when not all
//fields are specified. [Skotlex]
- if ((count = sscanf(line,"%[^\t]\t%[^\t]\t%[^\t\r\n]\t%n%[^\t\r\n]", w1, w2, w3, &w4pos, w4)) < 3 &&
- (count = sscanf(line,"%s%s%s%n%s", w1, w2, w3, &w4pos, w4)) < 3) {
- continue;
+ if ((count = sscanf(line, "%[^\t\n]\t%[^\t\n]\t%[^\t\n]\t%n%[^\n]", w1, w2, w3, &w4pos, w4)) < 3)
+ {
+ if ((count = sscanf(line, "%s %s %[^\t]\t %n%[^\n]", w1, w2, w3, &w4pos, w4)) == 4 ||
+ (count = sscanf(line, "%s %s %s %n%[^\n]\n", w1, w2, w3, &w4pos, w4)) >= 3)
+ {
+ ShowWarning("\r");
+ ShowWarning("Incorrect separator syntax in file '%s', line '%i'. Use tabs instead of spaces!\n * %s %s %s %s\n",current_file,lines,w1,w2,w3,w4);
+ } else {
+ ShowError("\r"); //Erase the npc spinner.
+ ShowError("Could not parse file '%s', line '%i'.\n * %s %s %s %s\n",current_file,lines,w1,w2,w3,w4);
+ continue;
+ }
}
+
// マップの存在確認
if (strcmp(w1,"-") !=0 && strcmpi(w1,"function") != 0 ){
sscanf(w1,"%[^,]",mapname);
@@ -2689,7 +2690,7 @@ void npc_parsesrcfile (char *name) } else if (strcmpi(w2,"setcell") == 0 && count >= 3) {
npc_parse_mapcell(w1,w2,w3,w4);
} else {
- ShowError("Probably TAB is missing: %s %s %s %s line '%i', file '%s'\n",w1,w2,w3,w4,lines,current_file); //Lupus
+ ShowError("Probably TAB is missing in file '%s', line '%i':\n * %s %s %s %s\n",current_file,lines,w1,w2,w3,w4);
}
}
fclose(fp);
|