From 973d4950bb399db5a44783d3f4849f92ec4f978b Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 5 Dec 2014 23:12:33 +0000 Subject: [PATCH] LunaCON: implement 'qstrncat' command. git-svn-id: https://svn.eduke32.com/eduke32@4795 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/control.lua | 11 +++++++++-- polymer/eduke32/source/lunatic/lunacon.lua | 4 ++-- polymer/eduke32/source/lunatic/test/quote_ops.con | 8 +++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 1a94ac838..e88ea63d4 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -747,7 +747,7 @@ function _qstrcpy(qdst, qsrc) end -- NOTE: qdst==qsrc is OK (duplicates the quote) -function _qstrcat(qdst, qsrc) +function _qstrcat(qdst, qsrc, n) local cstr_dst = bcheck.quote_idx(qdst) local cstr_src = bcheck.quote_idx(qsrc) @@ -759,6 +759,12 @@ function _qstrcat(qdst, qsrc) return strcpy(cstr_dst, cstr_src) end + if (n == nil) then + n = 0x7fffffff + elseif (n < 0) then + error("invalid number of chars to concatenate: "..n, 2) + end + -- From here on: destination and source quote (potentially aliased) are -- nonempty. @@ -775,10 +781,11 @@ function _qstrcat(qdst, qsrc) repeat -- NOTE: don't copy the first char yet, so that the qdst==qsrc case -- works correctly. + n = n-1 i = i+1 j = j+1 cstr_dst[i] = cstr_src[j] - until (i >= MAXQUOTELEN-1 or cstr_src[j]==0) + until (n == 0 or i >= MAXQUOTELEN-1 or cstr_src[j]==0) -- Now copy the first char! cstr_dst[slen_dst] = cstr_src[0] diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index a2370a40a..55ff60b78 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -2669,8 +2669,8 @@ local Cinner = { / "_con._qstrcpy(%1,%2)", qstrlen = cmd(W,R) / "%1=_con._qstrlen(%2)", - qstrncat = cmd(R,R) - / handle.NYI, + qstrncat = cmd(R,R,R) + / "_con._qstrcat(%1,%2,%3)", qsubstr = cmd(R,R,R,R) / "_con._qsubstr(%1,%2,%3,%4)", quote = cmd(D) diff --git a/polymer/eduke32/source/lunatic/test/quote_ops.con b/polymer/eduke32/source/lunatic/test/quote_ops.con index 234a0fcdd..f4ca93297 100644 --- a/polymer/eduke32/source/lunatic/test/quote_ops.con +++ b/polymer/eduke32/source/lunatic/test/quote_ops.con @@ -51,6 +51,12 @@ onevent EVENT_ENTERLEVEL qstrcat 115 115 // this one is redundant, but must not overflow the quote buffer userquote 115 + ////////// qstrncat test + redefinequote 300 012345678| + qstrncat 300 300 2 + userquote 300 // "012345678|01" + ////////// + redefinequote 117 X%s qsprintf 117 /*<-*/ 117 /*args:*/ 115 userquote 117 // result: "X" .. 12 x "012345678|" .. "012345" (= total length 127 = MAXQUOTELEN-1) @@ -78,7 +84,7 @@ onevent EVENT_ENTERLEVEL // qgetsysstr test qgetsysstr 401 STR_MAPNAME qgetsysstr 402 STR_MAPFILENAME - qgetsysstr 403 STR_PLAYERNAME +// qgetsysstr 403 STR_PLAYERNAME qgetsysstr 404 STR_VERSION qgetsysstr 405 STR_GAMETYPE qgetsysstr 406 STR_VOLUMENAME