This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Ui-out table cleanup


Hello,

Attatched is a cosmetic change to the ui-out table implementation.  It 
moves all the table variables to their own struct and renames 
get_curr_header() to get_next_header() so that it better matches its 
semantics.

It doesn't fix JimI's bug but, I think, it does make it easier to 
understand why it is there.

	Andrew
2001-12-07  Andrew Cagney  <ac131313@redhat.com>

	* ui-out.c (ui_out_table_begin): Initialize body_flag.
	(struct ui_out_table): New structure.  Move table fields to here.
	Rename headercurr to headernext.
	(struct ui_out): Remove table specific fields.  Add field table.
	(ui_out_table_begin, ui_out_table_body, ui_out_table_end): Update.
	(ui_out_table_header, ui_out_begin): Update.
	(verify_field_proper_position, verify_field_alignment): Update.
	(ui_out_new, clear_header_list, append_header_to_list): Update.
	(get_next_header): Rename get_curr_header.  Update comments and
	code.

Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.18
diff -p -r1.18 ui-out.c
*** ui-out.c	2001/07/06 03:53:11	1.18
--- ui-out.c	2001/12/07 17:41:15
*************** struct ui_out_level
*** 58,63 ****
--- 58,95 ----
      enum ui_out_type type;
    };
  
+ /* Tables are special.  Maintain a separate structure that tracks
+    their state.  At present an output can only contain a single table
+    but that restriction might eventually be lifted.  */
+ 
+ struct ui_out_table
+ {
+   /* If on, a table is being generated.  */
+   int flag;
+ 
+   /* If on, the body of a table is being generated.  If off, the table
+      header is being generated.  */
+   int body_flag;
+ 
+   /* Number of table columns (as specified in the table_begin call).  */
+   int columns;
+ 
+   /* String identifying the table (as specified in the table_begin
+      call).  */
+   char *id;
+ 
+   /* Points to the first table header (if any).  */
+   struct ui_out_hdr *header_first;
+ 
+   /* Points to the last table header (if any).  */
+   struct ui_out_hdr *header_last;
+ 
+   /* Points to header of NEXT column to format.  */
+   struct ui_out_hdr *header_next;
+ 
+ };
+ 
+ 
  /* The ui_out structure */
  /* Any change here requires a corresponding one in the initialization
     of the default uiout, which is statically initialized */
*************** struct ui_out
*** 68,99 ****
      /* specific implementation of ui-out */
      struct ui_out_impl *impl;
      struct ui_out_data *data;
- 
-     /* if on, a table is being generated */
-     int table_flag;
- 
-     /* if on, the body of a table is being generated */
-     int body_flag;
- 
-     /* number of table columns (as specified in the table_begin call) */
-     int table_columns;
  
!     /* strinf identifying the table (as specified in the table_begin call) */
!     char *table_id;
! 
!     /* Sub structure tracking the table depth. */
      int level;
      struct ui_out_level levels[MAX_UI_OUT_LEVELS];
- 
-     /* points to the first header (if any) */
-     struct ui_out_hdr *headerfirst;
- 
-     /* points to the last header (if any) */
-     struct ui_out_hdr *headerlast;
- 
-     /* points to header of next column to format */
-     struct ui_out_hdr *headercurr;
  
    };
  
  /* The current (inner most) level. */
--- 100,112 ----
      /* specific implementation of ui-out */
      struct ui_out_impl *impl;
      struct ui_out_data *data;
  
!     /* Sub structure tracking the ui-out depth.  */
      int level;
      struct ui_out_level levels[MAX_UI_OUT_LEVELS];
  
+     /* A table, if any.  At present only a single table is supported.  */
+     struct ui_out_table table;
    };
  
  /* The current (inner most) level. */
*************** extern void _initialize_ui_out (void);
*** 246,252 ****
  static void append_header_to_list (struct ui_out *uiout, int width,
  				   int alignment, const char *col_name,
  				   const char *colhdr);
