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