2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.10 1997-10-31 12:36:12 adam
8 * Minor change that avoids compiler warning.
10 * Revision 1.9 1997/09/29 09:02:49 adam
11 * Fixed small bug (introduced by previous commit).
13 * Revision 1.8 1997/09/17 12:19:22 adam
14 * Zebra version corresponds to YAZ version 1.4.
15 * Changed Zebra server so that it doesn't depend on global common_resource.
17 * Revision 1.7 1997/07/15 16:33:07 adam
18 * Check for zero length in execData.
20 * Revision 1.6 1997/02/24 10:41:51 adam
21 * Cleanup of code and commented out the "end element-end-record" code.
23 * Revision 1.5 1997/02/19 16:22:33 adam
24 * Fixed "end element" to terminate record in outer-most level.
26 * Revision 1.4 1997/02/12 20:42:58 adam
27 * Changed some log messages.
29 * Revision 1.3 1996/11/08 14:05:33 adam
30 * Bug fix: data1 node member u.tag.get_bytes weren't initialized.
32 * Revision 1.2 1996/10/29 14:02:09 adam
33 * Doesn't use the global data1_tabpath (from YAZ). Instead the function
34 * data1_get_tabpath is used.
36 * Revision 1.1 1996/10/11 10:57:30 adam
37 * New module recctrl. Used to manage records (extract/retrieval).
39 * Revision 1.24 1996/06/17 14:25:31 adam
40 * Removed LOG_DEBUG logs; can still be enabled by setting REGX_DEBUG.
42 * Revision 1.23 1996/06/04 10:19:00 adam
43 * Minor changes - removed include of ctype.h.
45 * Revision 1.22 1996/06/03 15:23:13 adam
46 * Bug fix: /../ BODY /../ - pattern didn't match EOF.
48 * Revision 1.21 1996/05/14 16:58:38 adam
51 * Revision 1.20 1996/05/01 13:46:36 adam
52 * First work on multiple records in one file.
53 * New option, -offset, to the "unread" command in the filter module.
55 * Revision 1.19 1996/02/12 16:18:20 adam
56 * Yet another bug fix in implementation of unread command.
58 * Revision 1.18 1996/02/12 16:07:54 adam
59 * Bug fix in new unread command.
61 * Revision 1.17 1996/02/12 15:56:11 adam
62 * New code command: unread.
64 * Revision 1.16 1996/01/17 14:57:51 adam
65 * Prototype changed for reader functions in extract/retrieve. File
66 * is identified by 'void *' instead of 'int.
68 * Revision 1.15 1996/01/08 19:15:47 adam
69 * New input filter that works!
71 * Revision 1.14 1996/01/08 09:10:38 adam
72 * Yet another complete rework on this module.
74 * Revision 1.13 1995/12/15 17:21:50 adam
75 * This version is able to set data.formatted_text in data1-nodes.
77 * Revision 1.12 1995/12/15 16:20:10 adam
78 * The filter files (*.flt) are read from the path given by data1_tabpath.
80 * Revision 1.11 1995/12/15 12:35:16 adam
83 * Revision 1.10 1995/12/15 10:35:36 adam
86 * Revision 1.9 1995/12/14 16:38:48 adam
87 * Completely new attempt to make regular expression parsing.
89 * Revision 1.8 1995/12/13 17:16:59 adam
92 * Revision 1.7 1995/12/13 16:51:58 adam
93 * Modified to set last_child in data1_nodes.
94 * Uses destroy handler to free up data text nodes.
96 * Revision 1.6 1995/12/13 13:45:37 quinn
97 * Changed data1 to use nmem.
99 * Revision 1.5 1995/12/11 09:12:52 adam
100 * The rec_get function returns NULL if record doesn't exist - will
101 * happen in the server if the result set records have been deleted since
102 * the creation of the set (i.e. the search).
103 * The server saves a result temporarily if it is 'volatile', i.e. the
104 * set is register dependent.
106 * Revision 1.4 1995/12/05 16:57:40 adam
107 * More work on regular patterns.
109 * Revision 1.3 1995/12/05 09:37:09 adam
110 * One malloc was renamed to xmalloc.
112 * Revision 1.2 1995/12/04 17:59:24 adam
113 * More work on regular expression conversion.
115 * Revision 1.1 1995/12/04 14:25:30 adam
116 * Started work on regular expression parsed input to structured records.
124 #include <zebrautl.h>
130 #define F_WIN_EOF 2000000000
134 #define REGX_PATTERN 1
144 struct lexRuleAction {
148 struct DFA *dfa; /* REGX_PATTERN */
151 struct regxCode *code; /* REGX_CODE */
153 struct lexRuleAction *next;
158 struct lexRuleAction *actionList;
162 struct lexRuleInfo info;
163 struct lexRule *next;
168 struct lexRule *rules;
169 struct lexRuleInfo **fastRule;
175 struct lexTrans trans;
180 void (*f_win_ef)(void *, off_t);
186 int (*f_win_rf)(void *, char *, size_t);
187 off_t (*f_win_sf)(void *, off_t);
189 struct lexRuleAction *beginActionList;
190 struct lexRuleAction *endActionList;
194 static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos,
199 if (start_pos < spec->f_win_start || start_pos >= spec->f_win_end)
201 (*spec->f_win_sf)(spec->f_win_fh, start_pos);
202 spec->f_win_start = start_pos;
204 if (!spec->f_win_buf)
205 spec->f_win_buf = xmalloc (spec->f_win_size);
206 *size = (*spec->f_win_rf)(spec->f_win_fh, spec->f_win_buf,
208 spec->f_win_end = spec->f_win_start + *size;
210 if (*size > end_pos - start_pos)
211 *size = end_pos - start_pos;
212 return spec->f_win_buf;
214 if (end_pos <= spec->f_win_end)
216 *size = end_pos - start_pos;
217 return spec->f_win_buf + (start_pos - spec->f_win_start);
219 off = start_pos - spec->f_win_start;
220 for (i = 0; i<spec->f_win_end - start_pos; i++)
221 spec->f_win_buf[i] = spec->f_win_buf[i + off];
222 r = (*spec->f_win_rf)(spec->f_win_fh,
224 spec->f_win_size - i);
225 spec->f_win_start = start_pos;
226 spec->f_win_end += r;
228 if (*size > end_pos - start_pos)
229 *size = end_pos - start_pos;
230 return spec->f_win_buf;
233 static int f_win_advance (struct lexSpec *spec, int *pos)
238 if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
239 return spec->f_win_buf[(*pos)++ - spec->f_win_start];
240 if (*pos == F_WIN_EOF)
242 buf = f_win_get (spec, *pos, *pos+1, &size);
252 static void regxCodeDel (struct regxCode **pp)
254 struct regxCode *p = *pp;
263 static void regxCodeMk (struct regxCode **pp, const char *buf, int len)
267 p = xmalloc (sizeof(*p));
268 p->str = xmalloc (len+1);
269 memcpy (p->str, buf, len);
274 static struct DFA *lexSpecDFA (void)
279 dfa_parse_cmap_del (dfa, ' ');
280 dfa_parse_cmap_del (dfa, '\t');
281 dfa_parse_cmap_add (dfa, '/', 0);
285 static struct lexSpec *lexSpecMk (const char *name)
289 p = xmalloc (sizeof(*p));
290 p->name = xmalloc (strlen(name)+1);
291 strcpy (p->name, name);
292 p->trans.dfa = lexSpecDFA ();
293 p->trans.rules = NULL;
294 p->trans.fastRule = NULL;
295 p->beginActionList = NULL;
296 p->endActionList = NULL;
301 static void actionListDel (struct lexRuleAction **rap)
303 struct lexRuleAction *ra1, *ra;
305 for (ra = *rap; ra; ra = ra1)
311 dfa_delete (&ra->u.pattern.dfa);
314 regxCodeDel (&ra->u.code);
322 static void lexSpecDel (struct lexSpec **pp)
325 struct lexRule *rp, *rp1;
331 dfa_delete (&p->trans.dfa);
333 xfree (p->trans.fastRule);
334 for (rp = p->trans.rules; rp; rp = rp1)
336 actionListDel (&rp->info.actionList);
339 actionListDel (&p->beginActionList);
340 actionListDel (&p->endActionList);
341 xfree (p->f_win_buf);
346 static int readParseToken (const char **cpp, int *len)
348 const char *cp = *cpp;
352 while (*cp == ' ' || *cp == '\t' || *cp == '\n')
381 if (*cp >= 'a' && *cp <= 'z')
383 else if (*cp >= 'A' && *cp <= 'Z')
384 cmd[i] = *cp + 'a' - 'A';
387 if (i > sizeof(cmd)-2)
395 logf (LOG_WARN, "bad character %d %c", *cp, *cp);
397 while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
403 if (!strcmp (cmd, "begin"))
405 else if (!strcmp (cmd, "end"))
407 else if (!strcmp (cmd, "body"))
411 logf (LOG_WARN, "bad command %s", cmd);
417 static int actionListMk (struct lexSpec *spec, const char *s,
418 struct lexRuleAction **ap)
423 while ((tok = readParseToken (&s, &len)))
431 *ap = xmalloc (sizeof(**ap));
433 regxCodeMk (&(*ap)->u.code, s, len);
437 *ap = xmalloc (sizeof(**ap));
439 (*ap)->u.pattern.body = bodyMark;
441 (*ap)->u.pattern.dfa = lexSpecDFA ();
442 r = dfa_parse ((*ap)->u.pattern.dfa, &s);
447 logf (LOG_WARN, "regular expression error. r=%d", r);
450 dfa_mkstate ((*ap)->u.pattern.dfa);
454 logf (LOG_WARN, "cannot use begin here");
457 *ap = xmalloc (sizeof(**ap));
467 int readOneSpec (struct lexSpec *spec, const char *s)
471 tok = readParseToken (&s, &len);
472 if (tok == REGX_BEGIN)
474 actionListDel (&spec->beginActionList);
475 actionListMk (spec, s, &spec->beginActionList);
477 else if (tok == REGX_END)
479 actionListDel (&spec->endActionList);
480 actionListMk (spec, s, &spec->endActionList);
482 else if (tok == REGX_PATTERN)
486 r = dfa_parse (spec->trans.dfa, &s);
489 logf (LOG_WARN, "regular expression error. r=%d", r);
494 logf (LOG_WARN, "expects / at end of pattern. got %c", *s);
498 rp = xmalloc (sizeof(*rp));
499 rp->info.no = spec->trans.ruleNo++;
500 rp->next = spec->trans.rules;
501 spec->trans.rules = rp;
502 actionListMk (spec, s, &rp->info.actionList);
507 int readFileSpec (struct lexSpec *spec)
512 int c, i, errors = 0;
515 lineBuf = xmalloc (1+lineSize);
516 logf (LOG_LOG, "reading regx filter %s.flt", spec->name);
517 sprintf (lineBuf, "%s.flt", spec->name);
518 if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(spec->dh),
521 logf (LOG_ERRNO|LOG_WARN, "cannot read spec file %s", spec->name);
526 spec->trans.ruleNo = 1;
531 if (c == '#' || c == '\n' || c == ' ' || c == '\t')
533 while (c != '\n' && c != EOF)
552 if (c != ' ' && c != '\t')
561 readOneSpec (spec, lineBuf);
562 spec->lineNo += addLine;
567 spec->trans.fastRule = xmalloc (sizeof(*spec->trans.fastRule) *
569 for (i = 0; i<spec->trans.ruleNo; i++)
570 spec->trans.fastRule[i] = NULL;
571 for (rp = spec->trans.rules; rp; rp = rp->next)
572 spec->trans.fastRule[rp->info.no] = &rp->info;
578 debug_dfa_followpos = 1;
581 dfa_mkstate (spec->trans.dfa);
585 static struct lexSpec *curLexSpec = NULL;
587 static void destroy_data (struct data1_node *n)
589 assert (n->which == DATA1N_data);
590 xfree (n->u.data.data);
593 static void execData (struct lexSpec *spec,
594 data1_node **d1_stack, int *d1_level,
595 const char *ebuf, int elen, int formatted_text)
597 struct data1_node *res, *parent;
599 if (elen == 0) /* shouldn't happen, but it does! */
603 logf (LOG_DEBUG, "execData %.15s ... %.*s", ebuf, 15, ebuf + elen-15);
605 logf (LOG_DEBUG, "execData %.*s", elen, ebuf);
607 logf (LOG_DEBUG, "execData len=%d", elen);
613 parent = d1_stack[*d1_level -1];
615 if ((res=d1_stack[*d1_level]) && res->which == DATA1N_data)
617 if (elen + res->u.data.len <= DATA1_LOCALDATA)
618 memcpy (res->u.data.data + res->u.data.len, ebuf, elen);
621 char *nb = xmalloc (elen + res->u.data.len);
622 memcpy (nb, res->u.data.data, res->u.data.len);
623 memcpy (nb + res->u.data.len, ebuf, elen);
624 if (res->u.data.len > DATA1_LOCALDATA)
625 xfree (res->u.data.data);
626 res->u.data.data = nb;
627 res->destroy = destroy_data;
629 res->u.data.len += elen;
633 res = data1_mk_node (spec->dh, spec->m);
634 res->parent = parent;
635 res->which = DATA1N_data;
636 res->u.data.what = DATA1I_text;
637 res->u.data.len = elen;
638 res->u.data.formatted_text = formatted_text;
639 if (elen > DATA1_LOCALDATA)
641 res->u.data.data = xmalloc (elen);
642 res->destroy = destroy_data;
645 res->u.data.data = res->lbuf;
646 memcpy (res->u.data.data, ebuf, elen);
647 res->root = parent->root;
649 parent->num_children++;
650 parent->last_child = res;
651 if (d1_stack[*d1_level])
652 d1_stack[*d1_level]->next = res;
655 d1_stack[*d1_level] = res;
659 static void execDataP (struct lexSpec *spec,
660 data1_node **d1_stack, int *d1_level,
661 const char *ebuf, int elen, int formatted_text)
663 execData (spec, d1_stack, d1_level, ebuf, elen, formatted_text);
667 static void tagBegin (struct lexSpec *spec,
668 data1_node **d1_stack, int *d1_level,
669 const char *tag, int len)
671 struct data1_node *parent = d1_stack[*d1_level -1];
672 data1_element *elem = NULL;
673 data1_node *partag = get_parent_tag(spec->dh, parent);
675 data1_element *e = NULL;
680 logf (LOG_WARN, "in element begin. No record type defined");
684 res = data1_mk_node (spec->dh, spec->m);
685 res->parent = parent;
686 res->which = DATA1N_tag;
687 res->u.tag.tag = res->lbuf;
688 res->u.tag.get_bytes = -1;
690 if (len >= DATA1_LOCALDATA)
691 len = DATA1_LOCALDATA-1;
693 memcpy (res->u.tag.tag, tag, len);
694 res->u.tag.tag[len] = '\0';
697 logf (LOG_DEBUG, "tag begin %s (%d)", res->u.tag.tag, *d1_level);
699 if (parent->which == DATA1N_variant)
702 if (!(e = partag->u.tag.element))
705 elem = data1_getelementbytagname (spec->dh, d1_stack[0]->u.root.absyn,
708 res->u.tag.element = elem;
709 res->u.tag.node_selected = 0;
710 res->u.tag.make_variantlist = 0;
711 res->u.tag.no_data_requested = 0;
712 res->root = parent->root;
713 parent->num_children++;
714 parent->last_child = res;
715 if (d1_stack[*d1_level])
716 d1_stack[*d1_level]->next = res;
719 d1_stack[*d1_level] = res;
720 d1_stack[++(*d1_level)] = NULL;
723 static void tagEnd (struct lexSpec *spec,
724 data1_node **d1_stack, int *d1_level,
725 const char *tag, int len)
727 while (*d1_level > 1)
731 (strlen(d1_stack[*d1_level]->u.tag.tag) == (size_t) len &&
732 !memcmp (d1_stack[*d1_level]->u.tag.tag, tag, len)))
736 logf (LOG_DEBUG, "tag end (%d)", *d1_level);
741 static int tryMatch (struct lexSpec *spec, int *pptr, int *mptr,
744 struct DFA_state *state = dfa->states[0];
747 unsigned char c_prev = 0;
749 int start_ptr = *pptr;
756 c = f_win_advance (spec, &ptr);
757 if (ptr == F_WIN_EOF)
774 *mptr = start_ptr; /* match starts here */
775 *pptr = last_ptr; /* match end here (+1) */
778 state = dfa->states[0];
783 else if (c >= t->ch[0] && c <= t->ch[1])
785 state = dfa->states[t->to];
790 last_rule = state->rule_no;
795 last_rule = state->rule_nno;
807 static int execTok (struct lexSpec *spec, const char **src,
808 int arg_no, int *arg_start, int *arg_end,
809 const char **tokBuf, int *tokLen)
811 const char *s = *src;
813 while (*s == ' ' || *s == '\t')
817 if (*s == '$' && s[1] >= '0' && s[1] <= '9')
821 while (*s >= '0' && *s <= '9')
822 n = n*10 + (*s++ -'0');
832 *tokBuf = f_win_get (spec, arg_start[n], arg_end[n], tokLen);
838 while (*s && *s != '\"')
840 *tokLen = s - *tokBuf;
845 else if (*s == '\n' || *s == ';')
853 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
855 *tokLen = s - *tokBuf;
862 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
864 *tokLen = s - *tokBuf;
870 static char *regxStrz (const char *src, int len)
876 memcpy (str, src, len);
881 static int execCode (struct lexSpec *spec,
882 int arg_no, int *arg_start, int *arg_end, int *pptr,
883 struct regxCode *code,
884 data1_node **d1_stack, int *d1_level)
886 const char *s = code->str;
891 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str, &cmd_len);
898 r = execTok (spec, &s, arg_no, arg_start, arg_end,
902 p = regxStrz (cmd_str, cmd_len);
903 if (!strcmp (p, "begin"))
905 r = execTok (spec, &s, arg_no, arg_start, arg_end,
909 p = regxStrz (cmd_str, cmd_len);
910 if (!strcmp (p, "record"))
912 r = execTok (spec, &s, arg_no, arg_start, arg_end,
918 static char absynName[64];
923 memcpy (absynName, cmd_str, cmd_len);
924 absynName[cmd_len] = '\0';
927 logf (LOG_DEBUG, "begin record %s", absynName);
929 if (!(absyn = data1_get_absyn (spec->dh, absynName)))
930 logf (LOG_WARN, "Unknown tagset: %s", absynName);
935 res = data1_mk_node (spec->dh, spec->m);
936 res->which = DATA1N_root;
937 res->u.root.type = absynName;
938 res->u.root.absyn = absyn;
941 d1_stack[*d1_level] = res;
942 d1_stack[++(*d1_level)] = NULL;
945 r = execTok (spec, &s, arg_no, arg_start, arg_end,
948 else if (!strcmp (p, "element"))
950 r = execTok (spec, &s, arg_no, arg_start, arg_end,
954 tagBegin (spec, d1_stack, d1_level, cmd_str, cmd_len);
955 r = execTok (spec, &s, arg_no, arg_start, arg_end,
959 else if (!strcmp (p, "end"))
961 r = execTok (spec, &s, arg_no, arg_start, arg_end,
965 p = regxStrz (cmd_str, cmd_len);
966 if (!strcmp (p, "record"))
969 r = execTok (spec, &s, arg_no, arg_start, arg_end,
972 logf (LOG_DEBUG, "end record");
976 else if (!strcmp (p, "element"))
978 r = execTok (spec, &s, arg_no, arg_start, arg_end,
989 tagEnd (spec, d1_stack, d1_level, cmd_str, cmd_len);
990 r = execTok (spec, &s, arg_no, arg_start, arg_end,
994 tagEnd (spec, d1_stack, d1_level, NULL, 0);
997 logf (LOG_WARN, "missing record/element/variant");
1000 logf (LOG_WARN, "missing record/element/variant");
1002 else if (!strcmp (p, "data"))
1006 const char *element_str = NULL;
1008 while ((r = execTok (spec, &s, arg_no, arg_start, arg_end,
1009 &cmd_str, &cmd_len)) == 3)
1011 if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
1013 else if (cmd_len==8 && !memcmp ("-element", cmd_str, cmd_len))
1015 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1016 &element_str, &element_len);
1021 logf (LOG_WARN, "bad data option: %.*s",
1026 logf (LOG_WARN, "missing data item after data");
1030 tagBegin (spec, d1_stack, d1_level, element_str, element_len);
1033 execData (spec, d1_stack, d1_level, cmd_str, cmd_len,
1035 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1036 &cmd_str, &cmd_len);
1039 tagEnd (spec, d1_stack, d1_level, NULL, 0);
1041 else if (!strcmp (p, "unread"))
1044 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1045 &cmd_str, &cmd_len);
1046 if (r==3 && cmd_len == 7 && !memcmp ("-offset", cmd_str, cmd_len))
1048 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1049 &cmd_str, &cmd_len);
1052 logf (LOG_WARN, "missing number after -offset");
1055 p = regxStrz (cmd_str, cmd_len);
1057 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1058 &cmd_str, &cmd_len);
1064 logf (LOG_WARN, "missing index after unread command");
1067 if (cmd_len != 1 || *cmd_str < '0' || *cmd_str > '9')
1069 logf (LOG_WARN, "bad index after unread command");
1074 no = *cmd_str - '0';
1077 *pptr = arg_start[no] + offset;
1079 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1080 &cmd_str, &cmd_len);
1084 logf (LOG_WARN, "unknown code command: %.*s", cmd_len, cmd_str);
1085 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1086 &cmd_str, &cmd_len);
1091 logf (LOG_WARN, "ignoring token %.*s", cmd_len, cmd_str);
1093 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str,
1102 static int execAction (struct lexSpec *spec, struct lexRuleAction *ap,
1103 data1_node **d1_stack, int *d1_level,
1104 int start_ptr, int *pptr)
1111 arg_start[0] = start_ptr;
1119 if (ap->u.pattern.body)
1121 arg_start[arg_no] = *pptr;
1122 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1124 arg_end[arg_no] = F_WIN_EOF;
1126 arg_start[arg_no] = F_WIN_EOF;
1127 arg_end[arg_no] = F_WIN_EOF;
1132 arg_end[arg_no] = sptr;
1134 arg_start[arg_no] = sptr;
1135 arg_end[arg_no] = *pptr;
1140 arg_start[arg_no] = *pptr;
1141 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1143 if (sptr != arg_start[arg_no])
1145 arg_end[arg_no] = *pptr;
1150 if (!execCode (spec, arg_no, arg_start, arg_end, pptr,
1151 ap->u.code, d1_stack, d1_level))
1155 arg_start[arg_no] = *pptr;
1156 arg_end[arg_no] = F_WIN_EOF;
1165 static int execRule (struct lexSpec *spec, struct lexTrans *trans,
1166 data1_node **d1_stack, int *d1_level,
1167 int ruleNo, int start_ptr, int *pptr)
1170 logf (LOG_DEBUG, "execRule %d", ruleNo);
1172 return execAction (spec, trans->fastRule[ruleNo]->actionList,
1173 d1_stack, d1_level, start_ptr, pptr);
1176 data1_node *lexNode (struct lexSpec *spec, struct lexTrans *trans,
1177 data1_node **d1_stack, int *d1_level,
1180 struct DFA_state *state = trans->dfa->states[0];
1183 unsigned char c_prev = '\n';
1186 int last_ptr = *ptr;
1187 int start_ptr = *ptr;
1188 int skip_ptr = *ptr;
1192 c = f_win_advance (spec, ptr);
1193 if (*ptr == F_WIN_EOF)
1197 if (skip_ptr < start_ptr)
1201 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1202 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1205 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1211 else if (skip_ptr < *ptr)
1215 buf = f_win_get (spec, skip_ptr, *ptr, &size);
1216 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1218 if (*ptr == F_WIN_EOF)
1225 { /* no transition for character c ... */
1228 if (skip_ptr < start_ptr)
1232 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1233 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1236 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1239 if (spec->f_win_ef && *ptr != F_WIN_EOF)
1242 logf (LOG_DEBUG, "regx: endf ptr=%d", *ptr);
1244 (*spec->f_win_ef)(spec->f_win_fh, *ptr);
1254 c_prev = f_win_advance (spec, &start_ptr);
1259 c_prev = f_win_advance (spec, &start_ptr);
1262 state = trans->dfa->states[0];
1265 else if (c >= t->ch[0] && c <= t->ch[1])
1266 { /* transition ... */
1267 state = trans->dfa->states[t->to];
1272 last_rule = state->rule_no;
1275 else if (state->rule_nno)
1277 last_rule = state->rule_nno;
1289 static data1_node *lexRoot (struct lexSpec *spec, off_t offset)
1291 data1_node *d1_stack[512];
1295 d1_stack[d1_level] = NULL;
1296 if (spec->beginActionList)
1297 execAction (spec, spec->beginActionList,
1298 d1_stack, &d1_level, 0, &ptr);
1299 lexNode (spec, &spec->trans, d1_stack, &d1_level, &ptr);
1300 if (spec->endActionList)
1301 execAction (spec, spec->endActionList,
1302 d1_stack, &d1_level, ptr, &ptr);
1306 data1_node *grs_read_regx (struct grs_read_info *p)
1312 logf (LOG_DEBUG, "grs_read_regx");
1314 if (!curLexSpec || strcmp (curLexSpec->name, p->type))
1317 lexSpecDel (&curLexSpec);
1318 curLexSpec = lexSpecMk (p->type);
1319 curLexSpec->dh = p->dh;
1320 res = readFileSpec (curLexSpec);
1323 lexSpecDel (&curLexSpec);
1329 curLexSpec->f_win_start = 0;
1330 curLexSpec->f_win_end = 0;
1331 curLexSpec->f_win_rf = p->readf;
1332 curLexSpec->f_win_sf = p->seekf;
1333 curLexSpec->f_win_fh = p->fh;
1334 curLexSpec->f_win_ef = p->endf;
1335 curLexSpec->f_win_size = 500000;
1337 curLexSpec->m = p->mem;
1338 n = lexRoot (curLexSpec, p->offset);