static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out) { struct instance *o = vo; if (!strcmp(name, "succeeded")) { *out = ncd_make_boolean(mem, o->succeeded, o->i->params->iparams->string_index); return 1; } size_t pos; uintmax_t n; if ((pos = string_begins_with(name, "match")) && parse_unsigned_integer(MemRef_MakeCstr(name + pos), &n)) { if (o->succeeded && n < MAX_MATCHES && o->matches[n].rm_so >= 0) { regmatch_t *m = &o->matches[n]; ASSERT(m->rm_so <= o->input.len) ASSERT(m->rm_eo >= m->rm_so) ASSERT(m->rm_eo <= o->input.len) size_t len = m->rm_eo - m->rm_so; *out = NCDVal_NewStringBinMr(mem, MemRef_Sub(o->input, m->rm_so, len)); return 1; } } return 0; }
static int replace_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *out) { struct replace_instance *o = vo; if (!strcmp(name, "")) { *out = NCDVal_NewStringBinMr(mem, o->output); return 1; } return 0; }
static void concat_eval (NCDCall call) { ExpString estr; if (!ExpString_Init(&estr)) { FunctionLog(&call, BLOG_ERROR, "ExpString_Init failed"); goto fail0; } size_t count = NCDCall_ArgCount(&call); for (size_t i = 0; i < count; i++) { NCDValRef arg = NCDCall_EvalArg(&call, i, NCDCall_ResMem(&call)); if (NCDVal_IsInvalid(arg)) { goto fail1; } if (!concat_recurser(&estr, arg, &call)) { goto fail1; } } NCDCall_SetResult(&call, NCDVal_NewStringBinMr(NCDCall_ResMem(&call), ExpString_GetMr(&estr))); fail1: ExpString_Free(&estr); fail0: return; }