// If LINE is an argument-setting command, add it to the list of arguments void add_to_arguments(const string& line) { if (is_set_args_cmd(line)) { string args = line.after("args"); args = args.after(rxwhite); add_argument(args, run_arguments, last_run_argument, run_arguments_updated); } else if (gdb->type() == PERL && line.contains("@ARGV = ", 0)) { // @ARGV = ('arg1', 'arg2', ) string args = line.after("('"); args.gsub("', '", " "); args = args.before("', )"); add_argument(args, run_arguments, last_run_argument, run_arguments_updated); } else if (is_run_cmd(line)) { string args; if (gdb->type() == JDB) { // `run CLASS ARGS...' args = line.after(rxwhite); args = args.after(rxwhite); } else if (gdb->type() == PERL && line.contains("exec ", 0)) { // `exec "perl -d PROGRAM ARGS..."' args = line.after("exec "); strip_leading_space(args); if (args.contains('\"', 0) || args.contains('\'', 0)) args = unquote(args); args = args.after("-d "); strip_leading_space(args); args = args.after(rxwhite); } else { // `run ARGS...' args = line.after(rxwhite); } add_argument(args, run_arguments, last_run_argument, run_arguments_updated); } else if (is_make_cmd(line)) { string args = line.after("make"); args = args.after(rxwhite); add_argument(args, make_arguments, last_make_argument, make_arguments_updated); } else if (gdb->type() == PERL && line.contains("system 'make", 0)) { string args = line.after("make"); args = args.after(rxwhite); args = args.before("'"); add_argument(args, make_arguments, last_make_argument, make_arguments_updated); } else if (is_cd_cmd(line)) { string dir = line.after("cd"); dir = dir.after(rxwhite); dir = source_view->full_path(dir); if (dir.contains('/', 0)) add_argument(dir, cd_arguments, last_cd_argument, cd_arguments_updated); } else if (gdb->type() == PERL && line.contains("chdir '", 0)) { string dir = line.after("'"); dir = dir.before("'"); add_argument(dir, cd_arguments, last_cd_argument, cd_arguments_updated); } else if (gdb->type() == PERL && is_file_cmd(line, gdb)) { string args = line.after(" -d "); args = args.after(rxwhite); // Skip file name args = args.before('\"'); add_argument(args, run_arguments, last_run_argument, run_arguments_updated); } }
// Load history from history file void load_history(const string& file) { if (file.empty()) return; // Delay d; std::ifstream is(file.chars()); if (is.bad()) return; static const StringArray empty; gdb_history = empty; #if WITH_READLINE clear_history(); #endif assert(gdb_history.size() == 0); // If the first command in history is a `file' command, // insert them all and disregard later ones. bool first_command = true; bool first_is_file = false; bool get_files = true; while (is) { // We accept lines up to a length of ARG_MAX (the maximum // length of the ARGV argument passed to a program) char _line[ARG_MAX + BUFSIZ]; _line[0] = '\0'; is.getline(_line, sizeof(_line)); if (_line[0] != '\0') { string line(_line); bool added = false; if (is_file_cmd(line, gdb) && line != "# reset") { if (first_command) first_is_file = true; if (get_files) { string arg = line.after(rxwhite); if (gdb->type() == PERL) { arg = arg.after(" -d "); arg = arg.before('\"'); if (arg.contains(rxwhite)) arg = arg.before(rxwhite); } add_to_recent(arg); added = first_is_file; } } else { if (first_is_file) get_files = false; if (first_command) first_is_file = false; } if (!added && line[0] != '#') { gdb_history += line; add_to_arguments(line); #if WITH_READLINE add_history(line.chars()); #endif } first_command = false; } } gdb_history += ""; gdb_current_history = gdb_history.size() - 1; gdb_new_history = true; update_arguments(); update_combo_boxes(); }