From a46c5b799de0d33be85dce39bdc32edc6edc3a65 Mon Sep 17 00:00:00 2001 From: codemaster Date: Mon, 20 Dec 2004 20:12:39 +0000 Subject: * Updated makefiles to new strlib locations [Codemaster] * Moved strlib.h and strlib.c into the common directory [Codemaster] * Updated a bit of jA 1081 - it's not completly updated yet!!! [Codemaster] git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/branches/stable@682 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/strlib.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/common/strlib.c (limited to 'src/common/strlib.c') diff --git a/src/common/strlib.c b/src/common/strlib.c new file mode 100644 index 000000000..61439d7de --- /dev/null +++ b/src/common/strlib.c @@ -0,0 +1,79 @@ +#include +#include +#include + +#include "strlib.h" +#include "utils.h" + +//----------------------------------------------- +// string lib. +unsigned char* jstrescape (unsigned char* pt) { + //copy from here + unsigned char * ptr; + int i =0, j=0; + + //copy string to temporary + CREATE(ptr, char, J_MAX_MALLOC_SIZE); + strcpy (ptr,pt); + + while (ptr[i] != '\0') { + switch (ptr[i]) { + case '\'': + pt[j++] = '\\'; + pt[j++] = ptr[i++]; + break; + case '\\': + pt[j++] = '\\'; + pt[j++] = ptr[i++]; + break; + default: + pt[j++] = ptr[i++]; + } + } + pt[j++] = '\0'; + free (ptr); + return (unsigned char*) &pt[0]; +} + +unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) { + //copy from here + int i =0, j=0; + + while (spt[i] != '\0') { + switch (spt[i]) { + case '\'': + pt[j++] = '\\'; + pt[j++] = spt[i++]; + break; + case '\\': + pt[j++] = '\\'; + pt[j++] = spt[i++]; + break; + default: + pt[j++] = spt[i++]; + } + } + pt[j++] = '\0'; + return (unsigned char*) &pt[0]; +} +int jmemescapecpy (unsigned char* pt,unsigned char* spt, int size) { + //copy from here + int i =0, j=0; + + while (i < size) { + switch (spt[i]) { + case '\'': + pt[j++] = '\\'; + pt[j++] = spt[i++]; + break; + case '\\': + pt[j++] = '\\'; + pt[j++] = spt[i++]; + break; + default: + pt[j++] = spt[i++]; + } + } + // copy size is 0 ~ (j-1) + return j; +} -- cgit v1.2.3-60-g2f50