#include "expression.h"
#include "language.h"
#include "command.h"
+#include "source.h"
#include "gdbcmd.h"
#include "frame.h"
#include "value.h"
#include "objfiles.h"
#include "annotate.h"
#include "gdbtypes.h"
+#ifdef UI_OUT
+#include "ui-out.h"
+#endif
#ifdef CRLF_SOURCE_FILES
#endif /* ! defined (CRLF_SOURCE_FILES) */
-/* Forward declarations */
-
-int open_source_file PARAMS ((struct symtab *));
-
-void find_source_lines PARAMS ((struct symtab *, int));
-
/* Prototypes for exported functions. */
void _initialize_source PARAMS ((void));
current_source_line = line;
first_line_listed = line;
+#ifdef UI_OUT
+ /* If printing of source lines is disabled, just print file and line number */
+ if (ui_out_test_flags (uiout, ui_source_list))
+ {
+#endif
/* Only prints "No such file or directory" once */
if ((s != last_source_visited) || (!last_source_error))
{
desc = last_source_error;
noerror = 1;
}
+#ifdef UI_OUT
+ }
+ else
+ {
+ desc = -1;
+ noerror = 1;
+ }
+#endif
if (desc < 0)
{
print_sys_errmsg (name, errno);
}
else
+#ifdef UI_OUT
+ ui_out_field_int (uiout, "line", line);
+ ui_out_text (uiout, "\tin ");
+ ui_out_field_string (uiout, "file", s->filename);
+ ui_out_text (uiout, "\n");
+#else
printf_filtered ("%d\tin %s\n", line, s->filename);
+#endif
return;
}
while (nlines-- > 0)
{
+#ifdef UI_OUT
+ char buf[20];
+
+ c = fgetc (stream);
+ if (c == EOF)
+ break;
+ last_line_listed = current_source_line;
+ sprintf (buf, "%d\t", current_source_line++);
+ ui_out_text (uiout, buf);
+ do
+ {
+ if (c < 040 && c != '\t' && c != '\n' && c != '\r')
+ {
+ sprintf (buf, "^%c", c + 0100);
+ ui_out_text (uiout, buf);
+ }
+ else if (c == 0177)
+ ui_out_text (uiout, "^?");
+#ifdef CRLF_SOURCE_FILES
+ else if (c == '\r')
+ {
+ /* Skip a \r character, but only before a \n. */
+ int c1 = fgetc (stream);
+
+ if (c1 != '\n')
+ printf_filtered ("^%c", c + 0100);
+ if (c1 != EOF)
+ ungetc (c1, stream);
+ }
+#endif
+ else
+ {
+ sprintf (buf, "%c", c);
+ ui_out_text (uiout, buf);
+ }
+ }
+ while (c != '\n' && (c = fgetc (stream)) >= 0);
+#else
c = fgetc (stream);
if (c == EOF)
break;
printf_filtered ("%c", c);
}
while (c != '\n' && (c = fgetc (stream)) >= 0);
+#endif
}
fclose (stream);
error ("No default source file yet. Do \"help list\".");
else if (no_end)
{
- if (lines_to_list % 2 == 0)
- print_source_lines (sal.symtab,
- max (sal.line - (lines_to_list / 2), 1),
- sal.line + (lines_to_list / 2), 0);
- else
- /* If lines_to_list is odd, then we round down in
- * one of the lines_to_list/2 computations, round up in
- * the other, so the total window size around the specified
- * line comes out right.
- */
- print_source_lines (sal.symtab,
- max (sal.line - (lines_to_list / 2), 1),
- sal.line + ((1 + lines_to_list) / 2), 0);
+ int first_line = sal.line - lines_to_list / 2;
+
+ if (first_line < 1) first_line = 1;
+
+ print_source_lines (sal.symtab, first_line, first_line + lines_to_list,
+ 0);
}
else
print_source_lines (sal.symtab, sal.line,