! static int get_curr_header (struct ui_out *uiout, int *colno, int *width,
  			    int *alignment, char **colhdr);
  static void clear_header_list (struct ui_out *uiout);
  static void verify_field_proper_position (struct ui_out *uiout);
--- 259,265 ----
  static void append_header_to_list (struct ui_out *uiout, int width,
  				   int alignment, const char *col_name,
  				   const char *colhdr);
! static int get_next_header (struct ui_out *uiout, int *colno, int *width,
  			    int *alignment, char **colhdr);
  static void clear_header_list (struct ui_out *uiout);
  static void verify_field_proper_position (struct ui_out *uiout);
*************** ui_out_table_begin (struct ui_out *uiout
*** 263,302 ****
  		    int nr_rows,
  		    const char *tblid)
  {
!   if (uiout->table_flag)
      internal_error (__FILE__, __LINE__,
  		    "tables cannot be nested; table_begin found before \
  previous table_end.");
  
!   uiout->table_flag = 1;
!   uiout->table_columns = nbrofcols;
    if (tblid != NULL)
!     uiout->table_id = xstrdup (tblid);
    else
!     uiout->table_id = NULL;
    clear_header_list (uiout);
  
!   uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table_id);
  }
  
  void
  ui_out_table_body (struct ui_out *uiout)
  {
!   if (!uiout->table_flag)
      internal_error (__FILE__, __LINE__,
  		    "table_body outside a table is not valid; it must be \
  after a table_begin and before a table_end.");
!   if (uiout->body_flag)
      internal_error (__FILE__, __LINE__,
  		    "extra table_body call not allowed; there must be \
  only one table_body after a table_begin and before a table_end.");
!   if (uiout->headercurr->colno != uiout->table_columns)
      internal_error (__FILE__, __LINE__,
  		    "number of headers differ from number of table \
  columns.");
  
!   uiout->body_flag = 1;
!   uiout->headercurr = uiout->headerfirst;
  
    uo_table_body (uiout);
  }
--- 276,316 ----
  		    int nr_rows,
  		    const char *tblid)
  {
!   if (uiout->table.flag)
      internal_error (__FILE__, __LINE__,
  		    "tables cannot be nested; table_begin found before \
  previous table_end.");
  
!   uiout->table.flag = 1;
!   uiout->table.body_flag = 0;
!   uiout->table.columns = nbrofcols;
    if (tblid != NULL)
!     uiout->table.id = xstrdup (tblid);
    else
!     uiout->table.id = NULL;
    clear_header_list (uiout);
  
!   uo_table_begin (uiout, nbrofcols, nr_rows, uiout->table.id);
  }
  
  void
  ui_out_table_body (struct ui_out *uiout)
  {
!   if (!uiout->table.flag)
      internal_error (__FILE__, __LINE__,
  		    "table_body outside a table is not valid; it must be \
  after a table_begin and before a table_end.");
!   if (uiout->table.body_flag)
      internal_error (__FILE__, __LINE__,
  		    "extra table_body call not allowed; there must be \
  only one table_body after a table_begin and before a table_end.");
!   if (uiout->table.header_next->colno != uiout->table.columns)
      internal_error (__FILE__, __LINE__,
  		    "number of headers differ from number of table \
  columns.");
  
!   uiout->table.body_flag = 1;
!   uiout->table.header_next = uiout->table.header_first;
  
    uo_table_body (uiout);
  }
*************** columns.");
*** 304,320 ****
  void
  ui_out_table_end (struct ui_out *uiout)
  {
!   if (!uiout->table_flag)
      internal_error (__FILE__, __LINE__,
  		    "misplaced table_end or missing table_begin.");
  
!   uiout->body_flag = 0;
!   uiout->table_flag = 0;
  
    uo_table_end (uiout);
  
!   if (uiout->table_id)
!     xfree (uiout->table_id);
    clear_header_list (uiout);
  }
  
