/* The MIT License (MIT) Copyright © 2020-2025 pacman64 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* iavoid [regular expressions...] Avoid/ignore lines which case-insensitively match any of the regexes given. When not given any regex, ignore all empty lines by default. */ // g++ -Wall -O2 -s -o iavoid iavoid.cpp #include #include #include using namespace std; const auto regex_opts = regex_constants::ECMAScript | regex_constants::icase; int compile(int argc, char** argv, vector& res) { size_t errors = 0; for (int i = 1; i < argc; i++) { try { regex expr(argv[i], regex_opts); res.push_back(expr); } catch (const regex_error& e) { cerr << "\x1b[31m" << e.code() << ": " << e.what() << "\x1b[0m" << endl; errors++; } } return errors; } bool match(string& s, const vector& expressions) { for (regex e : expressions) { if (regex_search(s, e)) { return true; } } return false; } void lines() { string line; while (getline(cin, line)) { cout << line << endl; if (cout.eof()) { return; } } } int main(int argc, char** argv) { if (argc == 1) { lines(); return 0; } cin.tie(NULL); ios_base::sync_with_stdio(false); vector expressions; size_t errors = compile(argc, argv, expressions); if (errors > 0) { return 1; } string line; while (getline(cin, line)) { if (match(line, expressions)) { continue; } cout << line << endl; if (cout.eof()) { break; } } return 0; }