int32_t mrb_debug_list(mrb_state *mrb, mrb_debug_context *dbg, char *filename, uint16_t line_min, uint16_t line_max) { char *ext; source_file *file; if (mrb == NULL || dbg == NULL || filename == NULL) { return MRB_DEBUG_INVALID_ARGUMENT; } ext = strrchr(filename, '.'); if (ext == NULL || strcmp(ext, ".rb")) { printf("List command only supports .rb file.\n"); return MRB_DEBUG_INVALID_ARGUMENT; } if (line_min > line_max) { return MRB_DEBUG_INVALID_ARGUMENT; } if ((file = source_file_new(mrb, dbg, filename)) != NULL) { show_lines(file, line_min, line_max); source_file_free(mrb, file); return MRB_DEBUG_OK; } else { printf("Invalid source file named %s.\n", filename); return MRB_DEBUG_INVALID_ARGUMENT; } }
int main (int argc, char** argv) { output_file = stdout; program_name = basename (argv[0]); init_command (argc-1, argv+1); source_path = getenv ("COVERAGE_PATH"); if (source_path == NULL) { source_path = "."; } augment_source_path (source_path); while (TRUE) { get_command (); switch ((int)command) { case QUIT: { exit (0); break; } case DUMMY: { break; } case EXEC_FILE: { FILE *f = fopen (*arg_v, "r"); if (f == NULL) { sprintf (error_message, "cannot open command file %s", *arg_v); error (); } command_file_stack [++nb_command_files] = f; command_source = FROM_FILE; break; } case READ_DATABASE: { while (arg_c-- > 0) { read_coverage_data (*arg_v++); } break; } case WRITE_DATABASE: { ensure_that_database_is_loaded (); while (arg_c-- > 0) { write_coverage_data (*arg_v++); } break; } case SHOW_LINES: { ensure_that_database_is_loaded (); while (arg_c-- > 0) { show_lines (basename (*arg_v++)); } break; } case SHOW_LINES_ALL: { collection c; ensure_that_database_is_loaded (); for (c = collections; c != NULL; c = c->next) { show_lines (c->file_name); } break; } case SHOW_PROCS: { ensure_that_database_is_loaded (); while (arg_c-- > 0) { show_procs (basename (*arg_v++)); } break; } case SHOW_PROCS_ALL: { collection c; ensure_that_database_is_loaded (); for (c = collections; c != NULL; c = c->next) { show_procs (c->file_name); } break; } case AUGMENT_SOURCE_PATH: { while (arg_c-- > 0) { augment_source_path (*arg_v++); } break; } case SELECT_OUTPUT: { FILE* f = fopen (*arg_v, "w"); if (f == NULL) { sprintf (error_message, "cannot open %s for output - %s", *arg_v, "redirection ignored\n"); warning (); } else { if (output_file != stdout) { fclose (output_file); } if (verbose_mode) { fprintf (stderr, "output file is now %s\n", *arg_v); } output_file = f; } break; } case VERBOSE_ON: { verbose_mode = TRUE; break; }}} /* exit (0); */ }