From e52a9cc1a80c1463acf356c00afd4f43454e65a7 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sun, 24 Oct 2021 06:35:03 +0330 Subject: added -C option. llvm 14 --- .travis.yml | 15 +++++++++++++++ cgrep.cpp | 15 +++++++++++++-- cgrep.roff | 4 ++++ 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 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 + 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 @@ -37,6 +37,10 @@ How many lines after the matched line to print. Defaults to 0. \fB-B=\fP Howm many lines before the matched line to print. Defaults to 0. +.TP +\fB-C=\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. -- cgit v1.2.3