+
+/* Implement the "show substitute-path" command. */
+
+static void
+show_substitute_path_command (const char *args, int from_tty)
+{
+ struct substitute_path_rule *rule = substitute_path_rules;
+ char *from = NULL;
+
+ gdb_argv argv (args);
+
+ /* We expect zero or one argument. */
+
+ if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
+ error (_("Too many arguments in command"));
+
+ if (argv != NULL && argv[0] != NULL)
+ from = argv[0];
+
+ /* Print the substitution rules. */
+
+ if (from != NULL)
+ printf_filtered
+ (_("Source path substitution rule matching `%s':\n"), from);
+ else
+ printf_filtered (_("List of all source path substitution rules:\n"));
+
+ while (rule != NULL)
+ {
+ if (from == NULL || substitute_path_rule_matches (rule, from) != 0)
+ printf_filtered (" `%s' -> `%s'.\n", rule->from, rule->to);
+ rule = rule->next;
+ }
+}
+
+/* Implement the "unset substitute-path" command. */
+
+static void
+unset_substitute_path_command (const char *args, int from_tty)
+{
+ struct substitute_path_rule *rule = substitute_path_rules;
+ gdb_argv argv (args);
+ char *from = NULL;
+ int rule_found = 0;
+
+ /* This function takes either 0 or 1 argument. */
+
+ if (argv != NULL && argv[0] != NULL && argv[1] != NULL)
+ error (_("Incorrect usage, too many arguments in command"));
+
+ if (argv != NULL && argv[0] != NULL)
+ from = argv[0];
+
+ /* If the user asked for all the rules to be deleted, ask him
+ to confirm and give him a chance to abort before the action
+ is performed. */
+
+ if (from == NULL
+ && !query (_("Delete all source path substitution rules? ")))
+ error (_("Canceled"));
+
+ /* Delete the rule matching the argument. No argument means that
+ all rules should be deleted. */
+
+ while (rule != NULL)
+ {
+ struct substitute_path_rule *next = rule->next;
+
+ if (from == NULL || FILENAME_CMP (from, rule->from) == 0)
+ {
+ delete_substitute_path_rule (rule);
+ rule_found = 1;
+ }
+
+ rule = next;
+ }
+
+ /* If the user asked for a specific rule to be deleted but
+ we could not find it, then report an error. */
+
+ if (from != NULL && !rule_found)
+ error (_("No substitution rule defined for `%s'"), from);
+
+ forget_cached_source_info ();
+}
+
+/* Add a new source path substitution rule. */
+
+static void
+set_substitute_path_command (const char *args, int from_tty)
+{
+ struct substitute_path_rule *rule;
+
+ gdb_argv argv (args);
+
+ if (argv == NULL || argv[0] == NULL || argv [1] == NULL)
+ error (_("Incorrect usage, too few arguments in command"));
+
+ if (argv[2] != NULL)
+ error (_("Incorrect usage, too many arguments in command"));
+
+ if (*(argv[0]) == '\0')
+ error (_("First argument must be at least one character long"));
+
+ /* Strip any trailing directory separator character in either FROM
+ or TO. The substitution rule already implicitly contains them. */
+ strip_trailing_directory_separator (argv[0]);
+ strip_trailing_directory_separator (argv[1]);
+
+ /* If a rule with the same "from" was previously defined, then
+ delete it. This new rule replaces it. */
+
+ rule = find_substitute_path_rule (argv[0]);
+ if (rule != NULL)
+ delete_substitute_path_rule (rule);
+
+ /* Insert the new substitution rule. */
+
+ add_substitute_path_rule (argv[0], argv[1]);
+ forget_cached_source_info ();
+}
+
+/* See source.h. */
+
+source_lines_range::source_lines_range (int startline,
+ source_lines_range::direction dir)
+{
+ if (dir == source_lines_range::FORWARD)
+ {
+ LONGEST end = static_cast <LONGEST> (startline) + get_lines_to_list ();
+
+ if (end > INT_MAX)
+ end = INT_MAX;
+
+ m_startline = startline;
+ m_stopline = static_cast <int> (end);
+ }
+ else
+ {
+ LONGEST start = static_cast <LONGEST> (startline) - get_lines_to_list ();
+
+ if (start < 1)
+ start = 1;
+
+ m_startline = static_cast <int> (start);
+ m_stopline = startline;
+ }
+}
+