grep before stdin
This commit is contained in:
parent
30bf5df03e
commit
7b5a87df38
@ -119,14 +119,22 @@ void grepit(const Rcl::Doc& doc)
|
|||||||
ppath += doc.ipath + "::";
|
ppath += doc.ipath + "::";
|
||||||
}
|
}
|
||||||
int lnum = 0;
|
int lnum = 0;
|
||||||
|
int idx;
|
||||||
std::string ln;
|
std::string ln;
|
||||||
bool inmatch{false};
|
bool inmatch{false};
|
||||||
for (const auto& line: lines) {
|
for (const auto& line: lines) {
|
||||||
|
idx = lnum;
|
||||||
++lnum;
|
++lnum;
|
||||||
//std::cout << "LINE:[" << line << "]\n";
|
//std::cout << "LINE:[" << line << "]\n";
|
||||||
for (const auto e_p : g_expressions) {
|
for (const auto e_p : g_expressions) {
|
||||||
auto match = e_p->simpleMatch(line);
|
auto match = e_p->simpleMatch(line);
|
||||||
if (((op_flags & OPT_v) && match) || (!(op_flags&OPT_v) && !match)) {
|
if (((op_flags & OPT_v) && match) || (!(op_flags & OPT_v) && !match)) {
|
||||||
|
if (inmatch && aftercontext && !(op_flags&OPT_c) && idx < int(lines.size())) {
|
||||||
|
for (int i = idx; i < std::min(int(lines.size()), idx + aftercontext); i++) {
|
||||||
|
std::cout << ppath << ln << lines[i] << "\n";
|
||||||
|
}
|
||||||
|
std::cout << "--\n";
|
||||||
|
}
|
||||||
inmatch = false;
|
inmatch = false;
|
||||||
goto nextline;
|
goto nextline;
|
||||||
}
|
}
|
||||||
@ -137,19 +145,13 @@ void grepit(const Rcl::Doc& doc)
|
|||||||
if (op_flags & OPT_n) {
|
if (op_flags & OPT_n) {
|
||||||
ln = ulltodecstr(lnum) + ":";
|
ln = ulltodecstr(lnum) + ":";
|
||||||
}
|
}
|
||||||
int idx = lnum -1;
|
if (!inmatch && !(op_flags&OPT_c) && beforecontext) {
|
||||||
if (beforecontext) {
|
|
||||||
for (int i = std::max(0, idx - beforecontext); i < idx; i++) {
|
for (int i = std::max(0, idx - beforecontext); i < idx; i++) {
|
||||||
std::cout << ppath << ln << lines[i] << "\n";
|
std::cout << ppath << ln << lines[i] << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
inmatch=true;
|
||||||
std::cout << ppath << ln << line << "\n";
|
std::cout << ppath << ln << line << "\n";
|
||||||
if (aftercontext && idx < int(lines.size() - 1)) {
|
|
||||||
for (int i = idx + 1; i < std::min(int(lines.size()), idx + aftercontext + 1); i++) {
|
|
||||||
std::cout << ppath << ln << lines[i] << "\n";
|
|
||||||
}
|
|
||||||
std::cout << "--\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
nextline:
|
nextline:
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user