static int load(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv) { const char *fileName; XmlState *parser; Exml *xp; MprFile *file; if (argc != 1 || !ejsVarIsString(argv[0])) { ejsError(ep, EJS_ARG_ERROR, "Bad args. Usage: load(fileName);"); return -1; } fileName = argv[0]->string; /* FUTURE -- not romable Need rom code in MPR not MprServices */ file = mprOpen(ep, fileName, O_RDONLY, 0664); if (file == 0) { ejsError(ep, EJS_IO_ERROR, "Can't open: %s", fileName); return -1; } xp = initParser(ep, thisObj, fileName); parser = exmlGetParseArg(xp); exmlSetInputStream(xp, readFileData, (void*) file); if (exmlParse(xp) < 0) { if (! ejsGotException(ep)) { ejsError(ep, EJS_IO_ERROR, "Can't parse XML file: %s\nDetails %s", fileName, exmlGetErrorMsg(xp)); } termParser(xp); mprClose(file); return -1; } ejsSetReturnValue(ep, parser->nodeStack[0].obj); termParser(xp); mprClose(file); return 0; }
/* set the return value then free the variable */ void mpr_Return(int eid, struct MprVar v) { ejsSetReturnValue(eid, v); mprDestroyVar(&v); }
void espSetReturnString(EspRequest *ep, char *str) { mprAssert(ep); ejsSetReturnValue(ep->eid, mprCreateStringVar(str, 0)); }
void espSetReturn(EspRequest *ep, MprVar value) { mprAssert(ep); ejsSetReturnValue(ep->eid, value); }