Use bool for is_exec_point
[deliverable/binutils-gdb.git] / gdb / tui / tui-source.c
index 9c2a982cc0cdbbc94c77645a322a6cd56b322d7b..54e4e1be903efdcd9a5cc8399f4be985d78b29e3 100644 (file)
@@ -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,96 +129,86 @@ 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;
 
-      if ((ret = tui_alloc_source_buffer (TUI_SRC_WIN)) == TUI_SUCCESS)
+      ret = TUI_SUCCESS;
+      tui_alloc_source_buffer (TUI_SRC_WIN);
+      line_width = TUI_SRC_WIN->width - 1;
+      /* Take hilite (window border) into account, when
+        calculating the number of lines.  */
+      nlines = (line_no + (TUI_SRC_WIN->height - 2)) - line_no;
+
+      std::string srclines;
+      if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
+                                           &srclines))
        {
-         line_width = TUI_SRC_WIN->generic.width - 1;
-         /* Take hilite (window border) into account, when
-            calculating the number of lines.  */
-         nlines = (line_no + (TUI_SRC_WIN->generic.height - 2)) - line_no;
-
-         std::string srclines;
-         if (!g_source_cache.get_source_lines (s, line_no, line_no + nlines,
-                                               &srclines))
+         if (!noerror)
            {
-             if (!noerror)
-               {
-                 const char *filename = symtab_to_filename_for_display (s);
-                 char *name = (char *) alloca (strlen (filename) + 100);
-
-                 sprintf (name, "%s:%d", filename, line_no);
-                 print_sys_errmsg (name, errno);
-               }
-             ret = TUI_FAILURE;
+             const char *filename = symtab_to_filename_for_display (s);
+             char *name = (char *) alloca (strlen (filename) + 100);
+
+             sprintf (name, "%s:%d", filename, line_no);
+             print_sys_errmsg (name, errno);
            }
-         else
+         ret = TUI_FAILURE;
+       }
+      else
+       {
+         int cur_line_no, cur_line;
+         struct tui_locator_window *locator
+           = tui_locator_win_info_ptr ();
+         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->title)
+           xfree (TUI_SRC_WIN->title);
+         TUI_SRC_WIN->title = xstrdup (s_filename);
+
+         xfree (src->fullname);
+         src->fullname = xstrdup (symtab_to_fullname (s));
+
+         cur_line = 0;
+         src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+         src->start_line_or_addr.loa = LOA_LINE;
+         cur_line_no = src->start_line_or_addr.u.line_no = line_no;
+
+         const char *iter = srclines.c_str ();
+         while (cur_line < nlines)
            {
-             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;
-             const char *s_filename = symtab_to_filename_for_display (s);
-
-             if (TUI_SRC_WIN->generic.title)
-               xfree (TUI_SRC_WIN->generic.title);
-             TUI_SRC_WIN->generic.title = xstrdup (s_filename);
-
-             xfree (src->fullname);
-             src->fullname = xstrdup (symtab_to_fullname (s));
-
-             cur_line = 0;
-             src->gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
-             src->start_line_or_addr.loa = LOA_LINE;
-             cur_line_no = src->start_line_or_addr.u.line_no = line_no;
-
-             const char *iter = srclines.c_str ();
-             while (cur_line < nlines)
-               {
-                 struct tui_win_element *element
-                   = TUI_SRC_WIN->generic.content[cur_line];
-
-                 std::string text;
-                 if (*iter != '\0')
-                   text = copy_source_line (&iter, cur_line_no,
-                                            src->horizontal_offset,
-                                            line_width);
-
-                 /* Set whether element is the execution point
-                    and whether there is a break point on it.  */
-                 element->which_element.source.line_or_addr.loa =
-                   LOA_LINE;
-                 element->which_element.source.line_or_addr.u.line_no =
-                   cur_line_no;
-                 element->which_element.source.is_exec_point =
-                   (filename_cmp (locator->content[0]
-                                  ->which_element.locator.full_name,
-                                  symtab_to_fullname (s)) == 0
-                    && cur_line_no
-                    == locator->content[0]
-                    ->which_element.locator.line_no);
-
-                 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 ());
-
-                 cur_line++;
-                 cur_line_no++;
-               }
-             TUI_SRC_WIN->generic.content_size = nlines;
-             ret = TUI_SUCCESS;
+             struct tui_win_element *element
+               = TUI_SRC_WIN->content[cur_line];
+
+             std::string text;
+             if (*iter != '\0')
+               text = copy_source_line (&iter, cur_line_no,
+                                        src->horizontal_offset,
+                                        line_width);
+
+             /* Set whether element is the execution point
+                and whether there is a break point on it.  */
+             element->which_element.source.line_or_addr.loa =
+               LOA_LINE;
+             element->which_element.source.line_or_addr.u.line_no =
+               cur_line_no;
+             element->which_element.source.is_exec_point =
+               (filename_cmp (locator->full_name,
+                              symtab_to_fullname (s)) == 0
+                && cur_line_no == locator->line_no);
+
+             xfree (TUI_SRC_WIN->content[cur_line]
+                    ->which_element.source.line);
+             TUI_SRC_WIN->content[cur_line]
+               ->which_element.source.line
+               = xstrdup (text.c_str ());
+
+             cur_line++;
+             cur_line_no++;
            }
