@@ -31,25 +31,34 @@ int main(int argc, char **argv)
3131 // Settings..
3232 simplecpp::DUI dui;
3333 bool quiet = false ;
34+ bool error_only = false ;
3435 for (int i = 1 ; i < argc; i++) {
3536 const char * const arg = argv[i];
3637 if (*arg == ' -' ) {
3738 bool found = false ;
3839 const char c = arg[1 ];
39- const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
4040 switch (c) {
4141 case ' D' : // define symbol
42+ {
43+ const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
4244 dui.defines .push_back (value);
4345 found = true ;
4446 break ;
47+ }
4548 case ' U' : // undefine symbol
49+ {
50+ const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
4651 dui.undefined .insert (value);
4752 found = true ;
4853 break ;
54+ }
4955 case ' I' : // include path
56+ {
57+ const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
5058 dui.includePaths .push_back (value);
5159 found = true ;
5260 break ;
61+ }
5362 case ' i' :
5463 if (std::strncmp (arg, " -include=" ,9 )==0 ) {
5564 dui.includes .push_back (arg+9 );
@@ -70,11 +79,18 @@ int main(int argc, char **argv)
7079 quiet = true ;
7180 found = true ;
7281 break ;
82+ case ' e' :
83+ error_only = true ;
84+ found = true ;
85+ break ;
7386 }
7487 if (!found) {
75- std::cout << " Option '" << arg << " ' is unknown." << std::endl;
88+ std::cout << " error: option '" << arg << " ' is unknown." << std::endl;
7689 error = true ;
7790 }
91+ } else if (filename) {
92+ std::cout << " error: multiple filenames specified" << std::endl;
93+ std::exit (1 );
7894 } else {
7995 filename = arg;
8096 }
@@ -83,6 +99,11 @@ int main(int argc, char **argv)
8399 if (error)
84100 std::exit (1 );
85101
102+ if (quiet && error_only) {
103+ std::cout << " error: -e cannot be used in conjunction with -q" << std::endl;
104+ std::exit (1 );
105+ }
106+
86107 if (!filename) {
87108 std::cout << " Syntax:" << std::endl;
88109 std::cout << " simplecpp [options] filename" << std::endl;
@@ -93,6 +114,7 @@ int main(int argc, char **argv)
93114 std::cout << " -std=STD Specify standard." << std::endl;
94115 std::cout << " -q Quiet mode (no output)." << std::endl;
95116 std::cout << " -is Use std::istream interface." << std::endl;
117+ std::cout << " -e Output errors only." << std::endl;
96118 std::exit (0 );
97119 }
98120
@@ -102,6 +124,10 @@ int main(int argc, char **argv)
102124 simplecpp::TokenList *rawtokens;
103125 if (use_istream) {
104126 std::ifstream f (filename);
127+ if (!f.is_open ()) {
128+ std::cout << " error: could not open file '" << filename << " '" << std::endl;
129+ std::exit (1 );
130+ }
105131 rawtokens = new simplecpp::TokenList (f, files,filename,&outputList);
106132 }
107133 else {
@@ -118,7 +144,8 @@ int main(int argc, char **argv)
118144
119145 // Output
120146 if (!quiet) {
121- std::cout << outputTokens.stringify () << std::endl;
147+ if (!error_only)
148+ std::cout << outputTokens.stringify () << std::endl;
122149
123150 for (const simplecpp::Output &output : outputList) {
124151 std::cerr << output.location .file () << ' :' << output.location .line << " : " ;
0 commit comments