| 1 | /* |
| 2 | setop -- apply set operations to several input files and print resulting set to standard output |
| 3 | Copyright (C) 2015 Frank Stähr, GPL v2 or later |
| 4 | |
| 5 | This program is free software: |
| 6 | you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 9 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | See the GNU General Public License for more details. |
| 11 | |
| 12 | You can find a copy of the GNU General Public License at <http://www.gnu.org/licenses/>. |
| 13 | */ |
| 14 | |
| 15 | |
| 16 | #include <iostream> |
| 17 | #include <string> |
| 18 | #include <set> |
| 19 | #include <map> |
| 20 | #include <vector> |
| 21 | #include <stack> |
| 22 | #include <regex> |
| 23 | #include <fstream> |
| 24 | #include <functional> |
| 25 | #include <memory> |
| 26 | #include <cstdlib> |
| 27 | |
| 28 | #include <boost/program_options.hpp> |
| 29 | #include <boost/algorithm/string/trim.hpp> |
| 30 | #include <boost/algorithm/string/case_conv.hpp> |
| 31 | #include <boost/algorithm/string/predicate.hpp> |
| 32 | #include <boost/regex.hpp> |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | \file |
| 37 | \brief Program for parsing input files and streams for string elements and applying several set operations and special queries |
| 38 | \details For details how to use the program start it with `--help` and see help text. |
| 39 | \author Frank Stähr |
| 40 | \date Oct., 1st, 2015 |
| 41 | */ |
| 42 | |
| 43 | #define PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! "setop" ///< official name of program |
| 44 | #define PROGRAM_VERSIONcxx . . $ `src/main.cpp:44:9`! "0.2" ///< version of setop |
| 45 | /** \brief used when query has negative result (e. g. element not part of input), but program flow has no (other) error */ |
| 46 | #define EXIT_QUERY_NEGATIVEcxx . . $ `src/main.cpp:46:9`! 3 |
| 47 | static_assert((EXIT_QUERY_NEGATIVEcxx . . $ `src/main.cpp:46:9`! != EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!) && (EXIT_QUERY_NEGATIVEcxx . . $ `src/main.cpp:46:9`! != EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!), |
| 48 | "Macro EXIT_QUERY_NEGATIVE must not be equal to EXIT_SUCCESS or to EXIT_FAILURE."); |
| 49 | |
| 50 | /** \brief all possible commutative set operations */ |
| 51 | enum class SetConcatcxx . . $ SetConcat# : unsigned char { UNIONcxx . . $ SetConcat#UNION., INTERSECTIONcxx . . $ SetConcat#INTERSECTION., SYM_DIFFERENCEcxx . . $ SetConcat#SYM_DIFFERENCE., FORMULAcxx . . $ SetConcat#FORMULA. }; |
| 52 | /** \brief types of different return possibilities for program */ |
| 53 | enum class SetQuerycxx . . $ SetQuery# : unsigned char { RETURN_SETcxx . . $ SetQuery#RETURN_SET., CARDINALITYcxx . . $ SetQuery#CARDINALITY., ISEMPTYcxx . . $ SetQuery#ISEMPTY., SUBSETcxx . . $ SetQuery#SUBSET., SUPERSETcxx . . $ SetQuery#SUPERSET., CONTAINS_ELEMENTcxx . . $ SetQuery#CONTAINS_ELEMENT., SET_EQUALITYcxx . . $ SetQuery#SET_EQUALITY. }; |
| 54 | |
| 55 | using element_tcxx . . $ element_t# = stdcxx . . $ std/::stringcxx . . $ std/string#; ///< basic type of element in sets, must base on character type char |
| 56 | using el_comp_tcxx . . $ el_comp_t# = stdcxx . . $ std/::functioncxx . . $ std/function#<bool(element_tcxx . . $ element_t# const&, element_tcxx . . $ element_t# const&)>; ///< type of function for comparing elements |
| 57 | /** |
| 58 | \brief basic type for sets |
| 59 | \details A hash set would be faster, but: |
| 60 | - even with 1,000,000 elements only about with factor 1.7 or 1.8 (depending on several other influences) |
| 61 | - no advantage in memory saving |
| 62 | - output is not sorted (at least one more option necessary for letting user to decide if this is acceptable) |
| 63 | - much more source code (sorted/unsorted output; overhead for case-insensitive hash function etc.) |
| 64 | */ |
| 65 | using set_tcxx . . $ set_t# = stdcxx . . $ std/::setcxx . . $ std/set#<element_tcxx . . $ element_t#, el_comp_tcxx . . $ el_comp_t#>; |
| 66 | |
| 67 | /** \brief Encapsulates all options for reading and parsing input streams. */ |
| 68 | class InputOptionscxx . . $ InputOptions# |
| 69 | { |
| 70 | public: |
| 71 | el_comp_tcxx . . $ el_comp_t# element_compcxx . . $ InputOptions#element_comp.; ///< comparator for set elements (e. g. case-insensitive comparison) |
| 72 | bool include_empty_elementscxx . . $ InputOptions#include_empty_elements.; ///< empty input elements are included instead of ignored |
| 73 | boostcxx . . $ boost/::regexcxx . . $ boost/regex# input_element_regexcxx . . $ InputOptions#input_element_regex.; ///< regular expression describing an input element (use `boost` instead of `std` because `match_partial` is needed) |
| 74 | boostcxx . . $ boost/::regexcxx . . $ boost/regex# input_separator_regexcxx . . $ InputOptions#input_separator_regex.; ///< regular expression describing an input separator |
| 75 | stdcxx . . $ std/::stringcxx . . $ std/string# output_separatorcxx . . $ InputOptions#output_separator.; ///< string elements shall be separated with in output |
| 76 | stdcxx . . $ std/::stringcxx . . $ std/string# trim_characterscxx . . $ InputOptions#trim_characters.; ///< list of characters that shall be ignored in element at begin and end |
| 77 | } input_optscxx . . $ input_opts.; |
| 78 | |
| 79 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> input_filenamescxx . . $ input_filenames.; |
| 80 | |
| 81 | |
| 82 | /** |
| 83 | \brief Parses escape sequences like `\n` and `\t` to “real” characters (e. g. ``.\'\\\"`` gets to ``.'\"``). |
| 84 | \details Escape sequences ``\'``, `\"`, `\?`, `\\`, `\f`, `\n`, `\r`, `\t`, `\v` are supported. |
| 85 | \param escape_seq sequence to unescape |
| 86 | \note There should be an `std` or `boost` library for a simple task like unescaping, but it seems that there isn’t (yet). |
| 87 | Replace this function in the future if possible. |
| 88 | \throws std::invalid_argument |
| 89 | */ |
| 90 | stdcxx . . $ std/::stringcxx . . $ std/string# unescape_sequencecxx . . $ unescape_sequence(fd626fc03107dd24).(stdcxx . . $ std/::stringcxx . . $ std/string# const& escape_seq) |
| 91 | { |
| 92 | stdcxx . . $ std/::mapcxx . . $ std/map#<char, char> const escape_characters = |
| 93 | {cxx . . $ std/map#map(7786ef3e167e36fa). |
| 94 | { '\'', '\'' }, |
| 95 | { '\"', '\"' }, |
| 96 | { '?', '?' }, |
| 97 | { '\\', '\\' }, |
| 98 | { 'f', '\f' }, |
| 99 | { 'n', '\n' }, |
| 100 | { 'r', '\r' }, |
| 101 | { 't', '\t' }, |
| 102 | { 'v', '\v' } |
| 103 | }; |
| 104 | |
| 105 | stdcxx . . $ std/::stringcxx . . $ std/string# resultcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 106 | for (auto curr_char = escape_seq.begincxx . . $ std/__cxx11/basic_string#begin(a865d278ca20c908).(); curr_char != escape_seq.endcxx . . $ std/__cxx11/basic_string#end(a865d278ca20c908).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).curr_char) |
| 107 | { |
| 108 | if (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_char == '\\') |
| 109 | { |
| 110 | if (++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).curr_char ==cxx . . $ __gnu_cxx/`operator==`(d2eded1addd76ab7). escape_seq.endcxx . . $ std/__cxx11/basic_string#end(a865d278ca20c908).()) |
| 111 | throw stdcxx . . $ std/::invalid_argumentcxx . . $ std/invalid_argument#("Parsing failed: Backslash at end of \"" +cxx . . $ std/operator+(42c652dfebe55ad7). escape_seq +cxx . . $ std/operator+(900ec9581c410ad9). "\" is invalid."); |
| 112 | auto second_char = escape_characters.findcxx . . $ std/map#find(7b3585bb5da8f7d).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_char); |
| 113 | if (second_char != escape_characters.endcxx . . $ std/map#end(b953fec338ad1a3b).()) |
| 114 | result.push_backcxx . . $ std/__cxx11/basic_string#push_back(9b289cee16747614).(second_char->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second.); |
| 115 | else |
| 116 | throw stdcxx . . $ std/::invalid_argumentcxx . . $ std/invalid_argument#(stdcxx . . $ std/::stringcxx . . $ std/string#("Parsing failed: ") +cxx . . $ std/operator+(900ec9581c410ad9). |
| 117 | "Escape sequence \"\\" +cxx . . $ std/operator+(cd4e1e16c2d05e54). *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_char +cxx . . $ std/operator+(900ec9581c410ad9). "\" in argument \"" +cxx . . $ std/operator+(db5dc2ea912c6495). escape_seq +cxx . . $ std/operator+(900ec9581c410ad9). "\" is not supported."); |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | result.push_backcxx . . $ std/__cxx11/basic_string#push_back(9b289cee16747614).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_char); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return resultcxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, set_tcxx . . $ set_t#> inputstream_cachecxx . . $ inputstream_cache.; // in case an input is needed more than once, do not parse input file again but cache it |
| 130 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, int> inputstream_to_usagecountcxx . . $ inputstream_to_usagecount.; // should in general be 1 for all entries |
| 131 | |
| 132 | /** |
| 133 | \brief Returns all elements from file as a set. |
| 134 | \param filename name of input file with elements to parse |
| 135 | */ |
| 136 | set_tcxx . . $ set_t# file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(stdcxx . . $ std/::stringcxx . . $ std/string# const& filename) |
| 137 | { |
| 138 | set_tcxx . . $ set_t# resultcxx . . $ std/set#set(19c357cac5bd4ecc).(input_optscxx . . $ input_opts..element_compcxx . . $ InputOptions#element_comp.); |
| 139 | |
| 140 | // handle caching of input streams in case they are needed multiple times |
| 141 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, int>::iteratorcxx . . $ std/map#iterator# usage_count = inputstream_to_usagecountcxx . . $ inputstream_to_usagecount..findcxx . . $ std/map#find(36f8d56706583706).(filename); |
| 142 | --usage_count->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.; |
| 143 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, set_t>::iteratorcxx . . $ std/map#iterator# cached_input_it = inputstream_cachecxx . . $ inputstream_cache..findcxx . . $ std/map#find(36f8d56706583706).(filename); |
| 144 | if (cached_input_it != inputstream_cachecxx . . $ inputstream_cache..endcxx . . $ std/map#end(7e4de33083b6e738).()) |
| 145 | { |
| 146 | if (usage_count->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. == 0) |
| 147 | { |
| 148 | result =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(cached_input_it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.); // not needed anymore |
| 149 | } |
| 150 | else |
| 151 | result =cxx . . $ std/set#`operator=`(7d6e6bfeb60e39ab). cached_input_it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second.; // copy |
| 152 | return resultcxx . . $ std/set#set(f3bfeaebad815056).; |
| 153 | } |
| 154 | |
| 155 | // set input stream (can be std::cin) |
| 156 | stdcxx . . $ std/::ifstreamcxx . . $ std/ifstream# inputfilecxx . . $ std/basic_ifstream#basic_ifstream(49f6e7a06ebc5aa8).; |
| 157 | if (filename != "-") |
| 158 | { |
| 159 | inputfile.opencxx . . $ std/basic_ifstream#open(be6c264dafcf0985).(filename); |
| 160 | if (!cxx . . $ std/basic_ios#`operator!`(50ce9a9e25b4a850).inputfile) |
| 161 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#("input file '" +cxx . . $ std/operator+(42c652dfebe55ad7). filename +cxx . . $ std/operator+(900ec9581c410ad9). "' could not be opened."); |
| 162 | } |
| 163 | stdcxx . . $ std/::istreamcxx . . $ std/istream#& inputstream = (filename ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "-" ? stdcxx . . $ std/::cincxx . . $ std/cin. : inputfile); |
| 164 | |
| 165 | // lambda for running adjust_element and inserting it right after (according to options) |
| 166 | auto adjust_and_insert_element = [&result](element_tcxx . . $ element_t# el_str, bool check_element_regex) |
| 167 | { |
| 168 | if (!check_element_regex || input_optscxx . . $ input_opts..input_element_regexcxx . . $ InputOptions#input_element_regex..emptycxx . . $ boost/basic_regex#empty(50ce9a9e25b4a850).() || |
| 169 | boostcxx . . $ boost/::regex_matchcxx . . $ boost/regex_match(362cf476b2c0bb33).(el_str, input_optscxx . . $ input_opts..input_element_regexcxx . . $ InputOptions#input_element_regex.)) |
| 170 | { |
| 171 | boostcxx . . $ boost/::trim_ifcxx . . $ boost/trim_if(33274b2173bbdc28).(el_str, boostcxx . . $ boost/::is_any_ofcxx . . $ boost/is_any_of(5573bd4edbd0fcc3).(input_optscxx . . $ input_opts..trim_characterscxx . . $ InputOptions#trim_characters.)); |
| 172 | if (!el_str.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() || input_optscxx . . $ input_opts..include_empty_elementscxx . . $ InputOptions#include_empty_elements.) |
| 173 | result.insertcxx . . $ std/set#insert(10916b2dbd511ba8).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(el_str)); |
| 174 | } |
| 175 | }; |
| 176 | |
| 177 | // general idea: parse input according to regular expression describing an element or a separator |
| 178 | |
| 179 | bool use_separator_regex = input_optscxx . . $ input_opts..input_element_regexcxx . . $ InputOptions#input_element_regex..emptycxx . . $ boost/basic_regex#empty(50ce9a9e25b4a850).(); |
| 180 | boostcxx . . $ boost/::regexcxx . . $ boost/regex# const& regex = (use_separator_regex ? input_optscxx . . $ input_opts..input_separator_regexcxx . . $ InputOptions#input_separator_regex. : input_optscxx . . $ input_opts..input_element_regexcxx . . $ InputOptions#input_element_regex.); |
| 181 | |
| 182 | // effect of value of initial buffer size is practically unmeasurable, so just take a nice value of form 2^n, |
| 183 | // at least it should be much bigger than expected size of elements |
| 184 | stdcxx . . $ std/::size_tcxx . . $ std/size_t# buffersize = 4096; |
| 185 | stdcxx . . $ std/::size_tcxx . . $ std/size_t# used_buffer = 0; |
| 186 | // use unique pointer instead of "plain" pointer so that there is no memory leak in case of exception |
| 187 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<char[]> buffercxx . . $ std/unique_ptr#unique_ptr(2bd1d077c542d025).(new char[buffersize]); |
| 188 | do |
| 189 | { |
| 190 | inputstream.readcxx . . $ std/basic_istream#read(ec7d6f01d31dcb96).(buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).() + used_buffer, buffersize - used_buffer); |
| 191 | char const* const buffer_end = buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).() + used_buffer + inputstream.gcountcxx . . $ std/basic_istream#gcount(57a65ae535d7db84).(); |
| 192 | char const* buffer_handled_until = buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(); |
| 193 | |
| 194 | // the whole following thing could be much easier by using a bidirectional input iterator here, but: |
| 195 | // do not do this because input "file" could be a named pipe, stream or similar (no backwards iterating would be possible!) |
| 196 | // so you have to manage the buffer (and release parts of it) yourself |
| 197 | // for a more efficient solution (hopefully in the near future) see <https://svn.boost.org/trac/boost/ticket/11776> |
| 198 | boostcxx . . $ boost/::cregex_iteratorcxx . . $ boost/cregex_iterator# curr_matchcxx . . $ boost/regex_iterator#regex_iterator(c3fd0304052248a9).(buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), buffer_end, regex, boostcxx . . $ boost/::match_defaultcxx . . $ boost/match_default. |cxx . . $ boost/regex_constants/`operator|`(b997cccb86dd7cf9). boostcxx . . $ boost/::match_partialcxx . . $ boost/match_partial.); |
| 199 | // add element to set when ... |
| 200 | while (curr_match !=cxx . . $ boost/regex_iterator#`operator!=`(c20b31e420a7d36). boostcxx . . $ boost/regex_iterator#regex_iterator(49f6e7a06ebc5aa8).::cregex_iteratorcxx . . $ boost/cregex_iterator#() && |
| 201 | curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).begincxx . . $ boost/match_results#begin(188039906b4583dd).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).matchedcxx . . $ boost/sub_match#matched. && // ... match is a full match and ... |
| 202 | (!cxx . . $ std/basic_ios#`operator!`(50ce9a9e25b4a850).inputstream || // ... when file is at end or ... |
| 203 | // (see next line) when match does not touch end of buffer (otherwise element could be longer, e. g. partial match) |
| 204 | !boostcxx . . $ boost/::regex_matchcxx . . $ boost/regex_match(99ba5a7efe07259a).(curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).begincxx . . $ boost/match_results#begin(188039906b4583dd).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).firstcxx . . $ std/pair#first., buffer_end, regex, boostcxx . . $ boost/::match_defaultcxx . . $ boost/match_default. |cxx . . $ boost/regex_constants/`operator|`(b997cccb86dd7cf9). boostcxx . . $ boost/::match_partialcxx . . $ boost/match_partial.))) |
| 205 | { |
| 206 | if (use_separator_regex) |
| 207 | { |
| 208 | adjust_and_insert_element(cxx . . $ file_to_set(5774bd19eeb5c1c4).$anonymous_type_0#`operator()`(b0f166b6a4bb6001).element_tcxx . . $ std/__cxx11/basic_string#basic_string(47be8e3519ed771f).(buffer_handled_until, curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).begincxx . . $ boost/match_results#begin(188039906b4583dd).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).firstcxx . . $ std/pair#first.), true); |
| 209 | buffer_handled_until = curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).begincxx . . $ boost/match_results#begin(188039906b4583dd).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).secondcxx . . $ std/pair#second.; |
| 210 | } |
| 211 | else |
| 212 | { |
| 213 | adjust_and_insert_element(cxx . . $ file_to_set(5774bd19eeb5c1c4).$anonymous_type_0#`operator()`(b0f166b6a4bb6001).curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).strcxx . . $ boost/match_results#str(e8abff648787bce1).(), false); |
| 214 | } |
| 215 | ++cxx . . $ boost/regex_iterator#operator++(6faece1549850852).curr_match; |
| 216 | } |
| 217 | if (!use_separator_regex) |
| 218 | // the last match is always a partial match except full match touches buffer end (or buffer is empty) |
| 219 | // so mark begin of last match as new begin of buffer when filling it up in next round of do-while-loop |
| 220 | buffer_handled_until = (curr_match !=cxx . . $ boost/regex_iterator#`operator!=`(c20b31e420a7d36). boostcxx . . $ boost/regex_iterator#regex_iterator(49f6e7a06ebc5aa8).::cregex_iteratorcxx . . $ boost/cregex_iterator#() ? curr_match->cxx . . $ boost/regex_iterator#`operator->`(d2f49d09776686b9).begincxx . . $ boost/match_results#begin(188039906b4583dd).()->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).firstcxx . . $ std/pair#first. : |
| 221 | buffer_end); |
| 222 | |
| 223 | used_buffer = buffer_end - buffer_handled_until; |
| 224 | if (buffer_handled_until == buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()) |
| 225 | { |
| 226 | // if current element fills the whole buffer, buffer is too small and thus doubled |
| 227 | buffersize *= 2; |
| 228 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<char[]> new_buffercxx . . $ std/unique_ptr#unique_ptr(2bd1d077c542d025).(new char[buffersize]); |
| 229 | stdcxx . . $ std/::memmove(new_buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), buffer_handled_until, used_buffer); |
| 230 | buffer =cxx . . $ std/unique_ptr#`operator=`(7f5789f8996c1c93). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(new_buffer); |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | // move the rest of new element (buffer_handled_until) to beginning of buffer and mark it as used |
| 235 | stdcxx . . $ std/::memmove(buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), buffer_handled_until, used_buffer); |
| 236 | } |
| 237 | } while (inputstream); |
| 238 | |
| 239 | if (use_separator_regex && used_buffer > 0) |
| 240 | adjust_and_insert_element(cxx . . $ file_to_set(5774bd19eeb5c1c4).$anonymous_type_0#`operator()`(b0f166b6a4bb6001).element_tcxx . . $ std/__cxx11/basic_string#basic_string(6f2e210728d16ac0).(buffer.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).(), used_buffer), true); |
| 241 | |
| 242 | if (usage_count->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second. > 0) |
| 243 | inputstream_cachecxx . . $ inputstream_cache.[cxx . . $ std/map#`operator[]`(bbd415b616967878).filename] =cxx . . $ std/set#`operator=`(7d6e6bfeb60e39ab). result; // cache result because it is needed later |
| 244 | |
| 245 | return resultcxx . . $ std/set#set(f3bfeaebad815056).; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | \brief Prints complete warning message to console `std::cerr` including hint, that this is a warning. |
| 250 | \param warning_message warning message without new line at end |
| 251 | */ |
| 252 | inline void print_warningcxx . . $ print_warning(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const& warning_message) |
| 253 | { |
| 254 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Warning: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). warning_message <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | \brief Prints complete error message to console `std::cerr` including hint, that this is an error. |
| 259 | \param error_message error message without new line at end |
| 260 | \return exit code `EXIT_FAILURE` (normally 1) |
| 261 | */ |
| 262 | inline int print_errorcxx . . $ print_error(7787e0c995c81e02).(stdcxx . . $ std/::stringcxx . . $ std/string# const& error_message) |
| 263 | { |
| 264 | stdcxx . . $ std/::cerrcxx . . $ std/cerr. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). error_message <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 265 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | \brief Prints complete error message to console `std::cerr` that an option used a faulty parameter. |
| 270 | \param option option with faulty parameter, i. e. `combination` or `output` (without minus signs) |
| 271 | \param parameter faulty parameter (e. g. `intersect` instead of `intersection`) |
| 272 | \return exit code `EXIT_FAILURE` (normally 1) |
| 273 | */ |
| 274 | inline int print_unsupported_parameter_errorcxx . . $ print_unsupported_parameter_error(ff1c98e35c114d02).(stdcxx . . $ std/::stringcxx . . $ std/string# const& option, stdcxx . . $ std/::stringcxx . . $ std/string# const& parameter) |
| 275 | { |
| 276 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("option '--" +cxx . . $ std/operator+(42c652dfebe55ad7). option +cxx . . $ std/operator+(900ec9581c410ad9). "' does not support a parameter '" +cxx . . $ std/operator+(db5dc2ea912c6495). parameter +cxx . . $ std/operator+(900ec9581c410ad9). "'."); |
| 277 | } |
| 278 | |
| 279 | class invalid_formula_exceptioncxx . . $ invalid_formula_exception# : public stdcxx . . $ std/::invalid_argumentcxx . . $ std/invalid_argument# |
| 280 | { |
| 281 | public: |
| 282 | invalid_formula_exceptioncxx . . $ invalid_formula_exception#invalid_formula_exception(9c546c94e5fcce4e).(stdcxx . . $ std/::stringcxx . . $ std/string# const& error_message) |
| 283 | : invalid_argumentcxx . . $ std/invalid_argument#(error_message) {} |
| 284 | }; |
| 285 | |
| 286 | enum class SetCombineOperationcxx . . $ SetCombineOperation# |
| 287 | { |
| 288 | Intersectioncxx . . $ SetCombineOperation#Intersection., |
| 289 | SymmetricDiffcxx . . $ SetCombineOperation#SymmetricDiff., |
| 290 | Unioncxx . . $ SetCombineOperation#Union., |
| 291 | SetDifferencecxx . . $ SetCombineOperation#SetDifference. |
| 292 | }; |
| 293 | |
| 294 | /// Combine `output_set` with `next_input` via `operation` and store result in `output_set`. |
| 295 | void combine_with_next_setcxx . . $ combine_with_next_set(6ecbcf41c7462268).(set_tcxx . . $ set_t#& output_set, SetCombineOperationcxx . . $ SetCombineOperation# operation, set_tcxx . . $ set_t#&& next_input) |
| 296 | { |
| 297 | switch (operation) |
| 298 | { |
| 299 | case SetCombineOperationcxx . . $ SetCombineOperation#::Intersectioncxx . . $ SetCombineOperation#Intersection.: |
| 300 | { |
| 301 | set_tcxx . . $ set_t# intersectcxx . . $ std/set#set(19c357cac5bd4ecc).(input_optscxx . . $ input_opts..element_compcxx . . $ InputOptions#element_comp.); |
| 302 | for (element_tcxx . . $ element_t# const& el : output_set) |
| 303 | if (next_input.containscxx . . $ std/set#contains(8877ebe272b9620d).(el)) |
| 304 | intersect.insertcxx . . $ std/set#insert(411a10a755068dfe).(el); |
| 305 | |
| 306 | output_set =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(intersect); |
| 307 | break; |
| 308 | } |
| 309 | case SetCombineOperationcxx . . $ SetCombineOperation#::SymmetricDiffcxx . . $ SetCombineOperation#SymmetricDiff.: |
| 310 | for (element_tcxx . . $ element_t# const& el : next_input) |
| 311 | { |
| 312 | set_tcxx . . $ set_t#::const_iteratorcxx . . $ std/set#const_iterator# it = output_set.findcxx . . $ std/set#find(f8922f46a681e6cc).(el); |
| 313 | if (it != output_set.endcxx . . $ std/set#end(3220b82c0db6d2a1).()) |
| 314 | output_set.erasecxx . . $ std/set#erase(36a7984e631cd3e9).(it); |
| 315 | else |
| 316 | output_set.insertcxx . . $ std/set#insert(411a10a755068dfe).(el); |
| 317 | } |
| 318 | break; |
| 319 | case SetCombineOperationcxx . . $ SetCombineOperation#::Unioncxx . . $ SetCombineOperation#Union.: |
| 320 | output_set.mergecxx . . $ std/set#merge(77a44e9216a4a212).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(next_input)); |
| 321 | break; |
| 322 | case SetCombineOperationcxx . . $ SetCombineOperation#::SetDifferencecxx . . $ SetCombineOperation#SetDifference.: |
| 323 | for (element_tcxx . . $ element_t# const& el : next_input) |
| 324 | output_set.erasecxx . . $ std/set#erase(3a53bfe100edb289).(el); |
| 325 | break; |
| 326 | default: // can never happen |
| 327 | assertcxx . . $ `/usr/include/assert.h:102:11`!(false && "Internal error, a set comination type is not covered."); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /** |
| 332 | \brief Move `formula_it` forward so it shows to non-whitespace (= tab, space, new line). |
| 333 | \return `true` if next character is valid, `false` if string is at end (= null character) |
| 334 | */ |
| 335 | bool goto_next_nonwhitespacecxx . . $ goto_next_nonwhitespace(53f75cbb86d2cb2).(stdcxx . . $ std/::stringcxx . . $ std/string#::const_iteratorcxx . . $ std/__cxx11/basic_string#const_iterator#& formula_it) |
| 336 | { |
| 337 | while (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it && stdcxx . . $ std/::isspacecxx . . $ std/isspace(a1851578aea3f541).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it)) |
| 338 | ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).formula_it; |
| 339 | return *cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it; |
| 340 | } |
| 341 | |
| 342 | set_tcxx . . $ set_t# evaluate_formulacxx . . $ evaluate_formula(e474eca3f6cdac01).(stdcxx . . $ std/::stringcxx . . $ std/string#::const_iteratorcxx . . $ std/__cxx11/basic_string#const_iterator#& formula_it, bool within_brackets = false); // needed forward declaration |
| 343 | |
| 344 | /** |
| 345 | \brief Calculate next complete term represented by input stream index or by term in brackets. |
| 346 | \details E. g. "3 & 4" results in set of input stream 3 and `formula_it` is moved to character after '&', |
| 347 | whereas "(3 & 4)" would include calculation of intersection and set `formula_it` to end of string. |
| 348 | A term is always expected, i. e. formula must start with number or opening bracket and an empty string triggers an exception. |
| 349 | \param formula_it iterator of formula where evaluation shall start, is moved forward to next unread character |
| 350 | \return set of evaluated term |
| 351 | */ |
| 352 | set_tcxx . . $ set_t# evaluate_next_termcxx . . $ evaluate_next_term(de89eaeddc4ba0db).(stdcxx . . $ std/::stringcxx . . $ std/string#::const_iteratorcxx . . $ std/__cxx11/basic_string#const_iterator#& formula_it) |
| 353 | { |
| 354 | set_tcxx . . $ set_t# resultcxx . . $ std/set#set(49f6e7a06ebc5aa8).; |
| 355 | if (!goto_next_nonwhitespacecxx . . $ goto_next_nonwhitespace(53f75cbb86d2cb2).(formula_it)) |
| 356 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("a term is missing"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 357 | if (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it == '(') |
| 358 | { |
| 359 | ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).formula_it; |
| 360 | result =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). evaluate_formulacxx . . $ evaluate_formula(e474eca3f6cdac01).(formula_it, true); |
| 361 | } |
| 362 | else |
| 363 | { |
| 364 | stdcxx . . $ std/::stringcxx . . $ std/string#::size_typecxx . . $ std/__cxx11/basic_string#size_type# number_read_chars; |
| 365 | unsigned long inputstream_index; |
| 366 | try |
| 367 | { |
| 368 | inputstream_index = stdcxx . . $ std/::stoulcxx . . $ std/__cxx11/stoul(83a5b6ad71410cff).(&cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it, &number_read_chars); // throws std::invalid_argument or std::out_of_range |
| 369 | } |
| 370 | catch (stdcxx . . $ std/::logic_errorcxx . . $ std/logic_error# const&) |
| 371 | { |
| 372 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("a positive integer or opening bracket is expected"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 373 | } |
| 374 | if (inputstream_index < 1 || inputstream_index > input_filenamescxx . . $ input_filenames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) |
| 375 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("input stream indices should be in the range from 1 to " +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(354ce04007c9ea85).(input_filenamescxx . . $ input_filenames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).())); |
| 376 | result =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(input_filenamescxx . . $ input_filenames.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).inputstream_index - 1]); |
| 377 | formula_it +=cxx . . $ __gnu_cxx/__normal_iterator#`operator+=`(b47b0e78c70c3399). number_read_chars; |
| 378 | } |
| 379 | return resultcxx . . $ std/set#set(f3bfeaebad815056).; |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | \brief Calculate resulting set from formula. |
| 384 | \param formula_it iterator of formula where evaluation shall start, is moved forward to next unread character |
| 385 | \param within_brackets for recursively evaluating "subformulas" within brackets; when true, stops directly after closing bracket and returns |
| 386 | \return set of evaluated formula |
| 387 | */ |
| 388 | set_tcxx . . $ set_t# evaluate_formulacxx . . $ evaluate_formula(e474eca3f6cdac01).(stdcxx . . $ std/::stringcxx . . $ std/string#::const_iteratorcxx . . $ std/__cxx11/basic_string#const_iterator#& formula_it, bool within_brackets) |
| 389 | { |
| 390 | // STEP A: a formula contains at least one term, so read it |
| 391 | set_tcxx . . $ set_t# result = evaluate_next_termcxx . . $ evaluate_next_term(de89eaeddc4ba0db).(formula_it); |
| 392 | |
| 393 | class OperationSetPaircxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair# |
| 394 | { |
| 395 | public: |
| 396 | SetCombineOperationcxx . . $ SetCombineOperation# operationcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#operation.; |
| 397 | set_tcxx . . $ set_t# setcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#set.; |
| 398 | }; |
| 399 | stdcxx . . $ std/::stackcxx . . $ std/stack#<OperationSetPaircxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#> op_set_pairscxx . . $ std/stack#stack(49f6e7a06ebc5aa8).; |
| 400 | auto shorten_stack = [&]() // remove top element of stack while letting total value of all operations unchanged |
| 401 | { |
| 402 | OperationSetPaircxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair# top_term = stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(op_set_pairs.topcxx . . $ std/stack#top(d8c1a3bbdff15733).()); |
| 403 | op_set_pairs.popcxx . . $ std/stack#pop(49f6e7a06ebc5aa8).(); |
| 404 | set_tcxx . . $ set_t#& base_term = (op_set_pairs.emptycxx . . $ std/stack#empty(50ce9a9e25b4a850).() ? result : op_set_pairs.topcxx . . $ std/stack#top(d8c1a3bbdff15733).().setcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#set.); |
| 405 | combine_with_next_setcxx . . $ combine_with_next_set(6ecbcf41c7462268).(base_term, top_term.operationcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#operation., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(top_term.setcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#set.)); |
| 406 | }; |
| 407 | |
| 408 | while (goto_next_nonwhitespacecxx . . $ goto_next_nonwhitespace(53f75cbb86d2cb2).(formula_it)) |
| 409 | { |
| 410 | // either STEP B: return from recursive call when end of subformula within brackets is reached |
| 411 | if (*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it == ')') |
| 412 | { |
| 413 | if (!within_brackets) |
| 414 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("found closing bracket without opening bracket"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 415 | ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).formula_it; |
| 416 | within_brackets = false; |
| 417 | break; |
| 418 | } |
| 419 | |
| 420 | // or STEP C |
| 421 | // STEP C-1: parse operation |
| 422 | stdcxx . . $ std/::mapcxx . . $ std/map#<char, SetCombineOperationcxx . . $ SetCombineOperation#> const combineoperation_by_operator = {cxx . . $ std/map#map(7786ef3e167e36fa). |
| 423 | {'&', SetCombineOperationcxx . . $ SetCombineOperation#::Intersectioncxx . . $ SetCombineOperation#Intersection.}, |
| 424 | {'^', SetCombineOperationcxx . . $ SetCombineOperation#::SymmetricDiffcxx . . $ SetCombineOperation#SymmetricDiff.}, |
| 425 | {'|', SetCombineOperationcxx . . $ SetCombineOperation#::Unioncxx . . $ SetCombineOperation#Union.}, |
| 426 | {'-', SetCombineOperationcxx . . $ SetCombineOperation#::SetDifferencecxx . . $ SetCombineOperation#SetDifference.} |
| 427 | }; |
| 428 | stdcxx . . $ std/::mapcxx . . $ std/map#<char, SetCombineOperation>::const_iteratorcxx . . $ std/map#const_iterator# next_operation = combineoperation_by_operator.findcxx . . $ std/map#find(7b3585bb5da8f7d).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).formula_it); |
| 429 | if (next_operation ==cxx . . $ std/`operator==`(a84eb84a7a5e8237). combineoperation_by_operator.endcxx . . $ std/map#end(b953fec338ad1a3b).()) |
| 430 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("an operator like &, |, ^, or - is missing"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 431 | ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).formula_it; |
| 432 | |
| 433 | // STEP C-2: parse value |
| 434 | set_tcxx . . $ set_t# next_set = evaluate_next_termcxx . . $ evaluate_next_term(de89eaeddc4ba0db).(formula_it); |
| 435 | |
| 436 | // STEP C-3: handle new value-operation-pair |
| 437 | if (next_operation->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second. == SetCombineOperationcxx . . $ SetCombineOperation#::Intersectioncxx . . $ SetCombineOperation#Intersection.) // has highest priority, calculate immediately for better performance |
| 438 | { |
| 439 | set_tcxx . . $ set_t#& base_term = (op_set_pairs.emptycxx . . $ std/stack#empty(50ce9a9e25b4a850).() ? result : op_set_pairs.topcxx . . $ std/stack#top(d8c1a3bbdff15733).().setcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#set.); |
| 440 | combine_with_next_setcxx . . $ combine_with_next_set(6ecbcf41c7462268).(base_term, next_operation->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second., stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(next_set)); |
| 441 | } |
| 442 | else // try to merge elements from stack when their operation is as least as important as current operation |
| 443 | { |
| 444 | while (!op_set_pairs.emptycxx . . $ std/stack#empty(50ce9a9e25b4a850).() && next_operation->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second. >= op_set_pairs.topcxx . . $ std/stack#top(d8c1a3bbdff15733).().operationcxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#operation.) |
| 445 | shorten_stack(cxx . . $ evaluate_formula(e474eca3f6cdac01).$anonymous_type_1#`operator()`(83f5f38750778ac8).); |
| 446 | op_set_pairs.pushcxx . . $ std/stack#push(bfe8a576267fe2ec).(OperationSetPaircxx . . $ evaluate_formula(e474eca3f6cdac01).OperationSetPair#{.operation = next_operation->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second., .set = stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(next_set)}); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (within_brackets) |
| 451 | throw invalid_formula_exceptioncxx . . $ invalid_formula_exception#("a closing bracket is missing"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 452 | |
| 453 | // STEP D: handle remaining stack of operations and sets |
| 454 | while (!op_set_pairs.emptycxx . . $ std/stack#empty(50ce9a9e25b4a850).()) |
| 455 | shorten_stack(cxx . . $ evaluate_formula(e474eca3f6cdac01).$anonymous_type_1#`operator()`(83f5f38750778ac8).); |
| 456 | |
| 457 | return resultcxx . . $ std/set#set(f3bfeaebad815056).; |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | \brief Main function of program: take command line options and arguments and execute output. |
| 462 | \throws std::runtime_error |
| 463 | */ |
| 464 | int execute_setopcxx . . $ execute_setop(afcd3168fc1188a4).(int argc, char* argv[]) |
| 465 | { |
| 466 | // needed variables, mainly options and arguments from command line |
| 467 | bool quiet, verbose, ignore_case; |
| 468 | stdcxx . . $ std/::stringcxx . . $ std/string# formulacxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., inputstream_for_set_comparisoncxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., separator_formatcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391)., element_formatcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 469 | element_tcxx . . $ element_t# element_for_contains_checkcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).; |
| 470 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> combine_parameterscxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., setdifference_filenamescxx . . $ std/vector#vector(49f6e7a06ebc5aa8)., output_parameterscxx . . $ std/vector#vector(49f6e7a06ebc5aa8).; |
| 471 | |
| 472 | |
| 473 | // PARSE COMMAND LINE |
| 474 | |
| 475 | namespace po = boostcxx . . $ boost/::program_options; |
| 476 | po::options_descriptioncxx . . $ boost/program_options/options_description# visible_optionscxx . . $ boost/program_options/options_description#options_description(57e0960c78011e90).("Options"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 477 | visible_options.add_optionscxx . . $ boost/program_options/options_description#add_options(ca8b5692d6dd720e).() |
| 478 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."help", "produce this help message and exit") |
| 479 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."version", "output name and version") |
| 480 | |
| 481 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."ignore-case,C", po::bool_switchcxx . . $ boost/program_options/bool_switch(6ac09256a017dac0).(&ignore_case)->default_valuecxx . . $ boost/program_options/typed_value#default_value(902a3340f3c7bcb8).(false), "handle input elements case-insensitive") |
| 482 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."include-empty", po::bool_switchcxx . . $ boost/program_options/bool_switch(6ac09256a017dac0).(&input_optscxx . . $ input_opts..include_empty_elementscxx . . $ InputOptions#include_empty_elements.)->default_valuecxx . . $ boost/program_options/typed_value#default_value(902a3340f3c7bcb8).(false), "don’t ignore empty elements (these can come from empty lines, trimming, etc.)") |
| 483 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."input-separator,n", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&separator_format), "describe the form of an input separator as regular expression in ECMAScript syntax; " |
| 484 | "defaults to new line only if --input-element is not present; i. e. don’t forget to include the new line character \\n when you set the input element manually, when desired!") |
| 485 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."input-element,l", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&element_format), "describe the form of input elements as regular expression in ECMAScript syntax") |
| 486 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."output-separator,o", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&input_optscxx . . $ input_opts..output_separatorcxx . . $ InputOptions#output_separator.)->default_valuecxx . . $ boost/program_options/typed_value#default_value(902a3340f3c7bcb8).("\\n"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).), "string for separating output elements; escape sequences are allowed") |
| 487 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."trim,t", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&input_optscxx . . $ input_opts..trim_characterscxx . . $ InputOptions#trim_characters.), "trim all given characters at beginning and end of elements (escape sequences allowed)") |
| 488 | |
| 489 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."combine", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&combine_parameters)->multitokencxx . . $ boost/program_options/typed_value#multitoken(e3bd407297ed8dca).()/*->default_value("union")*/, "define combination operation applied to given input streams; " |
| 490 | "possible parameters are 'union' (default), 'intersection', 'symmetric-difference', and 'formula <value>'") |
| 491 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."subtract", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&setdifference_filenames)->multitokencxx . . $ boost/program_options/typed_value#multitoken(e3bd407297ed8dca).(), "subtract all elements of all given streams from output set") |
| 492 | |
| 493 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."output", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&output_parameters)->multitokencxx . . $ boost/program_options/typed_value#multitoken(e3bd407297ed8dca).()/*->default_value("set")*/, "whether to output determined set or a certain information of this set instead; " |
| 494 | "possible parameters are:\n" |
| 495 | "set (default): stream all output elements\n" |
| 496 | "count: just output number of (different) elements, don’t list them\n" |
| 497 | "is-empty: check if resulting set is empty\n" |
| 498 | "contains <element-string>: check if given element is contained in set\n" |
| 499 | "equals <input-stream>: check set equality, i. e. check if output corresponds with content of <input-stream>\n" |
| 500 | "has-subset <input-stream>: check if content of <input-stream> is subset of output set\n" |
| 501 | "has-superset <input-stream>: check if content of <input-stream> is superset of output set") |
| 502 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."quiet", po::bool_switchcxx . . $ boost/program_options/bool_switch(6ac09256a017dac0).(&quiet)->default_valuecxx . . $ boost/program_options/typed_value#default_value(902a3340f3c7bcb8).(false), |
| 503 | "suppress all output messages in case of special queries (e. g. when check if element is contained in set)"); |
| 504 | |
| 505 | po::options_descriptioncxx . . $ boost/program_options/options_description# invisible_optionscxx . . $ boost/program_options/options_description#options_description(57e0960c78011e90).("Invisible options"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 506 | invisible_options.add_optionscxx . . $ boost/program_options/options_description#add_options(ca8b5692d6dd720e).()(cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."inputfile", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&input_filenamescxx . . $ input_filenames.)->composingcxx . . $ boost/program_options/typed_value#composing(e3bd407297ed8dca).(), ""); |
| 507 | po::options_descriptioncxx . . $ boost/program_options/options_description# deprecated_optionscxx . . $ boost/program_options/options_description#options_description(57e0960c78011e90).("Deprecated options"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 508 | deprecated_options.add_optionscxx . . $ boost/program_options/options_description#add_options(ca8b5692d6dd720e).() |
| 509 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."union,u", "") |
| 510 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."intersection,i", "") |
| 511 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."symmetric-difference,s", "") |
| 512 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."difference,d", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&setdifference_filenames)->composingcxx . . $ boost/program_options/typed_value#composing(e3bd407297ed8dca).(), "") |
| 513 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."verbose", "") |
| 514 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."count,#", "") |
| 515 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(2537e97a627b1340)."is-empty", "") |
| 516 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."contains,c", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&element_for_contains_check), "") |
| 517 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."equal,e", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&inputstream_for_set_comparison), "") |
| 518 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."subset,b", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&inputstream_for_set_comparison), "") |
| 519 | (cxx . . $ boost/program_options/options_description_easy_init#`operator()`(72e6b0c223f9f4db)."superset,p", po::valuecxx . . $ boost/program_options/value(86ffcdfc62d4bfa1).(&inputstream_for_set_comparison), ""); |
| 520 | po::options_descriptioncxx . . $ boost/program_options/options_description# all_optionscxx . . $ boost/program_options/options_description#options_description(57e0960c78011e90).("All options"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 521 | all_options.addcxx . . $ boost/program_options/options_description#add(5914956174c23f54).(invisible_options).addcxx . . $ boost/program_options/options_description#add(5914956174c23f54).(deprecated_options).addcxx . . $ boost/program_options/options_description#add(5914956174c23f54).(visible_options); |
| 522 | |
| 523 | po::variables_mapcxx . . $ boost/program_options/variables_map# opt_mapcxx . . $ boost/program_options/variables_map#variables_map(49f6e7a06ebc5aa8).; |
| 524 | po::positional_options_descriptioncxx . . $ boost/program_options/positional_options_description# argumentscxx . . $ boost/program_options/positional_options_description#positional_options_description(49f6e7a06ebc5aa8).; |
| 525 | arguments.addcxx . . $ boost/program_options/positional_options_description#add(aa9117c60b8f3865).("inputfile", -1); |
| 526 | try |
| 527 | { |
| 528 | po::parsed_optionscxx . . $ boost/program_options/parsed_options# parsed = pocxx . . $ boost/program_options/basic_command_line_parser#basic_command_line_parser(ca99421651bc14a1).::command_line_parsercxx . . $ boost/program_options/command_line_parser#(argc, argv).optionscxx . . $ boost/program_options/basic_command_line_parser#options(c4407f35e84a1420).(all_options).positionalcxx . . $ boost/program_options/basic_command_line_parser#positional(d0c16414fc52e1f3).(arguments).runcxx . . $ boost/program_options/basic_command_line_parser#run(ef9bbd0254819898).(); |
| 529 | po::storecxx . . $ boost/program_options/store(606417169b2d1a24).(parsed, opt_map); |
| 530 | po::notifycxx . . $ boost/program_options/notify(a895ac20828b3081).(opt_map); |
| 531 | } |
| 532 | catch (po::errorcxx . . $ boost/program_options/error# const& poexc) |
| 533 | { |
| 534 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(stdcxx . . $ std/::stringcxx . . $ std/string#("failed to process command line parameters: ") +cxx . . $ std/operator+(900ec9581c410ad9). poexc.whatcxx . . $ std/logic_error#what(ba32b354807b2b81).() +cxx . . $ std/operator+(900ec9581c410ad9). |
| 535 | "\nTry calling the program with option '--help'."); |
| 536 | } |
| 537 | |
| 538 | if (opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("help"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 539 | { |
| 540 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). |
| 541 | "Apply set operations like union, intersection, or set difference to input files " |
| 542 | "and print resulting set (sorted and with unique string elements) to standard output or give answer to special queries like number of elements.\n\n" |
| 543 | |
| 544 | "Usage:\n" |
| 545 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! " [input-stream]* [-C] [--include-empty] [--input-separator <value>] [--input-element <value>] [--trim <value>] " |
| 546 | "[--combine (union|intersection|symmetric-difference|formula <value>)] [--subtract [input-stream]*] " |
| 547 | "[--output (set|count|is-empty|contains <value>|equals <input-stream>|has-subset <input-stream>|has-superset <input-stream>)] " |
| 548 | "[--output-separator <value>] [--quiet]\n\n" |
| 549 | |
| 550 | <<cxx . . $ boost/program_options/`operator<<`(1b5195852e4aaab0). visible_options |
| 551 | |
| 552 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "No input filename or '-' is equal to reading from standard input. When an input stream occurs multiple times in the calling command, " |
| 553 | "it is read only once and cached.\n\n" |
| 554 | |
| 555 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "The sequence of events of " PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! " is as follows:\n" |
| 556 | "At first, all input files are parsed and combined according to the --combine option. " |
| 557 | "After that, all inputs from option --subtract are parsed and removed from result of first step. " |
| 558 | "Finally, the desired output given from option --output is printed to screen: " |
| 559 | "the set itself, or its number of elements, or a comparison to another set etc.\n\n" |
| 560 | |
| 561 | "The combination type 'formula' needs an additional string mainly consisting of positive integers and combining operators. " |
| 562 | "The integers 1, 2, etc. represent the first, second, etc. input stream; possible operators are '&' for intersection, " |
| 563 | "'^' for symmetric difference, '|' for union, and '-' for set difference. At the moment, they are prioritized in that order (i. e. &, ^, |, -), " |
| 564 | "but this may change in the future. Use brackets for being explicit about the order of evaluation. Example: " |
| 565 | "--combine formula '(1 | 2) & 3' unites first and second input stream and intersects the result with third input stream.\n\n" |
| 566 | |
| 567 | "By default each line of an input stream is considered to be an element, you can change this by defining regular expressions " |
| 568 | "within the options --input-separator or --input-element. When using both, the input stream is first split according to the separator " |
| 569 | "and after that filtered by the desired input element form. " |
| 570 | "After finding the elements they are finally trimmed according to the argument given with --trim.\n" |
| 571 | "The option --ignore-case lets you treat Word and WORD equal, only the first occurrence of all input streams is considered. " |
| 572 | "Note that --ignore-case does not affect the regular expressions used in --input-separator and --input-element.\n\n" |
| 573 | "When describing strings and characters for the output separator or for the option --trim you can use escape sequences like " R"(\t, \n, \" and \'. )" |
| 574 | "But be aware that some of these sequences " R"((especially \\ and \"))" " might be interpreted by your shell before passing the string to " |
| 575 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! ". In that case you have to use " R"(\\\\ respectively \\\" just for describing a \ or a ". )" |
| 576 | "You can check your shell’s behavior with\n" |
| 577 | R"(echo "\\ and \"")" "\n\n" |
| 578 | "Special boolean queries (e. g. check if element is contained in set) return exit code EXIT_SUCCESS (= " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!) |
| 579 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). ") when the answer is 'yes' and otherwise (e. g. element not contained in set) an exit code that is guaranteed to be unequal " |
| 580 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "to EXIT_SUCCESS and to EXIT_FAILURE (= " <<cxx . . $ std/`operator<<`(88df5bef833f7f83). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!) <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "). This way, " PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! " can be used in the shell. " |
| 581 | <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "With option --quiet a verbose result message is omitted for boolean queries.\n\n" |
| 582 | |
| 583 | "Examples:\n" |
| 584 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! R"( A.txt --subtract B.txt --output contains ":fooBAR-:" --trim ":-\t" --ignore-case)" |
| 585 | "\n\t" "case-insensitive check if element 'foobar' is contained in A minus B\n" |
| 586 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! R"( A.txt - B.txt --combine intersection --input-element "\d+")" |
| 587 | "\n\t" "output intersection of console, A, and B, where elements are recognized as strings of digits with at least one character; " |
| 588 | "i. e. elements are non-negative integers\n" |
| 589 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! " A.txt B.txt --combine symmetric-difference --input-separator [[:space:]-]" |
| 590 | "\n\t" "find all elements contained in either A or B, not both, where a whitespace" R"( (i. e. \v \t \n \r \f or space) )" |
| 591 | "or a minus is interpreted as a separator between elements\n\n" |
| 592 | |
| 593 | "For bug reports, use the issue tracker at\n" |
| 594 | "https://github.com/phisigma/setop.\n"; |
| 595 | |
| 596 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 597 | } |
| 598 | |
| 599 | for (boostcxx . . $ boost/::shared_ptrcxx . . $ boost/shared_ptr#<po::option_descriptioncxx . . $ boost/program_options/option_description#> const& deprecated_optdesc : deprecated_options.optionscxx . . $ boost/program_options/options_description#options(467074fe18ccb1cd).()) |
| 600 | { |
| 601 | if (opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).(deprecated_optdesc->cxx . . $ boost/shared_ptr#`operator->`(b6f31670a60786f7).long_namecxx . . $ boost/program_options/option_description#long_name(f4fff0029955a25f).())) |
| 602 | print_warningcxx . . $ print_warning(9c546c94e5fcce4e).("option '--" +cxx . . $ std/operator+(42c652dfebe55ad7). deprecated_optdesc->cxx . . $ boost/shared_ptr#`operator->`(b6f31670a60786f7).long_namecxx . . $ boost/program_options/option_description#long_name(f4fff0029955a25f).() +cxx . . $ std/operator+(900ec9581c410ad9). "' is deprecated and will be removed in later versions of " |
| 603 | PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! +cxx . . $ std/operator+(900ec9581c410ad9). "."); |
| 604 | } |
| 605 | |
| 606 | if (opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("version"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 607 | { |
| 608 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). " " <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). PROGRAM_VERSIONcxx . . $ `src/main.cpp:44:9`! <<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a). stdcxx . . $ std/::endlcxx . . $ std/endl(345bf97a19cc83a9).; |
| 609 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 610 | } |
| 611 | |
| 612 | |
| 613 | // CHECK PLAUSIBILITY OF INPUT OPTIONS AND ARGUMENTS AND HANDLE THESE OPTIONS |
| 614 | |
| 615 | verbose = opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("verbose"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 616 | if (quiet & verbose) |
| 617 | { |
| 618 | print_warningcxx . . $ print_warning(9c546c94e5fcce4e).("the options '--quiet' and '--verbose' must not be combined. Both ignored."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 619 | quiet = verbose = false; |
| 620 | } |
| 621 | |
| 622 | // report and delete redundant entries for set differences |
| 623 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, int> setdifference_streams_usagecountcxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 624 | for (stdcxx . . $ std/::stringcxx . . $ std/string# const& inputstream : setdifference_filenames) |
| 625 | ++setdifference_streams_usagecount[cxx . . $ std/map#`operator[]`(bbd415b616967878).inputstream]; |
| 626 | for (auto const& [setdifference_stream, usage_count] : setdifference_streams_usagecount) |
| 627 | { |
| 628 | if (usage_count > 1) |
| 629 | { |
| 630 | print_warningcxx . . $ print_warning(9c546c94e5fcce4e).("option '--" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::stringcxx . . $ std/string#(opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("subtract"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? "subtract" : "difference") +cxx . . $ std/operator+(900ec9581c410ad9). "' contains input stream '" |
| 631 | +cxx . . $ std/operator+(db5dc2ea912c6495). setdifference_stream +cxx . . $ std/operator+(900ec9581c410ad9). "' multiple times. Redundant entries ignored."); |
| 632 | for (int curr_redundant_entry_index = 1; curr_redundant_entry_index < usage_count; ++curr_redundant_entry_index) |
| 633 | { |
| 634 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<std::string>::const_iteratorcxx . . $ std/vector#const_iterator# found_redundant_entry = |
| 635 | stdcxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640).::rangescxx . . $ std/ranges/::find_lastcxx . . $ std/ranges/find_last.(cxx . . $ std/ranges/__find_last_fn#`operator()`(9f38e3d65ff2b9ac).setdifference_filenames, setdifference_stream).begincxx . . $ std/ranges/subrange#begin(8f5363d873dd4781).(); // remove from back so order stays preserved |
| 636 | assertcxx . . $ `/usr/include/assert.h:102:11`!(found_redundant_entry != setdifference_filenames.cend() && "Internal error, handling of multiple set difference streams is faulty."); |
| 637 | setdifference_filenames.erasecxx . . $ std/vector#erase(c18b40a49e8301f6).(found_redundant_entry); |
| 638 | } |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | if (opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("combine"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("union"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("intersection"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("symmetric-difference"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) > 1) |
| 643 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("the options '--combine', '--union', '--intersection', and '--symmetric difference' must not be combined."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 644 | SetConcatcxx . . $ SetConcat# setconcat_type; |
| 645 | if (opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("combine"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).)) |
| 646 | { |
| 647 | int number_parameters = combine_parameters.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 648 | if (number_parameters < 1) |
| 649 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("option '--combine' needs at least one parameter."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 650 | |
| 651 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, SetConcatcxx . . $ SetConcat#> concattype_by_parameter = |
| 652 | {cxx . . $ std/map#map(7786ef3e167e36fa).{"union", SetConcatcxx . . $ SetConcat#::UNIONcxx . . $ SetConcat#UNION.}, {"intersection", SetConcatcxx . . $ SetConcat#::INTERSECTIONcxx . . $ SetConcat#INTERSECTION.}, |
| 653 | {"symmetric-difference", SetConcatcxx . . $ SetConcat#::SYM_DIFFERENCEcxx . . $ SetConcat#SYM_DIFFERENCE.}, {"formula", SetConcatcxx . . $ SetConcat#::FORMULAcxx . . $ SetConcat#FORMULA.}}; |
| 654 | stdcxx . . $ std/::stringcxx . . $ std/string# const& combine_type_str = combine_parameters.frontcxx . . $ std/vector#front(6baabfa6fc7b3a8e).(); |
| 655 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, SetConcat>::const_iteratorcxx . . $ std/map#const_iterator# found_concattype_it = concattype_by_parametercxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..findcxx . . $ std/map#find(36f8d56706583706).(combine_type_str); |
| 656 | if (found_concattype_it ==cxx . . $ std/`operator==`(a84eb84a7a5e8237). concattype_by_parametercxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..endcxx . . $ std/map#end(7e4de33083b6e738).()) |
| 657 | return print_unsupported_parameter_errorcxx . . $ print_unsupported_parameter_error(ff1c98e35c114d02).("combine"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., combine_type_str); |
| 658 | else |
| 659 | setconcat_type = found_concattype_it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second.; |
| 660 | |
| 661 | int needed_number_parameters = setconcat_type == SetConcatcxx . . $ SetConcat#::FORMULAcxx . . $ SetConcat#FORMULA. ? 2 : 1; |
| 662 | if (number_parameters != needed_number_parameters) |
| 663 | { |
| 664 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(number_parameters < needed_number_parameters ? |
| 665 | "option '--combine' with parameter '" +cxx . . $ std/operator+(42c652dfebe55ad7). combine_type_str +cxx . . $ std/operator+(900ec9581c410ad9). "' needs an additional parameter." : |
| 666 | "option '--combine' with parameter '" +cxx . . $ std/operator+(42c652dfebe55ad7). combine_type_str +cxx . . $ std/operator+(900ec9581c410ad9). "' does not need additional parameters. Found unneeded value '" +cxx . . $ std/operator+(db5dc2ea912c6495). combine_parameters[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2] +cxx . . $ std/operator+(900ec9581c410ad9). "'."); |
| 667 | } |
| 668 | if (number_parameters == 2) |
| 669 | { |
| 670 | formula =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). combine_parameters[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1]; |
| 671 | |
| 672 | // analyze formula for missing input stream numbers and setup input stream usage counts |
| 673 | stdcxx . . $ std/::regexcxx . . $ std/__cxx11/regex# integer_regexcxx . . $ std/__cxx11/basic_regex#basic_regex(d1adbc785ae219ab).("[[:digit:]]+"); |
| 674 | stdcxx . . $ std/::mapcxx . . $ std/map#<unsigned long, int> inputstream_number_to_usagecountcxx . . $ std/map#map(49f6e7a06ebc5aa8).; |
| 675 | stdcxx . . $ std/::sregex_iteratorcxx . . $ std/__cxx11/sregex_iterator# curr_found_integercxx . . $ std/__cxx11/regex_iterator#regex_iterator(7a304ee62df067c3).(formulacxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), formulacxx . . $ __gnu_cxx/__normal_iterator#__normal_iterator(459a7e7b9fbe7640)..endcxx . . $ std/__cxx11/basic_string#end(fd29ebd65481b919).(), integer_regex); |
| 676 | for (; curr_found_integer != stdcxx . . $ std/__cxx11/regex_iterator#regex_iterator(49f6e7a06ebc5aa8).::sregex_iteratorcxx . . $ std/__cxx11/sregex_iterator#() /*== end*/; ++cxx . . $ std/__cxx11/regex_iterator#operator++(ebb65f41f26781c).curr_found_integer) |
| 677 | { |
| 678 | ++inputstream_number_to_usagecount[cxx . . $ std/map#`operator[]`(da459db78e6e18a3).stdcxx . . $ std/::stoulcxx . . $ std/__cxx11/stoul(83a5b6ad71410cff).(curr_found_integer->cxx . . $ std/__cxx11/regex_iterator#`operator->`(4ab9d54625d5896a).strcxx . . $ std/__cxx11/match_results#str(7bef7c5eeb31a273).())]; |
| 679 | } |
| 680 | |
| 681 | if (inputstream_number_to_usagecount.begincxx . . $ std/map#begin(7e4de33083b6e738).()->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).firstcxx . . $ std/pair#first. > 0 && inputstream_number_to_usagecount.rbegincxx . . $ std/map#rbegin(58dac208a2e4e5b4).()->cxx . . $ std/reverse_iterator#`operator->`(a68f0626e749d9f6).firstcxx . . $ std/pair#first. <= input_filenamescxx . . $ input_filenames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()) |
| 682 | // out-of-range error is handled later (to show exact position in formula), just exclude this case here to avoid error on array access |
| 683 | { |
| 684 | for (stdcxx . . $ std/::size_tcxx . . $ std/size_t# expected_inputstream_index = 0; expected_inputstream_index < input_filenamescxx . . $ input_filenames..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); ++expected_inputstream_index) |
| 685 | if (!inputstream_number_to_usagecount.containscxx . . $ std/map#contains(8877ebe272b9620d).(expected_inputstream_index + 1)) |
| 686 | print_warningcxx . . $ print_warning(9c546c94e5fcce4e).("the number " +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(354ce04007c9ea85).(expected_inputstream_index + 1) +cxx . . $ std/operator+(900ec9581c410ad9). " is not used in the formula " |
| 687 | "and thus the input stream '" +cxx . . $ std/operator+(db5dc2ea912c6495). input_filenamescxx . . $ input_filenames.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).expected_inputstream_index] +cxx . . $ std/operator+(900ec9581c410ad9). "' is ignored."); |
| 688 | |
| 689 | for (auto const& [inputstream_number, usagecount] : inputstream_number_to_usagecount) |
| 690 | inputstream_to_usagecountcxx . . $ inputstream_to_usagecount.[cxx . . $ std/map#`operator[]`(bbd415b616967878).input_filenamescxx . . $ input_filenames.[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).inputstream_number - 1]] += usagecount; |
| 691 | } |
| 692 | for (stdcxx . . $ std/::stringcxx . . $ std/string# const& setdifference_filename : setdifference_filenames) |
| 693 | ++inputstream_to_usagecountcxx . . $ inputstream_to_usagecount.[cxx . . $ std/map#`operator[]`(bbd415b616967878).setdifference_filename]; |
| 694 | if (!inputstream_for_set_comparison.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 695 | ++inputstream_to_usagecountcxx . . $ inputstream_to_usagecount.[cxx . . $ std/map#`operator[]`(bbd415b616967878).inputstream_for_set_comparison]; |
| 696 | } |
| 697 | } |
| 698 | else |
| 699 | { |
| 700 | setconcat_type = |
| 701 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("intersection"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetConcatcxx . . $ SetConcat#::INTERSECTIONcxx . . $ SetConcat#INTERSECTION. : |
| 702 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("symmetric-difference"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetConcatcxx . . $ SetConcat#::SYM_DIFFERENCEcxx . . $ SetConcat#SYM_DIFFERENCE. : |
| 703 | SetConcatcxx . . $ SetConcat#::UNIONcxx . . $ SetConcat#UNION.; |
| 704 | } |
| 705 | |
| 706 | if (opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("difference"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("subtract"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) > 1) |
| 707 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("the options '--difference' and '--subtract' must not be combined."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 708 | |
| 709 | if (opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("count"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("is-empty"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("subset"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) |
| 710 | + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("superset"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("contains"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) + opt_map.countcxx . . $ std/map#count(ea780b5adf43227).("equal"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) > 1) |
| 711 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("the options '--output', '--count', '--is-empty', '--subset', '--superset', '--contains', and '--equal' must not be combined."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 712 | SetQuerycxx . . $ SetQuery# output_type; |
| 713 | bool modern_outputoption_used = opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 714 | if (modern_outputoption_used) |
| 715 | { |
| 716 | int number_parameters = output_parameters.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).(); |
| 717 | if (number_parameters < 1) |
| 718 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("option '--output' needs at least one parameter."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 719 | |
| 720 | stdcxx . . $ std/::mapcxx . . $ std/map#<stdcxx . . $ std/::stringcxx . . $ std/string#, SetQuerycxx . . $ SetQuery#> outputtype_by_parameter = |
| 721 | {cxx . . $ std/map#map(7786ef3e167e36fa).{"set", SetQuerycxx . . $ SetQuery#::RETURN_SETcxx . . $ SetQuery#RETURN_SET.}, {"count", SetQuerycxx . . $ SetQuery#::CARDINALITYcxx . . $ SetQuery#CARDINALITY.}, {"is-empty", SetQuerycxx . . $ SetQuery#::ISEMPTYcxx . . $ SetQuery#ISEMPTY.}, {"contains", SetQuerycxx . . $ SetQuery#::CONTAINS_ELEMENTcxx . . $ SetQuery#CONTAINS_ELEMENT.}, |
| 722 | {"equals", SetQuerycxx . . $ SetQuery#::SET_EQUALITYcxx . . $ SetQuery#SET_EQUALITY.}, {"has-subset", SetQuerycxx . . $ SetQuery#::SUBSETcxx . . $ SetQuery#SUBSET.}, {"has-superset", SetQuerycxx . . $ SetQuery#::SUPERSETcxx . . $ SetQuery#SUPERSET.}}; |
| 723 | stdcxx . . $ std/::stringcxx . . $ std/string# const& output_type_str = output_parameters.frontcxx . . $ std/vector#front(6baabfa6fc7b3a8e).(); |
| 724 | stdcxx . . $ std/::mapcxx . . $ std/map#<std::string, SetQuery>::const_iteratorcxx . . $ std/map#const_iterator# found_outputtype_it = outputtype_by_parametercxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..findcxx . . $ std/map#find(36f8d56706583706).(output_type_str); |
| 725 | if (found_outputtype_it ==cxx . . $ std/`operator==`(a84eb84a7a5e8237). outputtype_by_parametercxx . . $ std/_Rb_tree_const_iterator#_Rb_tree_const_iterator(dc529b7882ffd73b)..endcxx . . $ std/map#end(7e4de33083b6e738).()) |
| 726 | return print_unsupported_parameter_errorcxx . . $ print_unsupported_parameter_error(ff1c98e35c114d02).("output"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., output_type_str); |
| 727 | else |
| 728 | output_type = found_outputtype_it->cxx . . $ std/_Rb_tree_const_iterator#`operator->`(8e614c7de0b1573e).secondcxx . . $ std/pair#second.; |
| 729 | |
| 730 | int needed_number_parameters = stdcxx . . $ std/::set({SetQuerycxx . . $ SetQuery#::RETURN_SETcxx . . $ SetQuery#RETURN_SET., SetQuerycxx . . $ SetQuery#::CARDINALITYcxx . . $ SetQuery#CARDINALITY., SetQuerycxx . . $ SetQuery#::ISEMPTYcxx . . $ SetQuery#ISEMPTY.}).containscxx . . $ std/set#contains(8877ebe272b9620d).(output_type) ? 1 : 2; |
| 731 | if (number_parameters != needed_number_parameters) |
| 732 | { |
| 733 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(number_parameters < needed_number_parameters ? |
| 734 | "option '--output' with parameter '" +cxx . . $ std/operator+(42c652dfebe55ad7). output_type_str +cxx . . $ std/operator+(900ec9581c410ad9). "' needs an additional parameter." : |
| 735 | "option '--output' with parameter '" +cxx . . $ std/operator+(42c652dfebe55ad7). output_type_str +cxx . . $ std/operator+(900ec9581c410ad9). "' does not need additional parameters. Found unneeded value '" +cxx . . $ std/operator+(db5dc2ea912c6495). output_parameters[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).2] +cxx . . $ std/operator+(900ec9581c410ad9). "'."); |
| 736 | } |
| 737 | if (number_parameters == 2) |
| 738 | (output_type == SetQuerycxx . . $ SetQuery#::CONTAINS_ELEMENTcxx . . $ SetQuery#CONTAINS_ELEMENT. ? element_for_contains_check : inputstream_for_set_comparison) =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). output_parameters[cxx . . $ std/vector#`operator[]`(81207c53da4b73ce).1]; |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | output_type = |
| 743 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("count"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::CARDINALITYcxx . . $ SetQuery#CARDINALITY. : |
| 744 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("is-empty"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::ISEMPTYcxx . . $ SetQuery#ISEMPTY. : |
| 745 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("subset"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::SUBSETcxx . . $ SetQuery#SUBSET. : |
| 746 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("superset"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::SUPERSETcxx . . $ SetQuery#SUPERSET. : |
| 747 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("contains"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::CONTAINS_ELEMENTcxx . . $ SetQuery#CONTAINS_ELEMENT. : |
| 748 | opt_map.containscxx . . $ std/map#contains(8877ebe272b9620d).("equal"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).) ? SetQuerycxx . . $ SetQuery#::SET_EQUALITYcxx . . $ SetQuery#SET_EQUALITY. : |
| 749 | SetQuerycxx . . $ SetQuery#::RETURN_SETcxx . . $ SetQuery#RETURN_SET.; |
| 750 | } |
| 751 | |
| 752 | // parse escape sequences of trim characters and output separator to "real" characters (e. g. ".\'\\" gets ".'\") |
| 753 | try |
| 754 | { |
| 755 | input_optscxx . . $ input_opts..trim_characterscxx . . $ InputOptions#trim_characters. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). unescape_sequencecxx . . $ unescape_sequence(fd626fc03107dd24).(input_optscxx . . $ input_opts..trim_characterscxx . . $ InputOptions#trim_characters.); |
| 756 | input_optscxx . . $ input_opts..output_separatorcxx . . $ InputOptions#output_separator. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). unescape_sequencecxx . . $ unescape_sequence(fd626fc03107dd24).(input_optscxx . . $ input_opts..output_separatorcxx . . $ InputOptions#output_separator.); |
| 757 | } |
| 758 | catch (stdcxx . . $ std/::invalid_argumentcxx . . $ std/invalid_argument# const& e) |
| 759 | { |
| 760 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(ecxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..whatcxx . . $ std/logic_error#what(ba32b354807b2b81).()); |
| 761 | } |
| 762 | |
| 763 | // check if regexes are ok |
| 764 | // separator "\n" is default when nothing else is given |
| 765 | if (element_format.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).() && separator_format.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 766 | separator_format =cxx . . $ std/__cxx11/basic_string#`operator=`(978ca1133b5f6e74). "\\n"; |
| 767 | for (auto [string_to_parse, resulting_regex_ref] : stdcxx . . $ std/vector#vector(9619226211e5a241).::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string# const&, boostcxx . . $ boost/::regexcxx . . $ boost/regex#&>>{ |
| 768 | {element_format, input_optscxx . . $ input_opts..input_element_regexcxx . . $ InputOptions#input_element_regex.}, |
| 769 | {separator_format, input_optscxx . . $ input_opts..input_separator_regexcxx . . $ InputOptions#input_separator_regex.}}) |
| 770 | { |
| 771 | boostcxx . . $ boost/::regexcxx . . $ boost/regex#::flag_typecxx . . $ boost/basic_regex#flag_type# regex_flags = boostcxx . . $ boost/::regex_constantscxx . . $ boost/regex_constants/::ECMAScriptcxx . . $ boost/regex_constants/ECMAScript. | boostcxx . . $ boost/::regex_constantscxx . . $ boost/regex_constants/::optimizecxx . . $ boost/regex_constants/optimize.; |
| 772 | if (!string_to_parse.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 773 | { |
| 774 | try |
| 775 | { |
| 776 | resulting_regex_ref =cxx . . $ boost/basic_regex#`operator=`(3156bb0d98eb009e). boostcxx . . $ boost/basic_regex#basic_regex(be1e6b5684b9a1d7).::regexcxx . . $ boost/regex#(string_to_parse, regex_flags); |
| 777 | } |
| 778 | catch (boostcxx . . $ boost/::regex_errorcxx . . $ boost/regex_error# const&) |
| 779 | { |
| 780 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("\"" +cxx . . $ std/operator+(42c652dfebe55ad7). string_to_parse +cxx . . $ std/operator+(900ec9581c410ad9). "\" is not a valid regular expression."); |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | // handle case-insensitive |
| 786 | if (ignore_case) |
| 787 | input_optscxx . . $ input_opts..element_compcxx . . $ InputOptions#element_comp. =cxx . . $ std/function#`operator=`(842f3727de83eb28). stdcxx . . $ std/::bindcxx . . $ std/bind(872fd79d47452673).( |
| 788 | boostcxx . . $ boost/::algorithmcxx . . $ boost/algorithm/::ilexicographical_comparecxx . . $ boost/algorithm/ilexicographical_compare(acd2c426688c4d67).<element_tcxx . . $ element_t#, element_tcxx . . $ element_t#>, stdcxx . . $ std/::placeholderscxx . . $ std/placeholders/::_1cxx . . $ std/placeholders/_1., stdcxx . . $ std/::placeholderscxx . . $ std/placeholders/::_2cxx . . $ std/placeholders/_2., stdcxx . . $ std/locale#locale(ced63f7c635d850d).::localecxx . . $ std/locale#() |
| 789 | ); |
| 790 | else |
| 791 | input_optscxx . . $ input_opts..element_compcxx . . $ InputOptions#element_comp. =cxx . . $ std/function#`operator=`(842f3727de83eb28). boostcxx . . $ boost/::algorithmcxx . . $ boost/algorithm/::lexicographical_comparecxx . . $ boost/algorithm/lexicographical_compare(acb94948942028a1).<element_tcxx . . $ element_t#, element_tcxx . . $ element_t#>; |
| 792 | |
| 793 | // use console as input when no file given |
| 794 | if (input_filenamescxx . . $ input_filenames..emptycxx . . $ std/vector#empty(3482b152b9333168).()) |
| 795 | input_filenamescxx . . $ input_filenames..push_backcxx . . $ std/vector#push_back(fe7a8a4d1eddb70).("-"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 796 | |
| 797 | // console must not be used multiple times (= inputstream "-") |
| 798 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> list_of_inputstreamscxx . . $ std/vector#vector(7b38ad08d995b4c0).(input_filenamescxx . . $ input_filenames.); |
| 799 | list_of_inputstreams.insertcxx . . $ std/vector#insert(fc7d616436af4ee).(list_of_inputstreams.cendcxx . . $ std/vector#cend(85e5e53179ff4ad2).(), setdifference_filenames.cbegincxx . . $ std/vector#cbegin(85e5e53179ff4ad2).(), setdifference_filenames.cendcxx . . $ std/vector#cend(85e5e53179ff4ad2).()); |
| 800 | if (!inputstream_for_set_comparison.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 801 | list_of_inputstreams.push_backcxx . . $ std/vector#push_back(77d9f17553126ecb).(inputstream_for_set_comparison); |
| 802 | bool found_console_as_input = false; |
| 803 | for (stdcxx . . $ std/::stringcxx . . $ std/string# const& inputstream : list_of_inputstreams) |
| 804 | if (inputstream ==cxx . . $ std/`operator==`(4b17aa87c9f300c6). "-") |
| 805 | { |
| 806 | if (found_console_as_input) |
| 807 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("reading from standard input via '-' is only allowed once within the calling "cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d). PROGRAM_NAMEcxx . . $ `src/main.cpp:43:9`! " command."); |
| 808 | else |
| 809 | found_console_as_input = true; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | // PROCESS CALCULATIONS IN THREE STEPS |
| 814 | |
| 815 | // STEP 1/3: execute all commutative set combinations (union, intersection, symmetric difference) or formula |
| 816 | |
| 817 | set_tcxx . . $ set_t# output_setcxx . . $ std/set#set(19c357cac5bd4ecc).(input_optscxx . . $ input_opts..element_compcxx . . $ InputOptions#element_comp.); |
| 818 | if (setconcat_type == SetConcatcxx . . $ SetConcat#::FORMULAcxx . . $ SetConcat#FORMULA.) |
| 819 | { |
| 820 | stdcxx . . $ std/::stringcxx . . $ std/string#::const_iteratorcxx . . $ std/__cxx11/basic_string#const_iterator# formula_it = formula.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(); |
| 821 | try |
| 822 | { |
| 823 | output_set =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). evaluate_formulacxx . . $ evaluate_formula(e474eca3f6cdac01).(formula_it); |
| 824 | } |
| 825 | catch (invalid_formula_exceptioncxx . . $ invalid_formula_exception# const& formula_exception) |
| 826 | { |
| 827 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(stdcxx . . $ std/::stringcxx . . $ std/string#("invalid formula, ") +cxx . . $ std/operator+(900ec9581c410ad9). formula_exception.whatcxx . . $ std/logic_error#what(ba32b354807b2b81).() +cxx . . $ std/operator+(900ec9581c410ad9). "\n" +cxx . . $ std/operator+(db5dc2ea912c6495). formula +cxx . . $ std/operator+(900ec9581c410ad9). "\n" |
| 828 | +cxx . . $ std/operator+(aa1c00e85b87da6b). stdcxx . . $ std/__cxx11/basic_string#basic_string(3bff756e0d570487).::stringcxx . . $ std/string#(formula_it -cxx . . $ __gnu_cxx/operator-(e8e0e2fa12b9b0ca). formula.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), ' ') +cxx . . $ std/operator+(900ec9581c410ad9). "^"); |
| 829 | } |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | for (auto curr_fn_it = input_filenamescxx . . $ input_filenames..cbegincxx . . $ std/vector#cbegin(85e5e53179ff4ad2).(); curr_fn_it != input_filenamescxx . . $ input_filenames..cendcxx . . $ std/vector#cend(85e5e53179ff4ad2).(); ++cxx . . $ __gnu_cxx/__normal_iterator#operator++(1613faa01bc3d014).curr_fn_it) |
| 834 | { |
| 835 | if (curr_fn_it ==cxx . . $ __gnu_cxx/`operator==`(d2eded1addd76ab7). input_filenamescxx . . $ input_filenames..cbegincxx . . $ std/vector#cbegin(85e5e53179ff4ad2).()) // if it is the first input stream |
| 836 | { |
| 837 | output_set =cxx . . $ std/set#`operator=`(3c964fc90d3047d2). file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_fn_it); |
| 838 | } |
| 839 | else |
| 840 | { |
| 841 | SetCombineOperationcxx . . $ SetCombineOperation# operation = setconcat_type == SetConcatcxx . . $ SetConcat#::UNIONcxx . . $ SetConcat#UNION. ? SetCombineOperationcxx . . $ SetCombineOperation#::Unioncxx . . $ SetCombineOperation#Union. : |
| 842 | setconcat_type == SetConcatcxx . . $ SetConcat#::INTERSECTIONcxx . . $ SetConcat#INTERSECTION. ? SetCombineOperationcxx . . $ SetCombineOperation#::Intersectioncxx . . $ SetCombineOperation#Intersection. : |
| 843 | SetCombineOperationcxx . . $ SetCombineOperation#::SymmetricDiffcxx . . $ SetCombineOperation#SymmetricDiff.; |
| 844 | combine_with_next_setcxx . . $ combine_with_next_set(6ecbcf41c7462268).(output_set, operation, file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(*cxx . . $ __gnu_cxx/__normal_iterator#`operator*`(f9c37c6e427d43d6).curr_fn_it)); |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | |
| 850 | // STEP 2/3: execute all set differences, that is erase all desired elements from current output set |
| 851 | |
| 852 | for (stdcxx . . $ std/::stringcxx . . $ std/string# const& filename : setdifference_filenames) |
| 853 | { |
| 854 | combine_with_next_setcxx . . $ combine_with_next_set(6ecbcf41c7462268).(output_set, SetCombineOperationcxx . . $ SetCombineOperation#::SetDifferencecxx . . $ SetCombineOperation#SetDifference., file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(filename)); |
| 855 | } |
| 856 | |
| 857 | |
| 858 | // STEP 3/3: calculate output depending on set query |
| 859 | |
| 860 | // print success and failure messages from query and return exit code of program |
| 861 | auto answer_query = [quiet, verbose, modern_outputoption_used](bool success, stdcxx . . $ std/::stringcxx . . $ std/string# const& success_msg, stdcxx . . $ std/::stringcxx . . $ std/string# const& unsuccess_msg) -> int |
| 862 | { |
| 863 | if (modern_outputoption_used) |
| 864 | { |
| 865 | if (!quiet) |
| 866 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). (success ? success_msg : unsuccess_msg); |
| 867 | return success ? EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! : EXIT_QUERY_NEGATIVEcxx . . $ `src/main.cpp:46:9`!; |
| 868 | } |
| 869 | else |
| 870 | { |
| 871 | if (success) |
| 872 | { |
| 873 | if (verbose) |
| 874 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). success_msg; |
| 875 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 876 | } |
| 877 | else |
| 878 | { |
| 879 | if (!quiet) |
| 880 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). unsuccess_msg; |
| 881 | return EXIT_QUERY_NEGATIVEcxx . . $ `src/main.cpp:46:9`!; |
| 882 | } |
| 883 | } |
| 884 | }; |
| 885 | |
| 886 | switch (output_type) |
| 887 | { |
| 888 | case SetQuerycxx . . $ SetQuery#::RETURN_SETcxx . . $ SetQuery#RETURN_SET.: |
| 889 | for (element_tcxx . . $ element_t# const& el : output_set) |
| 890 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(88df5bef833f7f83). el <<cxx . . $ std/`operator<<`(88df5bef833f7f83). input_optscxx . . $ input_opts..output_separatorcxx . . $ InputOptions#output_separator.; |
| 891 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 892 | case SetQuerycxx . . $ SetQuery#::CARDINALITYcxx . . $ SetQuery#CARDINALITY.: |
| 893 | stdcxx . . $ std/::coutcxx . . $ std/cout. <<cxx . . $ std/basic_ostream#`operator<<`(b09cd8ec4365c7ed). output_set.sizecxx . . $ std/set#size(fa801f5ac5d26b4e).() <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "\n"; |
| 894 | return EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!; |
| 895 | case SetQuerycxx . . $ SetQuery#::ISEMPTYcxx . . $ SetQuery#ISEMPTY.: |
| 896 | return answer_query(cxx . . $ execute_setop(afcd3168fc1188a4).$anonymous_type_2#`operator()`(22ac08565d1f1625). |
| 897 | output_set.emptycxx . . $ std/set#empty(3482b152b9333168).(), |
| 898 | "Resulting set is empty.\n"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 899 | "Resulting set is not empty.\n"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 900 | case SetQuerycxx . . $ SetQuery#::CONTAINS_ELEMENTcxx . . $ SetQuery#CONTAINS_ELEMENT.: |
| 901 | boostcxx . . $ boost/::trim_ifcxx . . $ boost/trim_if(33274b2173bbdc28).(element_for_contains_check, boostcxx . . $ boost/::is_any_ofcxx . . $ boost/is_any_of(5573bd4edbd0fcc3).(input_optscxx . . $ input_opts..trim_characterscxx . . $ InputOptions#trim_characters.)); |
| 902 | return answer_query(cxx . . $ execute_setop(afcd3168fc1188a4).$anonymous_type_2#`operator()`(22ac08565d1f1625). |
| 903 | output_set.containscxx . . $ std/set#contains(8877ebe272b9620d).(element_for_contains_check), |
| 904 | "\"" +cxx . . $ std/operator+(42c652dfebe55ad7). element_for_contains_check +cxx . . $ std/operator+(900ec9581c410ad9). "\" is contained in set.\n", |
| 905 | "Input does not contain element \"" +cxx . . $ std/operator+(42c652dfebe55ad7). element_for_contains_check +cxx . . $ std/operator+(900ec9581c410ad9). "\".\n"); |
| 906 | case SetQuerycxx . . $ SetQuery#::SET_EQUALITYcxx . . $ SetQuery#SET_EQUALITY.: |
| 907 | return answer_query(cxx . . $ execute_setop(afcd3168fc1188a4).$anonymous_type_2#`operator()`(22ac08565d1f1625). |
| 908 | file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(inputstream_for_set_comparison) ==cxx . . $ std/`operator==`(c27708345ce5fd4e). output_set, |
| 909 | "Resulting set is equal to input \"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\".\n", |
| 910 | "Resulting set is not equal to input \"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\".\n"); |
| 911 | case SetQuerycxx . . $ SetQuery#::SUBSETcxx . . $ SetQuery#SUBSET.: |
| 912 | return answer_query(cxx . . $ execute_setop(afcd3168fc1188a4).$anonymous_type_2#`operator()`(22ac08565d1f1625). |
| 913 | stdcxx . . $ std/::rangescxx . . $ std/ranges/::includescxx . . $ std/ranges/includes.(cxx . . $ std/ranges/__includes_fn#`operator()`(25862d4ade87ceb3).output_set, file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(inputstream_for_set_comparison)), |
| 914 | "\"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\" is a subset.\n", |
| 915 | "\"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\" is not a subset.\n"); |
| 916 | case SetQuerycxx . . $ SetQuery#::SUPERSETcxx . . $ SetQuery#SUPERSET.: |
| 917 | return answer_query(cxx . . $ execute_setop(afcd3168fc1188a4).$anonymous_type_2#`operator()`(22ac08565d1f1625). |
| 918 | stdcxx . . $ std/::rangescxx . . $ std/ranges/::includescxx . . $ std/ranges/includes.(cxx . . $ std/ranges/__includes_fn#`operator()`(25862d4ade87ceb3).file_to_setcxx . . $ file_to_set(5774bd19eeb5c1c4).(inputstream_for_set_comparison), output_set), |
| 919 | "\"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\" is a superset.\n", |
| 920 | "\"" +cxx . . $ std/operator+(42c652dfebe55ad7). inputstream_for_set_comparison +cxx . . $ std/operator+(900ec9581c410ad9). "\" is not a superset.\n"); |
| 921 | default: |
| 922 | // never happens because all cases are handled above |
| 923 | return EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
| 928 | /** |
| 929 | \brief Executes execute_setop, but handles all possible general exceptions. |
| 930 | */ |
| 931 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char* argv[]) |
| 932 | { |
| 933 | int exit_code; |
| 934 | try |
| 935 | { |
| 936 | exit_code = execute_setopcxx . . $ execute_setop(afcd3168fc1188a4).(argc, argv); |
| 937 | } |
| 938 | // too much complexity or stack overflow in ++regex_iterator |
| 939 | // input file could not be read |
| 940 | catch (stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error# const& rt_exc) |
| 941 | { |
| 942 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(rt_exccxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..whatcxx . . $ std/runtime_error#what(ba32b354807b2b81).()); |
| 943 | } |
| 944 | // no more memory for more elements, or one element is too large because of faulty regular expression |
| 945 | catch (stdcxx . . $ std/::bad_alloccxx . . $ std/bad_alloc# const&) |
| 946 | { |
| 947 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("not enough memory available. Input data could be too large, or input element or separator regex could be erroneous."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 948 | } |
| 949 | #ifndef _DEBUG |
| 950 | catch (stdcxx . . $ std/::exception const& exc) |
| 951 | { |
| 952 | return print_errorcxx . . $ print_error(7787e0c995c81e02).(exccxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)..what()); |
| 953 | } |
| 954 | catch (...) |
| 955 | { |
| 956 | return print_errorcxx . . $ print_error(7787e0c995c81e02).("unknown error occurred."cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).); |
| 957 | } |
| 958 | #endif |
| 959 | |
| 960 | return exit_code; |
| 961 | } |