GDB (API)
/home/stan/gdb/src/gdb/tui/tui-out.c
Go to the documentation of this file.
00001 /* Output generating routines for GDB CLI.
00002 
00003    Copyright (C) 1999-2013 Free Software Foundation, Inc.
00004 
00005    Contributed by Cygnus Solutions.
00006    Written by Fernando Nasser for Cygnus.
00007 
00008    This file is part of GDB.
00009 
00010    This program is free software; you can redistribute it and/or modify
00011    it under the terms of the GNU General Public License as published by
00012    the Free Software Foundation; either version 3 of the License, or
00013    (at your option) any later version.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    You should have received a copy of the GNU General Public License
00021    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00022 
00023 #include "defs.h"
00024 #include "ui-out.h"
00025 #include "cli-out.h"
00026 #include "tui.h"
00027 #include "gdb_string.h"
00028 #include "gdb_assert.h"
00029 
00030 struct tui_ui_out_data
00031   {
00032     struct cli_ui_out_data base;
00033 
00034     int line;
00035     int start_of_line;
00036   };
00037 typedef struct tui_ui_out_data tui_out_data;
00038 
00039 /* This is the TUI ui-out implementation functions vector.  It is
00040    initialized below in _initialize_tui_out, inheriting the CLI
00041    version, and overriding a few methods.  */
00042 
00043 static struct ui_out_impl tui_ui_out_impl;
00044 
00045 /* Output an int field.  */
00046 
00047 static void
00048 tui_field_int (struct ui_out *uiout, 
00049                int fldno, int width,
00050                enum ui_align alignment,
00051                const char *fldname, 
00052                int value)
00053 {
00054   tui_out_data *data = ui_out_data (uiout);
00055 
00056   if (data->base.suppress_output)
00057     return;
00058 
00059   /* Don't print line number, keep it for later.  */
00060   if (data->start_of_line == 0 && strcmp (fldname, "line") == 0)
00061     {
00062       data->start_of_line ++;
00063       data->line = value;
00064       return;
00065     }
00066   data->start_of_line ++;
00067 
00068   (*cli_ui_out_impl.field_int) (uiout, fldno,
00069                                 width, alignment, fldname, value);
00070 }
00071 
00072 /* Other cli_field_* end up here so alignment and field separators are
00073    both handled by tui_field_string.  */
00074 
00075 static void
00076 tui_field_string (struct ui_out *uiout,
00077                   int fldno, int width,
00078                   enum ui_align align,
00079                   const char *fldname,
00080                   const char *string)
00081 {
00082   tui_out_data *data = ui_out_data (uiout);
00083 
00084   if (data->base.suppress_output)
00085     return;
00086 
00087   if (fldname && data->line > 0 && strcmp (fldname, "fullname") == 0)
00088     {
00089       data->start_of_line ++;
00090       if (data->line > 0)
00091         {
00092           tui_show_source (string, data->line);
00093         }
00094       return;
00095     }
00096   
00097   data->start_of_line++;
00098 
00099   (*cli_ui_out_impl.field_string) (uiout, fldno,
00100                                    width, align,
00101                                    fldname, string);
00102 }
00103 
00104 /* This is the only field function that does not align.  */
00105 
00106 static void
00107 tui_field_fmt (struct ui_out *uiout, int fldno,
00108                int width, enum ui_align align,
00109                const char *fldname,
00110                const char *format,
00111                va_list args)
00112 {
00113   tui_out_data *data = ui_out_data (uiout);
00114 
00115   if (data->base.suppress_output)
00116     return;
00117 
00118   data->start_of_line++;
00119 
00120   (*cli_ui_out_impl.field_fmt) (uiout, fldno,
00121                                 width, align,
00122                                 fldname, format, args);
00123 }
00124 
00125 static void
00126 tui_text (struct ui_out *uiout, const char *string)
00127 {
00128   tui_out_data *data = ui_out_data (uiout);
00129 
00130   if (data->base.suppress_output)
00131     return;
00132   data->start_of_line ++;
00133   if (data->line > 0)
00134     {
00135       if (strchr (string, '\n') != 0)
00136         {
00137           data->line = -1;
00138           data->start_of_line = 0;
00139         }
00140       return;
00141     }
00142   if (strchr (string, '\n'))
00143     data->start_of_line = 0;
00144 
00145   (*cli_ui_out_impl.text) (uiout, string);
00146 }
00147 
00148 struct ui_out *
00149 tui_out_new (struct ui_file *stream)
00150 {
00151   int flags = 0;
00152 
00153   tui_out_data *data = XMALLOC (tui_out_data);
00154 
00155   /* Initialize base "class".  */
00156   cli_out_data_ctor (&data->base, stream);
00157 
00158   /* Initialize our fields.  */
00159   data->line = -1;
00160   data->start_of_line = 0;
00161 
00162   return ui_out_new (&tui_ui_out_impl, data, flags);
00163 }
00164 
00165 /* Standard gdb initialization hook.  */
00166 
00167 extern void _initialize_tui_out (void);
00168 
00169 void
00170 _initialize_tui_out (void)
00171 {
00172   /* Inherit the CLI version.  */
00173   tui_ui_out_impl = cli_ui_out_impl;
00174 
00175   /* Override a few methods.  */
00176   tui_ui_out_impl.field_int = tui_field_int;
00177   tui_ui_out_impl.field_string = tui_field_string;
00178   tui_ui_out_impl.field_fmt = tui_field_fmt;
00179   tui_ui_out_impl.text = tui_text;
00180 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines