* frame.h (selected_frame_level): Document as deprecated.
[deliverable/binutils-gdb.git] / gdb / mi / mi-console.c
CommitLineData
fb40c209 1/* MI Console code.
349c5d5f
AC
2
3 Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
4
ab91fdd5 5 Contributed by Cygnus Solutions (a Red Hat company).
fb40c209
AC
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24#include "defs.h"
25#include "mi-console.h"
27b82ed2 26#include "gdb_string.h"
fb40c209 27
fb40c209
AC
28/* MI-console: send output to std-out but correcty encapsulated */
29
30static ui_file_fputs_ftype mi_console_file_fputs;
31static ui_file_flush_ftype mi_console_file_flush;
32static ui_file_delete_ftype mi_console_file_delete;
33
34struct mi_console_file
35 {
36 int *magic;
37 struct ui_file *raw;
38 struct ui_file *buffer;
39 const char *prefix;
40 };
41
42int mi_console_file_magic;
43
44struct ui_file *
45mi_console_file_new (struct ui_file *raw,
46 const char *prefix)
47{
48 struct ui_file *ui_file = ui_file_new ();
49 struct mi_console_file *mi_console = XMALLOC (struct mi_console_file);
50 mi_console->magic = &mi_console_file_magic;
51 mi_console->raw = raw;
52 mi_console->buffer = mem_fileopen ();
53 mi_console->prefix = prefix;
54 set_ui_file_fputs (ui_file, mi_console_file_fputs);
55 set_ui_file_flush (ui_file, mi_console_file_flush);
56 set_ui_file_data (ui_file, mi_console, mi_console_file_delete);
57 return ui_file;
58}
59
60static void
61mi_console_file_delete (struct ui_file *file)
62{
63 struct mi_console_file *mi_console = ui_file_data (file);
64 if (mi_console->magic != &mi_console_file_magic)
8e65ff28
AC
65 internal_error (__FILE__, __LINE__,
66 "mi_console_file_delete: bad magic number");
b8c9b27d 67 xfree (mi_console);
fb40c209
AC
68}
69
70static void
71mi_console_file_fputs (const char *buf,
72 struct ui_file *file)
73{
74 struct mi_console_file *mi_console = ui_file_data (file);
75 if (mi_console->magic != &mi_console_file_magic)
8e65ff28
AC
76 internal_error (__FILE__, __LINE__,
77 "mi_console_file_fputs: bad magic number");
fb40c209
AC
78 /* Append the text to our internal buffer */
79 fputs_unfiltered (buf, mi_console->buffer);
80 /* Flush when an embedded \n */
81 if (strchr (buf, '\n') != NULL)
82 gdb_flush (file);
83}
84
85/* Transform a byte sequence into a console output packet. */
86static void
87mi_console_raw_packet (void *data,
88 const char *buf,
89 long length_buf)
90{
91 struct mi_console_file *mi_console = data;
92 if (mi_console->magic != &mi_console_file_magic)
8e65ff28
AC
93 internal_error (__FILE__, __LINE__,
94 "mi_console_file_transform: bad magic number");
fb40c209
AC
95
96 if (length_buf > 0)
97 {
98 fputs_unfiltered (mi_console->prefix, mi_console->raw);
99 fputs_unfiltered ("\"", mi_console->raw);
100 fputstrn_unfiltered (buf, length_buf, '"', mi_console->raw);
101 fputs_unfiltered ("\"\n", mi_console->raw);
102 gdb_flush (mi_console->raw);
103 }
104}
105
106static void
107mi_console_file_flush (struct ui_file *file)
108{
109 struct mi_console_file *mi_console = ui_file_data (file);
110 if (mi_console->magic != &mi_console_file_magic)
8e65ff28
AC
111 internal_error (__FILE__, __LINE__,
112 "mi_console_file_flush: bad magic number");
fb40c209
AC
113 ui_file_put (mi_console->buffer, mi_console_raw_packet, mi_console);
114 ui_file_rewind (mi_console->buffer);
115}
This page took 0.188662 seconds and 4 git commands to generate.