+         TUI_SRC_WIN->content_size = nlines;
+         ret = TUI_SUCCESS;
        }
     }
   return ret;
@@ -230,22 +229,22 @@ tui_set_source_content_nil (struct tui_win_info *win_info,
   int n_lines;
   int curr_line = 0;
 
-  line_width = win_info->generic.width - 1;
-  n_lines = win_info->generic.height - 2;
+  line_width = win_info->width - 1;
+  n_lines = win_info->height - 2;
 
   /* Set to empty each line in the window, except for the one which
      contains the message.  */
-  while (curr_line < win_info->generic.content_size)
+  while (curr_line < win_info->content_size)
     {
       /* Set the information related to each displayed line to null:
          i.e. the line number is 0, there is no bp, it is not where
          the program is stopped.  */
 
-      struct tui_win_element *element = win_info->generic.content[curr_line];
+      struct tui_win_element *element = win_info->content[curr_line];
 
       element->which_element.source.line_or_addr.loa = LOA_LINE;
       element->which_element.source.line_or_addr.u.line_no = 0;
-      element->which_element.source.is_exec_point = FALSE;
+      element->which_element.source.is_exec_point = false;
       element->which_element.source.has_break = FALSE;
 
       /* Set the contents of the line to blank.  */
@@ -260,33 +259,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 +285,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);
 }
 
@@ -308,48 +296,37 @@ int
 tui_source_is_displayed (const char *fullname)
 {
   return (TUI_SRC_WIN != NULL
-         && TUI_SRC_WIN->generic.content_in_use 
-         && (filename_cmp (tui_locator_win_info_ptr ()->content[0]
-                             ->which_element.locator.full_name,
+         && TUI_SRC_WIN->content_in_use 
+         && (filename_cmp (tui_locator_win_info_ptr ()->full_name,
                            fullname) == 0));
 }
 
 
 /* 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 (int num_to_scroll)
 {
-  if (TUI_SRC_WIN->generic.content != NULL)
+  if (content != NULL)
     {
       struct tui_line_or_address l;
       struct symtab *s;
-      tui_win_content content = TUI_SRC_WIN->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;
 
       l.loa = LOA_LINE;
-      if (scroll_direction == FORWARD_SCROLL)
-       {
-         l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
-           + num_to_scroll;
-         if (l.u.line_no > s->nlines)
-           /* line = s->nlines - win_info->generic.content_size + 1; */
-           /* elz: fix for dts 23398.  */
-           l.u.line_no
-             = content[0]->which_element.source.line_or_addr.u.line_no;
-       }
-      else
-       {
-         l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
-           - num_to_scroll;
-         if (l.u.line_no <= 0)
-           l.u.line_no = 1;
-       }
+      l.u.line_no = content[0]->which_element.source.line_or_addr.u.line_no
+       + num_to_scroll;
+      if (l.u.line_no > s->nlines)
+       /* line = s->nlines - win_info->content_size + 1; */
+       /* elz: fix for dts 23398.  */
+       l.u.line_no
+         = content[0]->which_element.source.line_or_addr.u.line_no;
+      if (l.u.line_no <= 0)
+       l.u.line_no = 1;
 
       print_source_lines (s, l.u.line_no, l.u.line_no + 1, 0);
     }
This page took 0.029242 seconds and 4 git commands to generate.