From a8504e1061d248a54be93716ead545b2f066f2cf Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 15 Oct 2005 09:32:04 +0000 Subject: r11085: as ejs doesn't support '&' '|' bitwise AND and OR, we need some helper functions for this metze (This used to be commit e27e36909d367748fc653ddc0fd1c699b77780e9) --- source4/scripting/ejs/smbcalls_sys.c | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source4') diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c index 340671cf0b..5f6a756f8f 100644 --- a/source4/scripting/ejs/smbcalls_sys.c +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -257,6 +257,51 @@ static int ejs_sys_lstat(MprVarHandle eid, int argc, char **argv) return 0; } +/* + bitwise AND + usage: + var z = sys.bitAND(x, 0x70); +*/ +static int ejs_sys_bitAND(MprVarHandle eid, int argc, struct MprVar **argv) +{ + int x, y, z; + + if (argc != 2 || + !mprVarIsNumber(argv[0]->type) || + !mprVarIsNumber(argv[1]->type)) { + ejsSetErrorMsg(eid, "bitand invalid arguments"); + return -1; + } + x = mprToInt(argv[0]); + y = mprToInt(argv[1]); + z = x & y; + + mpr_Return(eid, mprCreateIntegerVar(z)); + return 0; +} + +/* + bitwise OR + usage: + var z = sys.bitOR(x, 0x70); +*/ +static int ejs_sys_bitOR(MprVarHandle eid, int argc, struct MprVar **argv) +{ + int x, y, z; + + if (argc != 2 || + !mprVarIsNumber(argv[0]->type) || + !mprVarIsNumber(argv[1]->type)) { + ejsSetErrorMsg(eid, "bitand invalid arguments"); + return -1; + } + x = mprToInt(argv[0]); + y = mprToInt(argv[1]); + z = x | y; + + mpr_Return(eid, mprCreateIntegerVar(z)); + return 0; +} /* initialise sys ejs subsystem @@ -276,6 +321,8 @@ static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv) mprSetStringCFunction(obj, "file_save", ejs_sys_file_save); mprSetStringCFunction(obj, "stat", ejs_sys_stat); mprSetStringCFunction(obj, "lstat", ejs_sys_lstat); + mprSetCFunction(obj, "bitAND", ejs_sys_bitAND); + mprSetCFunction(obj, "bitOR", ejs_sys_bitOR); return 0; } -- cgit