2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.7 1997-07-15 16:33:07 adam
8 * Check for zero length in execData.
10 * Revision 1.6 1997/02/24 10:41:51 adam
11 * Cleanup of code and commented out the "end element-end-record" code.
13 * Revision 1.5 1997/02/19 16:22:33 adam
14 * Fixed "end element" to terminate record in outer-most level.
16 * Revision 1.4 1997/02/12 20:42:58 adam
17 * Changed some log messages.
19 * Revision 1.3 1996/11/08 14:05:33 adam
20 * Bug fix: data1 node member u.tag.get_bytes weren't initialized.
22 * Revision 1.2 1996/10/29 14:02:09 adam
23 * Doesn't use the global data1_tabpath (from YAZ). Instead the function
24 * data1_get_tabpath is used.
26 * Revision 1.1 1996/10/11 10:57:30 adam
27 * New module recctrl. Used to manage records (extract/retrieval).
29 * Revision 1.24 1996/06/17 14:25:31 adam
30 * Removed LOG_DEBUG logs; can still be enabled by setting REGX_DEBUG.
32 * Revision 1.23 1996/06/04 10:19:00 adam
33 * Minor changes - removed include of ctype.h.
35 * Revision 1.22 1996/06/03 15:23:13 adam
36 * Bug fix: /../ BODY /../ - pattern didn't match EOF.
38 * Revision 1.21 1996/05/14 16:58:38 adam
41 * Revision 1.20 1996/05/01 13:46:36 adam
42 * First work on multiple records in one file.
43 * New option, -offset, to the "unread" command in the filter module.
45 * Revision 1.19 1996/02/12 16:18:20 adam
46 * Yet another bug fix in implementation of unread command.
48 * Revision 1.18 1996/02/12 16:07:54 adam
49 * Bug fix in new unread command.
51 * Revision 1.17 1996/02/12 15:56:11 adam
52 * New code command: unread.
54 * Revision 1.16 1996/01/17 14:57:51 adam
55 * Prototype changed for reader functions in extract/retrieve. File
56 * is identified by 'void *' instead of 'int.
58 * Revision 1.15 1996/01/08 19:15:47 adam
59 * New input filter that works!
61 * Revision 1.14 1996/01/08 09:10:38 adam
62 * Yet another complete rework on this module.
64 * Revision 1.13 1995/12/15 17:21:50 adam
65 * This version is able to set data.formatted_text in data1-nodes.
67 * Revision 1.12 1995/12/15 16:20:10 adam
68 * The filter files (*.flt) are read from the path given by data1_tabpath.
70 * Revision 1.11 1995/12/15 12:35:16 adam
73 * Revision 1.10 1995/12/15 10:35:36 adam
76 * Revision 1.9 1995/12/14 16:38:48 adam
77 * Completely new attempt to make regular expression parsing.
79 * Revision 1.8 1995/12/13 17:16:59 adam
82 * Revision 1.7 1995/12/13 16:51:58 adam
83 * Modified to set last_child in data1_nodes.
84 * Uses destroy handler to free up data text nodes.
86 * Revision 1.6 1995/12/13 13:45:37 quinn
87 * Changed data1 to use nmem.
89 * Revision 1.5 1995/12/11 09:12:52 adam
90 * The rec_get function returns NULL if record doesn't exist - will
91 * happen in the server if the result set records have been deleted since
92 * the creation of the set (i.e. the search).
93 * The server saves a result temporarily if it is 'volatile', i.e. the
94 * set is register dependent.
96 * Revision 1.4 1995/12/05 16:57:40 adam
97 * More work on regular patterns.
99 * Revision 1.3 1995/12/05 09:37:09 adam
100 * One malloc was renamed to xmalloc.
102 * Revision 1.2 1995/12/04 17:59:24 adam
103 * More work on regular expression conversion.
105 * Revision 1.1 1995/12/04 14:25:30 adam
106 * Started work on regular expression parsed input to structured records.
114 #include <zebrautl.h>
120 #define F_WIN_EOF 2000000000
124 #define REGX_PATTERN 1
134 struct lexRuleAction {
138 struct DFA *dfa; /* REGX_PATTERN */
141 struct regxCode *code; /* REGX_CODE */
143 struct lexRuleAction *next;
148 struct lexRuleAction *actionList;
152 struct lexRuleInfo info;
153 struct lexRule *next;
158 struct lexRule *rules;
159 struct lexRuleInfo **fastRule;
165 struct lexTrans trans;
169 void (*f_win_ef)(void *, off_t);
175 int (*f_win_rf)(void *, char *, size_t);
176 off_t (*f_win_sf)(void *, off_t);
178 struct lexRuleAction *beginActionList;
179 struct lexRuleAction *endActionList;
183 static char *f_win_get (struct lexSpec *spec, off_t start_pos, off_t end_pos,
188 if (start_pos < spec->f_win_start || start_pos >= spec->f_win_end)
190 (*spec->f_win_sf)(spec->f_win_fh, start_pos);
191 spec->f_win_start = start_pos;
193 if (!spec->f_win_buf)
194 spec->f_win_buf = xmalloc (spec->f_win_size);
195 *size = (*spec->f_win_rf)(spec->f_win_fh, spec->f_win_buf,
197 spec->f_win_end = spec->f_win_start + *size;
199 if (*size > end_pos - start_pos)
200 *size = end_pos - start_pos;
201 return spec->f_win_buf;
203 if (end_pos <= spec->f_win_end)
205 *size = end_pos - start_pos;
206 return spec->f_win_buf + (start_pos - spec->f_win_start);
208 off = start_pos - spec->f_win_start;
209 for (i = 0; i<spec->f_win_end - start_pos; i++)
210 spec->f_win_buf[i] = spec->f_win_buf[i + off];
211 r = (*spec->f_win_rf)(spec->f_win_fh,
213 spec->f_win_size - i);
214 spec->f_win_start = start_pos;
215 spec->f_win_end += r;
217 if (*size > end_pos - start_pos)
218 *size = end_pos - start_pos;
219 return spec->f_win_buf;
222 static int f_win_advance (struct lexSpec *spec, int *pos)
227 if (*pos >= spec->f_win_start && *pos < spec->f_win_end)
228 return spec->f_win_buf[(*pos)++ - spec->f_win_start];
229 if (*pos == F_WIN_EOF)
231 buf = f_win_get (spec, *pos, *pos+1, &size);
241 static void regxCodeDel (struct regxCode **pp)
243 struct regxCode *p = *pp;
252 static void regxCodeMk (struct regxCode **pp, const char *buf, int len)
256 p = xmalloc (sizeof(*p));
257 p->str = xmalloc (len+1);
258 memcpy (p->str, buf, len);
263 static struct DFA *lexSpecDFA (void)
268 dfa_parse_cmap_del (dfa, ' ');
269 dfa_parse_cmap_del (dfa, '\t');
270 dfa_parse_cmap_add (dfa, '/', 0);
274 static struct lexSpec *lexSpecMk (const char *name)
278 p = xmalloc (sizeof(*p));
279 p->name = xmalloc (strlen(name)+1);
280 strcpy (p->name, name);
281 p->trans.dfa = lexSpecDFA ();
282 p->trans.rules = NULL;
283 p->trans.fastRule = NULL;
284 p->beginActionList = NULL;
285 p->endActionList = NULL;
290 static void actionListDel (struct lexRuleAction **rap)
292 struct lexRuleAction *ra1, *ra;
294 for (ra = *rap; ra; ra = ra1)
300 dfa_delete (&ra->u.pattern.dfa);
303 regxCodeDel (&ra->u.code);
311 static void lexSpecDel (struct lexSpec **pp)
314 struct lexRule *rp, *rp1;
320 dfa_delete (&p->trans.dfa);
322 xfree (p->trans.fastRule);
323 for (rp = p->trans.rules; rp; rp = rp1)
325 actionListDel (&rp->info.actionList);
328 actionListDel (&p->beginActionList);
329 actionListDel (&p->endActionList);
330 xfree (p->f_win_buf);
335 static int readParseToken (const char **cpp, int *len)
337 const char *cp = *cpp;
341 while (*cp == ' ' || *cp == '\t' || *cp == '\n')
370 if (*cp >= 'a' && *cp <= 'z')
372 else if (*cp >= 'A' && *cp <= 'Z')
373 cmd[i] = *cp + 'a' - 'A';
376 if (i > sizeof(cmd)-2)
384 logf (LOG_WARN, "bad character %d %c", *cp, *cp);
386 while (*cp && *cp != ' ' && *cp != '\t' && *cp != '\n')
392 if (!strcmp (cmd, "begin"))
394 else if (!strcmp (cmd, "end"))
396 else if (!strcmp (cmd, "body"))
400 logf (LOG_WARN, "bad command %s", cmd);
406 static int actionListMk (struct lexSpec *spec, const char *s,
407 struct lexRuleAction **ap)
412 while ((tok = readParseToken (&s, &len)))
420 *ap = xmalloc (sizeof(**ap));
422 regxCodeMk (&(*ap)->u.code, s, len);
426 *ap = xmalloc (sizeof(**ap));
428 (*ap)->u.pattern.body = bodyMark;
430 (*ap)->u.pattern.dfa = lexSpecDFA ();
431 r = dfa_parse ((*ap)->u.pattern.dfa, &s);
436 logf (LOG_WARN, "regular expression error. r=%d", r);
439 dfa_mkstate ((*ap)->u.pattern.dfa);
443 logf (LOG_WARN, "cannot use begin here");
446 *ap = xmalloc (sizeof(**ap));
456 int readOneSpec (struct lexSpec *spec, const char *s)
460 tok = readParseToken (&s, &len);
461 if (tok == REGX_BEGIN)
463 actionListDel (&spec->beginActionList);
464 actionListMk (spec, s, &spec->beginActionList);
466 else if (tok == REGX_END)
468 actionListDel (&spec->endActionList);
469 actionListMk (spec, s, &spec->endActionList);
471 else if (tok == REGX_PATTERN)
475 r = dfa_parse (spec->trans.dfa, &s);
478 logf (LOG_WARN, "regular expression error. r=%d", r);
483 logf (LOG_WARN, "expects / at end of pattern. got %c", *s);
487 rp = xmalloc (sizeof(*rp));
488 rp->info.no = spec->trans.ruleNo++;
489 rp->next = spec->trans.rules;
490 spec->trans.rules = rp;
491 actionListMk (spec, s, &rp->info.actionList);
496 int readFileSpec (struct lexSpec *spec)
501 int c, i, errors = 0;
504 lineBuf = xmalloc (1+lineSize);
505 logf (LOG_LOG, "reading regx filter %s.flt", spec->name);
506 sprintf (lineBuf, "%s.flt", spec->name);
507 if (!(spec_inf = yaz_path_fopen (data1_get_tabpath(), lineBuf, "r")))
509 logf (LOG_ERRNO|LOG_WARN, "cannot read spec file %s", spec->name);
514 spec->trans.ruleNo = 1;
519 if (c == '#' || c == '\n' || c == ' ' || c == '\t')
521 while (c != '\n' && c != EOF)
540 if (c != ' ' && c != '\t')
549 readOneSpec (spec, lineBuf);
550 spec->lineNo += addLine;
555 spec->trans.fastRule = xmalloc (sizeof(*spec->trans.fastRule) *
557 for (i = 0; i<spec->trans.ruleNo; i++)
558 spec->trans.fastRule[i] = NULL;
559 for (rp = spec->trans.rules; rp; rp = rp->next)
560 spec->trans.fastRule[rp->info.no] = &rp->info;
566 debug_dfa_followpos = 1;
569 dfa_mkstate (spec->trans.dfa);
573 static struct lexSpec *curLexSpec = NULL;
575 static void destroy_data (struct data1_node *n)
577 assert (n->which == DATA1N_data);
578 xfree (n->u.data.data);
581 static void execData (struct lexSpec *spec,
582 data1_node **d1_stack, int *d1_level,
583 const char *ebuf, int elen, int formatted_text)
585 struct data1_node *res, *parent;
587 if (elen == 0) /* shouldn't happen, but it does! */
591 logf (LOG_DEBUG, "execData %.15s ... %.*s", ebuf, 15, ebuf + elen-15);
593 logf (LOG_DEBUG, "execData %.*s", elen, ebuf);
595 logf (LOG_DEBUG, "execData len=%d", elen);
601 parent = d1_stack[*d1_level -1];
603 if ((res=d1_stack[*d1_level]) && res->which == DATA1N_data)
605 if (elen + res->u.data.len <= DATA1_LOCALDATA)
606 memcpy (res->u.data.data + res->u.data.len, ebuf, elen);
609 char *nb = xmalloc (elen + res->u.data.len);
610 memcpy (nb, res->u.data.data, res->u.data.len);
611 memcpy (nb + res->u.data.len, ebuf, elen);
612 if (res->u.data.len > DATA1_LOCALDATA)
613 xfree (res->u.data.data);
614 res->u.data.data = nb;
615 res->destroy = destroy_data;
617 res->u.data.len += elen;
621 res = data1_mk_node (spec->m);
622 res->parent = parent;
623 res->which = DATA1N_data;
624 res->u.data.what = DATA1I_text;
625 res->u.data.len = elen;
626 res->u.data.formatted_text = formatted_text;
627 if (elen > DATA1_LOCALDATA)
629 res->u.data.data = xmalloc (elen);
630 res->destroy = destroy_data;
633 res->u.data.data = res->lbuf;
634 memcpy (res->u.data.data, ebuf, elen);
635 res->root = parent->root;
637 parent->num_children++;
638 parent->last_child = res;
639 if (d1_stack[*d1_level])
640 d1_stack[*d1_level]->next = res;
643 d1_stack[*d1_level] = res;
647 static void execDataP (struct lexSpec *spec,
648 data1_node **d1_stack, int *d1_level,
649 const char *ebuf, int elen, int formatted_text)
651 execData (spec, d1_stack, d1_level, ebuf, elen, formatted_text);
655 static void tagBegin (struct lexSpec *spec,
656 data1_node **d1_stack, int *d1_level,
657 const char *tag, int len)
659 struct data1_node *parent = d1_stack[*d1_level -1];
660 data1_element *elem = NULL;
661 data1_node *partag = get_parent_tag(parent);
663 data1_element *e = NULL;
668 logf (LOG_WARN, "in element begin. No record type defined");
672 res = data1_mk_node (spec->m);
673 res->parent = parent;
674 res->which = DATA1N_tag;
675 res->u.tag.tag = res->lbuf;
676 res->u.tag.get_bytes = -1;
678 if (len >= DATA1_LOCALDATA)
679 len = DATA1_LOCALDATA-1;
681 memcpy (res->u.tag.tag, tag, len);
682 res->u.tag.tag[len] = '\0';
685 logf (LOG_DEBUG, "tag begin %s (%d)", res->u.tag.tag, *d1_level);
687 if (parent->which == DATA1N_variant)
690 if (!(e = partag->u.tag.element))
693 elem = data1_getelementbytagname (d1_stack[0]->u.root.absyn, e,
696 res->u.tag.element = elem;
697 res->u.tag.node_selected = 0;
698 res->u.tag.make_variantlist = 0;
699 res->u.tag.no_data_requested = 0;
700 res->root = parent->root;
701 parent->num_children++;
702 parent->last_child = res;
703 if (d1_stack[*d1_level])
704 d1_stack[*d1_level]->next = res;
707 d1_stack[*d1_level] = res;
708 d1_stack[++(*d1_level)] = NULL;
711 static void tagEnd (struct lexSpec *spec,
712 data1_node **d1_stack, int *d1_level,
713 const char *tag, int len)
715 while (*d1_level > 1)
719 (strlen(d1_stack[*d1_level]->u.tag.tag) == len &&
720 !memcmp (d1_stack[*d1_level]->u.tag.tag, tag, len)))
724 logf (LOG_DEBUG, "tag end (%d)", *d1_level);
729 static int tryMatch (struct lexSpec *spec, int *pptr, int *mptr,
732 struct DFA_state *state = dfa->states[0];
735 unsigned char c_prev = 0;
737 int start_ptr = *pptr;
744 c = f_win_advance (spec, &ptr);
745 if (ptr == F_WIN_EOF)
762 *mptr = start_ptr; /* match starts here */
763 *pptr = last_ptr; /* match end here (+1) */
766 state = dfa->states[0];
771 else if (c >= t->ch[0] && c <= t->ch[1])
773 state = dfa->states[t->to];
778 last_rule = state->rule_no;
783 last_rule = state->rule_nno;
795 static int execTok (struct lexSpec *spec, const char **src,
796 int arg_no, int *arg_start, int *arg_end,
797 const char **tokBuf, int *tokLen)
799 const char *s = *src;
801 while (*s == ' ' || *s == '\t')
805 if (*s == '$' && s[1] >= '0' && s[1] <= '9')
809 while (*s >= '0' && *s <= '9')
810 n = n*10 + (*s++ -'0');
820 *tokBuf = f_win_get (spec, arg_start[n], arg_end[n], tokLen);
826 while (*s && *s != '\"')
828 *tokLen = s - *tokBuf;
833 else if (*s == '\n' || *s == ';')
841 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
843 *tokLen = s - *tokBuf;
850 while (*s && *s != ' ' && *s != '\t' && *s != '\n' && *s != ';')
852 *tokLen = s - *tokBuf;
858 static char *regxStrz (const char *src, int len)
864 memcpy (str, src, len);
869 static int execCode (struct lexSpec *spec,
870 int arg_no, int *arg_start, int *arg_end, int *pptr,
871 struct regxCode *code,
872 data1_node **d1_stack, int *d1_level)
874 const char *s = code->str;
879 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str, &cmd_len);
886 r = execTok (spec, &s, arg_no, arg_start, arg_end,
890 p = regxStrz (cmd_str, cmd_len);
891 if (!strcmp (p, "begin"))
893 r = execTok (spec, &s, arg_no, arg_start, arg_end,
897 p = regxStrz (cmd_str, cmd_len);
898 if (!strcmp (p, "record"))
900 r = execTok (spec, &s, arg_no, arg_start, arg_end,
906 static char absynName[64];
911 memcpy (absynName, cmd_str, cmd_len);
912 absynName[cmd_len] = '\0';
915 logf (LOG_DEBUG, "begin record %s", absynName);
917 if (!(absyn = data1_get_absyn (absynName)))
918 logf (LOG_WARN, "Unknown tagset: %s", absynName);
923 res = data1_mk_node (spec->m);
924 res->which = DATA1N_root;
925 res->u.root.type = absynName;
926 res->u.root.absyn = absyn;
929 d1_stack[*d1_level] = res;
930 d1_stack[++(*d1_level)] = NULL;
933 r = execTok (spec, &s, arg_no, arg_start, arg_end,
936 else if (!strcmp (p, "element"))
938 r = execTok (spec, &s, arg_no, arg_start, arg_end,
942 tagBegin (spec, d1_stack, d1_level, cmd_str, cmd_len);
943 r = execTok (spec, &s, arg_no, arg_start, arg_end,
947 else if (!strcmp (p, "end"))
949 r = execTok (spec, &s, arg_no, arg_start, arg_end,
953 p = regxStrz (cmd_str, cmd_len);
954 if (!strcmp (p, "record"))
957 r = execTok (spec, &s, arg_no, arg_start, arg_end,
960 logf (LOG_DEBUG, "end record");
964 else if (!strcmp (p, "element"))
966 r = execTok (spec, &s, arg_no, arg_start, arg_end,
977 tagEnd (spec, d1_stack, d1_level, cmd_str, cmd_len);
978 r = execTok (spec, &s, arg_no, arg_start, arg_end,
982 tagEnd (spec, d1_stack, d1_level, NULL, 0);
985 logf (LOG_WARN, "missing record/element/variant");
988 logf (LOG_WARN, "missing record/element/variant");
990 else if (!strcmp (p, "data"))
994 const char *element_str = NULL;
996 while ((r = execTok (spec, &s, arg_no, arg_start, arg_end,
997 &cmd_str, &cmd_len)) == 3)
999 if (cmd_len==5 && !memcmp ("-text", cmd_str, cmd_len))
1001 else if (cmd_len==8 && !memcmp ("-element", cmd_str, cmd_len))
1003 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1004 &element_str, &element_len);
1009 logf (LOG_WARN, "bad data option: %.*s",
1014 logf (LOG_WARN, "missing data item after data");
1018 tagBegin (spec, d1_stack, d1_level, element_str, element_len);
1021 execData (spec, d1_stack, d1_level, cmd_str, cmd_len,
1023 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1024 &cmd_str, &cmd_len);
1027 tagEnd (spec, d1_stack, d1_level, NULL, 0);
1029 else if (!strcmp (p, "unread"))
1032 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1033 &cmd_str, &cmd_len);
1034 if (r==3 && cmd_len == 7 && !memcmp ("-offset", cmd_str, cmd_len))
1036 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1037 &cmd_str, &cmd_len);
1040 logf (LOG_WARN, "missing number after -offset");
1043 p = regxStrz (cmd_str, cmd_len);
1045 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1046 &cmd_str, &cmd_len);
1052 logf (LOG_WARN, "missing index after unread command");
1055 if (cmd_len != 1 || *cmd_str < '0' || *cmd_str > '9')
1057 logf (LOG_WARN, "bad index after unread command");
1062 no = *cmd_str - '0';
1065 *pptr = arg_start[no] + offset;
1067 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1068 &cmd_str, &cmd_len);
1072 logf (LOG_WARN, "unknown code command: %.*s", cmd_len, cmd_str);
1073 r = execTok (spec, &s, arg_no, arg_start, arg_end,
1074 &cmd_str, &cmd_len);
1079 logf (LOG_WARN, "ignoring token %.*s", cmd_len, cmd_str);
1081 r = execTok (spec, &s, arg_no, arg_start, arg_end, &cmd_str,
1090 static int execAction (struct lexSpec *spec, struct lexRuleAction *ap,
1091 data1_node **d1_stack, int *d1_level,
1092 int start_ptr, int *pptr)
1099 arg_start[0] = start_ptr;
1107 if (ap->u.pattern.body)
1109 arg_start[arg_no] = *pptr;
1110 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1112 arg_end[arg_no] = F_WIN_EOF;
1114 arg_start[arg_no] = F_WIN_EOF;
1115 arg_end[arg_no] = F_WIN_EOF;
1120 arg_end[arg_no] = sptr;
1122 arg_start[arg_no] = sptr;
1123 arg_end[arg_no] = *pptr;
1128 arg_start[arg_no] = *pptr;
1129 if (!tryMatch (spec, pptr, &sptr, ap->u.pattern.dfa))
1131 if (sptr != arg_start[arg_no])
1133 arg_end[arg_no] = *pptr;
1138 if (!execCode (spec, arg_no, arg_start, arg_end, pptr,
1139 ap->u.code, d1_stack, d1_level))
1143 arg_start[arg_no] = *pptr;
1144 arg_end[arg_no] = F_WIN_EOF;
1153 static int execRule (struct lexSpec *spec, struct lexTrans *trans,
1154 data1_node **d1_stack, int *d1_level,
1155 int ruleNo, int start_ptr, int *pptr)
1158 logf (LOG_DEBUG, "execRule %d", ruleNo);
1160 return execAction (spec, trans->fastRule[ruleNo]->actionList,
1161 d1_stack, d1_level, start_ptr, pptr);
1164 data1_node *lexNode (struct lexSpec *spec, struct lexTrans *trans,
1165 data1_node **d1_stack, int *d1_level,
1168 struct DFA_state *state = trans->dfa->states[0];
1171 unsigned char c_prev = '\n';
1174 int last_ptr = *ptr;
1175 int start_ptr = *ptr;
1176 int skip_ptr = *ptr;
1180 c = f_win_advance (spec, ptr);
1181 if (*ptr == F_WIN_EOF)
1185 if (skip_ptr < start_ptr)
1189 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1190 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1193 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1199 else if (skip_ptr < *ptr)
1203 buf = f_win_get (spec, skip_ptr, *ptr, &size);
1204 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1206 if (*ptr == F_WIN_EOF)
1213 { /* no transition for character c ... */
1216 if (skip_ptr < start_ptr)
1220 buf = f_win_get (spec, skip_ptr, start_ptr, &size);
1221 execDataP (spec, d1_stack, d1_level, buf, size, 0);
1224 if (!execRule (spec, trans, d1_stack, d1_level, last_rule,
1227 if (spec->f_win_ef && *ptr != F_WIN_EOF)
1230 logf (LOG_DEBUG, "regx: endf ptr=%d", *ptr);
1232 (*spec->f_win_ef)(spec->f_win_fh, *ptr);
1242 c_prev = f_win_advance (spec, &start_ptr);
1247 c_prev = f_win_advance (spec, &start_ptr);
1250 state = trans->dfa->states[0];
1253 else if (c >= t->ch[0] && c <= t->ch[1])
1254 { /* transition ... */
1255 state = trans->dfa->states[t->to];
1260 last_rule = state->rule_no;
1263 else if (state->rule_nno)
1265 last_rule = state->rule_nno;
1277 static data1_node *lexRoot (struct lexSpec *spec, off_t offset)
1279 data1_node *d1_stack[512];
1283 d1_stack[d1_level] = NULL;
1284 if (spec->beginActionList)
1285 execAction (spec, spec->beginActionList,
1286 d1_stack, &d1_level, 0, &ptr);
1287 lexNode (spec, &spec->trans, d1_stack, &d1_level, &ptr);
1288 if (spec->endActionList)
1289 execAction (spec, spec->endActionList,
1290 d1_stack, &d1_level, ptr, &ptr);
1294 data1_node *grs_read_regx (struct grs_read_info *p)
1300 logf (LOG_DEBUG, "grs_read_regx");
1302 if (!curLexSpec || strcmp (curLexSpec->name, p->type))
1305 lexSpecDel (&curLexSpec);
1306 curLexSpec = lexSpecMk (p->type);
1307 res = readFileSpec (curLexSpec);
1310 lexSpecDel (&curLexSpec);
1316 curLexSpec->f_win_start = 0;
1317 curLexSpec->f_win_end = 0;
1318 curLexSpec->f_win_rf = p->readf;
1319 curLexSpec->f_win_sf = p->seekf;
1320 curLexSpec->f_win_fh = p->fh;
1321 curLexSpec->f_win_ef = p->endf;
1322 curLexSpec->f_win_size = 500000;
1324 curLexSpec->m = p->mem;
1325 n = lexRoot (curLexSpec, p->offset);