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 void printline(struct parsec *pc, int sep);
204 procmatch_match(struct mprintc *mc, struct parsec *pc)
217 printline(pc, ':');
218 while (pc->matchidx >= MAX_MATCHES) {
220 pc->matchidx = 0;
221 if (procline(pc) == !vflag)
222 printline(pc, ':');
233 procmatch_nomatch(struct mprintc *mc, struct parsec *pc)
238 grep_printline(&pc->ln, '-');
242 } else if (Bflag == 0 || (Bflag > 0 && enqueue(&pc->ln)))
258 procmatches(struct mprintc *mc, struct parsec *pc, bool matched)
266 grep_printline(&pc->ln, '-');
272 * XXX TODO: This should loop over pc->matches and handle things on a
277 procmatch_match(mc, pc);
287 procmatch_nomatch(mc, pc);
299 struct parsec pc;
329 pc.ln.file = grep_strdup(fn);
330 pc.ln.line_no = 0;
331 pc.ln.len = 0;
332 pc.ln.boff = 0;
333 pc.ln.off = -1;
334 pc.binary = f->binary;
335 pc.cntlines = false;
338 if ((pc.binary && binbehave == BINFILE_BIN) || cflag || qflag ||
344 pc.cntlines = true;
354 pc.printed = 0;
355 pc.matchidx = 0;
356 pc.lnstart = 0;
357 pc.ln.boff = 0;
358 pc.ln.off += pc.ln.len + 1;
360 if ((pc.ln.dat = grep_fgetln(f, &pc)) == NULL ||
361 pc.ln.len == 0)
364 if (pc.ln.len > 0 && pc.ln.dat[pc.ln.len - 1] == fileeol)
365 --pc.ln.len;
366 pc.ln.line_no++;
369 if (pc.binary && binbehave == BINFILE_SKIP) {
371 free(pc.ln.file);
381 if (!procmatches(&mc, &pc, false))
385 line_matched = procline(&pc) == !vflag;
390 if (!procmatches(&mc, &pc, line_matched))
399 printf("%s:", pc.ln.file);
410 free(pc.ln.file);
486 procline(struct parsec *pc)
497 matchidx = pc->matchidx;
501 if (xflag && pc->ln.len == 0) {
524 st = pc->lnstart;
530 while (st <= pc->ln.len) {
534 if (st > 0 && pc->ln.dat[st - 1] != fileeol)
539 pmatch.rm_eo = pc->ln.len;
542 r = litexec(&pattern[i], pc->ln.dat, 1, &pmatch);
545 r = regexec(&r_pattern[i], pc->ln.dat, 1, &pmatch,
551 (size_t)pmatch.rm_eo != pc->ln.len))
557 sscanf(&pc->ln.dat[pmatch.rm_so - 1],
561 pc->ln.len &&
562 sscanf(&pc->ln.dat[pmatch.rm_eo],
577 (retry == pc->lnstart ||
596 chkmatch = pc->matches[matchidx - 1];
601 pc->matches[matchidx - 1] = pmatch;
606 pc->matches[matchidx++] = pmatch;
612 pc->lnstart = nst;
623 if (!lastmatched && retry > pc->lnstart) {
635 nst = pc->ln.len;
646 pc->lnstart = st;
650 pc->matchidx = matchidx;
754 printline(struct parsec *pc, int sep)
764 matchidx = pc->matchidx;
769 if (!oflag && pc->printed == 0)
770 printline_metadata(&pc->ln, sep);
772 match = pc->matches[i];
781 pc->ln.boff = match.rm_so;
782 printline_metadata(&pc->ln, sep);
784 fwrite(pc->ln.dat + a, match.rm_so - a, 1,
788 fwrite(pc->ln.dat + match.rm_so,
797 if (pc->ln.len - a > 0)
798 fwrite(pc->ln.dat + a, pc->ln.len - a, 1,
803 grep_printline(&pc->ln, sep);
804 pc->printed++;