22
22
#include "confmagic.h"
24
24
void do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs,
25
char **args, dbref executor, dbref caller, dbref enactor,
25
char **args, dbref executor, dbref caller, dbref enactor,
72
72
* standpoint. We require control.
74
74
if (((obj = match_thing(executor, name)) == NOTHING)
75
|| !controls(executor, obj))
75
|| !controls(executor, obj))
78
78
/* In order to evaluate from something else's viewpoint, you
79
79
* must control it, or be able to see_all.
81
81
if (((obj = match_thing(executor, name)) == NOTHING)
82
|| (!controls(executor, obj) && !See_All(executor)))
82
|| (!controls(executor, obj) && !See_All(executor)))
87
87
process_expression(buff, bp, &p, obj, executor, enactor, PE_DEFAULT,
91
91
/** Helper function for ufun and family.
104
104
do_userfn(char *buff, char **bp, dbref obj, ATTR *attrib, int nargs,
105
char **args, dbref executor, dbref caller
106
__attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info)
105
char **args, dbref executor, dbref caller
106
__attribute__ ((__unused__)), dbref enactor, PE_Info * pe_info)
112
112
int pe_flags = PE_DEFAULT;
114
115
/* save our stack */
115
116
for (j = 0; j < 10; j++)
118
119
/* copy the appropriate args into the stack */
120
nargs = 10; /* maximum ten args */
121
nargs = 10; /* maximum ten args */
121
122
for (j = 0; j < nargs; j++)
122
123
global_eval_context.wenv[j] = args[j];
123
124
for (; j < 10; j++)
124
125
global_eval_context.wenv[j] = NULL;
127
old_args = pe_info->arg_count;
128
pe_info->arg_count = nargs;
126
131
tp = tbuf = safe_atr_value(attrib);
127
132
if (attrib->flags & AF_DEBUG)
128
133
pe_flags |= PE_DEBUG;
129
134
process_expression(buff, bp, &tp, obj, executor, enactor, pe_flags,
130
PT_DEFAULT, pe_info);
135
PT_DEFAULT, pe_info);
133
138
/* restore the stack */
134
139
for (j = 0; j < 10; j++)
135
140
global_eval_context.wenv[j] = tptr[j];
142
pe_info->arg_count = old_args;
139
146
FUNCTION(fun_ufun)
144
/* find the user function attribute */
145
parse_attrib(executor, args[0], &obj, &attrib);
146
if (!GoodObject(obj)) {
147
safe_str(T("#-1 INVALID OBJECT"), buff, bp);
150
if (attrib && Can_Read_Attr(executor, obj, attrib)) {
151
if (!CanEvalAttr(executor, obj, attrib)) {
152
safe_str(T(e_perm), buff, bp);
155
do_userfn(buff, bp, obj, attrib, nargs - 1, args + 1, executor, caller,
158
} else if (attrib || !Can_Examine(executor, obj)) {
159
safe_str(T(e_atrperm), buff, bp);
148
char rbuff[BUFFER_LEN];
151
if (!fetch_ufun_attrib(args[0], executor, &ufun, 0)) {
152
safe_str(T(ufun.errmess), buff, bp);
156
call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
158
safe_str(rbuff, buff, bp);
164
FUNCTION(fun_ulambda)
166
char rbuff[BUFFER_LEN];
169
if (!fetch_ufun_attrib(args[0], executor, &ufun, 1)) {
170
safe_str(T(ufun.errmess), buff, bp);
174
call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
176
safe_str(rbuff, buff, bp);
168
184
/* Like fun_ufun, but saves the state of the q0-q9 registers
173
187
char *preserve[NUMQ];
175
/* find the user function attribute */
176
parse_attrib(executor, args[0], &obj, &attrib);
177
if (!GoodObject(obj)) {
178
safe_str(T("#-1 INVALID OBJECT"), buff, bp);
181
if (attrib && Can_Read_Attr(executor, obj, attrib)) {
182
if (!CanEvalAttr(executor, obj, attrib)) {
183
safe_str(T(e_perm), buff, bp);
186
save_global_regs("ulocal.save", preserve);
187
do_userfn(buff, bp, obj, attrib, nargs - 1, args + 1, executor, caller,
189
restore_global_regs("ulocal.save", preserve);
191
} else if (attrib || !Can_Examine(executor, obj)) {
192
safe_str(T(e_atrperm), buff, bp);
188
char rbuff[BUFFER_LEN];
191
if (!fetch_ufun_attrib(args[0], executor, &ufun, 0)) {
192
safe_str(T(ufun.errmess), buff, bp);
196
/* Save global regs */
197
save_global_regs("ulocal.save", preserve);
199
call_ufun(&ufun, args + 1, nargs - 1, rbuff, executor, enactor, pe_info);
200
safe_str(rbuff, buff, bp);
202
restore_global_regs("ulocal.save", preserve);
217
226
process_expression(mstr, &dp, &sp, executor, caller, enactor,
218
PE_DEFAULT, PT_DEFAULT, pe_info);
227
PE_DEFAULT, PT_DEFAULT, pe_info);
220
229
parse_attrib(executor, mstr, &thing, &attrib);
221
230
if (GoodObject(thing) && attrib && CanEvalAttr(executor, thing, attrib)
229
(char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs");
238
(char **) mush_malloc((nargs - 2) * sizeof(char *), "udefault.xargs");
230
239
for (i = 0; i < nargs - 2; i++) {
231
xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault");
234
process_expression(xargs[i], &dp, &sp, executor, caller, enactor,
235
PE_DEFAULT, PT_DEFAULT, pe_info);
240
xargs[i] = (char *) mush_malloc(BUFFER_LEN, "udefault");
243
process_expression(xargs[i], &dp, &sp, executor, caller, enactor,
244
PE_DEFAULT, PT_DEFAULT, pe_info);
239
248
if (called_as[1] == 'L')
240
249
save_global_regs("uldefault.save", preserve);
241
250
do_userfn(buff, bp, thing, attrib, nargs - 2, xargs,
242
executor, caller, enactor, pe_info);
251
executor, caller, enactor, pe_info);
243
252
if (called_as[1] == 'L')
244
253
restore_global_regs("uldefault.save", preserve);
246
255
/* Free the xargs */
248
257
for (i = 0; i < nargs - 2; i++)
249
mush_free(xargs[i], "udefault");
258
mush_free(xargs[i], "udefault");
250
259
mush_free(xargs, "udefault.xargs");
257
266
if (called_as[1] == 'L')
258
267
save_global_regs("uldefault.save", preserve);
259
268
process_expression(buff, bp, &sp, executor, caller, enactor,
260
PE_DEFAULT, PT_DEFAULT, pe_info);
269
PE_DEFAULT, PT_DEFAULT, pe_info);
261
270
if (called_as[1] == 'L')
262
271
restore_global_regs("uldefault.save", preserve);
286
295
do_userfn(buff, bp, zone, attrib, nargs - 1, args + 1, executor, caller,
289
298
} else if (attrib || !Can_Examine(executor, zone)) {
290
299
safe_str(T(e_atrperm), buff, bp);