Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | // ========== Copyright Header Begin ========================================== |
2 | // | |
3 | // OpenSPARC T2 Processor File: ui.cc | |
4 | // Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
5 | // DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
6 | // | |
7 | // The above named program is free software; you can redistribute it and/or | |
8 | // modify it under the terms of the GNU General Public | |
9 | // License version 2 as published by the Free Software Foundation. | |
10 | // | |
11 | // The above named program is distributed in the hope that it will be | |
12 | // useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public | |
17 | // License along with this work; if not, write to the Free Software | |
18 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | // | |
20 | // ========== Copyright Header End ============================================ | |
21 | ||
22 | #include "ui.h" | |
23 | #include <stdarg.h> | |
24 | #include <stdlib.h> | |
25 | #include <errno.h> | |
26 | ||
27 | UserInterface* ui = new UserInterface(); | |
28 | ||
29 | FILE* UserInterface::log_file = 0; | |
30 | ||
31 | UserInterface::UserInterface( const char* module_name_ )/*{{{*/ | |
32 | : | |
33 | module_name(module_name_ ? strdup(module_name) : 0) | |
34 | {} | |
35 | /*}}}*/ | |
36 | ||
37 | void UserInterface::output( const char* format, ... )/*{{{*/ | |
38 | { | |
39 | va_list ap; | |
40 | ||
41 | va_start(ap, fmt); | |
42 | vfprintf(stdout,format,ap); | |
43 | va_end(ap); | |
44 | ||
45 | if (log_file) | |
46 | { | |
47 | va_start(ap, fmt); | |
48 | vfprintf(log_file,format,ap); | |
49 | va_end(ap); | |
50 | } | |
51 | } | |
52 | /*}}}*/ | |
53 | void UserInterface::verbose( const char* format, ... )/*{{{*/ | |
54 | { | |
55 | va_list ap; | |
56 | ||
57 | if (log_file) | |
58 | { | |
59 | va_start(ap, fmt); | |
60 | vfprintf(log_file,format,ap); | |
61 | va_end(ap); | |
62 | } | |
63 | } | |
64 | /*}}}*/ | |
65 | void UserInterface::warning( const char* format, ... )/*{{{*/ | |
66 | { | |
67 | va_list ap; | |
68 | ||
69 | va_start(ap, fmt); | |
70 | fprintf(stdout,"WARNING: "); | |
71 | if (module_name) | |
72 | fprintf(stdout,"%s: ",module_name); | |
73 | vfprintf(stdout,format,ap); | |
74 | va_end(ap); | |
75 | ||
76 | if (log_file) | |
77 | { | |
78 | va_start(ap, fmt); | |
79 | fprintf(log_file,"WARNING: "); | |
80 | if (module_name) | |
81 | fprintf(stdout,"%s: ",module_name); | |
82 | vfprintf(log_file,format,ap); | |
83 | va_end(ap); | |
84 | } | |
85 | } | |
86 | /*}}}*/ | |
87 | void UserInterface::error( const char* format, ... )/*{{{*/ | |
88 | { | |
89 | va_list ap; | |
90 | ||
91 | va_start(ap, fmt); | |
92 | fprintf(stdout,"ERROR: "); | |
93 | if (module_name) | |
94 | fprintf(stdout,"%s: ",module_name); | |
95 | vfprintf(stdout,format,ap); | |
96 | va_end(ap); | |
97 | ||
98 | if (log_file) | |
99 | { | |
100 | va_start(ap, fmt); | |
101 | fprintf(log_file,"ERROR: "); | |
102 | if (module_name) | |
103 | fprintf(stdout,"%s: ",module_name); | |
104 | vfprintf(log_file,format,ap); | |
105 | va_end(ap); | |
106 | } | |
107 | } | |
108 | /*}}}*/ | |
109 | void UserInterface::fatal( const char* format, ... )/*{{{*/ | |
110 | { | |
111 | va_list ap; | |
112 | ||
113 | va_start(ap, fmt); | |
114 | fprintf(stdout,"FATAL: "); | |
115 | if (module_name) | |
116 | fprintf(stdout,"%s: ",module_name); | |
117 | vfprintf(stdout,format,ap); | |
118 | va_end(ap); | |
119 | fprintf(stdout,"FATAL: forcing core dump.\n"); | |
120 | fflush(stdout); | |
121 | ||
122 | if (log_file) | |
123 | { | |
124 | va_start(ap, fmt); | |
125 | fprintf(log_file,"FATAL: "); | |
126 | if (module_name) | |
127 | fprintf(log_file,"%s: ",module_name); | |
128 | vfprintf(log_file,format,ap); | |
129 | va_end(ap); | |
130 | fprintf(log_file,"FATAL: forcing core dump.\n"); | |
131 | fflush(log_file); | |
132 | } | |
133 | ||
134 | abort(); | |
135 | ||
136 | *(int*)0=0; | |
137 | } | |
138 | /*}}}*/ | |
139 | void UserInterface::perror( const char* s )/*{{{*/ | |
140 | { | |
141 | error("s: %s",strerror(errno)); | |
142 | } | |
143 | /*}}}*/ | |
144 | ||
145 | ||
146 | void UserInterface::input( const char* s )/*{{{*/ | |
147 | { | |
148 | if (log_file) | |
149 | fprintf(log_file,s); | |
150 | } | |
151 | /*}}}*/ | |
152 | void UserInterface::flush()/*{{{*/ | |
153 | { | |
154 | fflush(stdout); | |
155 | if (log_file) | |
156 | fflush(log_file); | |
157 | } | |
158 | /*}}}*/ | |
159 | ||
160 | void UserInterface::set_log_file( FILE* log_file_ )/*{{{*/ | |
161 | { | |
162 | if (log_file) | |
163 | fflush(log_file); | |
164 | ||
165 | log_file = log_file_; | |
166 | } | |
167 | /*}}}*/ | |
168 | FILE* UserInterface::get_output_file()/*{{{*/ | |
169 | { | |
170 | return stdout; | |
171 | } | |
172 | /*}}}*/ | |
173 |