PIPS
xv_log.c
Go to the documentation of this file.
1 /*
2 
3  $Id: xv_log.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <stdarg.h>
31 #include <errno.h>
32 
33 #include <sys/time.h>
34 #include <sys/resource.h>
35 #include <xview/xview.h>
36 #include <xview/panel.h>
37 #include <xview/text.h>
38 #include <xview/textsw.h>
39 #include <xview/notice.h>
40 #include <xview/xv_error.h>
41 
42 /* xview/newgen interaction
43  */
44 #if (defined(TEXT))
45 #undef TEXT
46 #endif
47 
48 #if (defined(TEXT_TYPE))
49 #undef TEXT_TYPE
50 #endif
51 
52 #include "genC.h"
53 #include "misc.h"
54 #include "linear.h"
55 #include "ri.h"
56 #include "ri-util.h"
57 #include "database.h"
58 #include "pipsdbm.h"
59 #include "top-level.h"
60 
61 #include "properties.h"
62 
63 #include "wpips.h"
64 
65 static Textsw log_textsw;
66 static Menu_item open_front, clear, close;
67 
68 
69 void
70 prompt_user(string a_printf_format, ...)
71 {
72  Event e;
73  va_list some_arguments;
74  static char message_buffer[SMALL_BUFFER_LENGTH];
75 
76  va_start(some_arguments, a_printf_format);
77 
78  (void) vsprintf(message_buffer, a_printf_format, some_arguments);
79 
80  if (wpips_emacs_mode)
81  send_prompt_user_to_emacs(message_buffer);
82  (void) notice_prompt(xv_find(main_frame, WINDOW, 0),
83  &e,
84  NOTICE_MESSAGE_STRINGS,
85  message_buffer,
86  0,
87  NOTICE_BUTTON_YES, "Press Here",
88  0);
89 }
90 
91 
92 static void
94 {
95  int new_length;
96  int message_length = strlen(a_message);
97  int old_length = (int) xv_get(log_textsw, TEXTSW_LENGTH);
98 
99  /* Try to insert at the end: */
100  xv_set(log_textsw,
101  TEXTSW_INSERTION_POINT, old_length,
102  NULL);
103  textsw_insert(log_textsw, a_message, message_length);
104  /* Verify it fitted: */
105  new_length = (int) xv_get(log_textsw, TEXTSW_LENGTH);
106  if (new_length != old_length + message_length)
107  {
108  /* It ran out of space! */
109  /* recreate_log_window(); */
110  /* Discard the content without keeping the undo buffer: */
111  textsw_reset(log_textsw, 0, 0);
112 
113  xv_set(log_textsw,
114  TEXTSW_INSERTION_POINT, 0,
115  NULL);
116  /* Hope there is no use of recursion... */
117  textsw_insert(log_textsw, a_message, message_length);
118 
119  prompt_user("As you have just clicked, "
120  "you saw the log window was full :-) ...\n"
121  "It is now cut down to 0 byte again...\n\n"
122  "Anyway, you can retrieve all the log content "
123  "in the file \"%s/LOGFILE\"\n",
125  }
126 
127  textsw_possibly_normalize(log_textsw,
128  (Textsw_index) xv_get(log_textsw, TEXTSW_INSERTION_POINT));
129 
130  XFlush((Display *) xv_get(main_frame, XV_DISPLAY));
131  XFlush((Display *) xv_get(log_frame, XV_DISPLAY));
132 
133  xv_set(clear, MENU_INACTIVE, FALSE, 0);
134 }
135 
136 
137 void
138 wpips_user_error_message(char error_buffer[])
139 {
140  log_on_file(error_buffer);
141 
142  if (wpips_emacs_mode)
143  send_user_error_to_emacs(error_buffer);
144  else
146 
147  show_message(error_buffer);
148  if (!wpips_emacs_mode)
150 
151  /* prompt_user("Something went wrong. Check the log window"); */
152 
153  /* terminate PIPS request */
154  if(get_bool_property("ABORT_ON_USER_ERROR"))
155  abort();
156 
158 
159  (void) exit(1);
160 }
161 
162 void
163 wpips_user_warning_message(char warning_buffer[])
164 {
165  log_on_file(warning_buffer);
166 
167  if (wpips_emacs_mode)
168  send_user_warning_to_emacs(warning_buffer);
169  else {
171  /* Franc,ois said a warning is not important enough...
172  unhide_window(log_frame);
173  */
174  }
175 
176  show_message(warning_buffer);
177 }
178 
179 
180 #define MAXARGS 100
181 
182 void
183 wpips_user_log(string fmt, va_list args)
184 {
185  static char log_buffer[SMALL_BUFFER_LENGTH];
186 
187  (void) vsprintf(log_buffer, fmt, args);
188 
189  log_on_file(log_buffer);
190 
191  if(get_bool_property("USER_LOG_P")==FALSE)
192  return;
193 
194  if (wpips_emacs_mode)
195  send_user_log_to_emacs(log_buffer);
196  else
198  /* Display the "Message:" line in the main window also in the emacs
199  mode: */
200  show_message(log_buffer);
201 }
202 
203 
204 void open_log_subwindow(menu, menu_item)
205 Menu menu;
206 Menu_item menu_item;
207 {
208  xv_set(open_front, MENU_STRING, "Front", 0);
209  xv_set(close, MENU_INACTIVE, FALSE, 0);
211 }
212 
213 
214 void clear_log_subwindow(menu, menu_item)
215 Menu menu;
216 Menu_item menu_item;
217 {
218  int l = (int) xv_get(log_textsw, TEXTSW_LENGTH);
219  textsw_delete(log_textsw, 0, l);
220  xv_set(clear, MENU_INACTIVE, TRUE, 0);
221 }
222 
223 
224 
225 void close_log_subwindow(menu, menu_item)
226 Menu menu;
227 Menu_item menu_item;
228 {
229  xv_set(open_front, MENU_STRING, "Open", 0); /*MENU_INACTIVE, FALSE, 0);*/
230  xv_set(close, MENU_INACTIVE, TRUE, 0);
232 }
233 
234 
236 {
237  Menu menu;
238  Panel_item log_button;
239 
240  open_front = xv_create(NULL, MENUITEM,
241  MENU_STRING, "Open",
242  MENU_NOTIFY_PROC, open_log_subwindow,
243  MENU_RELEASE,
244  NULL);
245 
246  clear = xv_create(NULL, MENUITEM,
247  MENU_STRING, "Clear",
248  MENU_NOTIFY_PROC, clear_log_subwindow,
249  MENU_INACTIVE, TRUE,
250  MENU_RELEASE,
251  NULL);
252 
253  close = xv_create(NULL, MENUITEM,
254  MENU_STRING, "Close",
255  MENU_NOTIFY_PROC, close_log_subwindow,
256  MENU_INACTIVE, TRUE,
257  MENU_RELEASE,
258  NULL);
259 
260  menu = xv_create(XV_NULL, MENU_COMMAND_MENU,
261  MENU_APPEND_ITEM, open_front,
262  MENU_APPEND_ITEM, clear,
263  MENU_APPEND_ITEM, close,
264  NULL);
265 
266  log_button = xv_create(main_panel, PANEL_BUTTON,
267  PANEL_LABEL_STRING, "Log ",
268  PANEL_ITEM_MENU, menu,
269  0);
270 
271  if (wpips_emacs_mode)
272  /* In fact, create it but disabled to keep the same frame
273  layout in the Emacs mode: */
274  xv_set(log_button, PANEL_INACTIVE, TRUE,
275  NULL);
276 }
277 
278 
279 /* This works but it is cleaner to use textsw_reset() instead...
280 void
281 recreate_log_window()
282 {
283  xv_destroy(log_textsw);
284  log_textsw = (Xv_Window) xv_create(log_frame, TEXTSW, 0);
285 }
286 */
287 
288 
290 {
291  /* Xv_Window window; */
292 
293 
294  log_textsw = (Xv_Window) xv_create(log_frame, TEXTSW, 0);
295 /* recuperation d'event ne fonctionne pas -> installer TEXTSW_NOTIFY_PROC, */
296 /* autre suggestion: mettre un masque X */
297 
298 /* window = (Xv_Window) xv_find(log_frame, WINDOW, 0);
299 
300  xv_set(window,
301  WIN_CONSUME_X_EVENT_MASK, EnterWindowMask,
302  WIN_EVENT_PROC, default_win_interpose,
303  NULL);
304 */
305 }
void log_on_file(const char *desc)
Definition: message.c:190
@ user_exception_error
#define THROW(what)
void const char const char const int
void show_message(char *fmt,...)
ARARGS0.
Definition: dialogue.c:46
void send_user_error_to_emacs(char *some_text)
Definition: emacs.c:171
void send_prompt_user_to_emacs(char *some_text)
Definition: emacs.c:164
void send_user_warning_to_emacs(char *some_text)
Definition: emacs.c:185
bool wpips_emacs_mode
Here are all the stuff to interface Pips with Emacs.
Definition: emacs.c:65
void send_user_log_to_emacs(char *some_text)
Definition: emacs.c:178
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define SMALL_BUFFER_LENGTH
Definition: gpips-local.h:24
GtkWidget * main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: gpips.c:60
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89
#define exit(code)
Definition: misc-local.h:54
#define abort()
Definition: misc-local.h:53
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
Frame log_frame
Definition: wpips-local.h:40
Panel main_panel
Definition: wpips.c:63
static Menu_item clear
Definition: xv_log.c:66
void wpips_user_warning_message(char warning_buffer[])
Definition: xv_log.c:163
static Menu_item close
Definition: xv_log.c:66
void open_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:204
void wpips_user_log(string fmt, va_list args)
Definition: xv_log.c:183
void prompt_user(string a_printf_format,...)
Definition: xv_log.c:70
static Textsw log_textsw
xview/newgen interaction
Definition: xv_log.c:65
static void insert_something_in_the_wpips_log_window(char *a_message)
Definition: xv_log.c:93
void wpips_user_error_message(char error_buffer[])
Definition: xv_log.c:138
void clear_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:214
void create_log_menu()
Definition: xv_log.c:235
void create_log_window()
This works but it is cleaner to use textsw_reset() instead...
Definition: xv_log.c:289
void close_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:225
static Menu_item open_front
Definition: xv_log.c:66
void unhide_window(Frame frame)
map a frame on the screen
Definition: xv_utils.c:55