Inline constructors and initializers
[deliverable/binutils-gdb.git] / gdb / tui / tui-source.c
index 260b27429789bd04f9e9c489a2529b6a64740e1d..ac3f225e1b1e0be6c6e9f7b28afb42ef80ebd821 100644 (file)
@@ -1,6 +1,6 @@
 /* TUI display source window.
 
-   Copyright (C) 1998-2018 Free Software Foundation, Inc.
+   Copyright (C) 1998-2019 Free Software Foundation, Inc.
 
    Contributed by Hewlett-Packard Company.
 
@@ -25,7 +25,6 @@
 #include "frame.h"
 #include "breakpoint.h"
 #include "source.h"
-#include "symtab.h"
 #include "objfiles.h"
 #include "filenames.h"
 #include "source-cache.h"
@@ -72,10 +71,27 @@ copy_source_line (const char **ptr, int line_no, int first_col,
 
       ++lineptr;
       ++column;
+
+      auto process_tab = [&] ()
+       {
+         int max_tab_len = tui_tab_width;
+
+         --column;
+         for (int j = column % max_tab_len;
+              j < max_tab_len && column < first_col + line_width;
+              column++, j++)
+           if (column >= first_col)
+             result.push_back (' ');
+       };
+
       /* We have to process all the text in order to pick up all the
         escapes.  */
-      if (column < first_col || column > first_col + line_width)
-       continue;
+      if (column <= first_col || column > first_col + line_width)
+       {
+         if (c == '\t')
+           process_tab ();
+         continue;
+       }
 
       if (c == '\n' || c == '\r' || c == '\0')
        {
@@ -92,14 +108,7 @@ copy_source_line (const char **ptr, int line_no, int first_col,
          result.push_back ('?');
        }
       else if (c == '\t')
-       {
-         int j, max_tab_len = tui_tab_width;
-
-         for (j = column - ((column / max_tab_len) * max_tab_len);
-              j < max_tab_len && column < first_col + line_width;
-              column++, j++)
-           result.push_back (' ');
-       }
+       process_tab ();
       else
        result.push_back (c);
     }
@@ -120,7 +129,7 @@ tui_set_source_content (struct symtab *s,
 {
   enum tui_status ret = TUI_FAILURE;
 
-  if (s != (struct symtab *) NULL)
+  if (s != NULL)
     {
       int line_width, nlines;
 
@@ -150,8 +159,8 @@ tui_set_source_content (struct symtab *s,
              int cur_line_no, cur_line;
              struct tui_gen_win_info *locator
                = tui_locator_win_info_ptr ();
-             struct tui_source_info *src
-               = &TUI_SRC_WIN->detail.source_info;
+             struct tui_source_window_base *src
+               = (struct tui_source_window_base *) TUI_SRC_WIN;
              const char *s_filename = symtab_to_filename_for_display (s);
 
              if (TUI_SRC_WIN->generic.title)
@@ -194,15 +203,9 @@ tui_set_source_content (struct symtab *s,
 
                  xfree (TUI_SRC_WIN->generic.content[cur_line]
                         ->which_element.source.line);
-                 int alloc_len = text.size ();
-                 if (alloc_len < line_width)
-                   alloc_len = line_width + 1;
                  TUI_SRC_WIN->generic.content[cur_line]
                    ->which_element.source.line
-                   = (char *) xmalloc (alloc_len);
-                 strcpy (TUI_SRC_WIN->generic.content[cur_line]
-                         ->which_element.source.line,
-                         text.c_str ());
+                   = xstrdup (text.c_str ());
 
                  cur_line++;
                  cur_line_no++;
@@ -260,33 +263,22 @@ tui_set_source_content_nil (struct tui_win_info *win_info,
 
       if (curr_line == (n_lines / 2 + 1))
        {
-         int i;
          int xpos;
          int warning_length = strlen (warning_string);
          char *src_line;
 
-         src_line = element->which_element.source.line;
-
          if (warning_length >= ((line_width - 1) / 2))
            xpos = 1;
          else
            xpos = (line_width - 1) / 2 - warning_length;
 
-         for (i = 0; i < xpos; i++)
-           src_line[i] = ' ';
-
-         sprintf (src_line + i, "%s", warning_string);
-
-         for (i = xpos + warning_length; i < line_width; i++)
-           src_line[i] = ' ';
-
-         src_line[i] = '\n';
-
-       }                       /* end if */
+         src_line = xstrprintf ("%s%s", n_spaces (xpos), warning_string);
+         xfree (element->which_element.source.line);
+         element->which_element.source.line = src_line;
+       }
 
       curr_line++;
-
-    }                          /* end while */
+    }
 }
 
 
@@ -297,7 +289,7 @@ tui_show_symtab_source (struct gdbarch *gdbarch, struct symtab *s,
                        struct tui_line_or_address line, 
                        int noerror)
 {
-  TUI_SRC_WIN->detail.source_info.horizontal_offset = 0;
+  TUI_SRC_WIN->horizontal_offset = 0;
   tui_update_source_window_as_is (TUI_SRC_WIN, gdbarch, s, line, noerror);
 }
 
@@ -317,17 +309,17 @@ tui_source_is_displayed (const char *fullname)
 
 /* Scroll the source forward or backward vertically.  */
 void
-tui_vertical_source_scroll (enum tui_scroll_direction scroll_direction,
-                           int num_to_scroll)
+tui_source_window::do_scroll_vertical
+  (enum tui_scroll_direction scroll_direction, int num_to_scroll)
 {
-  if (TUI_SRC_WIN->generic.content != NULL)
+  if (generic.content != NULL)
     {
       struct tui_line_or_address l;
       struct symtab *s;
-      tui_win_content content = TUI_SRC_WIN->generic.content;
+      tui_win_content content = generic.content;
       struct symtab_and_line cursal = get_current_source_symtab_and_line ();
 
-      if (cursal.symtab == (struct symtab *) NULL)
+      if (cursal.symtab == NULL)
        s = find_pc_line_symtab (get_frame_pc (get_selected_frame (NULL)));
       else
        s = cursal.symtab;
This page took 0.027976 seconds and 4 git commands to generate.