head 1.2; access; symbols last-version-before-change-to-ossp-style:1.1.1.1 VAR_0_0_0:1.1.1.1 VENDOR:1.1.1; locks; strict; comment @ * @; 1.2 date 2001.11.13.12.08.30; author simons; state dead; branches; next 1.1; 1.1 date 2001.11.09.17.01.37; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.11.09.17.01.37; author rse; state Exp; branches; next ; desc @@ 1.2 log @- Moved all routines into a single source file var.c. - Renamed varexp.h to var.h. - Removed odin-based build system. - Moved test cases into var_test.c. - Adapted build system. @ text @#include "internal.h" int variable(const char* begin, const char* end, const var_config_t* config, const char nameclass[256], var_cb_t lookup, void* lookup_context, int force_expand, tokenbuf* result) { const char* p = begin; const char* data; size_t len, buffer_size; int rc, rc2; /* Clear the result tokenbuf to make sure we're in a defined state. */ init_tokenbuf(result); /* Expect VARINIT. */ if (p == end || *p != config->varinit) return 0; if (++p == end) return VAR_INCOMPLETE_VARIABLE_SPEC; /* Try to read the variable name. If that fails, we're parsing a complex expression. */ rc = varname(p, end, nameclass); if (rc < 0) return rc; else if (rc > 0) { rc2 = (*lookup)(lookup_context, p, rc, &data, &len, &buffer_size); if (rc2 < 0) return rc2; else if (rc2 == 0) { if (force_expand) return VAR_UNDEFINED_VARIABLE; else { result->begin = begin; result->end = begin + 1 + rc; result->buffer_size = 0; return 1 + rc; } } else { result->begin = data; result->end = data + len; result->buffer_size = buffer_size; return 1 + rc; } } /* OK, we're dealing with a complex expression here. */ rc = expression(p, end, config, nameclass, lookup, lookup_context, force_expand, result); if (rc > 0) ++rc; return rc; } @ 1.1 log @Initial revision @ text @@ 1.1.1.1 log @import first cut of OSSP var @ text @@