2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1997-02-24 10:41:51 adam
8 * Cleanup of code and commented out the "end element-end-record" code.
10 * Revision 1.5 1997/02/19 16:22:33 adam
11 * Fixed "end element" to terminate record in outer-most level.
13 * Revision 1.4 1997/02/12 20:42:58 adam
14 * Changed some log messages.
16 * Revision 1.3 1996/11/08 14:05:33 adam
17 * Bug fix: data1 node member u.tag.get_bytes weren't initialized.
19 * Revision 1.2 1996/10/29 14:02:09 adam
20 * Doesn't use the global data1_tabpath (from YAZ). Instead the function
21 * data1_get_tabpath is used.
23 * Revision 1.1 1996/10/11 10:57:30 adam
24 * New module recctrl. Used to manage records (extract/retrieval).
26 * Revision 1.24 1996/06/17 14:25:31 adam
27 * Removed LOG_DEBUG logs; can still be enabled by setting REGX_DEBUG.
29 * Revision 1.23 1996/06/04 10:19:00 adam
30 * Minor changes - removed include of ctype.h.
32 * Revision 1.22 1996/06/03 15:23:13 adam
33 * Bug fix: /../ BODY /../ - pattern didn't match EOF.
35 * Revision 1.21 1996/05/14 16:58:38 adam
38 * Revision 1.20 1996/05/01 13:46:36 adam
39 * First work on multiple records in one file.
40 * New option, -offset, to the "unread" command in the filter module.
42 * Revision 1.19 1996/02/12 16:18:20 adam
43 * Yet another bug fix in implementation of unread command.
45 * Revision 1.18 1996/02/12 16:07:54 adam
46 * Bug fix in new unread command.
48 * Revision 1.17 1996/02/12 15:56:11 adam
49 * New code command: unread.
51 * Revision 1.16 1996/01/17 14:57:51 adam
52 * Prototype changed for reader functions in extract/retrieve. File
53 * is identified by 'void *' instead of 'int.
55 * Revision 1.15 1996/01/08 19:15:47 adam
56 * New input filter that works!
58 * Revision 1.14 1996/01/08 09:10:38 adam
59 * Yet another complete rework on this module.
61 * Revision 1.13 1995/12/15 17:21:50 adam
62 * This version is able to set data.formatted_text in data1-nodes.
64 * Revision 1.12 1995/12/15 16:20:10 adam
65 * The filter files (*.flt) are read from the path given by data1_tabpath.
67 * Revision 1.11 1995/12/15 12:35:16 adam
70 * Revision 1.10 1995/12/15 10:35:36 adam
73 * Revision 1.9 1995/12/14 16:38:48 adam
74 * Completely new attempt to make regular expression parsing.
76 * Revision 1.8 1995/12/13 17:16:59 adam
79 * Revision 1.7 1995/12/13 16:51:58 adam
80 * Modified to set last_child in data1_nodes.
81 * Uses destroy handler to free up data text nodes.
83 * Revision 1.6 1995/12/13 13:45:37 quinn
84 * Changed data1 to use nmem.
86 * Revision 1.5 1995/12/11 09:12:52 adam
87 * The rec_get function returns NULL if record doesn't exist - will
88 * happen in the server if the result set records have been deleted since
89 * the creation of the set (i.e. the search).
90 * The server saves a result temporarily if it is 'volatile', i.e. the
91 * set is register dependent.
93 * Revision 1.4 1995/12/05 16:57:40 adam
94 * More work on regular patterns.
96 * Revision 1.3 1995/12/05 09:37:09 adam
97 * One malloc was renamed to xmalloc.
99 * Revision 1.2 1995/12/04 17:59:24 adam
100 * More work on regular expression conversion.
102 * Revision 1.1 1995/12/04 14:25:30 adam
103 * Started work on regular expression parsed input to structured records.
111 #include <zebrautl.h>
117 #define F_WIN_EOF 2000000000
121 #define REGX_PATTERN 1
131 struct lexRuleAction {
135 struct DFA *dfa; /* REGX_PATTERN */
138 struct regxCode *code; /* REGX_CODE */
140 struct lexRuleAction *next;
145 struct lexRuleAction *actionList;
149 struct lexRuleInfo info;
150 struct lexRule *next;
155 struct lexRule *rules;
156 struct lexRuleInfo **fastRule;
162 struct lexTrans trans;
166 void (*f_win_ef)(void *, off_t);
172 int (*f_win_rf)(void *, char *, size_t);
173 off_t (*f_win_sf)(void *, off_t);
175 struct lexRuleAction *beginActionList;
176 struct lexRuleAction *endActionList;
180 static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos,
185 if (start_pos < spec->f_win_start || start_pos >= spec->f_win_end)
187 (*spec->f_win_sf)(spec->f_win_fh, start_pos);
188 spec->f_win_start = start_pos;
190 if (!spec->f_win_buf)
191 spec->f_win_buf = xmalloc (spec->f_win_size);
192 *size = (*spec->f_win_rf)(spec->f_win_fh, spec->f_win_buf,
194 spec->f_win_end = spec->f_win_start + *size;
196 if (*size > end_pos - start_pos)
197 *size = end_pos - start_pos;
198 return spec->f_win_buf;
200 if (end_pos <= spec->f_win_end)
202 *size = end_pos - start_pos;
203 return spec->f_win_buf + (start_pos - spec->f_win_start);
205 off = start_pos - spec->f_win_start;
206 for (i = 0; i<spec->f_win_end - start_pos; i++)
207 spec->f_win_buf[i] = spec->f_win_buf[i + off];
208 r = (*spec->f_win_rf)(spec->f_win_fh,
210 spec->f_win_size - i);
211 spec->f_win_start = start_pos;
212 spec->f_win_end += r;
214 if (*size > end_pos - start_pos)
215 *size = end_pos - start_pos;
216 return spec->f_win_buf;
219 static int f_win_advance (struct lexSpec *spec, int *pos)
224 if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
225 return spec->f_win_buf[(*pos)++ - spec->f_win_start];
226 if (*pos == F_WIN_EOF)
228 buf = f_win_get (spec, *pos, *pos+1, &size);
238 static void regxCodeDel (struct regxCode **pp)
240 struct regxCode *p = *pp;
249 static void regxCodeMk (struct regxCode **pp, const char *buf, int len)
253 p = xmalloc (sizeof(*p));
254 p->str = xmalloc (len+1);
255 memcpy (p->str, buf, len);
260 static struct DFA *lexSpecDFA (void)
265 dfa_parse_cmap_del (dfa, ' ');
266 dfa_parse_cmap_del (dfa, '\t');
267 dfa_parse_cmap_add (dfa, '/', 0);
271 static struct lexSpec *lexSpecMk (const char *name)
275 p = xmalloc (sizeof(*p));
276 p->name = xmalloc (strlen(name)+1);
277 strcpy (p->name, name);
278 p->trans.dfa = lexSpecDFA ();
279 p->trans.rules = NULL;
280 p->trans.fastRule = NULL;
281 p->beginActionList = NULL;
282 p->endActionList = NULL;
287 static void actionListDel (struct lexRuleAction **rap)
289 struct lexRuleAction *ra1, *ra;
291 for (ra = *rap; ra; ra = ra1)
297 dfa_delete (&ra->u.pattern.dfa);
300 regxCodeDel (&ra->u.code);
308 static void lexSpecDel (struct lexSpec **pp)
311 struct lexRule *rp, *rp1;
317 dfa_delete (&p->trans.dfa);
319 xfree (p->trans.fastRule);
320 for (rp = p->trans.rules; rp; rp = rp1)
322 actionListDel (&rp->info.actionList);
325 actionListDel (&p->beginActionList);
326 actionListDel (&p->endActionList);
327 xfree (p->f_win_buf);
332 static int readParseToken (const char **cpp, int *len)
334 const char *cp = *cpp;
338 while (*cp == ' ' || *cp == '\t' || *cp == '\n')
367 if (*cp >= 'a' && *cp <= 'z')
369 else if (*cp >= 'A' && *cp <= 'Z')
370 cmd[i] = *cp + 'a' - 'A';
373 if (i > sizeof(cmd)-2)
381 logf (LOG_WARN, "bad character %d %c", *cp, *cp);
383 while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
389 if (!strcmp (cmd, "begin"))
391 else if (!strcmp (cmd, "end"))
393 else if (!strcmp (cmd, "body"))
397 logf (LOG_WARN, "bad command %s", cmd);
403 static int actionListMk (struct lexSpec *spec, const char *s,
404 struct lexRuleAction **ap)
409 while ((tok = readParseToken (&s, &len)))
417 *ap = xmalloc (sizeof(**ap));
419 regxCodeMk (&(*ap)->u.code, s, len);
423 *ap = xmalloc (sizeof(**ap));
425 (*ap)->u.pattern.body = bodyMark;
427 (*ap)->u.pattern.dfa = lexSpecDFA ();
428 r = dfa_parse ((*ap)->u.pattern.dfa, &s);
433 logf (LOG_WARN, "regular expression error. r=%d", r);
436 dfa_mkstate ((*ap)->u.pattern.dfa);
440 logf (LOG_WARN, "cannot use begin here");
443 *ap = xmalloc (sizeof(**ap));
453 int readOneSpec (struct lexSpec *spec, const char *s)
457 tok = readParseToken (&s, &len);
458 if (tok == REGX_BEGIN)
460 actionListDel (&spec->beginActionList);
461 actionListMk (spec, s, &spec->beginActionList);
463 else if (tok == REGX_END)
465 actionListDel (&spec->endActionList);
466 actionListMk (spec, s, &spec->endActionList);
468 else if (tok == REGX_PATTERN)
472 r = dfa_parse (spec->trans.dfa, &s);
475 logf (LOG_WARN, "regular expression error. r=%d", r);
480 logf (LOG_WARN, "expects / at end of pattern. got %c", *s);
484 rp = xmalloc (sizeof(*rp));
485 rp->info.no = spec->trans.ruleNo++;
486 rp->next = spec->trans.rules;
487 spec->trans.rules = rp;
488 actionListMk (spec, s, &rp->info.actionList);
493 int readFileSpec (struct lexSpec *spec)
498 int c, i, errors = 0;
501 lineBuf = xmalloc (1+lineSize);
502 logf (LOG_LOG, "reading regx filter %s.flt", spec->name);
503 sprintf (lineBuf, "%s.flt", spec->name);
504 if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(), lineBuf, "r")))
506 logf (LOG_ERRNO|LOG_WARN, "cannot read spec file %s", spec->name);
511 spec->trans.ruleNo = 1;
516 if (c == '#' || c == '\n' || c == ' ' || c == '\t')
518 while (c != '\n' && c != EOF)
537 if (c != ' ' && c != '\t')
546 readOneSpec (spec, lineBuf);
547 spec->lineNo += addLine;
552 spec->trans.fastRule = xmalloc (sizeof(*spec->trans.fastRule) *
554 for (i = 0; i<spec->trans.ruleNo; i++)
555 spec->trans.fastRule[i] = NULL;
556 for (rp = spec->trans.rules; rp; rp = rp->next)
557 spec->trans.fastRule[rp->info.no] = &rp->info;
563 debug_dfa_followpos = 1;
566 dfa_mkstate (spec->trans.dfa);
570 static struct lexSpec *curLexSpec = NULL;
572 static void destroy_data (struct data1_node *n)
574 assert (n->which == DATA1N_data);
575 xfree (n->u.data.data);
578 static void execData (struct lexSpec *spec,
579 data1_node **d1_stack, int *d1_level,
580 const char *ebuf, int elen, int formatted_text)
582 struct data1_node *res, *parent;
585 logf (LOG_DEBUG, "execData %.15s ... %.*s", ebuf, 15, ebuf + elen-15);
587 logf (LOG_DEBUG, "execData %.*s", elen, ebuf);
589 logf (LOG_DEBUG, "execData len=%d", elen);
595 parent = d1_stack[*d1_level -1];
597 if ((res=d1_stack[*d1_level]) && res->which == DATA1N_data)
599 if (elen + res->u.data.len <= DATA1_LOCALDATA)
600 memcpy (res->u.data.data + res->u.data.len, ebuf, elen);
603 char *nb = xmalloc (elen + res->u.data.len);
604 memcpy (nb, res->u.data.data, res->u.data.len);
605 memcpy (nb + res->u.data.len, ebuf, elen);
606 if (res->u.data.len > DATA1_LOCALDATA)
607 xfree (res->u.data.data);
608 res->u.data.data = nb;
609 res->destroy = destroy_data;
611 res->u.data.len += elen;
615 res = data1_mk_node (spec->m);
616 res->parent = parent;
617 res->which = DATA1N_data;
618 res->u.data.what = DATA1I_text;
619 res->u.data.len = elen;
620 res->u.data.formatted_text = formatted_text;
621 if (elen > DATA1_LOCALDATA)
623 res->u.data.data = xmalloc (elen);
624 res->destroy = destroy_data;
627 res->u.data.data = res->lbuf;
628 memcpy (res->u.data.data, ebuf, elen);
629 res->root = parent->root;
631 parent->num_children++;
632 parent->last_child = res;
633 if (d1_stack[*d1_level])
634 d1_stack[*d1_level]->next = res;
637 d1_stack[*d1_level] = res;
641 static void execDataP (struct lexSpec *spec,
642 data1_node **d1_stack, int *d1_level,
643 const char *ebuf, int elen, int formatted_text)
645 execData (spec, d1_stack, d1_level, ebuf, elen, formatted_text);
649 static void tagBegin (struct lexSpec *spec,
650 data1_node **d1_stack, int *d1_level,
651 const char *tag, int len)
653 struct data1_node *parent = d1_stack[*d1_level -1];
654 data1_element *elem = NULL;
655 data1_node *partag = get_parent_tag(parent);
657 data1_element *e = NULL;
662 logf (LOG_WARN, "in element begin. No record type defined");
666 res = data1_mk_node (spec->m);
667 res->parent = parent;
668 res->which = DATA1N_tag;
669 res->u.tag.tag = res->lbuf;
670 res->u.tag.get_bytes = -1;
672 if (len >= DATA1_LOCALDATA)
673 len = DATA1_LOCALDATA-1;
675 memcpy (res->u.tag.tag, tag, len);
676 res->u.tag.tag[len] = '\0';
679 logf (LOG_DEBUG, "tag begin %s (%d)", res->u.tag.tag, *d1_level);
681 if (parent->which == DATA1N_variant)
684 if (!(e = partag->u.tag.element))
687 elem = data1_getelementbytagname (d1_stack[0]->u.root.absyn, e,
690 res->u.tag.element = elem;
691 res->u.tag.node_selected = 0;
692 res->u.tag.make_variantlist = 0;
693 res->u.tag.no_data_requested = 0;
694 res->root = parent->root;
695 parent->num_children++;
696 parent->last_child = res;
697 if (d1_stack[*d1_level])
698 d1_stack[*d1_level]->next = res;
701 d1_stack[*d1_level] = res;
702 d1_stack[++(*d1_level)] = NULL;
705 static void tagEnd (struct lexSpec *spec,
706 data1_node **d1_stack, int *d1_level,
707 const char *tag, int len)
709 while (*d1_level > 1)
713 (strlen(d1_stack[*d1_level]->u.tag.tag) == len &&
714 !memcmp (d1_stack[*d1_level]->u.tag.tag, tag, len)))
718 logf (LOG_DEBUG, "tag end (%d)", *d1_level);
723 static int tryMatch (struct lexSpec *spec, int *pptr, int *mptr,
726 struct DFA_state *state = dfa->states[0];
729 unsigned char c_prev = 0;
731 int start_ptr = *pptr;
738 c = f_win_advance (spec, &ptr);
739 if (ptr == F_WIN_EOF)
756 *mptr = start_ptr; /* match starts here */
757 *pptr = last_ptr; /* match end here (+1) */
760 state = dfa->states[0];
765 else if (c >= t->ch[0] && c <= t->ch[1])
767 state = dfa->states[t->to];
772 last_rule = state->rule_no;
777 last_rule = state->rule_nno;
789 static int execTok (struct lexSpec *spec, const char **src,
790 int arg_no, int *arg_start, int *arg_end,
791 const char **tokBuf, int *tokLen)
793 const char *s = *src;
795 while (*s == ' ' || *s == '\t')
799 if (*s == '$' && s[1] >= '0' && s[1] <= '9')
803 while (*s >= '0' && *s <= '9')
804 n = n*10 + (*s++ -'0');
814 *tokBuf = f_win_get (spec, arg_start[n], arg_end[n], tokLen);
820 while (*s && *s != '\"')
822 *tokLen = s - *tokBuf;
827 else if (*s == '\n' || *s == ';')
835 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
837 *tokLen = s - *tokBuf;
844 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
846 *tokLen = s - *tokBuf;
852 static char *regxStrz (const char *src, int len)
858 memcpy (str, src, len);
863 static int execCode (struct lexSpec *spec,
864 int arg_no, int *arg_start, int *arg_end, int *pptr,
865 struct regxCode *code,
866 data1_node **d1_stack, int *d1_level)
868 const char *s = code->str;
873 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str, &cmd_len);
880 r = execTok (spec, &s, arg_no, arg_start, arg_end,
884 p = regxStrz (cmd_str, cmd_len);
885 if (!strcmp (p, "begin"))
887 r = execTok (spec, &s, arg_no, arg_start, arg_end,
891 p = regxStrz (cmd_str, cmd_len);
892 if (!strcmp (p, "record"))
894 r = execTok (spec, &s, arg_no, arg_start, arg_end,
900 static char absynName[64];
905 memcpy (absynName, cmd_str, cmd_len);
906 absynName[cmd_len] = '\0';
909 logf (LOG_DEBUG, "begin record %s", absynName);
911 if (!(absyn = data1_get_absyn (absynName)))
912 logf (LOG_WARN, "Unknown tagset: %s", absynName);
917 res = data1_mk_node (spec->m);
918 res->which = DATA1N_root;
919 res->u.root.type = absynName;
920 res->u.root.absyn = absyn;
923 d1_stack[*d1_level] = res;
924 d1_stack[++(*d1_level)] = NULL;
927 r = execTok (spec, &s, arg_no, arg_start, arg_end,
930 else if (!strcmp (p, "element"))
932 r = execTok (spec, &s, arg_no, arg_start, arg_end,
936 tagBegin (spec, d1_stack, d1_level, cmd_str, cmd_len);
937 r = execTok (spec, &s, arg_no, arg_start, arg_end,
941 else if (!strcmp (p, "end"))
943 r = execTok (spec, &s, arg_no, arg_start, arg_end,
947 p = regxStrz (cmd_str, cmd_len);
948 if (!strcmp (p, "record"))
951 r = execTok (spec, &s, arg_no, arg_start, arg_end,
954 logf (LOG_DEBUG, "end record");
958 else if (!strcmp (p, "element"))
960 r = execTok (spec, &s, arg_no, arg_start, arg_end,
971 tagEnd (spec, d1_stack, d1_level, cmd_str, cmd_len);
972 r = execTok (spec, &s, arg_no, arg_start, arg_end,
976 tagEnd (spec, d1_stack, d1_level, NULL, 0);
979 logf (LOG_WARN, "missing record/element/variant");
982 logf (LOG_WARN, "missing record/element/variant");
984 else if (!strcmp (p, "data"))
988 const char *element_str = NULL;
990 while ((r = execTok (spec, &s, arg_no, arg_start, arg_end,
991 &cmd_str, &cmd_len)) == 3)
993 if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
995 else if (cmd_len==8 && !memcmp ("-element", cmd_str, cmd_len))
997 r = execTok (spec, &s, arg_no, arg_start, arg_end,
998 &element_str, &element_len);
1003 logf (LOG_WARN, "bad data option: %.*s",
1008 logf (LOG_WARN, "missing data item after data");
1012 tagBegin (spec, d1_stack, d1_level, element_str, element_len);
1015 execData (spec, d1_stack, d1_level, cmd_str, cmd_len,
1017 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1018 &cmd_str, &cmd_len);
1021 tagEnd (spec, d1_stack, d1_level, NULL, 0);
1023 else if (!strcmp (p, "unread"))
1026 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1027 &cmd_str, &cmd_len);
1028 if (r==3 && cmd_len == 7 && !memcmp ("-offset", cmd_str, cmd_len))
1030 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1031 &cmd_str, &cmd_len);
1034 logf (LOG_WARN, "missing number after -offset");
1037 p = regxStrz (cmd_str, cmd_len);
1039 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1040 &cmd_str, &cmd_len);
1046 logf (LOG_WARN, "missing index after unread command");
1049 if (cmd_len != 1 || *cmd_str < '0' || *cmd_str > '9')
1051 logf (LOG_WARN, "bad index after unread command");
1056 no = *cmd_str - '0';
1059 *pptr = arg_start[no] + offset;
1061 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1062 &cmd_str, &cmd_len);
1066 logf (LOG_WARN, "unknown code command: %.*s", cmd_len, cmd_str);
1067 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1068 &cmd_str, &cmd_len);
1073 logf (LOG_WARN, "ignoring token %.*s", cmd_len, cmd_str);
1075 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str,
1084 static int execAction (struct lexSpec *spec, struct lexRuleAction *ap,
1085 data1_node **d1_stack, int *d1_level,
1086 int start_ptr, int *pptr)
1093 arg_start[0] = start_ptr;
1101 if (ap->u.pattern.body)
1103 arg_start[arg_no] = *pptr;
1104 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1106 arg_end[arg_no] = F_WIN_EOF;
1108 arg_start[arg_no] = F_WIN_EOF;
1109 arg_end[arg_no] = F_WIN_EOF;
1114 arg_end[arg_no] = sptr;
1116 arg_start[arg_no] = sptr;
1117 arg_end[arg_no] = *pptr;
1122 arg_start[arg_no] = *pptr;
1123 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1125 if (sptr != arg_start[arg_no])
1127 arg_end[arg_no] = *pptr;
1132 if (!execCode (spec, arg_no, arg_start, arg_end, pptr,
1133 ap->u.code, d1_stack, d1_level))
1137 arg_start[arg_no] = *pptr;
1138 arg_end[arg_no] = F_WIN_EOF;
1147 static int execRule (struct lexSpec *spec, struct lexTrans *trans,
1148 data1_node **d1_stack, int *d1_level,
1149 int ruleNo, int start_ptr, int *pptr)
1152 logf (LOG_DEBUG, "execRule %d", ruleNo);
1154 return execAction (spec, trans->fastRule[ruleNo]->actionList,
1155 d1_stack, d1_level, start_ptr, pptr);
1158 data1_node *lexNode (struct lexSpec *spec, struct lexTrans *trans,
1159 data1_node **d1_stack, int *d1_level,
1162 struct DFA_state *state = trans->dfa->states[0];
1165 unsigned char c_prev = '\n';
1168 int last_ptr = *ptr;
1169 int start_ptr = *ptr;
1170 int skip_ptr = *ptr;
1174 c = f_win_advance (spec, ptr);
1175 if (*ptr == F_WIN_EOF)
1179 if (skip_ptr < start_ptr)
1183 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1184 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1187 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1193 else if (skip_ptr < *ptr)
1197 buf = f_win_get (spec, skip_ptr, *ptr, &size);
1198 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1200 if (*ptr == F_WIN_EOF)
1207 { /* no transition for character c ... */
1210 if (skip_ptr < start_ptr)
1214 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1215 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1218 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1221 if (spec->f_win_ef && *ptr != F_WIN_EOF)
1224 logf (LOG_DEBUG, "regx: endf ptr=%d", *ptr);
1226 (*spec->f_win_ef)(spec->f_win_fh, *ptr);
1236 c_prev = f_win_advance (spec, &start_ptr);
1241 c_prev = f_win_advance (spec, &start_ptr);
1244 state = trans->dfa->states[0];
1247 else if (c >= t->ch[0] && c <= t->ch[1])
1248 { /* transition ... */
1249 state = trans->dfa->states[t->to];
1254 last_rule = state->rule_no;
1257 else if (state->rule_nno)
1259 last_rule = state->rule_nno;
1271 static data1_node *lexRoot (struct lexSpec *spec, off_t offset)
1273 data1_node *d1_stack[512];
1277 d1_stack[d1_level] = NULL;
1278 if (spec->beginActionList)
1279 execAction (spec, spec->beginActionList,
1280 d1_stack, &d1_level, 0, &ptr);
1281 lexNode (spec, &spec->trans, d1_stack, &d1_level, &ptr);
1282 if (spec->endActionList)
1283 execAction (spec, spec->endActionList,
1284 d1_stack, &d1_level, ptr, &ptr);
1288 data1_node *grs_read_regx (struct grs_read_info *p)
1294 logf (LOG_DEBUG, "grs_read_regx");
1296 if (!curLexSpec || strcmp (curLexSpec->name, p->type))
1299 lexSpecDel (&curLexSpec);
1300 curLexSpec = lexSpecMk (p->type);
1301 res = readFileSpec (curLexSpec);
1304 lexSpecDel (&curLexSpec);
1310 curLexSpec->f_win_start = 0;
1311 curLexSpec->f_win_end = 0;
1312 curLexSpec->f_win_rf = p->readf;
1313 curLexSpec->f_win_sf = p->seekf;
1314 curLexSpec->f_win_fh = p->fh;
1315 curLexSpec->f_win_ef = p->endf;
1316 curLexSpec->f_win_size = 500000;
1318 curLexSpec->m = p->mem;
1319 n = lexRoot (curLexSpec, p->offset);