commit abd0447997ccb032dfc3fb25365bd7d99eed5f83
parent 43f66fdb43189533c4a5a26e6cf31e095a1de9bf
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date: Sun, 19 Jul 2020 02:39:03 +0200
implemented verbosity (hard-coded value)
Diffstat:
M | main.cpp | | | 26 | +++++++++++++++++++++++--- |
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/main.cpp b/main.cpp
@@ -1,3 +1,5 @@
+#include <errno.h>
+#include <string.h>
#include <assert.h>
#include <stdio.h>
@@ -5,6 +7,8 @@
bool parse_file( char const* file_name );
+enum { QUIET, FATAL, NORMAL, VERBOSE } verbosity = VERBOSE;
+
int main( int argc, char** argv )
{
FILE* target = stdin;
@@ -28,22 +32,34 @@ int main( int argc, char** argv )
bool parse_file( char const* file_name )
{
+ if( verbosity >= VERBOSE )
+ {
+ fwprintf( stderr, L"parsing file %s\n", file_name );
+ }
bool failed = false;
FILE* target = file_name ? fopen( file_name, "r" ) : stdin;
+ if( !target && verbosity >= FATAL )
+ {
+ fwprintf( stderr, L"Unable to open file %s: %s(%02x)\n", file_name, strerror( errno ), errno );
+ return true;
+ }
try
{
Scanner scanner( target );
Parser parser( &scanner );
parser.Parse();
failed = parser.errors && parser.errors->count > 0;
- if( failed )
+ if( failed && verbosity >= NORMAL )
{
- wprintf( L"%d errors found in file %s\n", parser.errors->count, file_name );
+ fwprintf( stderr, L"%d errors found in file %s\n", parser.errors->count, file_name );
}
}
catch(...)
{
- wprintf( L"Exception caught while analyzing %s\n", file_name );
+ if( verbosity >= FATAL )
+ {
+ fwprintf( stderr, L"Exception caught while analyzing %s\n", file_name );
+ }
failed = true;
}
@@ -51,5 +67,9 @@ bool parse_file( char const* file_name )
{
fclose( target );
}
+ if( verbosity >= VERBOSE )
+ {
+ fwprintf( stderr, L"parsing file %s completed\n", file_name );
+ }
return failed;
}