From: Jérôme Benoit Date: Tue, 13 Feb 2018 14:16:07 +0000 (+0100) Subject: Merge branch 'master' of git.piment-noir.org:TP_AL_C X-Git-Url: https://git.piment-noir.org/?p=TP_AL_C.git;a=commitdiff_plain;h=8aa14fa6392221f27472350490ebd334738f8ac2;hp=a20d3e7405deb4b0565e41968ff2047f4e9e37af Merge branch 'master' of git.piment-noir.org:TP_AL_C --- diff --git a/lexer/lexical_analyzer.c b/lexer/lexical_analyzer.c index 6f995ba..56415a0 100644 --- a/lexer/lexical_analyzer.c +++ b/lexer/lexical_analyzer.c @@ -201,13 +201,13 @@ FIN: error: if (tokenType == MOT || tokenType == MOTCLE) { fwprintf(stderr, L"%s error with token type: %s and value: %ls\n", - __func__, - tokenTypestr[tokenType], - token[tokenFound].value); + __func__, + tokenTypestr[tokenType], + token[tokenFound].value); } else { fwprintf(stderr, L"%s error with token type: %s\n", - __func__, - tokenTypestr[tokenType]); + __func__, + tokenTypestr[tokenType]); } fflush(stderr); tokenType = FIN; diff --git a/lexer/main.c b/lexer/main.c index f862217..7c31ee3 100644 --- a/lexer/main.c +++ b/lexer/main.c @@ -13,7 +13,7 @@ void do_lexical_analysis() { c = fgetwc(source); // lecture du premier caractere do { scanner(); - wprint_token_target(); + wprint_token(target); token[tokenFound].type = tokenTypestr[tokenType]; tokenFound++; } while (tokenType != FIN); // tant que la fin du fichier n'est pas atteinte @@ -84,13 +84,15 @@ int main(int argc, char **argv) { case ':': /* missing option argument */ pr_error("%s: option '-%c' requires an argument\n", - argv[0], optopt); + argv[0], optopt); break; case '?': default: /* invalid option */ pr_error("%s: option '-%c' is invalid: ignored\n", - argv[0], optopt); + argv[0], optopt); + /* print the help message for invalid options */ + hflag = 1; break; } } @@ -120,7 +122,7 @@ int main(int argc, char **argv) { if (hflag) { print_usage(argv[0]); - } else if (lflag){ + } else if (lflag) { do_lexical_analysis(); } else { do_syntactic_analysis(); diff --git a/lexer/print_helper.c b/lexer/print_helper.c index f7ab04f..630985b 100644 --- a/lexer/print_helper.c +++ b/lexer/print_helper.c @@ -1,7 +1,7 @@ -#include #include #include +#include "print_helper.h" #include "global_vars.h" void pr_warning(const char* format, ...) { @@ -53,19 +53,11 @@ void wpr_error(const wchar_t *format, ...) { fflush(stderr); } -void wprint_token_stdout() { +void wprint_token(FILE* out_file) { if (tokenType == MOT || tokenType == MOTCLE) { - fwprintf(stdout, L"%20s: %ls\n", tokenTypestr[tokenType], token[tokenFound].value); + fwprintf(out_file, L"%20s: %ls\n", tokenTypestr[tokenType], token[tokenFound].value); } else { - fwprintf(stdout, L"%20s\n", tokenTypestr[tokenType]); - } - fflush(stdout); -} - -void wprint_token_target() { - if (tokenType == MOT || tokenType == MOTCLE) { - fwprintf(target, L"%20s: %ls\n", tokenTypestr[tokenType], token[tokenFound].value); - } else { - fwprintf(target, L"%20s\n", tokenTypestr[tokenType]); + fwprintf(out_file, L"%20s\n", tokenTypestr[tokenType]); } + fflush(out_file); } diff --git a/lexer/print_helper.h b/lexer/print_helper.h index 396afd4..080ea9d 100644 --- a/lexer/print_helper.h +++ b/lexer/print_helper.h @@ -1,6 +1,8 @@ #ifndef PRINT_HELPER_H_ #define PRINT_HELPER_H_ +#include + void pr_warning(const char *format, ...); void pr_error(const char *format, ...); @@ -9,7 +11,6 @@ void pr_debug(const char *format, ...); void wpr_warning(const wchar_t *format, ...); void wpr_error(const wchar_t *format, ...); -void wprint_token_stdout(); -void wprint_token_target(); +void wprint_token(FILE* out_file); #endif /* PRINT_HELPER_H_ */ diff --git a/lexer/syntactic_analyzer.c b/lexer/syntactic_analyzer.c index 29524f0..ddef90b 100644 --- a/lexer/syntactic_analyzer.c +++ b/lexer/syntactic_analyzer.c @@ -25,7 +25,7 @@ static void analyze_TEXT() { fputws(L" ", target); } #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif token[tokenFound].type = tokenTypestr[tokenType]; tokenFound++; @@ -48,7 +48,7 @@ static void analyze_P() { if (tokenType == NPARA) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif if (target != NULL) { fputws(L"

\n", target); @@ -60,7 +60,7 @@ static void analyze_P() { if (tokenType == MOT) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif if (target != NULL) { fputws((const wchar_t*)token[tokenFound].value, target); @@ -91,7 +91,7 @@ static void analyze_HEAD() { if (tokenType == MOTCLE) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif /* PRINT_TOKEN */ token[tokenFound].type = tokenTypestr[tokenType]; tokenFound++; @@ -108,7 +108,7 @@ static void analyze_HEAD() { if (tokenType == MOTCLE) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif /* PRINT_TOKEN */ token[tokenFound].type = tokenTypestr[tokenType]; tokenFound++; @@ -132,7 +132,7 @@ static void analyze_H1() { if (tokenType == SECTION) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif /* PRINT_TOKEN */ if (target != NULL) { fputws(L"

\n", target); @@ -158,7 +158,7 @@ static void analyze_H2() { if (tokenType == SSECTION) { scanner(); #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif /* PRINT_TOKEN */ if (target != NULL) { fputws(L"

\n", target); @@ -234,7 +234,7 @@ void analyze_AXIOME() { scanner(); /* print the lexical analysis result */ #if PRINT_TOKEN - wprint_token_stdout(); + wprint_token(stdout); #endif /* PRINT_TOKEN */ token[tokenFound].type = tokenTypestr[tokenType]; tokenFound++;