File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424
2525int main (int argc, char **argv)
2626{
27- const char *filename = nullptr ;
27+ bool error = false ;
2828
2929 // Settings..
30+ const char *filename = nullptr ;
3031 simplecpp::DUI dui;
3132 bool quiet = false ;
3233 for (int i = 1 ; i < argc; i++) {
3334 const char * const arg = argv[i];
3435 if (*arg == ' -' ) {
36+ bool found = false ;
3537 const char c = arg[1 ];
36- if (c != ' D' && c != ' U' && c != ' I' && c != ' i' && c != ' s' && c != ' q' )
37- continue ; // Ignored
3838 const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
3939 switch (c) {
4040 case ' D' : // define symbol
4141 dui.defines .push_back (value);
42+ found = true ;
4243 break ;
4344 case ' U' : // undefine symbol
4445 dui.undefined .insert (value);
46+ found = true ;
4547 break ;
4648 case ' I' : // include path
4749 dui.includePaths .push_back (value);
50+ found = true ;
4851 break ;
4952 case ' i' :
50- if (std::strncmp (arg, " -include=" ,9 )==0 )
53+ if (std::strncmp (arg, " -include=" ,9 )==0 ) {
5154 dui.includes .push_back (arg+9 );
55+ found = true ;
56+ }
5257 break ;
5358 case ' s' :
54- if (std::strncmp (arg, " -std=" ,5 )==0 )
59+ if (std::strncmp (arg, " -std=" ,5 )==0 ) {
5560 dui.std = arg + 5 ;
61+ found = true ;
62+ }
5663 break ;
5764 case ' q' :
5865 quiet = true ;
66+ found = true ;
5967 break ;
6068 }
69+ if (!found) {
70+ std::cout << " Option '" << arg << " ' is unknown." << std::endl;
71+ error = true ;
72+ }
6173 } else {
6274 filename = arg;
6375 }
6476 }
6577
78+ if (error)
79+ std::exit (1 );
80+
6681 if (!filename) {
6782 std::cout << " Syntax:" << std::endl;
6883 std::cout << " simplecpp [options] filename" << std::endl;
You can’t perform that action at this time.
0 commit comments