2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.8 1997-09-17 12:19:22 adam
8 * Zebra version corresponds to YAZ version 1.4.
9 * Changed Zebra server so that it doesn't depend on global common_resource.
11 * Revision 1.7 1997/07/15 16:33:07 adam
12 * Check for zero length in execData.
14 * Revision 1.6 1997/02/24 10:41:51 adam
15 * Cleanup of code and commented out the "end element-end-record" code.
17 * Revision 1.5 1997/02/19 16:22:33 adam
18 * Fixed "end element" to terminate record in outer-most level.
20 * Revision 1.4 1997/02/12 20:42:58 adam
21 * Changed some log messages.
23 * Revision 1.3 1996/11/08 14:05:33 adam
24 * Bug fix: data1 node member u.tag.get_bytes weren't initialized.
26 * Revision 1.2 1996/10/29 14:02:09 adam
27 * Doesn't use the global data1_tabpath (from YAZ). Instead the function
28 * data1_get_tabpath is used.
30 * Revision 1.1 1996/10/11 10:57:30 adam
31 * New module recctrl. Used to manage records (extract/retrieval).
33 * Revision 1.24 1996/06/17 14:25:31 adam
34 * Removed LOG_DEBUG logs; can still be enabled by setting REGX_DEBUG.
36 * Revision 1.23 1996/06/04 10:19:00 adam
37 * Minor changes - removed include of ctype.h.
39 * Revision 1.22 1996/06/03 15:23:13 adam
40 * Bug fix: /../ BODY /../ - pattern didn't match EOF.
42 * Revision 1.21 1996/05/14 16:58:38 adam
45 * Revision 1.20 1996/05/01 13:46:36 adam
46 * First work on multiple records in one file.
47 * New option, -offset, to the "unread" command in the filter module.
49 * Revision 1.19 1996/02/12 16:18:20 adam
50 * Yet another bug fix in implementation of unread command.
52 * Revision 1.18 1996/02/12 16:07:54 adam
53 * Bug fix in new unread command.
55 * Revision 1.17 1996/02/12 15:56:11 adam
56 * New code command: unread.
58 * Revision 1.16 1996/01/17 14:57:51 adam
59 * Prototype changed for reader functions in extract/retrieve. File
60 * is identified by 'void *' instead of 'int.
62 * Revision 1.15 1996/01/08 19:15:47 adam
63 * New input filter that works!
65 * Revision 1.14 1996/01/08 09:10:38 adam
66 * Yet another complete rework on this module.
68 * Revision 1.13 1995/12/15 17:21:50 adam
69 * This version is able to set data.formatted_text in data1-nodes.
71 * Revision 1.12 1995/12/15 16:20:10 adam
72 * The filter files (*.flt) are read from the path given by data1_tabpath.
74 * Revision 1.11 1995/12/15 12:35:16 adam
77 * Revision 1.10 1995/12/15 10:35:36 adam
80 * Revision 1.9 1995/12/14 16:38:48 adam
81 * Completely new attempt to make regular expression parsing.
83 * Revision 1.8 1995/12/13 17:16:59 adam
86 * Revision 1.7 1995/12/13 16:51:58 adam
87 * Modified to set last_child in data1_nodes.
88 * Uses destroy handler to free up data text nodes.
90 * Revision 1.6 1995/12/13 13:45:37 quinn
91 * Changed data1 to use nmem.
93 * Revision 1.5 1995/12/11 09:12:52 adam
94 * The rec_get function returns NULL if record doesn't exist - will
95 * happen in the server if the result set records have been deleted since
96 * the creation of the set (i.e. the search).
97 * The server saves a result temporarily if it is 'volatile', i.e. the
98 * set is register dependent.
100 * Revision 1.4 1995/12/05 16:57:40 adam
101 * More work on regular patterns.
103 * Revision 1.3 1995/12/05 09:37:09 adam
104 * One malloc was renamed to xmalloc.
106 * Revision 1.2 1995/12/04 17:59:24 adam
107 * More work on regular expression conversion.
109 * Revision 1.1 1995/12/04 14:25:30 adam
110 * Started work on regular expression parsed input to structured records.
118 #include <zebrautl.h>
124 #define F_WIN_EOF 2000000000
128 #define REGX_PATTERN 1
138 struct lexRuleAction {
142 struct DFA *dfa; /* REGX_PATTERN */
145 struct regxCode *code; /* REGX_CODE */
147 struct lexRuleAction *next;
152 struct lexRuleAction *actionList;
156 struct lexRuleInfo info;
157 struct lexRule *next;
162 struct lexRule *rules;
163 struct lexRuleInfo **fastRule;
169 struct lexTrans trans;
174 void (*f_win_ef)(void *, off_t);
180 int (*f_win_rf)(void *, char *, size_t);
181 off_t (*f_win_sf)(void *, off_t);
183 struct lexRuleAction *beginActionList;
184 struct lexRuleAction *endActionList;
188 static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos,
193 if (start_pos < spec->f_win_start || start_pos >= spec->f_win_end)
195 (*spec->f_win_sf)(spec->f_win_fh, start_pos);
196 spec->f_win_start = start_pos;
198 if (!spec->f_win_buf)
199 spec->f_win_buf = xmalloc (spec->f_win_size);
200 *size = (*spec->f_win_rf)(spec->f_win_fh, spec->f_win_buf,
202 spec->f_win_end = spec->f_win_start + *size;
204 if (*size > end_pos - start_pos)
205 *size = end_pos - start_pos;
206 return spec->f_win_buf;
208 if (end_pos <= spec->f_win_end)
210 *size = end_pos - start_pos;
211 return spec->f_win_buf + (start_pos - spec->f_win_start);
213 off = start_pos - spec->f_win_start;
214 for (i = 0; i<spec->f_win_end - start_pos; i++)
215 spec->f_win_buf[i] = spec->f_win_buf[i + off];
216 r = (*spec->f_win_rf)(spec->f_win_fh,
218 spec->f_win_size - i);
219 spec->f_win_start = start_pos;
220 spec->f_win_end += r;
222 if (*size > end_pos - start_pos)
223 *size = end_pos - start_pos;
224 return spec->f_win_buf;
227 static int f_win_advance (struct lexSpec *spec, int *pos)
232 if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
233 return spec->f_win_buf[(*pos)++ - spec->f_win_start];
234 if (*pos == F_WIN_EOF)
236 buf = f_win_get (spec, *pos, *pos+1, &size);
246 static void regxCodeDel (struct regxCode **pp)
248 struct regxCode *p = *pp;
257 static void regxCodeMk (struct regxCode **pp, const char *buf, int len)
261 p = xmalloc (sizeof(*p));
262 p->str = xmalloc (len+1);
263 memcpy (p->str, buf, len);
268 static struct DFA *lexSpecDFA (void)
273 dfa_parse_cmap_del (dfa, ' ');
274 dfa_parse_cmap_del (dfa, '\t');
275 dfa_parse_cmap_add (dfa, '/', 0);
279 static struct lexSpec *lexSpecMk (const char *name)
283 p = xmalloc (sizeof(*p));
284 p->name = xmalloc (strlen(name)+1);
285 strcpy (p->name, name);
286 p->trans.dfa = lexSpecDFA ();
287 p->trans.rules = NULL;
288 p->trans.fastRule = NULL;
289 p->beginActionList = NULL;
290 p->endActionList = NULL;
295 static void actionListDel (struct lexRuleAction **rap)
297 struct lexRuleAction *ra1, *ra;
299 for (ra = *rap; ra; ra = ra1)
305 dfa_delete (&ra->u.pattern.dfa);
308 regxCodeDel (&ra->u.code);
316 static void lexSpecDel (struct lexSpec **pp)
319 struct lexRule *rp, *rp1;
325 dfa_delete (&p->trans.dfa);
327 xfree (p->trans.fastRule);
328 for (rp = p->trans.rules; rp; rp = rp1)
330 actionListDel (&rp->info.actionList);
333 actionListDel (&p->beginActionList);
334 actionListDel (&p->endActionList);
335 xfree (p->f_win_buf);
340 static int readParseToken (const char **cpp, int *len)
342 const char *cp = *cpp;
346 while (*cp == ' ' || *cp == '\t' || *cp == '\n')
375 if (*cp >= 'a' && *cp <= 'z')
377 else if (*cp >= 'A' && *cp <= 'Z')
378 cmd[i] = *cp + 'a' - 'A';
381 if (i > sizeof(cmd)-2)
389 logf (LOG_WARN, "bad character %d %c", *cp, *cp);
391 while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
397 if (!strcmp (cmd, "begin"))
399 else if (!strcmp (cmd, "end"))
401 else if (!strcmp (cmd, "body"))
405 logf (LOG_WARN, "bad command %s", cmd);
411 static int actionListMk (struct lexSpec *spec, const char *s,
412 struct lexRuleAction **ap)
417 while ((tok = readParseToken (&s, &len)))
425 *ap = xmalloc (sizeof(**ap));
427 regxCodeMk (&(*ap)->u.code, s, len);
431 *ap = xmalloc (sizeof(**ap));
433 (*ap)->u.pattern.body = bodyMark;
435 (*ap)->u.pattern.dfa = lexSpecDFA ();
436 r = dfa_parse ((*ap)->u.pattern.dfa, &s);
441 logf (LOG_WARN, "regular expression error. r=%d", r);
444 dfa_mkstate ((*ap)->u.pattern.dfa);
448 logf (LOG_WARN, "cannot use begin here");
451 *ap = xmalloc (sizeof(**ap));
461 int readOneSpec (struct lexSpec *spec, const char *s)
465 tok = readParseToken (&s, &len);
466 if (tok == REGX_BEGIN)
468 actionListDel (&spec->beginActionList);
469 actionListMk (spec, s, &spec->beginActionList);
471 else if (tok == REGX_END)
473 actionListDel (&spec->endActionList);
474 actionListMk (spec, s, &spec->endActionList);
476 else if (tok == REGX_PATTERN)
480 r = dfa_parse (spec->trans.dfa, &s);
483 logf (LOG_WARN, "regular expression error. r=%d", r);
488 logf (LOG_WARN, "expects / at end of pattern. got %c", *s);
492 rp = xmalloc (sizeof(*rp));
493 rp->info.no = spec->trans.ruleNo++;
494 rp->next = spec->trans.rules;
495 spec->trans.rules = rp;
496 actionListMk (spec, s, &rp->info.actionList);
501 int readFileSpec (struct lexSpec *spec)
506 int c, i, errors = 0;
509 lineBuf = xmalloc (1+lineSize);
510 logf (LOG_LOG, "reading regx filter %s.flt", spec->name);
511 sprintf (lineBuf, "%s.flt", spec->name);
512 if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(spec->dh),
515 logf (LOG_ERRNO|LOG_WARN, "cannot read spec file %s", spec->name);
520 spec->trans.ruleNo = 1;
525 if (c == '#' || c == '\n' || c == ' ' || c == '\t')
527 while (c != '\n' && c != EOF)
546 if (c != ' ' && c != '\t')
555 readOneSpec (spec, lineBuf);
556 spec->lineNo += addLine;
561 spec->trans.fastRule = xmalloc (sizeof(*spec->trans.fastRule) *
563 for (i = 0; i<spec->trans.ruleNo; i++)
564 spec->trans.fastRule[i] = NULL;
565 for (rp = spec->trans.rules; rp; rp = rp->next)
566 spec->trans.fastRule[rp->info.no] = &rp->info;
572 debug_dfa_followpos = 1;
575 dfa_mkstate (spec->trans.dfa);
579 static struct lexSpec *curLexSpec = NULL;
581 static void destroy_data (struct data1_node *n)
583 assert (n->which == DATA1N_data);
584 xfree (n->u.data.data);
587 static void execData (struct lexSpec *spec,
588 data1_node **d1_stack, int *d1_level,
589 const char *ebuf, int elen, int formatted_text)
591 struct data1_node *res, *parent;
593 if (elen == 0) /* shouldn't happen, but it does! */
597 logf (LOG_DEBUG, "execData %.15s ... %.*s", ebuf, 15, ebuf + elen-15);
599 logf (LOG_DEBUG, "execData %.*s", elen, ebuf);
601 logf (LOG_DEBUG, "execData len=%d", elen);
607 parent = d1_stack[*d1_level -1];
609 if ((res=d1_stack[*d1_level]) && res->which == DATA1N_data)
611 if (elen + res->u.data.len <= DATA1_LOCALDATA)
612 memcpy (res->u.data.data + res->u.data.len, ebuf, elen);
615 char *nb = xmalloc (elen + res->u.data.len);
616 memcpy (nb, res->u.data.data, res->u.data.len);
617 memcpy (nb + res->u.data.len, ebuf, elen);
618 if (res->u.data.len > DATA1_LOCALDATA)
619 xfree (res->u.data.data);
620 res->u.data.data = nb;
621 res->destroy = destroy_data;
623 res->u.data.len += elen;
627 res = data1_mk_node (spec->dh, spec->m);
628 res->parent = parent;
629 res->which = DATA1N_data;
630 res->u.data.what = DATA1I_text;
631 res->u.data.len = elen;
632 res->u.data.formatted_text = formatted_text;
633 if (elen > DATA1_LOCALDATA)
635 res->u.data.data = xmalloc (elen);
636 res->destroy = destroy_data;
639 res->u.data.data = res->lbuf;
640 memcpy (res->u.data.data, ebuf, elen);
641 res->root = parent->root;
643 parent->num_children++;
644 parent->last_child = res;
645 if (d1_stack[*d1_level])
646 d1_stack[*d1_level]->next = res;
649 d1_stack[*d1_level] = res;
653 static void execDataP (struct lexSpec *spec,
654 data1_node **d1_stack, int *d1_level,
655 const char *ebuf, int elen, int formatted_text)
657 execData (spec, d1_stack, d1_level, ebuf, elen, formatted_text);
661 static void tagBegin (struct lexSpec *spec,
662 data1_node **d1_stack, int *d1_level,
663 const char *tag, int len)
665 struct data1_node *parent = d1_stack[*d1_level -1];
666 data1_element *elem = NULL;
667 data1_node *partag = get_parent_tag(spec->dh, parent);
669 data1_element *e = NULL;
674 logf (LOG_WARN, "in element begin. No record type defined");
678 res = data1_mk_node (spec->dh, spec->m);
679 res->parent = parent;
680 res->which = DATA1N_tag;
681 res->u.tag.tag = res->lbuf;
682 res->u.tag.get_bytes = -1;
684 if (len >= DATA1_LOCALDATA)
685 len = DATA1_LOCALDATA-1;
687 memcpy (res->u.tag.tag, tag, len);
688 res->u.tag.tag[len] = '\0';
691 logf (LOG_DEBUG, "tag begin %s (%d)", res->u.tag.tag, *d1_level);
693 if (parent->which == DATA1N_variant)
696 if (!(e = partag->u.tag.element))
699 elem = data1_getelementbytagname (spec->dh, d1_stack[0]->u.root.absyn,
702 res->u.tag.element = elem;
703 res->u.tag.node_selected = 0;
704 res->u.tag.make_variantlist = 0;
705 res->u.tag.no_data_requested = 0;
706 res->root = parent->root;
707 parent->num_children++;
708 parent->last_child = res;
709 if (d1_stack[*d1_level])
710 d1_stack[*d1_level]->next = res;
713 d1_stack[*d1_level] = res;
714 d1_stack[++(*d1_level)] = NULL;
717 static void tagEnd (struct lexSpec *spec,
718 data1_node **d1_stack, int *d1_level,
719 const char *tag, int len)
721 while (*d1_level > 1)
725 (strlen(d1_stack[*d1_level]->u.tag.tag) == len &&
726 !memcmp (d1_stack[*d1_level]->u.tag.tag, tag, len)))
730 logf (LOG_DEBUG, "tag end (%d)", *d1_level);
735 static int tryMatch (struct lexSpec *spec, int *pptr, int *mptr,
738 struct DFA_state *state = dfa->states[0];
741 unsigned char c_prev = 0;
743 int start_ptr = *pptr;
750 c = f_win_advance (spec, &ptr);
751 if (ptr == F_WIN_EOF)
768 *mptr = start_ptr; /* match starts here */
769 *pptr = last_ptr; /* match end here (+1) */
772 state = dfa->states[0];
777 else if (c >= t->ch[0] && c <= t->ch[1])
779 state = dfa->states[t->to];
784 last_rule = state->rule_no;
789 last_rule = state->rule_nno;
801 static int execTok (struct lexSpec *spec, const char **src,
802 int arg_no, int *arg_start, int *arg_end,
803 const char **tokBuf, int *tokLen)
805 const char *s = *src;
807 while (*s == ' ' || *s == '\t')
811 if (*s == '$' && s[1] >= '0' && s[1] <= '9')
815 while (*s >= '0' && *s <= '9')
816 n = n*10 + (*s++ -'0');
826 *tokBuf = f_win_get (spec, arg_start[n], arg_end[n], tokLen);
832 while (*s && *s != '\"')
834 *tokLen = s - *tokBuf;
839 else if (*s == '\n' || *s == ';')
847 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
849 *tokLen = s - *tokBuf;
856 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
858 *tokLen = s - *tokBuf;
864 static char *regxStrz (const char *src, int len)
870 memcpy (str, src, len);
875 static int execCode (struct lexSpec *spec,
876 int arg_no, int *arg_start, int *arg_end, int *pptr,
877 struct regxCode *code,
878 data1_node **d1_stack, int *d1_level)
880 const char *s = code->str;
885 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str, &cmd_len);
892 r = execTok (spec, &s, arg_no, arg_start, arg_end,
896 p = regxStrz (cmd_str, cmd_len);
897 if (!strcmp (p, "begin"))
899 r = execTok (spec, &s, arg_no, arg_start, arg_end,
903 p = regxStrz (cmd_str, cmd_len);
904 if (!strcmp (p, "record"))
906 r = execTok (spec, &s, arg_no, arg_start, arg_end,
912 static char absynName[64];
917 memcpy (absynName, cmd_str, cmd_len);
918 absynName[cmd_len] = '\0';
921 logf (LOG_DEBUG, "begin record %s", absynName);
923 if (!(absyn = data1_get_absyn (spec->dh, absynName)))
924 logf (LOG_WARN, "Unknown tagset: %s", absynName);
929 res = data1_mk_node (spec->dh, spec->m);
930 res->which = DATA1N_root;
931 res->u.root.type = absynName;
932 res->u.root.absyn = absyn;
935 d1_stack[*d1_level] = res;
936 d1_stack[++(*d1_level)] = NULL;
939 r = execTok (spec, &s, arg_no, arg_start, arg_end,
942 else if (!strcmp (p, "element"))
944 r = execTok (spec, &s, arg_no, arg_start, arg_end,
948 tagBegin (spec, d1_stack, d1_level, cmd_str, cmd_len);
949 r = execTok (spec, &s, arg_no, arg_start, arg_end,
953 else if (!strcmp (p, "end"))
955 r = execTok (spec, &s, arg_no, arg_start, arg_end,
959 p = regxStrz (cmd_str, cmd_len);
960 if (!strcmp (p, "record"))
963 r = execTok (spec, &s, arg_no, arg_start, arg_end,
966 logf (LOG_DEBUG, "end record");
970 else if (!strcmp (p, "element"))
972 r = execTok (spec, &s, arg_no, arg_start, arg_end,
983 tagEnd (spec, d1_stack, d1_level, cmd_str, cmd_len);
984 r = execTok (spec, &s, arg_no, arg_start, arg_end,
988 tagEnd (spec, d1_stack, d1_level, NULL, 0);
991 logf (LOG_WARN, "missing record/element/variant");
994 logf (LOG_WARN, "missing record/element/variant");
996 else if (!strcmp (p, "data"))
1000 const char *element_str = NULL;
1002 while ((r = execTok (spec, &s, arg_no, arg_start, arg_end,
1003 &cmd_str, &cmd_len)) == 3)
1005 if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
1007 else if (cmd_len==8 && !memcmp ("-element", cmd_str, cmd_len))
1009 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1010 &element_str, &element_len);
1015 logf (LOG_WARN, "bad data option: %.*s",
1020 logf (LOG_WARN, "missing data item after data");
1024 tagBegin (spec, d1_stack, d1_level, element_str, element_len);
1027 execData (spec, d1_stack, d1_level, cmd_str, cmd_len,
1029 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1030 &cmd_str, &cmd_len);
1033 tagEnd (spec, d1_stack, d1_level, NULL, 0);
1035 else if (!strcmp (p, "unread"))
1038 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1039 &cmd_str, &cmd_len);
1040 if (r==3 && cmd_len == 7 && !memcmp ("-offset", cmd_str, cmd_len))
1042 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1043 &cmd_str, &cmd_len);
1046 logf (LOG_WARN, "missing number after -offset");
1049 p = regxStrz (cmd_str, cmd_len);
1051 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1052 &cmd_str, &cmd_len);
1058 logf (LOG_WARN, "missing index after unread command");
1061 if (cmd_len != 1 || *cmd_str < '0' || *cmd_str > '9')
1063 logf (LOG_WARN, "bad index after unread command");
1068 no = *cmd_str - '0';
1071 *pptr = arg_start[no] + offset;
1073 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1074 &cmd_str, &cmd_len);
1078 logf (LOG_WARN, "unknown code command: %.*s", cmd_len, cmd_str);
1079 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1080 &cmd_str, &cmd_len);
1085 logf (LOG_WARN, "ignoring token %.*s", cmd_len, cmd_str);
1087 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str,
1096 static int execAction (struct lexSpec *spec, struct lexRuleAction *ap,
1097 data1_node **d1_stack, int *d1_level,
1098 int start_ptr, int *pptr)
1105 arg_start[0] = start_ptr;
1113 if (ap->u.pattern.body)
1115 arg_start[arg_no] = *pptr;
1116 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1118 arg_end[arg_no] = F_WIN_EOF;
1120 arg_start[arg_no] = F_WIN_EOF;
1121 arg_end[arg_no] = F_WIN_EOF;
1126 arg_end[arg_no] = sptr;
1128 arg_start[arg_no] = sptr;
1129 arg_end[arg_no] = *pptr;
1134 arg_start[arg_no] = *pptr;
1135 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1137 if (sptr != arg_start[arg_no])
1139 arg_end[arg_no] = *pptr;
1144 if (!execCode (spec, arg_no, arg_start, arg_end, pptr,
1145 ap->u.code, d1_stack, d1_level))
1149 arg_start[arg_no] = *pptr;
1150 arg_end[arg_no] = F_WIN_EOF;
1159 static int execRule (struct lexSpec *spec, struct lexTrans *trans,
1160 data1_node **d1_stack, int *d1_level,
1161 int ruleNo, int start_ptr, int *pptr)
1164 logf (LOG_DEBUG, "execRule %d", ruleNo);
1166 return execAction (spec, trans->fastRule[ruleNo]->actionList,
1167 d1_stack, d1_level, start_ptr, pptr);
1170 data1_node *lexNode (struct lexSpec *spec, struct lexTrans *trans,
1171 data1_node **d1_stack, int *d1_level,
1174 struct DFA_state *state = trans->dfa->states[0];
1177 unsigned char c_prev = '\n';
1180 int last_ptr = *ptr;
1181 int start_ptr = *ptr;
1182 int skip_ptr = *ptr;
1186 c = f_win_advance (spec, ptr);
1187 if (*ptr == F_WIN_EOF)
1191 if (skip_ptr < start_ptr)
1195 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1196 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1199 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1205 else if (skip_ptr < *ptr)
1209 buf = f_win_get (spec, skip_ptr, *ptr, &size);
1210 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1212 if (*ptr == F_WIN_EOF)
1219 { /* no transition for character c ... */
1222 if (skip_ptr < start_ptr)
1226 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1227 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1230 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1233 if (spec->f_win_ef && *ptr != F_WIN_EOF)
1236 logf (LOG_DEBUG, "regx: endf ptr=%d", *ptr);
1238 (*spec->f_win_ef)(spec->f_win_fh, *ptr);
1248 c_prev = f_win_advance (spec, &start_ptr);
1253 c_prev = f_win_advance (spec, &start_ptr);
1256 state = trans->dfa->states[0];
1259 else if (c >= t->ch[0] && c <= t->ch[1])
1260 { /* transition ... */
1261 state = trans->dfa->states[t->to];
1266 last_rule = state->rule_no;
1269 else if (state->rule_nno)
1271 last_rule = state->rule_nno;
1283 static data1_node *lexRoot (struct lexSpec *spec, off_t offset)
1285 data1_node *d1_stack[512];
1289 d1_stack[d1_level] = NULL;
1290 if (spec->beginActionList)
1291 execAction (spec, spec->beginActionList,
1292 d1_stack, &d1_level, 0, &ptr);
1293 lexNode (spec, &spec->trans, d1_stack, &d1_level, &ptr);
1294 if (spec->endActionList)
1295 execAction (spec, spec->endActionList,
1296 d1_stack, &d1_level, ptr, &ptr);
1300 data1_node *grs_read_regx (struct grs_read_info *p)
1306 logf (LOG_DEBUG, "grs_read_regx");
1308 if (!curLexSpec || strcmp (curLexSpec->name, p->type))
1311 lexSpecDel (&curLexSpec);
1312 curLexSpec = lexSpecMk (p->type);
1313 res = readFileSpec (curLexSpec);
1316 lexSpecDel (&curLexSpec);
1322 curLexSpec->f_win_start = 0;
1323 curLexSpec->f_win_end = 0;
1324 curLexSpec->f_win_rf = p->readf;
1325 curLexSpec->f_win_sf = p->seekf;
1326 curLexSpec->f_win_fh = p->fh;
1327 curLexSpec->f_win_ef = p->endf;
1328 curLexSpec->f_win_size = 500000;
1330 curLexSpec->m = p->mem;
1331 curLexSpec->dh = p->dh;
1332 n = lexRoot (curLexSpec, p->offset);