]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/osdata.c
Use ui_out_emit_tuple
[thirdparty/binutils-gdb.git] / gdb / osdata.c
index 887b4e3d2828babe224c39b1dbd605234965c899..b9014dddf278a0d5e61b35bf098278ecb1757124 100644 (file)
@@ -1,6 +1,6 @@
 /* Routines for handling XML generic OS data provided by target.
 
-   Copyright (C) 2008-2014 Free Software Foundation, Inc.
+   Copyright (C) 2008-2017 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -22,7 +22,6 @@
 #include "vec.h"
 #include "xml-support.h"
 #include "osdata.h"
-#include <string.h>
 #include "ui-out.h"
 #include "gdbcmd.h"
 
@@ -59,15 +58,15 @@ osdata_start_osdata (struct gdb_xml_parser *parser,
                         const struct gdb_xml_element *element,
                         void *user_data, VEC(gdb_xml_value_s) *attributes)
 {
-  struct osdata_parsing_data *data = user_data;
+  struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
   char *type;
   struct osdata *osdata;
 
   if (data->osdata)
     gdb_xml_error (parser, _("Seen more than on osdata element"));
 
-  type = xml_find_attribute (attributes, "type")->value;
-  osdata = XZALLOC (struct osdata);
+  type = (char *) xml_find_attribute (attributes, "type")->value;
+  osdata = XCNEW (struct osdata);
   osdata->type = xstrdup (type);
   data->osdata = osdata;
 }
@@ -79,7 +78,7 @@ osdata_start_item (struct gdb_xml_parser *parser,
                   const struct gdb_xml_element *element,
                   void *user_data, VEC(gdb_xml_value_s) *attributes)
 {
-  struct osdata_parsing_data *data = user_data;
+  struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
   struct osdata_item item = { NULL };
 
   VEC_safe_push (osdata_item_s, data->osdata->items, &item);
@@ -92,8 +91,9 @@ osdata_start_column (struct gdb_xml_parser *parser,
                     const struct gdb_xml_element *element,
                     void *user_data, VEC(gdb_xml_value_s) *attributes)
 {
-  struct osdata_parsing_data *data = user_data;
-  const char *name = xml_find_attribute (attributes, "name")->value;
+  struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
+  const char *name
+    = (const char *) xml_find_attribute (attributes, "name")->value;
 
   data->property_name = xstrdup (name);
 }
@@ -105,7 +105,7 @@ osdata_end_column (struct gdb_xml_parser *parser,
                   const struct gdb_xml_element *element,
                   void *user_data, const char *body_text)
 {
-  struct osdata_parsing_data *data = user_data;
+  struct osdata_parsing_data *data = (struct osdata_parsing_data *) user_data;
   struct osdata *osdata = data->osdata;
   struct osdata_item *item = VEC_last (osdata_item_s, osdata->items);
   struct osdata_column *col = VEC_safe_push (osdata_column_s,
@@ -122,7 +122,7 @@ osdata_end_column (struct gdb_xml_parser *parser,
 static void
 clear_parsing_data (void *p)
 {
-  struct osdata_parsing_data *data = p;
+  struct osdata_parsing_data *data = (struct osdata_parsing_data *) p;
 
   osdata_free (data->osdata);
   data->osdata = NULL;
@@ -230,7 +230,7 @@ osdata_free (struct osdata *osdata)
 static void
 osdata_free_cleanup (void *arg)
 {
-  struct osdata *osdata = arg;
+  struct osdata *osdata = (struct osdata *) arg;
 
   osdata_free (osdata);
 }
@@ -287,7 +287,7 @@ get_osdata_column (struct osdata_item *item, const char *name)
 }
 
 void
-info_osdata_command (char *type, int from_tty)
+info_osdata (const char *type)
 {
   struct ui_out *uiout = current_uiout;
   struct osdata *osdata = NULL;
@@ -297,12 +297,15 @@ info_osdata_command (char *type, int from_tty)
   int nrows;
   int col_to_skip = -1;
 
+  if (type == NULL)
+    type = "";
+
   osdata = get_osdata (type);
   old_chain = make_cleanup_osdata_free (osdata);
 
   nrows = VEC_length (osdata_item_s, osdata->items);
 
-  if (!type && nrows == 0)
+  if (*type == '\0' && nrows == 0)
     error (_("Available types of OS data not reported."));
   
   if (!VEC_empty (osdata_item_s, osdata->items))
@@ -315,7 +318,7 @@ info_osdata_command (char *type, int from_tty)
         for a column named "Title", and only include it with MI
         output; this column's normal use is for titles for interface
         elements like menus, and it clutters up CLI output.  */
-      if (!type && !ui_out_is_mi_like_p (uiout))
+      if (*type == '\0' && !uiout->is_mi_like_p ())
        {
          struct osdata_column *col;
          int ix;
@@ -361,12 +364,12 @@ info_osdata_command (char *type, int from_tty)
            continue;
 
          snprintf (col_name, 32, "col%d", ix);
-         ui_out_table_header (uiout, 10, ui_left,
+         uiout->table_header (10, ui_left,
                               col_name, col->name);
         }
     }
 
-  ui_out_table_body (uiout);
+  uiout->table_body ();
 
   if (nrows != 0)
     {
@@ -378,35 +381,40 @@ info_osdata_command (char *type, int from_tty)
                        ix_items, item);
           ix_items++)
        {
-         struct cleanup *old_chain;
          int ix_cols;
          struct osdata_column *col;
 
-         old_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "item");
+        {
+          ui_out_emit_tuple tuple_emitter (uiout, "item");
 
-         for (ix_cols = 0;
-              VEC_iterate (osdata_column_s, item->columns,
-                           ix_cols, col);
-              ix_cols++)
-          {
-            char col_name[32];
+          for (ix_cols = 0;
+               VEC_iterate (osdata_column_s, item->columns,
+                            ix_cols, col);
+               ix_cols++)
+            {
+              char col_name[32];
 
-            if (ix_cols == col_to_skip)
-              continue;
+              if (ix_cols == col_to_skip)
+                continue;
 
-            snprintf (col_name, 32, "col%d", ix_cols);
-            ui_out_field_string (uiout, col_name, col->value);
-          }
-        
-         do_cleanups (old_chain);
+              snprintf (col_name, 32, "col%d", ix_cols);
+              uiout->field_string (col_name, col->value);
+            }
+        }
 
-         ui_out_text (uiout, "\n");
+         uiout->text ("\n");
        }
     }
 
   do_cleanups (old_chain);
 }
 
+static void
+info_osdata_command (char *arg, int from_tty)
+{
+  info_osdata (arg);
+}
+
 extern initialize_file_ftype _initialize_osdata; /* -Wmissing-prototypes */
 
 void