diff --git a/source/cli.cpp b/source/cli.cpp index 6503ea2..2d8d1b2 100644 --- a/source/cli.cpp +++ b/source/cli.cpp @@ -11,6 +11,7 @@ extern std::stack tag_stack; const char * const csml_extension = ".csml"; +bool did_any_work = false; static const char * const version = @@ -72,6 +73,11 @@ void yylex(FILE * &yyin, FILE * &yyout, int (*yylex_)(void)) { } // ### global functions ### +extern "C" +void usage(void) { + fputs(help_message, stdout); +} + extern "C" signed parse_round1_arguments(int argc, char * * argv){ const char * const optstring = "-" "hv" "cxs:S:i:o:q:"; @@ -86,7 +92,7 @@ signed parse_round1_arguments(int argc, char * * argv){ while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) { switch (opt) { case 'h': { - fputs(help_message, stdout); + usage(); } return EXIT_EARLY_SUCCESS; case 'v': { fputs(version, stdout); @@ -124,6 +130,7 @@ signed parse_round2_arguments(int argc, char * * argv) { ++n; output = argv[n]; } else { + did_any_work = true; input = argv[n]; if (input_type == input_type_t::AUTO_DETECT) { diff --git a/source/cli.hpp b/source/cli.hpp index 776a50a..8fcc798 100644 --- a/source/cli.hpp +++ b/source/cli.hpp @@ -3,6 +3,12 @@ #include #include +/* Used for outputting a help message as the default behaviour + */ +extern bool did_any_work; + +extern "C" void usage(void); + extern "C" signed parse_colon_list(char * const list, std::vector destination); extern "C" signed parse_sets(char * const list); diff --git a/source/main.cpp b/source/main.cpp index feb9012..0681095 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -83,6 +83,10 @@ signed main(int argc, char * * argv) { parse_round2_arguments(argc - 1, argv + 1); + if (not did_any_work) { + usage(); + } + xml_lex_destroy(); csml_lex_destroy();