disable debug
[AROS.git] / workbench / libs / rexxsupport / arexxdispatch.c
blob20196e97092d0149e470b8a4c4938c2aac2488ae
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: The query function called by rexxmast to find the library functions
6 Lang: English
7 */
9 #include <rexx/rexxcall.h>
10 #include <rexx/errors.h>
11 #include <aros/debug.h>
12 #include "rexxsupport_intern.h"
13 #include "rxfunctions.h"
15 #include <string.h>
16 #include <stdlib.h>
18 /* In arexxfunc the function names with the corresponding function
19 * to call are stored.
20 * UBYTE ** has to be filled with a value pointing to an argstring
21 * created from the rexxsyslib.library.
23 struct arexxfunc {
24 const char *commandname;
25 UBYTE minargs, maxargs;
26 LONG (*f)(struct Library *, struct RexxMsg *, UBYTE **);
29 /* The following function list has to be sorted on name */
30 struct arexxfunc funcs[] = {
31 { "ALLOCMEM" , 1, 2, rxsupp_allocmem },
32 { "BADDR" , 1, 1, rxsupp_baddr },
33 { "CLOSEPORT", 1, 1, rxsupp_closeport },
34 { "DELAY" , 1, 1, rxsupp_delay },
35 { "DELETE" , 1, 1, rxsupp_delete },
36 { "FORBID" , 0, 0, rxsupp_forbid },
37 { "FREEMEM" , 2, 2, rxsupp_freemem },
38 { "GETARG" , 1, 2, rxsupp_getarg },
39 { "GETPKT" , 1, 1, rxsupp_getpkt },
40 { "MAKEDIR" , 1, 1, rxsupp_makedir },
41 { "NEXT" , 1, 2, rxsupp_next },
42 { "NULL" , 0, 0, rxsupp_null },
43 { "OFFSET" , 2, 2, rxsupp_offset },
44 { "OPENPORT" , 1, 1, rxsupp_openport },
45 { "PERMIT" , 0, 0, rxsupp_permit },
46 { "RENAME" , 2, 2, rxsupp_rename },
47 { "REPLY" , 1, 2, rxsupp_reply },
48 { "SHOWDIR" , 1, 3, rxsupp_showdir },
49 { "SHOWLIST" , 1, 3, rxsupp_showlist },
50 { "STATEF" , 1, 1, rxsupp_statef },
51 { "TYPEPKT" , 1, 2, rxsupp_typepkt },
52 { "WAITPKT" , 1, 1, rxsupp_waitpkt }
54 #define FUNCCOUNT (sizeof(funcs)/sizeof(struct arexxfunc))
56 int comparefunc(const void *name, const void *func)
58 return strcmp((const char *)name, ((const struct arexxfunc *)func)->commandname);
61 AROS_AREXXLIBQUERYFUNC(ArexxDispatch, msg,
62 struct Library *, RexxSupportBase, 5, RexxSupport)
64 struct arexxfunc *func;
65 UBYTE *argstring = NULL;
66 LONG rc;
67 UBYTE n = msg->rm_Action & RXARGMASK;
69 func = bsearch(ARG0(msg), funcs, FUNCCOUNT, sizeof(struct arexxfunc), comparefunc);
70 if (func == NULL)
72 ReturnRexxQuery(1, NULL);
74 else if (n < func->minargs || n > func->maxargs)
76 ReturnRexxQuery(ERR10_018, NULL);
78 else
80 rc = func->f(RexxSupportBase, msg, &argstring);
81 ReturnRexxQuery(rc, argstring);
84 AROS_AREXXLIBQUERYFUNC_END