aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/grep/grep.h
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2018-06-08 01:25:07 +0000
committerKyle Evans <kevans@FreeBSD.org>2018-06-08 01:25:07 +0000
commitbd60b9b4993e823fc857f03f7f11c9ad1204ba2e (patch)
tree95fcab1737e86d9c9a844ae74b669a291e3b17b5 /usr.bin/grep/grep.h
parentc9ca1a70cce29057168692f5a3bdeedfee4faacc (diff)
downloadsrc-bd60b9b4993e823fc857f03f7f11c9ad1204ba2e.tar.gz
src-bd60b9b4993e823fc857f03f7f11c9ad1204ba2e.zip
bsdgrep(1): Slooowly peel away the chunky onion
(or peel off the band-aid, whatever floats your boat) This addresses two separate issues: 1.) Nothing within bsdgrep actually knew whether it cared about line numbers or not. 2.) The file layer knew nothing about the context in which it was being called. #1 is only important when we're *not* processing line-by-line. #2 is debatably a good idea; the parsing context is only handy because that's where we store current offset information and, as of this commit, whether or not it needs to be line-aware.
Notes
Notes: svn path=/head/; revision=334821
Diffstat (limited to 'usr.bin/grep/grep.h')
-rw-r--r--usr.bin/grep/grep.h17
1 files changed, 16 insertions, 1 deletions
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index b2c16e8767d7..6d1e87ae4d7c 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -97,6 +97,21 @@ struct epat {
int mode;
};
+/*
+ * Parsing context; used to hold things like matches made and
+ * other useful bits
+ */
+struct parsec {
+ regmatch_t matches[MAX_MATCHES]; /* Matches made */
+ /* XXX TODO: This should be a chunk, not a line */
+ struct str ln; /* Current line */
+ size_t lnstart; /* Position in line */
+ size_t matchidx; /* Latest match index */
+ int printed; /* Metadata printed? */
+ bool binary; /* Binary file? */
+ bool cntlines; /* Count lines? */
+};
+
/* Flags passed to regcomp() and regexec() */
extern int cflags, eflags;
@@ -141,4 +156,4 @@ void clearqueue(void);
/* file.c */
void grep_close(struct file *f);
struct file *grep_open(const char *path);
-char *grep_fgetln(struct file *f, size_t *len);
+char *grep_fgetln(struct file *f, struct parsec *pc);