ossp-pkg/l2/l2_spec.c
1.1
#include <stdio.h>
#include "l2.h"
#include "l2_p.h"
#include "l2_spec.h"
#include "l2_spec_parse.h"
extern int l2_spec_lex_init(void *);
extern int l2_spec_lex_destroy(void *);
extern void l2_spec_set_extra(void *, void *);
extern int l2_spec_debug;
void dump(int level, l2_channel_t *ch)
{
l2_channel_t *chD;
fprintf(stderr, "%*s%s (0x%lx)\n", level*4, "", ch->handler.name, ch);
chD = NULL;
while ((l2_channel_downstream(ch, &chD)) == L2_OK)
dump(level+1, chD);
return;
}
l2_result_t l2_spec(l2_channel_t **ch, l2_env_t *env, const char *spec)
{
l2_spec_ctx_t ctx;
void *yyscan;
l2_spec_lex_init(&yyscan);
l2_spec_set_extra(&ctx, yyscan);
ctx.yyscan = yyscan;
ctx.inputptr = spec;
ctx.inputbuf = spec;
ctx.inputlen = strlen(spec);
ctx.env = env;
ctx.ch = NULL;
ctx.chTmp = NULL;
ctx.rv = L2_OK;
#if 0
l2_spec_debug = 1;
#endif
if (l2_spec_parse(&ctx))
ctx.rv = (ctx.rv == L2_OK ? L2_ERR_INT : ctx.rv);
*ch = ctx.ch;
dump(0, ctx.ch);
l2_spec_lex_destroy(yyscan);
return ctx.rv;
}