@@ -73,7 +73,15 @@ int main(int argc, const char **argv) {
7373 bool show_usage = false ;
7474 bool bad_arguments = false ;
7575
76- while ((i < argc) && (std::strlen (argv[i]) > 1 ) && (argv[i][0 ] == ' -' ) && (std::strcmp (argv[i], " --" ) != 0 ) && !bad_arguments) {
76+ // handle all options:
77+ // valid option formats:
78+ // -h or -help
79+ // -Xparam where X is a single character option
80+ // -X param where X is a single character option
81+ // -OPT=param where OPT is long option
82+ // -OPT param where OPT is long option
83+ // -- Stops the scan for options.
84+ while (i < argc && argv[i][0 ] == ' -' && std::strcmp (argv[i], " --" ) != 0 && !bad_arguments) {
7785 const char *flag = &argv[i][1 ];
7886 if (*flag == ' -' ) {
7987 ++flag;
@@ -106,11 +114,21 @@ int main(int argc, const char **argv) {
106114 }
107115 ++i;
108116 }
109- if ((i < argc) && (std::strcmp (argv[i], " --" ) == 0 ))
117+
118+ // If a "--" stopped the scan, skip it.
119+ if (i < argc && std::strcmp (argv[i], " --" ) == 0 ){
110120 ++i;
111- if (show_usage || bad_arguments || (i >= argc)) {
121+ }
122+
123+ if (i >= argc){
124+ std::cerr << " No template file(s) on command line." << std::endl;
125+ bad_arguments = true ;
126+ }
127+
128+ // Handle errors and help requests then exit
129+ if (show_usage || bad_arguments) {
112130 std::ostream &output = show_usage ? std::cout : std::cerr;
113- output << " usage: " << command_name << " [-E symbol] [-H extension] [-I extension] [-C extension] file ...\n "
131+ output << " usage: " << command_name << " [-E symbol] [-H extension] [-I extension] [-C extension] template_file ...\n "
114132 " generate C++ bindings for FAST types\n " ;
115133 if (show_usage) {
116134 output << " \n "
@@ -121,18 +139,16 @@ int main(int argc, const char **argv) {
121139 " -C, --source-extension=EXT source filename extension (default .cpp)\n "
122140 " -H, --header-extension=EXT header filename extension (default .h)\n "
123141 " -I, --inline-extension=EXT inline function filename extension (default .inl)\n "
124- " file ... XML FAST message template inputs\n " ;
142+ " template_file ... One or more XML FAST message template inputs\n " ;
125143 }
126- return ( bad_arguments || (!show_usage && (i >= argc))) ? -1 : 0 ;
144+ return bad_arguments ? -1 : 0 ;
127145 }
128146
129- std::vector<mfast::dynamic_templates_description> descriptions;
130-
147+ // remaining arguments must be template file names
131148 std::vector<std::string> filebases;
132149
133- mfast::simple_template_repo_t repo;
134-
135- for (int j = 0 ; i < argc; ++i, ++j) {
150+ std::vector<mfast::dynamic_templates_description> descriptions;
151+ for (; i < argc; ++i) {
136152
137153 std::ifstream ifs (argv[i]);
138154
@@ -144,8 +160,6 @@ int main(int argc, const char **argv) {
144160 std::string xml ((std::istreambuf_iterator<char >(ifs)),
145161 std::istreambuf_iterator<char >());
146162
147- // path f(path(argv[i]).stem());
148-
149163#ifdef _WINDOWS
150164 char filebase_buf[_MAX_FNAME];
151165 _splitpath (argv[i], NULL , NULL , filebase_buf, NULL );
@@ -157,9 +171,10 @@ int main(int argc, const char **argv) {
157171#endif
158172 filebases.push_back (codegen_base::cpp_name (filebase));
159173
160- descriptions.emplace_back (xml.c_str (), filebases[j] .c_str (), ®istry);
174+ descriptions.emplace_back (xml.c_str (), filebases. back () .c_str (), ®istry);
161175 }
162176
177+ mfast::simple_template_repo_t repo;
163178 repo.build (descriptions.begin (), descriptions.end ());
164179
165180 for (std::size_t j = 0 ; j < filebases.size (); ++j) {
0 commit comments