From fb968e9db3af780c0d538a01601c48ac1f66c6a5 Mon Sep 17 00:00:00 2001 From: flowtron Date: Tue, 29 Mar 2011 19:03:20 +0000 Subject: [PATCH] CubeScript: strcpy git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6158 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- docs/reference.xml | 28 ++++++++++++++++++++++++++++ source/src/command.cpp | 16 ++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/docs/reference.xml b/docs/reference.xml index c24d78a8..d24abee2 100644 --- a/docs/reference.xml +++ b/docs/reference.xml @@ -337,6 +337,34 @@ + + Copys a substring out of the original. + + + + + + + + Character indexes begins at 0. The end position is the char that is not included anymore. + + + + + + + + + + + + + + + Controls the script flow based on a boolean expression. diff --git a/source/src/command.cpp b/source/src/command.cpp index cd17ac80..e53aa584 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1214,10 +1214,26 @@ void timestring_() int millis_() { extern int totalmillis; return totalmillis; } void strlen_(char *s) { string r; formatstring(r)("%d", strlen(s)); result(r); } +void strcpy_(char *s, char *a, char *b) +{ + int ia = atoi(a); + int ib = atoi(b); + string q; + string r; + r[0] = '\0'; + if(ia>=0) + { + if(ib<=0 && ib>=strlen(s)) ib = strlen(s)-1; + copystring(q, s + ia); + strncpy(r, q, ib - ia); + } + result(r); +} void l0(int p, int v) { string f; string r; formatstring(f)("%%0%dd", p); formatstring(r)(f, v); result(r); } COMMANDN(millis, millis_, ARG_IVAL); COMMANDN(strlen, strlen_, ARG_1STR); +COMMANDN(strcpy, strcpy_, ARG_3STR); COMMAND(l0, ARG_2INT); COMMAND(systime, ARG_NONE); COMMANDN(timestamp, timestamp_, ARG_NONE);