summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-10-17 20:15:39 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-10-17 20:15:39 +0000
commit724babffe10a6908d1510c941e5abfbe840fd271 (patch)
tree44191aa270ab766d2ccc6e6671cbc4596c1e18a8 /src/common
parenta4c3bb6153b6fd1a8d54abde6f7d9ecd593a4e4d (diff)
downloadhercules-724babffe10a6908d1510c941e5abfbe840fd271.tar.gz
hercules-724babffe10a6908d1510c941e5abfbe840fd271.tar.bz2
hercules-724babffe10a6908d1510c941e5abfbe840fd271.tar.xz
hercules-724babffe10a6908d1510c941e5abfbe840fd271.zip
* Reworked the parsing at npc.c.
- Fixes npc.c discarding the '}' at the end of file, when there is no newline. (uncovered as a side-effect of r11487) * Empty script functions always have code now (won't report as missing when you try to call them). * Changed userfunc_db to not limit the name to 50 characters. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11502 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r--src/common/strlib.c20
-rw-r--r--src/common/strlib.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/src/common/strlib.c b/src/common/strlib.c
index c0a6238f9..d0b312f0a 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -316,6 +316,26 @@ size_t safestrnlen(const char* string, size_t maxlen)
return ( string != NULL ) ? strnlen(string, maxlen) : 0;
}
+/// Returns the line of the target position in the string.
+/// Lines start at 1.
+int strline(const char* str, size_t pos)
+{
+ const char* target;
+ int line;
+
+ if( str == NULL || pos == 0 )
+ return 1;
+
+ target = str+pos;
+ for( line = 1; ; ++line )
+ {
+ str = strchr(str, '\n');
+ if( str == NULL || target <= str )
+ break;// found target line
+ ++str;// skip newline
+ }
+ return line;
+}
/////////////////////////////////////////////////////////////////////
// StringBuf - dynamic string
diff --git a/src/common/strlib.h b/src/common/strlib.h
index fd24b4b24..4df5a51d2 100644
--- a/src/common/strlib.h
+++ b/src/common/strlib.h
@@ -37,6 +37,10 @@ char* safestrncpy(char* dst, const char* src, size_t n);
/// doesn't crash on null pointer
size_t safestrnlen(const char* string, size_t maxlen);
+/// Returns the line of the target position in the string.
+/// Lines start at 1.
+int strline(const char* str, size_t pos);
+
/// StringBuf - dynamic string
struct StringBuf
{