--- 318,334 ----
  void
  ui_out_table_end (struct ui_out *uiout)
  {
!   if (!uiout->table.flag)
      internal_error (__FILE__, __LINE__,
  		    "misplaced table_end or missing table_begin.");
  
!   uiout->table.body_flag = 0;
!   uiout->table.flag = 0;
  
    uo_table_end (uiout);
  
!   if (uiout->table.id)
!     xfree (uiout->table.id);
    clear_header_list (uiout);
  }
  
*************** ui_out_table_header (struct ui_out *uiou
*** 323,329 ****
  		     const char *col_name,
  		     const char *colhdr)
  {
!   if (!uiout->table_flag || uiout->body_flag)
      internal_error (__FILE__, __LINE__,
  		    "table header must be specified after table_begin \
  and before table_body.");
--- 337,343 ----
  		     const char *col_name,
  		     const char *colhdr)
  {
!   if (!uiout->table.flag || uiout->table.body_flag)
      internal_error (__FILE__, __LINE__,
  		    "table header must be specified after table_begin \
  and before table_body.");
*************** ui_out_begin (struct ui_out *uiout,
*** 339,351 ****
  	      const char *id)
  {
    int new_level;
!   if (uiout->table_flag && !uiout->body_flag)
      internal_error (__FILE__, __LINE__,
  		    "table header or table_body expected; lists must be \
  specified after table_body.");
    new_level = push_level (uiout, type, id);
!   if (uiout->table_flag && (new_level == 1))
!     uiout->headercurr = uiout->headerfirst;
    uo_begin (uiout, type, new_level, id);
  }
  
--- 353,365 ----
  	      const char *id)
  {
    int new_level;
!   if (uiout->table.flag && !uiout->table.body_flag)
      internal_error (__FILE__, __LINE__,
  		    "table header or table_body expected; lists must be \
  specified after table_body.");
    new_level = push_level (uiout, type, id);
!   if (uiout->table.flag && (new_level == 1))
!     uiout->table.header_next = uiout->table.header_first;
    uo_begin (uiout, type, new_level, id);
  }
  
*************** uo_flush (struct ui_out *uiout)
*** 969,984 ****
  static void
  clear_header_list (struct ui_out *uiout)
  {
!   while (uiout->headerfirst != NULL)
      {
!       uiout->headercurr = uiout->headerfirst;
!       uiout->headerfirst = uiout->headerfirst->next;
!       if (uiout->headercurr->colhdr != NULL)
! 	xfree (uiout->headercurr->colhdr);
!       xfree (uiout->headercurr);
      }
!   uiout->headerlast = NULL;
!   uiout->headercurr = NULL;
  }
  
  static void
--- 983,999 ----
  static void
  clear_header_list (struct ui_out *uiout)
  {
!   while (uiout->table.header_first != NULL)
      {
!       uiout->table.header_next = uiout->table.header_first;
!       uiout->table.header_first = uiout->table.header_first->next;
!       if (uiout->table.header_next->colhdr != NULL)
! 	xfree (uiout->table.header_next->colhdr);
!       xfree (uiout->table.header_next);
      }
!   gdb_assert (uiout->table.header_first == NULL);
!   uiout->table.header_last = NULL;
!   uiout->table.header_next = NULL;
  }
  
  static void
*************** append_header_to_list (struct ui_out *ui
*** 1003,1040 ****
    else
      temphdr->col_name = xstrdup (colhdr);
    temphdr->next = NULL;
!   if (uiout->headerfirst == NULL)
      {
        temphdr->colno = 1;
!       uiout->headerfirst = temphdr;
!       uiout->headerlast = temphdr;
      }
    else
      {
!       temphdr->colno = uiout->headerlast->colno + 1;
!       uiout->headerlast->next = temphdr;
!       uiout->headerlast = temphdr;
      }
!   uiout->headercurr = uiout->headerlast;
  }
  
! /* returns 0 if there is no more headers */
  
  static int
