summaryrefslogtreecommitdiff
path: root/legacy/embryo
diff options
context:
space:
mode:
authortsauerbeck <tsauerbeck>2005-04-29 14:30:59 +0000
committertsauerbeck <tsauerbeck@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>2005-04-29 14:30:59 +0000
commit5828825639ef8d9c0fcee700963f93bfa78344e3 (patch)
tree983ffbcc499bca1b232efd0be8fd1d966374d4f4 /legacy/embryo
parent83f561fffaea8a9ebb4008f4d6f27c971a5ca75c (diff)
added getsarg() - copies the specified argument into a string buffer. use this instead of getarg(num, 0) if you want to retrieve all of the string
SVN revision: 14492
Diffstat (limited to 'legacy/embryo')
-rw-r--r--legacy/embryo/include/default.inc1
-rw-r--r--legacy/embryo/src/lib/embryo_args.c45
2 files changed, 46 insertions, 0 deletions
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
36native numargs(); 36native numargs();
37/* varags - get arg no "arg" */ 37/* varags - get arg no "arg" */
38native getarg(arg, index=0); 38native getarg(arg, index=0);
39native getsarg(arg, buf[], buflen);
39native Float:getfarg(arg, index=0); 40native Float:getfarg(arg, index=0);
40/* varags - set arg no "arg" */ 41/* varags - set arg no "arg" */
41native setarg(arg, index=0, value); 42native 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 @@
1/*
2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3 */
1#include "embryo_private.h" 4#include "embryo_private.h"
2 5
6#define STRSET(ep, par, str) { \
7 Embryo_Cell *___cptr; \
8 if ((___cptr = embryo_data_address_get(ep, par))) { \
9 embryo_data_string_set(ep, str, ___cptr); \
10 } }
11
3/* exported args api */ 12/* exported args api */
4 13
5static Embryo_Cell 14static Embryo_Cell
@@ -51,6 +60,41 @@ _embryo_args_setarg(Embryo_Program *ep, Embryo_Cell *params)
51 return 1; 60 return 1;
52} 61}
53 62
63static Embryo_Cell
64_embryo_args_getsarg(Embryo_Program *ep, Embryo_Cell *params)
65{
66 Embryo_Header *hdr;
67 unsigned char *data;
68 Embryo_Cell base_cell;
69 char *s;
70 int i = 0;
71
72 /* params[1] = arg_no */
73 /* params[2] = buf */
74 /* params[3] = buflen */
75 if (params[0] != (3 * sizeof(Embryo_Cell))) return 0;
76 if (params[3] <= 0) return 0; /* buflen must be > 0 */
77 hdr = (Embryo_Header *)ep->base;
78 data = ep->base + (int)hdr->dat;
79 base_cell = *(Embryo_Cell *)(data + (int)ep->frm +
80 (((int)params[1] + 3) * sizeof(Embryo_Cell)));
81
82 s = alloca(params[3]);
83
84 while (i < params[3])
85 {
86 int offset = base_cell + (i * sizeof(Embryo_Cell));
87
88 s[i] = *(Embryo_Cell *)(data + offset);
89 if (!s[++i]) break;
90 }
91
92 s[i - 1] = 0;
93 STRSET(ep, params[2], s);
94
95 return i - 1; /* characters written minus terminator */
96}
97
54/* functions used by the rest of embryo */ 98/* functions used by the rest of embryo */
55 99
56void 100void
@@ -61,4 +105,5 @@ _embryo_args_init(Embryo_Program *ep)
61 embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg); 105 embryo_program_native_call_add(ep, "setarg", _embryo_args_setarg);
62 embryo_program_native_call_add(ep, "getfarg", _embryo_args_getarg); 106 embryo_program_native_call_add(ep, "getfarg", _embryo_args_getarg);
63 embryo_program_native_call_add(ep, "setfarg", _embryo_args_setarg); 107 embryo_program_native_call_add(ep, "setfarg", _embryo_args_setarg);
108 embryo_program_native_call_add(ep, "getsarg", _embryo_args_getsarg);
64} 109}