31 #include <yaz/yaz-util.h>
47 #define INFBUF_SIZE 16384
56 m[mc->
n * ch + wno] |= 1<<off;
65 m[mc->
n * ch + wno] &= ~(1<<off);
74 return m[mc->
n * ch + wno] & (1<<off);
91 for (j=0; j<state->
tran_no; j++)
94 int ch0 = state->
trans[j].
ch[0];
95 int ch1 = state->
trans[j].
ch[1];
96 assert (ch0 >= 0 && ch1 >= 0);
98 for (ch = ch0; ch <= ch1; ch++)
107 struct DFA *dfa,
int ch)
113 for (j = 1; j<mc->
n; j++)
127 if (ch >= state->
trans[i].
ch[0] &&
136 if (ch >= state->
trans[i].
ch[0] &&
145 if (ch >= state->
trans[i].
ch[0] &&
154 if (ch >= state->
trans[i].
ch[0] &&
172 for (j = 0; j<mc->
n; j++)
222 for (i = 0; i<mc->
n; i++)
223 Rdst[i] = Rsrc1[i] | Rsrc2[i];
229 MatchWord *Rj, *Rj1, *Rj_a, *Rj_b, *Rj_c;
240 Rj_a =
icalloc (mc->
n *
sizeof(*Rj));
241 Rj_b =
icalloc (mc->
n *
sizeof(*Rj));
242 Rj_c =
icalloc (mc->
n *
sizeof(*Rj));
245 for (d = 1; d<=mc->
range; d++)
248 memcpy (Rj + mc->
n * d, Rj + mc->
n * (d-1), mc->
n *
sizeof(*Rj));
260 while ((ch = getc (
inf)) != EOF)
271 printf (
"%5d:", lineno);
276 }
while (infbuf[i] !=
'\n');
282 }
while (infbuf[i] !=
'\n');
290 for (d = 1; d <= mc->
range; d++)
294 or (mc, Rj_a, Rj+(d-1)*mc->
n, Rj1+(d-1)*mc->
n);
296 shift (mc, Rj_c, Rj_a, dfa);
298 or (mc, Rj_a, Rj_b, Rj_c);
300 or (mc, Rj1+d*mc->
n, Rj_a, Rj+(d-1)*mc->
n);
308 for (d = 0; d <= mc->
range; d++)
330 inf = fopen (fname,
"r");
333 yaz_log (YLOG_FATAL|YLOG_ERRNO,
"cannot open `%s'", fname);
349 int main (
int argc,
char **argv)
354 const char *pattern = NULL;
359 while ((ret = options (
"nr:dsv:", argv, argc, &arg)) != -2)
370 fprintf (stderr,
"%s: illegal pattern\n",
prog);
383 yaz_log_init (yaz_log_mask_str(arg),
prog, NULL);
405 yaz_log (YLOG_FATAL,
"Unknown option '-%s'", arg);
411 fprintf (stderr,
"usage:\n "
412 " %s [-d] [-n] [-r n] [-s] [-v n] pattern file ..\n",
prog);
415 else if (no_files == 0)
int dfa_parse(struct DFA *, const char **)
void dfa_mkstate(struct DFA *)
void dfa_delete(struct DFA **)
struct DFA * dfa_init(void)
static INLINE void set_bit(MatchContext *mc, MatchWord *m, int ch, int state)
static INLINE void reset_bit(MatchContext *mc, MatchWord *m, int ch, int state)
static int go(MatchContext *mc, struct DFA *dfa, FILE *inf)
static void mask_shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa, int ch)
int main(int argc, char **argv)
static void or(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc1, MatchWord *Rsrc2)
static INLINE MatchWord get_bit(MatchContext *mc, MatchWord *m, int ch, int state)
static int grep_file(struct DFA *dfa, const char *fname, int range)
static void shift(MatchContext *mc, MatchWord *Rdst, MatchWord *Rsrc, struct DFA *dfa)
static MatchContext * mk_MatchContext(struct DFA *dfa, int range)
void * icalloc(size_t size)
void * imalloc(size_t size)
struct DFA_state ** states