PIPS
xv_log.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/text.h>
#include <xview/textsw.h>
#include <xview/notice.h>
#include <xview/xv_error.h>
#include "genC.h"
#include "misc.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "database.h"
#include "pipsdbm.h"
#include "top-level.h"
#include "properties.h"
#include "wpips.h"
+ Include dependency graph for xv_log.c:

Go to the source code of this file.

Macros

#define MAXARGS   100
 

Functions

void prompt_user (string a_printf_format,...)
 
static void insert_something_in_the_wpips_log_window (char *a_message)
 
void wpips_user_error_message (char error_buffer[])
 
void wpips_user_warning_message (char warning_buffer[])
 
void wpips_user_log (string fmt, va_list args)
 
void open_log_subwindow (Menu menu, Menu_item menu_item)
 
void clear_log_subwindow (Menu menu, Menu_item menu_item)
 
void close_log_subwindow (Menu menu, Menu_item menu_item)
 
void create_log_menu ()
 
void create_log_window ()
 This works but it is cleaner to use textsw_reset() instead... More...
 

Variables

static Textsw log_textsw
 xview/newgen interaction More...
 
static Menu_item open_front
 
static Menu_item clear
 
static Menu_item close
 

Macro Definition Documentation

◆ MAXARGS

#define MAXARGS   100

Definition at line 180 of file xv_log.c.

Function Documentation

◆ clear_log_subwindow()

void clear_log_subwindow ( Menu  menu,
Menu_item  menu_item 
)

Definition at line 214 of file xv_log.c.

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 }
void const char const char const int
static Menu_item clear
Definition: xv_log.c:66
static Textsw log_textsw
xview/newgen interaction
Definition: xv_log.c:65

References clear, int, and log_textsw.

Referenced by create_log_menu().

+ Here is the caller graph for this function:

◆ close_log_subwindow()

void close_log_subwindow ( Menu  menu,
Menu_item  menu_item 
)

ENU_INACTIVE, FALSE, 0);

Definition at line 225 of file xv_log.c.

228 {
229  xv_set(open_front, MENU_STRING, "Open", 0); /*MENU_INACTIVE, FALSE, 0);*/
230  xv_set(close, MENU_INACTIVE, TRUE, 0);
232 }
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89
Frame log_frame
Definition: wpips-local.h:40
static Menu_item close
Definition: xv_log.c:66
static Menu_item open_front
Definition: xv_log.c:66

References close, hide_window(), log_frame, and open_front.

Referenced by create_log_menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create_log_menu()

void create_log_menu ( )

In fact, create it but disabled to keep the same frame layout in the Emacs mode:

Definition at line 235 of file xv_log.c.

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 }
bool wpips_emacs_mode
Here are all the stuff to interface Pips with Emacs.
Definition: emacs.c:65
Panel main_panel
Definition: wpips.c:63
void open_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:204
void clear_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:214
void close_log_subwindow(Menu menu, Menu_item menu_item)
Definition: xv_log.c:225

References clear, clear_log_subwindow(), close, close_log_subwindow(), main_panel, open_front, open_log_subwindow(), and wpips_emacs_mode.

+ Here is the call graph for this function:

◆ create_log_window()

void create_log_window ( )

This works but it is cleaner to use textsw_reset() instead...

void recreate_log_window() { xv_destroy(log_textsw); log_textsw = (Xv_Window) xv_create(log_frame, TEXTSW, 0); }

Xv_Window window;

recuperation d'event ne fonctionne pas -> installer TEXTSW_NOTIFY_PROC,

autre suggestion: mettre un masque X

window = (Xv_Window) xv_find(log_frame, WINDOW, 0);

xv_set(window, WIN_CONSUME_X_EVENT_MASK, EnterWindowMask, WIN_EVENT_PROC, default_win_interpose, NULL);

Definition at line 289 of file xv_log.c.

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 }

References log_frame, and log_textsw.

◆ insert_something_in_the_wpips_log_window()

static void insert_something_in_the_wpips_log_window ( char *  a_message)
static

Try to insert at the end:

Verify it fitted:

