From cd05265ac8dddbf0ffbb10d8ddf9cb046b202bed Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Tue, 10 Jan 2023 15:34:17 +0100 Subject: [PATCH 1/8] add option for every binary to print the GAPC command line call it was made from --- rtlib/generic_opts.hh | 29 ++++++++++++++++++++++------- src/cpp.cc | 15 ++++++++++++++- src/printer.cc | 9 ++++++--- src/printer.hh | 1 + 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index fb93de4e8..fde14652f 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -24,8 +24,10 @@ #ifndef RTLIB_GENERIC_OPTS_HH_ #define RTLIB_GENERIC_OPTS_HH_ - -#include +extern "C" { + #include + #include +} #include #include @@ -71,6 +73,7 @@ class Opts { unsigned int delta; unsigned int repeats; unsigned k; + bool print_call; Opts() : @@ -83,7 +86,8 @@ class Opts { window_increment(0), delta(0), repeats(1), - k(3) { + k(3), + print_call(false) { } ~Opts() { @@ -99,23 +103,31 @@ class Opts { #ifdef LIBRNA_RNALIB_H_ << " (-[tT] [0-9]+)? (-P PARAM-file)?" #endif - << " (-[drk] [0-9]+)* (-h)? (INPUT|-f INPUT-file)\n"; + << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" + << "--help,-h print this help message\n" + << "--printCall,-v print the GAPC call that \n" + << " generated the source code \n" + << " of this binary\n"; } void parse(int argc, char **argv) { int o = 0; char *input = 0; + const option long_opts[] = { + {"help", no_argument, nullptr, 'h'}, + {"printCall", no_argument, nullptr, 'v'}, + {nullptr, no_argument, nullptr, 0}}; #ifdef LIBRNA_RNALIB_H_ char *par_filename = 0; #endif - while ((o = getopt(argc, argv, ":f:" + while ((o = getopt_long(argc, argv, ":f:" #ifdef WINDOW_MODE "w:i:" #endif #ifdef LIBRNA_RNALIB_H_ "t:T:P:" #endif - "hd:r:k:")) != -1) { + "hvd:r:k:", long_opts, nullptr)) != -1) { switch (o) { case 'f' : { @@ -176,6 +188,9 @@ class Opts { case 'r' : repeats = std::atoi(optarg); break; + case 'v' : + print_call = true; + break; case '?' : case ':' : { @@ -191,7 +206,7 @@ class Opts { } } } - if (!input) { + if (!input && !print_call) { if (optind == argc) throw OptException("Missing input sequence or no -f."); for (; optind < argc; ++optind) { diff --git a/src/cpp.cc b/src/cpp.cc index f54f5ad43..65dbd831e 100644 --- a/src/cpp.cc +++ b/src/cpp.cc @@ -1578,7 +1578,13 @@ void Printer::Cpp::print_init_fn(const AST &ast) { inc_indent(); stream << indent() << "const std::vector >" - << " &inp = opts.inputs;\n"; + << " &inp = opts.inputs;" << endl << endl; + stream << indent() << "if (opts.print_call) {" << endl; + inc_indent(); + stream << indent() << "std::cerr << gapc_call_string << std::endl;" << endl; + stream << indent() << "exit(0);" << endl; + dec_indent(); + stream << indent() << "}" << endl << endl; print_buddy_init(ast); print_seq_init(ast); @@ -1688,9 +1694,16 @@ void Printer::Cpp::header(const AST &ast) { print_subseq_typedef(ast); print_type_defs(ast); } + imports(ast); print_hash_decls(ast); + stream << indent() << "class " << class_name << " {" << endl; + stream << indent() << " private:" << endl; + inc_indent(); + stream << indent() << "std::string gapc_call_string = \"" + << gapc_call_string << "\";" << endl << endl; + dec_indent(); stream << indent() << " public:" << endl; inc_indent(); diff --git a/src/printer.cc b/src/printer.cc index 8920f0c11..412ad467e 100644 --- a/src/printer.cc +++ b/src/printer.cc @@ -448,16 +448,19 @@ void Printer::Base::end_fwd_decls() { void Printer::Base::set_argv(char **argv, int argc) { - std::ostringstream o; + std::ostringstream o, gapc_call; o << "A dynamic programming evaluator generated by GAP-C.\n\n" << " GAP-C version:\n " << gapc::version_id << "\n\n" << " GAP-C call:\n "; for (int i = 0; i < argc; ++i) { - o << argv[i]; + gapc_call << argv[i]; if (i+1 < argc) { - o << ' '; + gapc_call << ' '; } } + + gapc_call_string = gapc_call.str(); + o << gapc_call_string; o << "\n\n"; id_string = o.str(); } diff --git a/src/printer.hh b/src/printer.hh index e1252e122..83ad5ffa6 100644 --- a/src/printer.hh +++ b/src/printer.hh @@ -81,6 +81,7 @@ class Base { bool fwd_decls; std::string id_string; + std::string gapc_call_string; public: Base() : ind_count(0), out(std::cerr), line_number(0), stream(*this), From ff506bc8cf963ec7932cf995f253bda9a1b0c473 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 00:27:17 +0100 Subject: [PATCH 2/8] print GAPC call when invoking help option --- rtlib/generic_opts.hh | 12 +++--------- src/cpp.cc | 14 +++----------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index fde14652f..e7670b790 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -104,10 +104,8 @@ class Opts { << " (-[tT] [0-9]+)? (-P PARAM-file)?" #endif << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" - << "--help,-h print this help message\n" - << "--printCall,-v print the GAPC call that \n" - << " generated the source code \n" - << " of this binary\n"; + << "--help,-h print this help message\n\n" + << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n\n"; } void parse(int argc, char **argv) { @@ -115,7 +113,6 @@ class Opts { char *input = 0; const option long_opts[] = { {"help", no_argument, nullptr, 'h'}, - {"printCall", no_argument, nullptr, 'v'}, {nullptr, no_argument, nullptr, 0}}; #ifdef LIBRNA_RNALIB_H_ char *par_filename = 0; @@ -188,9 +185,6 @@ class Opts { case 'r' : repeats = std::atoi(optarg); break; - case 'v' : - print_call = true; - break; case '?' : case ':' : { @@ -206,7 +200,7 @@ class Opts { } } } - if (!input && !print_call) { + if (!input) { if (optind == argc) throw OptException("Missing input sequence or no -f."); for (; optind < argc; ++optind) { diff --git a/src/cpp.cc b/src/cpp.cc index 65dbd831e..516c6e1a8 100644 --- a/src/cpp.cc +++ b/src/cpp.cc @@ -1579,12 +1579,6 @@ void Printer::Cpp::print_init_fn(const AST &ast) { inc_indent(); stream << indent() << "const std::vector >" << " &inp = opts.inputs;" << endl << endl; - stream << indent() << "if (opts.print_call) {" << endl; - inc_indent(); - stream << indent() << "std::cerr << gapc_call_string << std::endl;" << endl; - stream << indent() << "exit(0);" << endl; - dec_indent(); - stream << indent() << "}" << endl << endl; print_buddy_init(ast); print_seq_init(ast); @@ -1690,6 +1684,9 @@ void Printer::Cpp::header(const AST &ast) { if (ast.get_float_acc() > 0) { stream << "#define FLOAT_ACC " << ast.get_float_acc() << "\n"; } + + stream << "#define GAPC_CALL_STRING \"" << gapc_call_string << "\"" + << endl << endl; includes(); print_subseq_typedef(ast); print_type_defs(ast); @@ -1699,11 +1696,6 @@ void Printer::Cpp::header(const AST &ast) { print_hash_decls(ast); stream << indent() << "class " << class_name << " {" << endl; - stream << indent() << " private:" << endl; - inc_indent(); - stream << indent() << "std::string gapc_call_string = \"" - << gapc_call_string << "\";" << endl << endl; - dec_indent(); stream << indent() << " public:" << endl; inc_indent(); From c7ed9e69b11e91fa9edb0954a270af4cf0aed7f8 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 00:34:18 +0100 Subject: [PATCH 3/8] add ifdef guard around GAPC call print (shouldn't ever be needed as the macro should always be visible; just to be sure) --- rtlib/generic_opts.hh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index e7670b790..8ebf5b9a6 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -105,7 +105,10 @@ class Opts { #endif << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" << "--help,-h print this help message\n\n" - << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n\n"; +#ifdef GAPC_CALL_STRING + << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n\n" +#endif + ; } void parse(int argc, char **argv) { From a9fbc380c58ceb20f73331f4ec60377b30b0b802 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 00:38:19 +0100 Subject: [PATCH 4/8] fix linter errors --- rtlib/generic_opts.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index 8ebf5b9a6..c731dc720 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -104,11 +104,11 @@ class Opts { << " (-[tT] [0-9]+)? (-P PARAM-file)?" #endif << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" - << "--help,-h print this help message\n\n" + << "--help,-h print this help message\n" #ifdef GAPC_CALL_STRING - << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n\n" + << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n" #endif - ; + << "\n"; } void parse(int argc, char **argv) { From eadca8ce31ff0699f10257545bcb135b8421f58a Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 11:51:14 +0100 Subject: [PATCH 5/8] also print GAPC version in help message --- rtlib/generic_opts.hh | 5 +++-- src/cpp.cc | 2 ++ src/printer.cc | 3 ++- src/printer.hh | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index c731dc720..973f87b4f 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -105,8 +105,9 @@ class Opts { #endif << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" << "--help,-h print this help message\n" -#ifdef GAPC_CALL_STRING - << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n" +#if defined(GAPC_CALL_STRING) && defined(GAPC_VERSION_STRING) + << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n" + << "GAPC version: \"" << GAPC_VERSION_STRING << "\"\n" #endif << "\n"; } diff --git a/src/cpp.cc b/src/cpp.cc index 516c6e1a8..49de2e4bc 100644 --- a/src/cpp.cc +++ b/src/cpp.cc @@ -1686,6 +1686,8 @@ void Printer::Cpp::header(const AST &ast) { } stream << "#define GAPC_CALL_STRING \"" << gapc_call_string << "\"" + << endl; + stream << "#define GAPC_VERSION_STRING \"" << gapc_version_string << "\"" << endl << endl; includes(); print_subseq_typedef(ast); diff --git a/src/printer.cc b/src/printer.cc index 412ad467e..d1b650370 100644 --- a/src/printer.cc +++ b/src/printer.cc @@ -458,7 +458,8 @@ void Printer::Base::set_argv(char **argv, int argc) { gapc_call << ' '; } } - + + gapc_version_string = gapc::version_id; gapc_call_string = gapc_call.str(); o << gapc_call_string; o << "\n\n"; diff --git a/src/printer.hh b/src/printer.hh index 83ad5ffa6..3f9541b7e 100644 --- a/src/printer.hh +++ b/src/printer.hh @@ -81,7 +81,7 @@ class Base { bool fwd_decls; std::string id_string; - std::string gapc_call_string; + std::string gapc_call_string, gapc_version_string; public: Base() : ind_count(0), out(std::cerr), line_number(0), stream(*this), From 14a7e93a4143898ff332be29871f403805ca6929 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 11:53:35 +0100 Subject: [PATCH 6/8] fix linter errors --- rtlib/generic_opts.hh | 2 +- src/printer.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index 973f87b4f..c51d1c12e 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -107,7 +107,7 @@ class Opts { << "--help,-h print this help message\n" #if defined(GAPC_CALL_STRING) && defined(GAPC_VERSION_STRING) << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n" - << "GAPC version: \"" << GAPC_VERSION_STRING << "\"\n" + << "GAPC version: \"" << GAPC_VERSION_STRING << "\"\n" #endif << "\n"; } diff --git a/src/printer.cc b/src/printer.cc index d1b650370..1a2622890 100644 --- a/src/printer.cc +++ b/src/printer.cc @@ -458,7 +458,7 @@ void Printer::Base::set_argv(char **argv, int argc) { gapc_call << ' '; } } - + gapc_version_string = gapc::version_id; gapc_call_string = gapc_call.str(); o << gapc_call_string; From 93b61484d61f2fd59a6d3e0ae723e9f84c2bfe61 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 14:46:20 +0100 Subject: [PATCH 7/8] forgot to remove this --- rtlib/generic_opts.hh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index c51d1c12e..ad76563e3 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -73,7 +73,6 @@ class Opts { unsigned int delta; unsigned int repeats; unsigned k; - bool print_call; Opts() : @@ -86,8 +85,7 @@ class Opts { window_increment(0), delta(0), repeats(1), - k(3), - print_call(false) { + k(3) { } ~Opts() { @@ -103,8 +101,7 @@ class Opts { #ifdef LIBRNA_RNALIB_H_ << " (-[tT] [0-9]+)? (-P PARAM-file)?" #endif - << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n" - << "--help,-h print this help message\n" + << " (-[drk] [0-9]+)* (INPUT|-f INPUT-file)\n\n" #if defined(GAPC_CALL_STRING) && defined(GAPC_VERSION_STRING) << "GAPC call: \"" << GAPC_CALL_STRING << "\"\n" << "GAPC version: \"" << GAPC_VERSION_STRING << "\"\n" @@ -115,20 +112,17 @@ class Opts { void parse(int argc, char **argv) { int o = 0; char *input = 0; - const option long_opts[] = { - {"help", no_argument, nullptr, 'h'}, - {nullptr, no_argument, nullptr, 0}}; #ifdef LIBRNA_RNALIB_H_ char *par_filename = 0; #endif - while ((o = getopt_long(argc, argv, ":f:" + while ((o = getopt(argc, argv, ":f:" #ifdef WINDOW_MODE "w:i:" #endif #ifdef LIBRNA_RNALIB_H_ "t:T:P:" #endif - "hvd:r:k:", long_opts, nullptr)) != -1) { + "hvd:r:k:")) != -1) { switch (o) { case 'f' : { From 408430b3ab01c900dee7e0848388f6d3fe381248 Mon Sep 17 00:00:00 2001 From: Fynn Muermanns Date: Wed, 11 Jan 2023 17:04:29 +0100 Subject: [PATCH 8/8] also forgot to remove this --- rtlib/generic_opts.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtlib/generic_opts.hh b/rtlib/generic_opts.hh index ad76563e3..732fbbbb5 100644 --- a/rtlib/generic_opts.hh +++ b/rtlib/generic_opts.hh @@ -122,7 +122,7 @@ class Opts { #ifdef LIBRNA_RNALIB_H_ "t:T:P:" #endif - "hvd:r:k:")) != -1) { + "hd:r:k:")) != -1) { switch (o) { case 'f' : {