Lines Matching refs:state
142 typedef struct State_s /* program state */
180 addre(State_s *state, List_t* p, char* s)
188 if (state->label)
201 if (state->words)
205 if (!(state->options & REG_AUGMENTED))
209 if (!(state->options & REG_AUGMENTED))
217 if (c = regcomp(&x->re, s, state->options|REG_MULTIPLE))
224 if (state->number || state->before || state->after || !regrecord(&x->re))
225 state->byline = 1;
227 else if (state->label || regcomb(&p->tail->re, &x->re))
230 if (!state->byline && (state->number || !state->label || !regrecord(&x->re)))
231 state->byline = 1;
238 addstring(State_s *state, List_t* p, char* s)
253 compile(State_s *state)
263 for (x = state->pattern.head; x; x = x->next)
264 addre(state, &state->re, x->string);
265 for (x = state->file.head; x; x = x->next)
291 addre(state, &state->re, s);
298 addre(state, &state->re, s);
305 if (!state->re.head)
324 State_s *state;
332 State_s *state = r_x->state;
336 if (state->query || state->list)
338 if (!state->count)
340 if (state->prefix)
342 if (state->label)
344 if (state->pos)
345 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
353 execute(State_s *state, Sfio_t* input, char* name)
364 if (state->buffer.noshare)
366 if (state->buffer.size)
367 sfsetbuf(input, state->buffer.base, state->buffer.size);
374 if (state->byline)
395 x = state->re.head;
398 if (!(result = regnexec(&x->re, s, len, state->posnum, state->pos, 0)))
400 if (!state->label)
403 if (state->query || state->list)
405 if (!state->count)
407 if (state->prefix)
409 if (state->number)
412 if (state->pos)
413 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
421 if (!state->label && (x != 0) == state->match)
424 if (state->query || state->list)
426 if (!state->count)
428 if (state->prefix)
430 if (state->number)
432 if (state->pos)
433 highlight(sfstdout, s, len + 1, state->pos[0].rm_so, state->pos[0].rm_eo);
502 x = state->re.head;
505 record_handle r_x = { state, x };
506 if ((result = regrexec(&x->re, span, len, state->posnum, state->pos, state->options, '\n', (void*)&r_x, record)) < 0)
533 x = state->re.head;
536 record_handle r_x = { state, x };
538 if ((result = regrexec(&x->re, s, len, state->posnum, state->pos, state->options, '\n', (void*)&r_x, record)) < 0)
551 if (state->byline && !state->label)
553 if (hits && state->list >= 0)
554 state->any = 1;
555 if (!state->query)
557 if (!state->list)
559 if (state->count)
561 if (state->count & 2)
562 state->hits += hits;
565 if (state->prefix)
571 else if ((hits != 0) == (state->list > 0))
573 if (state->list < 0)
574 state->any = 1;
581 x = state->re.head;
584 if (x->hits && state->list >= 0)
586 state->any = 1;
587 if (state->query)
590 if (!state->query)
592 if (!state->list)
594 if (state->count)
596 if (state->count & 2)
599 state->hits += x->hits;
603 if (state->prefix)
605 if (state->label)
611 else if ((x->hits != 0) == (state->list > 0))
613 if (state->list < 0)
614 state->any = 1;
615 if (state->label)
638 State_s state;
639 memset(&state, 0, sizeof(state));
643 state.match = 1;
644 state.options = REG_FIRST|REG_NOSUB|REG_NULL;
647 state.options |= REG_LENIENT;
657 state.options |= REG_EXTENDED;
662 state.options |= REG_LITERAL;
667 state.options |= REG_EXTENDED|REG_LENIENT;
672 state.options |= REG_AUGMENTED;
685 state.before = (int)strtol(opt_info.arg, &s, 0);
686 state.after = (*s == ',') ? (int)strtol(s + 1, &s, 0) : state.before;
691 state.before = state.after = 2;
694 state.options |= REG_EXTENDED;
697 state.options |= REG_LITERAL;
700 state.options &= ~(REG_AUGMENTED|REG_EXTENDED);
703 state.prefix = opt_info.num;
706 state.list = -opt_info.num;
712 state.options |= REG_LENIENT;
715 state.options |= REG_EXTENDED|REG_LENIENT;
718 state.options &= ~REG_LENIENT;
727 state.buffer.size = strton(s, &s, NiL, 1);
728 if (c == 'b' && !(state.buffer.base = newof(0, char, state.buffer.size, 0)))
734 state.options |= REG_FIRST;
737 state.options |= REG_LEFT;
740 state.buffer.noshare = 1;
743 state.options |= REG_RIGHT;
751 state.options |= REG_AUGMENTED;
756 state.options &= ~(REG_FIRST|REG_NOSUB);
759 state.count |= 1;
762 addstring(&state, &state.pattern, opt_info.arg);
765 addstring(&state, &state.file, opt_info.arg);
768 state.prefix = 2;
771 state.options |= REG_ICASE;
774 state.list = opt_info.num;
777 state.label = 1;
780 state.number = 1;
783 state.query = 1;
792 state.suppress = opt_info.num;
795 state.count |= 2;
798 if (state.match = !opt_info.num)
799 state.options &= ~REG_INVERT;
801 state.options |= REG_INVERT;
804 state.words = 1;
807 state.options |= REG_LEFT|REG_RIGHT;
820 if ((state.options & REG_LITERAL) && (state.options & (REG_AUGMENTED|REG_EXTENDED)))
822 if ((state.options & REG_LITERAL) && state.words)
824 if (!state.file.head && !state.pattern.head)
828 addstring(&state, &state.pattern, *argv++);
830 if (!(state.options & (REG_FIRST|REG_NOSUB)))
832 if (state.count || state.list || state.query || (state.options & REG_INVERT))
833 state.options |= REG_FIRST|REG_NOSUB;
836 state.pos = state.posvec;
837 state.posnum = elementsof(state.posvec);
840 compile(&state);
843 state.prefix = h ? 1 : 0;
844 execute(&state, sfstdin, h);
848 if (state.prefix > 1)
849 state.prefix = 0;
851 state.prefix = 1;
856 execute(&state, f, s);
858 if (state.query && state.any)
863 state.notfound = 1;
864 if (!state.suppress)
871 if (state.prefix > 1)
872 state.prefix = 0;
874 state.prefix = 1;
883 execute(&state, f, ent->fts_path);
885 if (state.query && state.any)
891 state.notfound = 1;
892 if (!state.suppress)
908 if ((state.count & 2) && !state.query && !state.list)
910 if (state.label)
914 x = state.re.head;
921 sfprintf(sfstdout, "%I*u\n", sizeof(state.hits), state.hits);
923 return (state.notfound && !state.query) ? 2 : !state.any;