Lines Matching full:pc

67 static void procmatch_match(struct mprintc *mc, struct parsec *pc);
68 static void procmatch_nomatch(struct mprintc *mc, struct parsec *pc);
69 static bool procmatches(struct mprintc *mc, struct parsec *pc, bool matched);
74 static bool procline(struct parsec *pc);
75 static bool printline(struct parsec *pc, int sep, size_t *last_out);
204 procmatch_match(struct mprintc *mc, struct parsec *pc) in procmatch_match() argument
221 terminated = printline(pc, ':', &last_out); in procmatch_match()
222 while (pc->matchidx >= MAX_MATCHES) { in procmatch_match()
224 pc->matchidx = 0; in procmatch_match()
225 if (procline(pc) == !vflag) in procmatch_match()
226 terminated = printline(pc, ':', &last_out); in procmatch_match()
238 printline(pc, ':', &last_out); in procmatch_match()
247 procmatch_nomatch(struct mprintc *mc, struct parsec *pc) in procmatch_nomatch() argument
252 grep_printline(&pc->ln, '-'); in procmatch_nomatch()
256 } else if (Bflag == 0 || (Bflag > 0 && enqueue(&pc->ln))) in procmatch_nomatch()
272 procmatches(struct mprintc *mc, struct parsec *pc, bool matched) in procmatches() argument
280 grep_printline(&pc->ln, '-'); in procmatches()
286 * XXX TODO: This should loop over pc->matches and handle things on a in procmatches()
291 procmatch_match(mc, pc); in procmatches()
301 procmatch_nomatch(mc, pc); in procmatches()
313 struct parsec pc; in procfile() local
343 pc.ln.file = grep_strdup(fn); in procfile()
344 pc.ln.line_no = 0; in procfile()
345 pc.ln.len = 0; in procfile()
346 pc.ln.boff = 0; in procfile()
347 pc.ln.off = -1; in procfile()
348 pc.binary = f->binary; in procfile()
349 pc.cntlines = false; in procfile()
352 if ((pc.binary && binbehave == BINFILE_BIN) || cflag || qflag || in procfile()
358 pc.cntlines = true; in procfile()
368 pc.printed = 0; in procfile()
369 pc.matchidx = 0; in procfile()
370 pc.lnstart = 0; in procfile()
371 pc.ln.boff = 0; in procfile()
372 pc.ln.off += pc.ln.len + 1; in procfile()
374 if ((pc.ln.dat = grep_fgetln(f, &pc)) == NULL || in procfile()
375 pc.ln.len == 0) in procfile()
378 if (pc.ln.len > 0 && pc.ln.dat[pc.ln.len - 1] == fileeol) in procfile()
379 --pc.ln.len; in procfile()
380 pc.ln.line_no++; in procfile()
383 if (pc.binary && binbehave == BINFILE_SKIP) { in procfile()
385 free(pc.ln.file); in procfile()
395 if (!procmatches(&mc, &pc, false)) in procfile()
399 line_matched = procline(&pc) == !vflag; in procfile()
404 if (!procmatches(&mc, &pc, line_matched)) in procfile()
413 printf("%s:", pc.ln.file); in procfile()
424 free(pc.ln.file); in procfile()
500 procline(struct parsec *pc) in procline() argument
511 matchidx = pc->matchidx; in procline()
515 if (xflag && pc->ln.len == 0) { in procline()
538 st = pc->lnstart; in procline()
544 while (st <= pc->ln.len) { in procline()
548 if (st > 0 && pc->ln.dat[st - 1] != fileeol) in procline()
553 pmatch.rm_eo = pc->ln.len; in procline()
556 r = litexec(&pattern[i], pc->ln.dat, 1, &pmatch); in procline()
559 r = regexec(&r_pattern[i], pc->ln.dat, 1, &pmatch, in procline()
565 (size_t)pmatch.rm_eo != pc->ln.len)) in procline()
571 sscanf(&pc->ln.dat[pmatch.rm_so - 1], in procline()
575 pc->ln.len && in procline()
576 sscanf(&pc->ln.dat[pmatch.rm_eo], in procline()
591 (retry == pc->lnstart || in procline()
610 chkmatch = pc->matches[matchidx - 1]; in procline()
615 pc->matches[matchidx - 1] = pmatch; in procline()
620 pc->matches[matchidx++] = pmatch; in procline()
626 pc->lnstart = nst; in procline()
637 if (!lastmatched && retry > pc->lnstart) { in procline()
649 nst = pc->ln.len; in procline()
660 pc->lnstart = st; in procline()
664 pc->matchidx = matchidx; in procline()
772 printline(struct parsec *pc, int sep, size_t *last_out) in printline() argument
790 matchidx = pc->matchidx; in printline()
793 if ((oflag || color) && (pc->printed > 0 || matchidx > 0)) { in printline()
795 if (!oflag && pc->printed == 0) { in printline()
796 printline_metadata(&pc->ln, sep); in printline()
799 match = pc->matches[i]; in printline()
808 pc->ln.boff = match.rm_so; in printline()
809 printline_metadata(&pc->ln, sep); in printline()
811 fwrite(pc->ln.dat + a, match.rm_so - a, 1, in printline()
816 fwrite(pc->ln.dat + match.rm_so, in printline()
831 if (pc->ln.len - a > 0) { in printline()
832 fwrite(pc->ln.dat + a, pc->ln.len - a, 1, in printline()
834 *last_out = pc->ln.len; in printline()
848 grep_printline(&pc->ln, sep); in printline()
849 pc->printed++; in printline()