From 7fbb06045f9e5c0b7e55a0410f37ac0ddd4bd54d Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Fri, 4 Feb 2022 15:48:04 +0100 Subject: implement option handling --- src/srcut.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/srcut.cpp b/src/srcut.cpp index 8c59440..44131a0 100644 --- a/src/srcut.cpp +++ b/src/srcut.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include using namespace std; @@ -103,11 +104,34 @@ print(ostream& os, const string& key, const map>& contain int main(int argc, char* argv[]) { + int show_tags = 0; + int ch; + + while ( (ch = getopt(argc, argv, "t")) != -1 ) { + switch ( ch ) { + case 't': + show_tags = 1; + break; + default: + cerr << "unbekannte option" << endl; + return EXIT_FAILURE; + } + } + argc -= optind; + argv += optind; + map> container; cin >> container; - for ( int i = 1; i < argc; ++i ) { - print(cout, argv[i], container); + if ( show_tags ) { + for ( const auto& it: container ) { + cout << it.first << endl; + } + } + else { + for ( int i = 0; i < argc; ++i ) { + print(cout, argv[i], container); + } } } -- cgit v1.3