37 lines
1.2 KiB
C
37 lines
1.2 KiB
C
#include "cell.h"
|
|
#include "wildmatch.h"
|
|
#include "qjs_macros.h"
|
|
|
|
JSC_CCALL(wildstar_match,
|
|
const char *pattern = JS_ToCString(js, argv[0]);
|
|
const char *string = JS_ToCString(js, argv[1]);
|
|
int flags = 0;
|
|
if (argc > 2)
|
|
flags = js2number(js, argv[2]);
|
|
|
|
int result = wildmatch(pattern, string, flags);
|
|
|
|
JS_FreeCString(js, pattern);
|
|
JS_FreeCString(js, string);
|
|
|
|
return JS_NewBool(js, result == WM_MATCH);
|
|
)
|
|
|
|
static const JSCFunctionListEntry js_wildstar_funcs[] = {
|
|
MIST_FUNC_DEF(wildstar, match, 3),
|
|
JS_PROP_INT32_DEF("WM_MATCH", WM_MATCH, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_NOMATCH", WM_NOMATCH, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_NOESCAPE", WM_NOESCAPE, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_PATHNAME", WM_PATHNAME, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_PERIOD", WM_PERIOD, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_LEADING_DIR", WM_LEADING_DIR, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_CASEFOLD", WM_CASEFOLD, JS_PROP_CONFIGURABLE),
|
|
JS_PROP_INT32_DEF("WM_WILDSTAR", WM_WILDSTAR, JS_PROP_CONFIGURABLE),
|
|
};
|
|
|
|
JSValue js_wildstar_use(JSContext *js) {
|
|
JSValue mod = JS_NewObject(js);
|
|
JS_SetPropertyFunctionList(js, mod, js_wildstar_funcs, countof(js_wildstar_funcs));
|
|
return mod;
|
|
}
|