diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-08-02 14:05:54 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-08-02 14:05:54 +0100 |
commit | b3d0cc0588845d3cad3fd67943d93e1bd87b1700 (patch) | |
tree | 79486747a419a63700f497499dd56f56ebcba8aa /src/inspect-fs.c | |
parent | d40b5028762eeaf9235165301bd76d468b7e251c (diff) | |
download | libguestfs-b3d0cc0588845d3cad3fd67943d93e1bd87b1700.tar.gz libguestfs-b3d0cc0588845d3cad3fd67943d93e1bd87b1700.tar.xz libguestfs-b3d0cc0588845d3cad3fd67943d93e1bd87b1700.zip |
grep: Add optargs to grep API and deprecate fgrep etc.
This commit makes grep into an optargs API, with flags for extended,
fixed, [case-]insensitive and compressed.
At the same time it deprecates: egrep, fgrep, grepi, egrepi, fgrepi,
zgrep, zegrep, zfgrep, zgrepi, zegrepi and zfgrepi.
Diffstat (limited to 'src/inspect-fs.c')
-rw-r--r-- | src/inspect-fs.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/inspect-fs.c b/src/inspect-fs.c index 00500675..33aff353 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -551,7 +551,7 @@ guestfs___first_line_of_file (guestfs_h *g, const char *filename) return ret; } -/* Get the first matching line (using guestfs_egrep{,i}) of a small file, +/* Get the first matching line (using egrep [-i]) of a small file, * without any trailing newline character. * * Returns: 1 = returned a line (in *ret) @@ -565,8 +565,9 @@ guestfs___first_egrep_of_file (guestfs_h *g, const char *filename, char **lines; int64_t size; size_t i; + struct guestfs_grep_opts_argv optargs; - /* Don't trust guestfs_egrep not to break with very large files. + /* Don't trust guestfs_grep not to break with very large files. * Check the file size is something reasonable first. */ size = guestfs_filesize (g, filename); @@ -579,7 +580,13 @@ guestfs___first_egrep_of_file (guestfs_h *g, const char *filename, return -1; } - lines = (!iflag ? guestfs_egrep : guestfs_egrepi) (g, eregex, filename); + optargs.bitmask = GUESTFS_GREP_OPTS_EXTENDED_BITMASK; + optargs.extended = 1; + if (iflag) { + optargs.bitmask |= GUESTFS_GREP_OPTS_INSENSITIVE_BITMASK; + optargs.insensitive = 1; + } + lines = guestfs_grep_opts_argv (g, eregex, filename, &optargs); if (lines == NULL) return -1; if (lines[0] == NULL) { |