CubeScript: strcpy

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6158 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
flowtron
2011-03-29 19:03:20 +00:00
parent b85f1b8529
commit fb968e9db3
2 changed files with 44 additions and 0 deletions
+28
View File
@@ -337,6 +337,34 @@
<return token="N" description="the equality" valueNotes="1 (equal) or 0 (unequal)"/>
</command>
<command name="strcpy">
<description>Copys a substring out of the original.</description>
<arguments>
<argument token="S" description="the original string"/>
<argument token="A" description="start position"/>
<argument token="B" description="end position"/>
</arguments>
<return token="S" description="the substring" />
<remarks>
<remark>Character indexes begins at 0. The end position is the char that is not included anymore.</remark>
</remarks>
<examples>
<example>
<code><![CDATA[echo (strcpy abcdefgh 2 5)
cde]]></code>
</example>
<example>
<code><![CDATA[echo (strcpy abcdefgh 2 3)
c]]></code>
</example>
<example>
<code><![CDATA[echo (strcpy abcdefgh 2)
cdefgh]]></code>
</example>
</examples>
</command>
<command name="if">
<description>Controls the script flow based on a boolean expression.</description>
<examples>
+16
View File
@@ -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);