Bool parse_file(char *filename) { ParseCtx *ctx; OpenStruct *open_struct; int num_errors = get_num_errors(); ctx = ParseCtx_new(); if (opts.verbose) printf("Reading '%s'...\n", filename); /* display name of file */ src_push(); { if (src_open(filename, opts.inc_path)) { sym.tok = TK_NIL; while (sym.tok != TK_END) parseline(ctx); /* before parsing it */ open_struct = (OpenStruct *)utarray_back(ctx->open_structs); if (open_struct != NULL) error_unbalanced_struct_at(open_struct->filename, open_struct->line_nr); } } src_pop(); sym.tok = TK_NEWLINE; /* when called recursively, need to make tok != TK_NIL */ ParseCtx_delete(ctx); return num_errors == get_num_errors(); }
static void test_context_analyze_memory(TestContext *tc, Test *t, char *file) { int errors, contexts; FILE *fh = fopen(file, "r"); if (!get_num_errors(fh, &errors, &contexts)) { /* log failure to parse */ goto out; } tc->check_num++; if (errors == 0) { test_context_print_color(tc, GREEN, "."); } else { tc->check_failed++; test_context_print_color(tc, YELLOW, "M"); if (TC_IS_QUIET(tc)) goto out; oqueue_pushf(tc->logs, "Test %s failed:\ndetected %d memory %s in %d contexts\n", str_to_bold(t->name), errors, errors > 1 ? "error" : "errors", contexts); if (tc->verbose == MODE_VERBOSE) { oqueue_copy_from_valgrind(tc->logs, fh, contexts); } else { oqueue_push(tc->logs, "\n"); } } out: if (fh) fclose(fh); }
void info_total_errors(void) { STR_DEFINE(msg, STR_SIZE); str_append_sprintf( msg, "%d errors occurred during assembly", get_num_errors() ); do_error( ErrInfo, str_data(msg) ); STR_DELETE(msg); }
/*----------------------------------------------------------------------------- * parse the given assembly file, return FALSE if failed *----------------------------------------------------------------------------*/ static void parseline(ParseCtx *ctx) { int start_num_errors; next_PC(); /* update assembler program counter */ EOL = FALSE; /* reset END OF LINE flag */ start_num_errors = get_num_errors(); scan_expect_opcode(); GetSym(); if (get_num_errors() != start_num_errors) /* detect errors in GetSym() */ Skipline(); else if (!parse_statement(ctx)) { if (get_num_errors() == start_num_errors) /* no error output yet */ error_syntax(); Skipline(); } list_end_line(); /* Write current source line to list file */ }
/* save the current scanner context and parse the given expression */ struct Expr *parse_expr(char *expr_text) { Expr *expr; int num_errors; save_scan_state(); { src_push(); { SetTemporaryLine(expr_text); num_errors = get_num_errors(); EOL = FALSE; scan_expect_operands(); GetSym(); expr = expr_parse(); /* may output error */ if (sym.tok != TK_END && num_errors == get_num_errors()) error_syntax(); } src_pop(); } restore_scan_state(); return expr; }
/*----------------------------------------------------------------------------- * Parse command line, set options, including opts.files with list of * input files, including parsing of '@' lists *----------------------------------------------------------------------------*/ void parse_argv( int argc, char *argv[] ) { int arg; init_module(); if ( argc == 1 ) exit_copyright(); /* exit if no arguments */ process_options( &arg, argc, argv ); /* process all options, set arg to next */ if ( arg >= argc ) error_no_src_file(); /* no source file */ if ( opts.verbose ) display_options(); /* display status messages of select assembler options */ if ( ! get_num_errors() ) process_files( arg, argc, argv ); /* process each source file */ }