It ran out of space!

recreate_log_window();

Discard the content without keeping the undo buffer:

Hope there is no use of recursion...

Definition at line 93 of file xv_log.c.

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 }
GtkWidget * main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: gpips.c:60
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
void prompt_user(string a_printf_format,...)
Definition: xv_log.c:70

References clear, db_get_current_workspace_directory(), int, log_frame, log_textsw, main_frame, and prompt_user().

Referenced by wpips_user_error_message(), wpips_user_log(), and wpips_user_warning_message().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ open_log_subwindow()

void open_log_subwindow ( Menu  menu,
Menu_item  menu_item 
)

Definition at line 204 of file xv_log.c.

207 {
208  xv_set(open_front, MENU_STRING, "Front", 0);
209  xv_set(close, MENU_INACTIVE, FALSE, 0);
211 }
void unhide_window(Frame frame)
map a frame on the screen
Definition: xv_utils.c:55

References close, log_frame, open_front, and unhide_window().

Referenced by create_log_menu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ prompt_user()

void prompt_user ( string  a_printf_format,
  ... 
)

Definition at line 70 of file xv_log.c.

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 }
void send_prompt_user_to_emacs(char *some_text)
Definition: emacs.c:164
#define SMALL_BUFFER_LENGTH
Definition: gpips-local.h:24

References main_frame, send_prompt_user_to_emacs(), SMALL_BUFFER_LENGTH, and wpips_emacs_mode.

Referenced by insert_something_in_the_wpips_log_window().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wpips_user_error_message()

void wpips_user_error_message ( char  error_buffer[])

prompt_user("Something went wrong. Check the log window");

terminate PIPS request

Definition at line 138 of file xv_log.c.

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 }
void log_on_file(const char *desc)
Definition: message.c:190
@ user_exception_error
#define THROW(what)
void show_message(char *fmt,...)
ARARGS0.
Definition: dialogue.c:46
void send_user_error_to_emacs(char *some_text)
Definition: emacs.c:171
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define exit(code)
Definition: misc-local.h:54
#define abort()
Definition: misc-local.h:53
static void insert_something_in_the_wpips_log_window(char *a_message)
Definition: xv_log.c:93

References abort, exit, get_bool_property(), insert_something_in_the_wpips_log_window(), log_frame, log_on_file(), send_user_error_to_emacs(), show_message(), THROW, unhide_window(), user_exception_error, and wpips_emacs_mode.

+ Here is the call graph for this function:

◆ wpips_user_log()

void wpips_user_log ( string  fmt,
va_list  args 
)

Display the "Message:" line in the main window also in the emacs mode:

Definition at line 183 of file xv_log.c.

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 }
void send_user_log_to_emacs(char *some_text)
Definition: emacs.c:178

References get_bool_property(), insert_something_in_the_wpips_log_window(), log_on_file(), send_user_log_to_emacs(), show_message(), SMALL_BUFFER_LENGTH, and wpips_emacs_mode.

Referenced by wpips_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wpips_user_warning_message()

void wpips_user_warning_message ( char  warning_buffer[])

Franc,ois said a warning is not important enough... unhide_window(log_frame);

Definition at line 163 of file xv_log.c.

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 }
void send_user_warning_to_emacs(char *some_text)
Definition: emacs.c:185

References insert_something_in_the_wpips_log_window(), log_on_file(), send_user_warning_to_emacs(), show_message(), and wpips_emacs_mode.

+ Here is the call graph for this function:

Variable Documentation

◆ clear

Menu_item clear
static

◆ close

Menu_item close
static

Definition at line 66 of file xv_log.c.

Referenced by close_log_subwindow(), create_log_menu(), main(), and open_log_subwindow().

◆ log_textsw

Textsw log_textsw
static

xview/newgen interaction

Definition at line 65 of file xv_log.c.

Referenced by clear_log_subwindow(), create_log_window(), and insert_something_in_the_wpips_log_window().

◆ open_front

Menu_item open_front
static

Definition at line 66 of file xv_log.c.

Referenced by close_log_subwindow(), create_log_menu(), and open_log_subwindow().