static struct ekValue *fileFuncToString(struct ekContext *E, struct ekValue *p) { ekFile *file = (ekFile *)p->ptrVal; ekValueAddRefNote(E, file->filename, "fileFuncToString adding filename ref"); ekValueRemoveRefNote(E, p, "fileFuncToString doesnt need file anymore"); return file->filename; }
static ekRegex *ekRegexCreate(ekContext *E, ekValue *subject, ekValue *pattern, ekValue *options) { ekS32 regexFlags = 0; const char *regexError; ekS32 regexErrorOffset; ekRegex *regex = calloc(1, sizeof(ekRegex)); ekValueAddRefNote(E, subject, "ekRegexCreate"); regex->subject = subject; regex->offset = 0; regex->global = ekFalse; if(options) { const char *c = ekValueSafeStr(options); for(; *c; c++) { switch(*c) { case 'x': regexFlags |= PCRE_EXTENDED; break; case 'i': regexFlags |= PCRE_CASELESS; break; case 's': regexFlags |= PCRE_DOTALL; break; case 'm': regexFlags |= PCRE_MULTILINE; break; case 'g': regex->global = ekTrue; break; }; } } regex->regex = pcre_compile(ekValueSafeStr(pattern), regexFlags, ®exError, ®exErrorOffset, NULL); if(!regex->regex) { // Regex compilation errors are fatal for now. I think this is good. ekContextSetError(E, EVE_RUNTIME, "regex compilation error: %s", regexError); ekRegexDestroy(E, regex); regex = NULL; } return regex; }