diff --git a/legacy/embryo/include/default.inc b/legacy/embryo/include/default.inc index f4f0858662..6315ef8f27 100644 --- a/legacy/embryo/include/default.inc +++ b/legacy/embryo/include/default.inc @@ -36,6 +36,7 @@ enum Float_Angle_Mode native numargs(); /* varags - get arg no "arg" */ native getarg(arg, index=0); +native getsarg(arg, buf[], buflen); native Float:getfarg(arg, index=0); /* varags - set arg no "arg" */ native setarg(arg, index=0, value); diff --git a/legacy/embryo/src/lib/embryo_args.c b/legacy/embryo/src/lib/embryo_args.c index b12f60019f..4dc8a4ccfc 100644 --- a/legacy/embryo/src/lib/embryo_args.c +++ b/legacy/embryo/src/lib/embryo_args.c @@ -1,5 +1,14 @@ +/* + * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2 + */ #include "embryo_private.h" +#define STRSET(ep, par, str) { \ + Embryo_Cell *___cptr; \ + if ((___cptr = embryo_data_address_get(ep, par))) { \ + embryo_data_string_set(ep, str, ___cptr); \ + } } + /* exported args api */ static Embryo_Cell @@ -51,6 +60,41 @@ _embryo_args_setarg(Embryo_Program *ep, Embryo_Cell *params) return 1; } +static Embryo_Cell +_embryo_args_getsarg(Embryo_Program *ep, Embryo_Cell *params) +{ + Embryo_Header *hdr; + unsigned char *data; + Embryo_Cell base_cell; + char *s; + int i = 0; + + /* params[1] = arg_no */ + /* params[2] = buf */ + /* params[3] = buflen */ + if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; + if (params[3] <= 0) return 0; /* buflen must be > 0 */ + hdr = (Embryo_Header *)ep->base; + data = ep->base + (int)hdr->dat; + base_cell = *(Embryo_Cell *)(data + (int)ep->frm + + (((int)params[1] + 3) * sizeof(Embryo_Cell))); + + s = alloca(params[3]); + + while (i < params[3]) + { + int offset = base_cell + (i * sizeof(Embryo_Cell)); + + s[i] = *(Embryo_Cell *)(data + offset); + if (!s[++i]) break; + } + + s[i - 1] = 0; + STRSET(ep, params[2], s); + + return i - 1; /* characters written minus terminator */ +} + /* functions used by the rest of embryo */ void @@ -61,4 +105,5 @@ _embryo_args_init(Embryo_Program *ep) embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg); embryo_program_native_call_add(ep, "getfarg", _embryo_args_getarg); embryo_program_native_call_add(ep, "setfarg", _embryo_args_setarg); + embryo_program_native_call_add(ep, "getsarg", _embryo_args_getsarg); }