From 52e449e480fe479e28e2cca134eba691991d8a60 Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 16 Sep 2024 00:06:11 +0200 Subject: [PATCH] init/deinit in inline functions --- source/main.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/source/main.c b/source/main.c index eb547b4..2994d5f 100644 --- a/source/main.c +++ b/source/main.c @@ -102,30 +102,19 @@ void dump_output(void) { fputs(verbatim, yyout); } -signed main(const int argc, const char * const * const argv) { - #ifdef DEBUG - yydebug = 1; - #endif - - if (handle_arguments(argc, argv)) { return 1; } - +static inline +void init(void) { tbsp_yy_init(); tbsp_tab_init(); tbsp_c_yy_init(); +} - CHECKED_FOPEN(yyin, input_file_name, "r"); - - int yyparse_r = yyparse(); - if (yyparse_r) { return yyparse_r; } - - dump_output(); - - // Deinit +static inline +void deinit(void) { for (int i = 0; i < kv_size(rules); i++) { free(kv_A(rules, i).string); free(kv_A(rules, i).code); } - tbsp_yy_deinit(); tbsp_c_yy_deinit(); free(output_file_name); @@ -133,8 +122,27 @@ signed main(const int argc, const char * const * const argv) { free(verbatim); free(language); free(top); +} + +signed main(const int argc, const char * const * const argv) { + #ifdef DEBUG + yydebug = 1; + #endif + + if (handle_arguments(argc, argv)) { return 1; } + + init(); + + CHECKED_FOPEN(yyin, input_file_name, "r"); + + int yyparse_r = yyparse(); + if (yyparse_r) { return yyparse_r; } + CHECKED_FOPEN(yyout, output_file_name, "w"); + dump_output(); + + deinit(); return 0; }