Back |
Some examples for the usage of the Generic Call Interface follow. All
functions are taken from the C-library. The library has the name
'libc'
but this may vary for different systems.
This function has the following syntax:
char * setlocale(int category, const char *locale);
A complete definition is:
InitSetLocale: procedure setlocale.calltype = 'cdecl' setlocale.return.type = 'indirect string256' /* more than enough */ setlocale.return.name = 'return value' setlocale.0 = 2 setlocale.1.type = 'integer32' /* maybe */ setlocale.1.name = 'category' setlocale.2.type = 'indirect string256' /* more than enough */ setlocale.2.name = 'locale' err = RxFuncDefine('SETLOCALE', 'libc', 'setlocale', setlocale) if err \= 0 then ... return ... DoSetLocale: procedure /* setlocale.return will be assigned on exit */ setlocale.1.value = arg(1) setlocale.1.name = 'category' setlocale.2.value = arg(2) setlocale.2.name = 'locale' call SETLOCALE setlocale return setlocale.return.value
or in short:
InitSetLocale: procedure setlocale.calltype = 'cdecl' setlocale.return.type = 'indirect string256' /* more than enough */ setlocale.0 = 2 setlocale.1.type = 'integer32' /* maybe */ setlocale.2.type = 'indirect string256' /* more than enough */ err = RxFuncDefine('SETLOCALE', 'libc', 'setlocale', setlocale) if err \= 0 then ... return ... DoSetLocale: procedure /* setlocale.return will be assigned on exit */ setlocale.1.value = arg(1) setlocale.2.value = arg(2) call SETLOCALE setlocale return setlocale.return.value
and even shorter:
InitSetLocale: procedure setlocale.calltype = 'cdecl as function with parameters' setlocale.return.type = 'indirect string256' /* more than enough */ setlocale.0 = 2 setlocale.1.type = 'integer32' /* maybe */ setlocale.2.type = 'indirect string256' /* more than enough */ err = RxFuncDefine('SETLOCALE', 'libc', 'setlocale', setlocale) if err \= 0 then ... return ... desiredValue = SETLOCALE(arg(1), arg(2))
This function has the following syntax:
int getrlimit(int category, struct rlimit *rlp);
with
struct rlimit { rlim_t rlim_cur; rlim_t rlim_max; }
Note the same types of both entries. It can be interpreted as an array and may have the following definition:
InitGetRLimit1: procedure getrlimit.calltype = 'cdecl as function' getrlimit.return.type = 'integer32' /* maybe */ getrlimit.return.name = 'return value' getrlimit.0 = 2 getrlimit.1.type = 'integer32' /* maybe */ getrlimit.1.name = 'category' getrlimit.2.type = 'indirect array' getrlimit.2.name = 'rlp' getrlimit.2.0 = 2 getrlimit.2.1.type = 'integer32' /* maybe */ getrlimit.2.1.name = 'rlim' err = RxFuncDefine('GETRLIMIT1', 'libc', 'getrlimit', getrlimit) if err \= 0 then ... return ... DoGetRLimit1: procedure /* the array fields will be assigned on exit */ getrlimit.1.value = arg(1) getrlimit.2.value = 2 getrlimit.2.1.value = 0 getrlimit.2.2.value = 0 func_rc = GETRLIMIT1(getrlimit) if func_rc \= 0 then ... return getrlimit.2.1.value ';' getrlimit.2.2.value /* maybe */
This function has the following syntax:
int getrlimit(int category, struct rlimit *rlp);with
struct rlimit { rlim_t rlim_cur; rlim_t rlim_max; }
The correct form of the definition is:
InitGetRLimit2: procedure getrlimit.calltype = 'cdecl as function' getrlimit.return.type = 'integer32' /* maybe */ getrlimit.return.name = 'Return Value' getrlimit.0 = 2 getrlimit.1.type = 'integer32' /* maybe */ getrlimit.1.name = 'category' getrlimit.2.type = 'indirect container' getrlimit.2.name = 'rlp' getrlimit.2.0 = 2 getrlimit.2.1.type = 'integer32' /* maybe */ getrlimit.2.1.name = 'rlim_cur' getrlimit.2.2.type = 'integer32' /* maybe */ getrlimit.2.2.name = 'rlim_max' err = RxFuncDefine('GETRLIMIT2', 'libc', 'getrlimit', getrlimit) if err \= 0 then ... return ... DoGetRLimit2: procedure /* the array fields will be assigned on exit */ getrlimit.1.value = arg(1) getrlimit.2.value = 2 getrlimit.2.1.value = 0 getrlimit.2.2.value = 0 func_rc = GETRLIMIT2(getrlimit) if func_rc \= 0 then ... return getrlimit.2.1.value ';' getrlimit.2.2.value /* maybe */
This function has the following syntax:
int setrlimit(int category, struct rlimit *rlp);with
rlimit
defined as above.
Therefore one can use the above definition to reduce the definition to the
lines below if they share the same variable pool which is not the
case here. Remove the PROCEDURE
instruction of
InitGetRLimit2
to get it running.
InitSetRLimit: setrlimit.calltype = 'cdecl as function' setrlimit.return.type = 'integer32' /* maybe */ setrlimit.return.name = 'Return Value' setrlimit.0 = 2 setrlimit.1.type = 'integer32' /* maybe */ setrlimit.1.name = 'category' setrlimit.2.type = 'indirect container like getrlimit.2' setrlimit.2.name = 'rlp' err = RxFuncDefine('SETRLIMIT', 'libc', 'setrlimit', setrlimit) if err \= 0 then ... return ...
The use of setrlimit
is similar to the example shown
above in getrlimit(),
type 2
Back |