/* This file is part of the Zebra server.
- Copyright (C) 1994-2009 Index Data
+ Copyright (C) 2004-2013 Index Data
Zebra is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
};
struct lexRuleAction {
- int which;
+ int which;
union {
struct {
struct DFA *dfa; /* REGX_PATTERN */
data1_node **d1_stack;
int d1_level;
int stop_flag;
-
+
int *arg_start;
int *arg_end;
int arg_no;
{
int size;
char *buf;
-
+
if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
return spec->f_win_buf[(*pos)++ - spec->f_win_start];
if (*pos == F_WIN_EOF)
if (p->tcl_obj)
Tcl_DecrRefCount (p->tcl_obj);
#endif
- xfree (p->str);
+ xfree (p->str);
xfree (p);
*pp = NULL;
}
{
struct lexSpec *p;
int i;
-
+
p = (struct lexSpec *) xmalloc (sizeof(*p));
p->name = (char *) xmalloc (strlen(name)+1);
strcpy (p->name, name);
}
if (!spec->context)
spec->context = lexContextCreate ("main");
-
+
switch (tok)
{
case REGX_BEGIN:
else
{
int addLine = 0;
-
+
while (1)
{
int c1 = c;
}
if (errors)
return -1;
-
+
return 0;
}
}
else if (elen > 0)
yaz_log (YLOG_LOG, "data(%d bytes) %.*s", elen, elen, ebuf);
- else
+ else
yaz_log (YLOG_LOG, "data(%d bytes)", elen);
#endif
-
+
if (spec->d1_level <= 1)
return;
nv[strlen(nv)+elen] = '\0';
(*ap)->value = nv;
}
- }
- else
+ }
+ else
{
- if ((res = spec->d1_stack[spec->d1_level]) &&
+ if ((res = spec->d1_stack[spec->d1_level]) &&
res->which == DATA1N_data)
org_len = res->u.data.len;
else
{
org_len = 0;
-
+
res = data1_mk_node2 (spec->dh, spec->m, DATA1N_data, parent);
res->u.data.what = DATA1I_text;
res->u.data.len = 0;
res->u.data.formatted_text = formatted_text;
res->u.data.data = 0;
-
+
if (spec->d1_stack[spec->d1_level])
spec->d1_stack[spec->d1_level]->next = res;
spec->d1_stack[spec->d1_level] = res;
if (org_len + elen >= spec->concatBuf[spec->d1_level].max)
{
char *old_buf, *new_buf;
-
+
spec->concatBuf[spec->d1_level].max = org_len + elen + 256;
new_buf = (char *) xmalloc (spec->concatBuf[spec->d1_level].max);
if ((old_buf = spec->concatBuf[spec->d1_level].buf))
static void tagDataRelease (struct lexSpec *spec)
{
data1_node *res;
-
+
if ((res = spec->d1_stack[spec->d1_level]) &&
- res->which == DATA1N_data &&
+ res->which == DATA1N_data &&
res->u.data.what == DATA1I_text)
{
assert (!res->u.data.data);
}
}
-static void variantBegin (struct lexSpec *spec,
+static void variantBegin (struct lexSpec *spec,
const char *class_str, int class_len,
const char *type_str, int type_len,
const char *value_str, int value_len)
memcpy (ttype, type_str, type_len);
ttype[type_len] = '\0';
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "variant begin(%s,%s,%d)", tclass, ttype,
spec->d1_level);
#endif
data1_getvartypeby_absyn(spec->dh, parent->root->u.root.absyn,
tclass, ttype)))
return;
-
+
if (parent->which != DATA1N_variant)
{
res = data1_mk_node2 (spec->dh, spec->m, DATA1N_variant, parent);
break;
}
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "variant node(%d)", spec->d1_level);
#endif
parent = spec->d1_stack[spec->d1_level-1];
res->lbuf[value_len] = '\0';
res->u.variant.value = res->lbuf;
-
+
if (spec->d1_stack[spec->d1_level])
tagDataRelease (spec);
spec->d1_stack[spec->d1_level] = res;
*len -= i;
}
-static void tagBegin (struct lexSpec *spec,
+static void tagBegin (struct lexSpec *spec,
const char *tag, int len)
{
if (spec->d1_level == 0)
if (spec->d1_stack[spec->d1_level])
tagDataRelease (spec);
-#if REGX_DEBUG
+#if REGX_DEBUG
yaz_log (YLOG_LOG, "begin tag(%.*s, %d)", len, tag, spec->d1_level);
#endif
yaz_log (YLOG_LOG, "begin record %s", absynName);
#endif
res = data1_mk_root (spec->dh, spec->m, absynName);
-
+
spec->d1_level = 0;
spec->d1_stack[spec->d1_level++] = res;
struct lexSpec *spec = (struct lexSpec *) clientData;
if (argc < 2)
return TCL_ERROR;
-
+
if (!strcmp (argv[1], "record"))
{
while (spec->d1_level)
const char *element = 0;
const char *attribute = 0;
struct lexSpec *spec = (struct lexSpec *) clientData;
-
+
while (argi < argc)
{
if (!strcmp("-text", argv[argi]))
#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION > 0)
Tcl_DString ds;
char *native = Tcl_UtfToExternalDString(0, argv[argi], -1, &ds);
- execData (spec, native, strlen(native), textFlag, attribute,
+ execData (spec, native, strlen(native), textFlag, attribute,
attribute ? strlen(attribute) : 0);
Tcl_DStringFree (&ds);
#else
int argi = 1;
int offset = 0;
int no;
-
+
while (argi < argc)
{
if (!strcmp("-offset", argv[argi]))
}
static void execTcl (struct lexSpec *spec, struct regxCode *code)
-{
+{
int i;
int ret;
for (i = 0; i < spec->arg_no; i++)
{
char var_name[10], *var_buf;
int var_len, ch;
-
+
sprintf (var_name, "%d", i);
var_buf = f_win_get (spec, spec->arg_start[i], spec->arg_end[i],
- &var_len);
+ &var_len);
if (var_buf)
{
ch = var_buf[var_len];
if (ret != TCL_OK)
{
const char *err = Tcl_GetVar(spec->tcl_interp, "errorInfo", 0);
- yaz_log(YLOG_FATAL, "Tcl error, line=%d, \"%s\"\n%s",
+ yaz_log(YLOG_FATAL, "Tcl error, line=%d, \"%s\"\n%s",
spec->tcl_interp->errorLine,
spec->tcl_interp->result,
err ? err : "[NO ERRORINFO]");
const char *s = code->str;
int cmd_len, r;
const char *cmd_str;
-
+
r = execTok (spec, &s, &cmd_str, &cmd_len);
while (r)
{
char *p, ptmp[64];
-
+
if (r == 1)
{
r = execTok (spec, &s, &cmd_str, &cmd_len);
yaz_log (YLOG_LOG, "begin record %s", absynName);
#endif
res = data1_mk_root (spec->dh, spec->m, absynName);
-
+
spec->d1_level = 0;
spec->d1_stack[spec->d1_level++] = res;
continue;
tagBegin (spec, cmd_str, cmd_len);
r = execTok (spec, &s, &cmd_str, &cmd_len);
- }
+ }
else if (!strcmp (p, "variant"))
{
int class_len;
variantBegin (spec, class_str, class_len,
type_str, type_len, value_str, value_len);
-
-
+
+
r = execTok (spec, &s, &cmd_str, &cmd_len);
}
else if (!strcmp (p, "context"))
spec->context_stack[++(spec->context_stack_top)] = lc;
else
yaz_log (YLOG_WARN, "unknown context %s", p);
-
+
}
r = execTok (spec, &s, &cmd_str, &cmd_len);
}
if (spec->context_stack_top)
(spec->context_stack_top)--;
r = execTok (spec, &s, &cmd_str, &cmd_len);
- }
+ }
else
yaz_log (YLOG_WARN, "bad keyword '%s' after end", p);
}
const char *element_str = NULL;
int attribute_len;
const char *attribute_str = NULL;
-
+
while ((r = execTok (spec, &s, &cmd_str, &cmd_len)) == 3)
{
if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
if (r < 2)
break;
}
- else if (cmd_len==10 && !memcmp ("-attribute", cmd_str,
+ else if (cmd_len==10 && !memcmp ("-attribute", cmd_str,
cmd_len))
{
r = execTok (spec, &s, &attribute_str, &attribute_len);
if (r < 2)
break;
}
- else
+ else
yaz_log (YLOG_WARN, "bad data option: %.*s",
cmd_len, cmd_str);
}
struct lexContext *lc = spec->context;
r = execTok (spec, &s, &cmd_str, &cmd_len);
p = regxStrz (cmd_str, cmd_len, ptmp);
-
+
while (lc && strcmp (p, lc->name))
lc = lc->next;
if (lc)
{
last_rule = state->rule_no;
last_ptr = *ptr;
- }
+ }
else if (state->rule_nno)
{
last_rule = state->rule_nno;
spec->stop_flag = 0;
spec->d1_level = 0;
- spec->context_stack_top = 0;
+ spec->context_stack_top = 0;
while (lt)
{
if (!strcmp (lt->name, context_name))
#endif
RecType
-#ifdef IDZEBRA_STATIC_GRS_REGX
+#if IDZEBRA_STATIC_GRS_REGX
idzebra_filter_grs_regx
#else
idzebra_filter
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab