Lines Matching refs:state

137 typedef struct State_s			/* program state		*/
173 addre(State_s *state, List_t* p, char* s)
181 if (state->label)
194 if (state->words)
198 if (!(state->options & REG_AUGMENTED))
202 if (!(state->options & REG_AUGMENTED))
210 if (c = regcomp(&x->re, s, state->options|REG_MULTIPLE))
217 if (state->number || !regrecord(&x->re))
218 state->byline = 1;
220 else if (state->label || regcomb(&p->tail->re, &x->re))
223 if (!state->byline && (state->number || !state->label || !regrecord(&x->re)))
224 state->byline = 1;
231 addstring(State_s *state, List_t* p, char* s)
246 compile(State_s *state)
256 for (x = state->pattern.head; x; x = x->next)
257 addre(state, &state->re, x->string);
258 for (x = state->file.head; x; x = x->next)
284 addre(state, &state->re, s);
291 addre(state, &state->re, s);
298 if (!state->re.head)
317 State_s *state;
325 State_s *state = r_x->state;
329 if (state->query || state->list)
331 if (!state->count)
333 if (state->prefix)
335 if (state->label)
337 if (state->pos)
338 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
346 execute(State_s *state, Sfio_t* input, char* name)
357 if (state->buffer.noshare)
359 if (state->buffer.size)
360 sfsetbuf(input, state->buffer.base, state->buffer.size);
367 if (state->byline)
388 x = state->re.head;
391 if (!(result = regnexec(&x->re, s, len, state->posnum, state->pos, 0)))
393 if (!state->label)
396 if (state->query || state->list)
398 if (!state->count)
400 if (state->prefix)
402 if (state->number)
405 if (state->pos)
406 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
414 if (!state->label && (x != 0) == state->match)
417 if (state->query || state->list)
419 if (!state->count)
421 if (state->prefix)
423 if (state->number)
425 if (state->pos)
426 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
493 x = state->re.head;
496 record_handle r_x = { state, x };
497 if ((result = regrexec(&x->re, span, t - span, state->posnum, state->pos, state->options, '\n', (void*)&r_x, record)) < 0)
521 x = state->re.head;
524 record_handle r_x = { state, x };
525 if ((result = regrexec(&x->re, s, t - s, state->posnum, state->pos, state->options, '\n', (void*)&r_x, record)) < 0)
538 if (state->byline && !state->label)
540 if (hits && state->list >= 0)
541 state->any = 1;
542 if (!state->query)
544 if (!state->list)
546 if (state->count)
548 if (state->count & 2)
549 state->hits += hits;
552 if (state->prefix)
558 else if ((hits != 0) == (state->list > 0))
560 if (state->list < 0)
561 state->any = 1;
568 x = state->re.head;
571 if (x->hits && state->list >= 0)
573 state->any = 1;
574 if (state->query)
577 if (!state->query)
579 if (!state->list)
581 if (state->count)
583 if (state->count & 2)
586 state->hits += x->hits;
590 if (state->prefix)
592 if (state->label)
598 else if ((x->hits != 0) == (state->list > 0))
600 if (state->list < 0)
601 state->any = 1;
602 if (state->label)
621 State_s state;
622 memset(&state, 0, sizeof(state));
625 state.match = 1;
626 state.options = REG_FIRST|REG_NOSUB|REG_NULL;
629 state.options |= REG_LENIENT;
639 state.options |= REG_EXTENDED;
644 state.options |= REG_LITERAL;
649 state.options |= REG_EXTENDED|REG_LENIENT;
654 state.options |= REG_AUGMENTED;
665 state.options |= REG_EXTENDED;
668 state.options |= REG_LITERAL;
671 state.options &= ~(REG_AUGMENTED|REG_EXTENDED);
674 state.prefix = opt_info.num;
677 state.list = -opt_info.num;
683 state.options |= REG_LENIENT;
686 state.options |= REG_EXTENDED|REG_LENIENT;
689 state.options &= ~REG_LENIENT;
698 state.buffer.size = strton(s, &s, NiL, 1);
699 if (c == 'b' && !(state.buffer.base = newof(0, char, state.buffer.size, 0)))
705 state.options |= REG_FIRST;
708 state.options |= REG_LEFT;
711 state.buffer.noshare = 1;
714 state.options |= REG_RIGHT;
722 state.options |= REG_AUGMENTED;
727 state.options &= ~(REG_FIRST|REG_NOSUB);
730 state.count |= 1;
733 addstring(&state, &state.pattern, opt_info.arg);
736 addstring(&state, &state.file, opt_info.arg);
739 state.prefix = 2;
742 state.options |= REG_ICASE;
745 state.list = opt_info.num;
748 state.label = 1;
751 state.number = 1;
754 state.query = 1;
757 state.suppress = opt_info.num;
760 state.count |= 2;
763 if (state.match = !opt_info.num)
764 state.options &= ~REG_INVERT;
766 state.options |= REG_INVERT;
769 state.words = 1;
772 state.options |= REG_LEFT|REG_RIGHT;
785 if ((state.options & REG_LITERAL) && (state.options & (REG_AUGMENTED|REG_EXTENDED)))
787 if ((state.options & REG_LITERAL) && state.words)
789 if (!state.file.head && !state.pattern.head)
793 addstring(&state, &state.pattern, *argv++);
795 if (!(state.options & (REG_FIRST|REG_NOSUB)))
797 if (state.count || state.list || state.query || (state.options & REG_INVERT))
798 state.options |= REG_FIRST|REG_NOSUB;
801 state.pos = state.posvec;
802 state.posnum = elementsof(state.posvec);
805 compile(&state);
808 state.prefix = h ? 1 : 0;
809 execute(&state, sfstdin, h);
813 if (state.prefix > 1)
814 state.prefix = 0;
816 state.prefix = 1;
821 execute(&state, f, s);
823 if (state.query && state.any)
828 state.notfound = 1;
829 if (!state.suppress)
834 if ((state.count & 2) && !state.query && !state.list)
836 if (state.label)
840 x = state.re.head;
847 sfprintf(sfstdout, "%I*u\n", sizeof(state.hits), state.hits);
849 return (state.notfound && !state.query) ? 2 : !state.any;