summaryrefslogtreecommitdiff
path: root/src/common/utils.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-04-22 15:45:37 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-04-22 15:45:37 +0000
commite828c8642a637a3e3f63450b75ebc93f2bd4bce4 (patch)
treec21ac768b9b756ccdc36cf8f34d636d157cff337 /src/common/utils.c
parentb574d2412b1c882a1f7cc70e460662e1725ce97d (diff)
downloadhercules-e828c8642a637a3e3f63450b75ebc93f2bd4bce4.tar.gz
hercules-e828c8642a637a3e3f63450b75ebc93f2bd4bce4.tar.bz2
hercules-e828c8642a637a3e3f63450b75ebc93f2bd4bce4.tar.xz
hercules-e828c8642a637a3e3f63450b75ebc93f2bd4bce4.zip
* Extended the functionality of StringBuf - length and appending a string.
* menu/select/prompt script functions support grouped and empty options. The selected option number is consistent with them. * More work on ticket #41. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10316 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/utils.c')
-rw-r--r--src/common/utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index d6a017c95..3dc7fea16 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -123,6 +123,31 @@ int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2)
return (int)(buf1->ptr_ - buf1->buf_);
}
+// Appends str onto the end of buf
+int StringBuf_AppendStr(struct StringBuf* sbuf, const char* str)
+{
+ int available = sbuf->max_ - (sbuf->ptr_ - sbuf->buf_);
+ int size = (int)strlen(str);
+
+ if( size >= available )
+ {// not enough space, expand the buffer (minimum expansion = 1024)
+ int off = (int)(sbuf->ptr_ - sbuf->buf_);
+ sbuf->max_ += max(size, 1024);
+ sbuf->buf_ = (char *) aRealloc(sbuf->buf_, sbuf->max_ + 1);
+ sbuf->ptr_ = sbuf->buf_ + off;
+ }
+
+ memcpy(sbuf->ptr_, str, size);
+ sbuf->ptr_ += size;
+ return (int)(sbuf->ptr_ - sbuf->buf_);
+}
+
+// Returns the length of the data in a Stringbuf
+int StringBuf_Length(struct StringBuf *sbuf)
+{
+ return (int)(sbuf->ptr_ - sbuf->buf_);
+}
+
// Destroy a StringBuf [MouseJstr]
void StringBuf_Destroy(struct StringBuf *sbuf)
{