! get_curr_header (struct ui_out *uiout,
  		 int *colno,
  		 int *width,
  		 int *alignment,
  		 char **colhdr)
  {
!   /* There may be no headers at all or we may have used all columns */
!   if (uiout->headercurr == NULL)
      return 0;
!   *colno = uiout->headercurr->colno;
!   *width = uiout->headercurr->width;
!   *alignment = uiout->headercurr->alignment;
!   *colhdr = uiout->headercurr->colhdr;
!   uiout->headercurr = uiout->headercurr->next;
    return 1;
  }
  
--- 1018,1057 ----
    else
      temphdr->col_name = xstrdup (colhdr);
    temphdr->next = NULL;
!   if (uiout->table.header_first == NULL)
      {
        temphdr->colno = 1;
!       uiout->table.header_first = temphdr;
!       uiout->table.header_last = temphdr;
      }
    else
      {
!       temphdr->colno = uiout->table.header_last->colno + 1;
!       uiout->table.header_last->next = temphdr;
!       uiout->table.header_last = temphdr;
      }
!   uiout->table.header_next = uiout->table.header_last;
  }
  
! /* Extract the format information for the NEXT header and and advance
!    the header pointer.  Return 0 if there was no next header.  */
  
  static int
! get_next_header (struct ui_out *uiout,
  		 int *colno,
  		 int *width,
  		 int *alignment,
  		 char **colhdr)
  {
!   /* There may be no headers at all or we may have used all columns.  */
!   if (uiout->table.header_next == NULL)
      return 0;
!   *colno = uiout->table.header_next->colno;
!   *width = uiout->table.header_next->width;
!   *alignment = uiout->table.header_next->alignment;
!   *colhdr = uiout->table.header_next->colhdr;
!   /* Advance the header pointer to the next entry.  */
!   uiout->table.header_next = uiout->table.header_next->next;
    return 1;
  }
  
*************** get_curr_header (struct ui_out *uiout,
*** 1043,1051 ****
  static void
  verify_field_proper_position (struct ui_out *uiout)
  {
!   if (uiout->table_flag)
      {
!       if (!uiout->body_flag)
  	internal_error (__FILE__, __LINE__,
  			"table_body missing; table fields must be \
  specified after table_body and inside a list.");
--- 1060,1068 ----
  static void
  verify_field_proper_position (struct ui_out *uiout)
  {
!   if (uiout->table.flag)
      {
!       if (!uiout->table.body_flag)
  	internal_error (__FILE__, __LINE__,
  			"table_body missing; table fields must be \
  specified after table_body and inside a list.");
*************** verify_field_alignment (struct ui_out *u
*** 1067,1074 ****
    int colno;
    char *text;
  
!   if (uiout->table_flag
!       && get_curr_header (uiout, &colno, width, align, &text))
      {
        if (fldno != colno)
  	internal_error (__FILE__, __LINE__,
--- 1084,1091 ----
    int colno;
    char *text;
  
!   if (uiout->table.flag
!       && get_next_header (uiout, &colno, width, align, &text))
      {
        if (fldno != colno)
  	internal_error (__FILE__, __LINE__,
*************** ui_out_new (struct ui_out_impl *impl,
*** 1107,1119 ****
    uiout->data = data;
    uiout->impl = impl;
    uiout->flags = flags;
!   uiout->table_flag = 0;
!   uiout->body_flag = 0;
    uiout->level = 0;
    memset (uiout->levels, 0, sizeof (uiout->levels));
!   uiout->headerfirst = NULL;
!   uiout->headerlast = NULL;
!   uiout->headercurr = NULL;
    return uiout;
  }
  
--- 1124,1136 ----
    uiout->data = data;
    uiout->impl = impl;
    uiout->flags = flags;
!   uiout->table.flag = 0;
!   uiout->table.body_flag = 0;
    uiout->level = 0;
    memset (uiout->levels, 0, sizeof (uiout->levels));
!   uiout->table.header_first = NULL;
!   uiout->table.header_last = NULL;
!   uiout->table.header_next = NULL;
    return uiout;
  }
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]