SDEXT – Generic function for extending SD / BASIC to interface with C Functions.
(This command is unique to SD - not found in OpenQM or ScarletDME)
The purpose of this function is to add a generic function to SD / BASIC to allow for the interface of C code and C functions.
Function SDEXT
Function SDEXT(Arg, IsArgMV, Function_id)
Arg = string value passed to the c code / function.
For functions requiring multiple arguments, set IsArgMV to true and pass arguments in a
FIELD_MARK separated string, with a maximum of 10 arguments.
IsArgMV = If passing multiple arguments in Arg, set to true, otherwise false.
Function_Id = the integer value used to identify what c code / function is execute.
Defined in SYSCOM/KEYS.H and gplsrc/keys.h
Use the BASIC function STATUS() to return function status:
STATUS() = 0 successful call, otherwise error code returned from function, see SYSCOM/ERR.H and gplsrc/err.h.
Note: SDEXT is an internal function. Programs using it require the $internal compiler directive, and compiling a program with this directive requires starting sd with the -internal flag.
Source code for this function is found in gplsrc/op_sdext.c.
Sample call:
Sample program calls c code executed when issuing SDEXT_TestIt function id.
SDEXT_TestIt simply echos the passed arguments to stdout and returns the string
"op_sdext() found %d args\n"
01: PROGRAM SD_EXT
02: * note SDEXT is an internal function!!
03: $internal
04:
05: $include KEYS.H
06: $include ERR.H
07:
08:
09: crt 'attempt sdext call'
10: arglist = 'apple':@fm:'banana':@fm:'pear'
11: rsp = sdext(arglist,@TRUE,SDEXT_TestIt)
12: *
13: crt 'response:'
14: crt rsp
15: *
16: alldone:
17: END
Output:
:RUN BP SD_EXT
attempt sdext call
Arg 1 of 3
'apple'
Arg 2 of 3
'banana'
Arg 3 of 3
'pear'
response:
op_sdext() found 3 args
Snippet of c code the produces this result (found in gplsrc/op_sdext.c):
case SDEXT_TestIt:
/* simple test to see if any of this works, output args to stdout */
for (argIdx = 0; argIdx < argCnt; argIdx++) {
printf("Arg %d of %d\r\n",argIdx+1, argCnt);
printf("'%s'\r\n",SDMEArgArray[argIdx]);
}
snprintf(myErrMsg, SD_ErrMsg_LEN, "op_sdext() found %d args\n", argCnt);
k_put_c_string(myErrMsg, e_stack); /* sets descr pointed to by e_stack as type
string and place the string in myErrMsg
into it */
/* this will then get transferred as the
returned value */
e_stack++;
break;