summaryrefslogtreecommitdiff
path: root/src/common/strlib.c
diff options
context:
space:
mode:
authorai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-16 22:53:42 +0000
committerai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-16 22:53:42 +0000
commit91189252d417c62b168872cb13cfd1cd54cbf8f3 (patch)
tree0f7ab8a34664372682f279f3503abd3551e1c6ca /src/common/strlib.c
parent0cbf5d3429e72b56980c41611cdb798179f0366b (diff)
downloadhercules-91189252d417c62b168872cb13cfd1cd54cbf8f3.tar.gz
hercules-91189252d417c62b168872cb13cfd1cd54cbf8f3.tar.bz2
hercules-91189252d417c62b168872cb13cfd1cd54cbf8f3.tar.xz
hercules-91189252d417c62b168872cb13cfd1cd54cbf8f3.zip
* Reverted r14525 (introduction of SV_READDB_MAX_FIELDS) because it causes confusion to certain group of users and depends on MAX_LEVEL since r14526.
- Made sv_readdb be able to process any amount of columns instead. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14595 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/strlib.c')
-rw-r--r--src/common/strlib.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c
index bb1f67fdb..019e2d629 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -12,7 +12,6 @@
#include <errno.h>
-#define SV_READDB_MAX_FIELDS 105
#define J_MAX_MALLOC_SIZE 65535
// escapes a string in-place (' -> \' , \ -> \\ , % -> _)
@@ -923,18 +922,12 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
FILE* fp;
int lines = 0;
int entries = 0;
- char* fields[SV_READDB_MAX_FIELDS+1]; // room for SV_READDB_MAX_FIELDS fields ([0] is reserved)
- int columns;
+ char** fields; // buffer for fields ([0] is reserved)
+ int columns, fields_length;
char path[1024], line[1024];
snprintf(path, sizeof(path), "%s/%s", directory, filename);
- if( maxcols > ARRAYLENGTH(fields)-1 )
- {
- ShowError("sv_readdb: Insufficient column storage in parser for file \"%s\" (want %d, have only %d). Increase the capacity in the source code please.\n", path, maxcols, ARRAYLENGTH(fields)-1);
- return false;
- }
-
// open file
fp = fopen(path, "r");
if( fp == NULL )
@@ -943,6 +936,10 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
return false;
}
+ // allocate enough memory for the maximum requested amount of columns plus the reserved one
+ fields_length = maxcols+1;
+ fields = aMalloc(fields_length*sizeof(char*));
+
// process rows one by one
while( fgets(line, sizeof(line), fp) )
{
@@ -954,7 +951,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
if( line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
continue;
- columns = sv_split(line, strlen(line), 0, delim, fields, ARRAYLENGTH(fields), (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
+ columns = sv_split(line, strlen(line), 0, delim, fields, fields_length, (e_svopt)(SV_TERMINATE_LF|SV_TERMINATE_CRLF));
if( columns < mincols )
{
@@ -983,6 +980,7 @@ bool sv_readdb(const char* directory, const char* filename, char delim, int minc
entries++;
}
+ aFree(fields);
fclose(fp);
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", entries, path);