aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2021-10-24 03:05:03 +0000
committerterminaldweller <thabogre@gmail.com>2021-10-24 03:05:03 +0000
commite52a9cc1a80c1463acf356c00afd4f43454e65a7 (patch)
tree5d6993a2955455ae4c2cdb14e90abc87d07b7c7d
parentMerge pull request #21 from pJunger/readme (diff)
downloadcgrep-e52a9cc1a80c1463acf356c00afd4f43454e65a7.tar.gz
cgrep-e52a9cc1a80c1463acf356c00afd4f43454e65a7.zip
added -C option. llvm 14
-rw-r--r--.travis.yml15
-rw-r--r--cgrep.cpp15
-rw-r--r--cgrep.roff4
3 files changed, 32 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 0a8c68c..6edb944 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -121,3 +121,18 @@ matrix:
- git submodule update
script:
- make CXX=clang-13 LLVM_CONF=llvm-config-13
+ - dist: bionic
+ name: llvm14
+ sudo: required
+ language: cpp
+ before_script:
+ - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
+ - sudo apt-get update -y
+ - wget https://apt.llvm.org/llvm.sh
+ - chmod +x llvm.sh
+ - sudo ./llvm.sh 14
+ - sudo apt-get install -y clang-14 llvm-14-dev libclang-common-14-dev libclang-14-dev
+ - git submodule init
+ - git submodule update
+ script:
+ - make CXX=clang-14 LLVM_CONF=llvm-config-14
diff --git a/cgrep.cpp b/cgrep.cpp
index 4600668..07c313f 100644
--- a/cgrep.cpp
+++ b/cgrep.cpp
@@ -137,6 +137,11 @@ cl::opt<int> CO_B("B",
cl::desc("Same as grep, how many lines before the matched "
"line to print. Defaults to 0."),
cl::init(0), cl::cat(CGrepCat), cl::Optional); // done
+cl::opt<int>
+ CO_C("C",
+ cl::desc("Same as grep, how many lines before and after the matched "
+ "line to print. Defaults to 0."),
+ cl::init(0), cl::cat(CGrepCat), cl::Optional); // done
} // namespace
/***********************************************************************************************/
#if 1
@@ -253,8 +258,14 @@ void output_handler(const MatchFinder::MatchResult &MR, SourceRange SR,
std::cout << CC_RED << MR.SourceManager->getFilename(SR.getBegin()).str()
<< ":" << linenumber << ":" << columnnumber_start << CC_NORMAL;
} else {
- unsigned line_range_begin = linenumber - CO_B;
- unsigned line_range_end = linenumber + CO_A;
+ unsigned line_range_begin;
+ unsigned line_range_end;
+ if (0 >= CO_C) {
+ line_range_begin = linenumber - CO_C;
+ line_range_end = linenumber + CO_C;
+ }
+ line_range_begin = linenumber - CO_B;
+ line_range_end = linenumber + CO_A;
std::string line;
unsigned line_nu = 0;
while (getline(mainfile, line)) {
diff --git a/cgrep.roff b/cgrep.roff
index 817b4ed..f2a074d 100644
--- a/cgrep.roff
+++ b/cgrep.roff
@@ -38,6 +38,10 @@ How many lines after the matched line to print. Defaults to 0.
Howm many lines before the matched line to print. Defaults to 0.
.TP
+\fB-C=<int>\fP
+Howm many lines before and after the matched line to print. Defaults to 0.
+
+.TP
\fB--all\fP
Turns on all switches other than nameddecl.