PIPS
wpips.c
Go to the documentation of this file.
1 /*
2 
3  $Id: wpips.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 #include <stdio.h>
28 #include <stdlib.h>
29 
30 #include <sys/time.h>
31 #include <sys/resource.h>
32 #include <xview/xview.h>
33 #include <xview/panel.h>
34 #include <xview/svrimage.h>
35 
36 #include "genC.h"
37 #include "linear.h"
38 #include "ri.h"
39 #include "database.h"
40 
41 #include "misc.h"
42 #include "ri-util.h"
43 #include "pipsdbm.h"
44 #include "constants.h"
45 #include "resources.h"
46 #include "pipsmake.h"
47 
48 #include "top-level.h"
49 
50 #include "wpips.h"
51 #include "xv_sizes.h"
52 
53 /* If we are in the Emacs mode, the log_frame is no longer really used: */
54 Frame main_frame,
62 
63 Panel main_panel,
69 
70 
71 /* The variables to pass information between inside and outside the
72  XView notifyer: */
73 
74 /* By default, exiting the notifyer is to exit wpips: */
76 
77 /* To deal with argument parsing: */
78 string static workspace_name_given_to_wpips = NULL;
79 string static module_name_given_to_wpips = NULL;
81 
82 
83 
84 void static
86 {
89 /* create_analyze_menu();*/
92  /* The option panel use the definition of the edit menu and so
93  needs to be create after it: */
95  /* Gone in create_menus_end(): ...No ! */
97  /* In the Emacs mode, no XView log window: */
98  /* In fact, create it but disabled to keep the same frame layout: */
101 }
102 
103 
104 /*
105 void static
106 create_menus_end()
107 {
108  create_help_menu();
109 }
110 */
111 
112 
113 static int first_mapping = TRUE;
114 
115 void main_event_proc(window, event)
116 Xv_Window window;
117 Event *event;
118 {
119  if (first_mapping == TRUE && event_id(event)==32526) {
120  first_mapping = FALSE;
121 
122  /* we place all frames */
123  place_frames();
124  };
125 }
126 
127 
128 void
130 {
131  /* Xv_window main_window; */
132 
133  main_panel = xv_create(main_frame, PANEL,
134  NULL);
135 
136  /* The following mask is necessary to avoid that key events occure twice.
137  */
138  /* main_window = (Xv_Window) xv_find(main_frame, WINDOW, 0);
139  xv_set(main_window,
140  WIN_IGNORE_EVENT, WIN_UP_ASCII_EVENTS,
141  NULL);
142  */
143  /* commented out as we shifted to xview.3, 92.04 */
144 /* xv_set(canvas_paint_window(main_panel),
145  WIN_IGNORE_EVENT, WIN_UP_ASCII_EVENTS,
146  WIN_CONSUME_EVENT, 32526,
147  WIN_EVENT_PROC, main_event_proc,
148  NULL);
149 */
150 }
151 
152 
153 static unsigned short pips_bits[] = {
154 #include "pips.icon"
155 };
156 
158 {
159  Server_image pips_image;
160  Icon icon;
161  Rect rect;
162 
163  pips_image = (Server_image)xv_create(NULL, SERVER_IMAGE,
164  XV_WIDTH, 64,
165  XV_HEIGHT, 64,
166  SERVER_IMAGE_BITS, pips_bits,
167  NULL);
168  icon = (Icon)xv_create(XV_NULL, ICON,
169  ICON_IMAGE, pips_image,
170  NULL);
171  rect.r_width= (int)xv_get(icon, XV_WIDTH);
172  rect.r_height= (int)xv_get(icon, XV_HEIGHT);
173  rect.r_left= 0;
174  rect.r_top= 0;
175 
176  xv_set(main_frame, FRAME_ICON, icon,
177  FRAME_CLOSED_RECT, &rect,
178  NULL);
179 }
180 
181 
182 /* Try to parse the WPips arguments.
183 
184  The problem is that the -emacs option need to be known early but
185  the workspace and other typical PIPS options need to be evaluate
186  later...
187 
188  Should add a help and version option.
189 */
190 
191 void static
193  char * argv[])
194 {
195  extern int optind; /* the one of getopt (3) */
196  int iarg = optind;
197 
198  while (iarg < argc) {
199  if (same_string_p(argv[iarg], "-emacs")) {
200  argv[iarg] = NULL;
201  /* Wpips is called from emacs. RK. */
202  wpips_emacs_mode = 1;
203  }
204  else if (same_string_p(argv[iarg], "-workspace")) {
205  argv[iarg] = NULL;
206  workspace_name_given_to_wpips = argv[++iarg];
207  }
208  else if (same_string_p(argv[iarg], "-module")) {
209  argv[iarg] = NULL;
210  module_name_given_to_wpips = argv[++iarg];
211  }
212  else if (same_string_p(argv[iarg], "-files")) {
213  argv[iarg] = NULL;
214 
215  if (!files_given_to_wpips) /* lazy init */
217  gen_array_append(files_given_to_wpips, argv[++iarg]);
218  }
219  else {
220  if (argv[iarg][0] == '-') {
221  fprintf(stderr, "Usage: %s ", argv[0]);
222  fprintf(stderr, "[ X-Window options ] [ -emacs ]");
223  fprintf(stderr, "[ -workspace name [ -module name ] ");
224  fprintf(stderr, "[ -files file1.f file2.f ... ] ]\n");
225  exit(1);
226  }
227  }
228 
229  iarg += 1;
230  }
231 }
232 
233 
234 /* Execute some actions asked as option after XView initialization: */
235 void static
237 {
238  if (workspace_name_given_to_wpips != NULL)
239  {
240  if (files_given_to_wpips != NULL)
241  {
243  /* It fails, Go on with the normal WPips behaviour... */
244  return;
245 
247  /* It fails, Go on with the normal WPips behaviour... */
248  return;
249 
251  } else {
253  /* It fails, Go on with the normal WPips behaviour... */
254  return;
255  }
256 
257  if (module_name_given_to_wpips != NULL) {
259  }
261  show_workspace();
266  show_module();
267  }
268 }
269 
270 
271 /* How much to call the notifyer between each pipsmake phase: */
272 enum {
274 };
275 
276 /* Since XView is not called while pipsmake is running, explicitly run
277  a hook from pipsmake to run the notifyer such as to stop pipsmake: */
278 bool static
280 {
281  int i;
282 
283  /* First, try to show we are working :-) */
285 
287  /* Ask the XView notifyer to deal with one event. */
288  notify_dispatch();
289 
290  /* Refresh the main frame: */
291  XFlush((Display *) xv_get(main_frame, XV_DISPLAY));
292  /* pipsmake not interrupted by default: */
293  return TRUE;
294 }
295 
296 
297 /* To ask pipsmake to stop as soon as possible: */
298 void
299 wpips_interrupt_pipsmake(Panel_item item,
300  Event * event)
301 {
303  user_log("PIPS interruption requested...\n");
304 }
305 
306 
307 /* Try to inform the user about an XView error. For debug, use the
308  WPIPS_DEBUG_LEVEL to have an abort on this kind
309  of error. */
310 int static
311 wpips_xview_error(Xv_object object,
312  Attr_avlist avlist)
313 {
314  debug_on("WPIPS_DEBUG_LEVEL");
315 
316  fprintf(stderr, "wpips_xview_error caught an error:\n%s\n",
317  xv_error_format(object, avlist));
318  /* Cannot use pips_assert since it uses XView, neither
319  get_bool_property for the same reason: */
320  if (get_debug_level() > 0) {
321  fprintf(stderr, "wpips_xview_error is aborting as requested since WPIPS_DEBUG_LEVEL > 0...\n");
322  abort();
323  }
324 
325  debug_off();
326 
327  return XV_OK;
328 }
329 
330 
331 /* Exit the notify loop to execute a WPips command: */
332 void
334 {
335  wpips_main_loop_command = command;
336  notify_stop();
337  /* I guess the function above does not return... */
338 }
339 
340 
341 /* The main loop that deals with command outside the XView notifyer: */
342 void static
343 wpips_main_loop(Frame frame_to_map_first)
344 {
345  xv_main_loop(frame_to_map_first);
346 
347  /* The loop to execute commands: */
349  debug(1, "wpips_main_loop", "wpips_main_loop_command = %d\n", wpips_main_loop_command);
350 
351  switch((int) wpips_main_loop_command) {
352  case WPIPS_SAFE_APPLY:
354  break;
355 
358  break;
359 
360  default:
361  pips_assert("wpips_main_loop does not understand the wpips_main_loop_command", 0);
362  }
363 
364  /* If the notifyer happen to exit without a specifyed command,
365  just exit: */
367 
368  /* Restore the initial state of the blinking pips icon: */
370 
371  /* Wait again for something from X11 and emacs: */
372  notify_start();
373  }
374 }
375 
376 
377 int
378 wpips_main(int argc, char * argv[])
379 {
380  pips_checks();
382 
388 
392 
393  debug_on("WPIPS_DEBUG_LEVEL");
394 
395  /* we parse command line arguments */
396  /* XV_ERROR_PROC unset as we shifted to xview.3, Apr. 92 */
397  xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv,
398  XV_ERROR_PROC, wpips_xview_error,
399  0);
400 
401  /* we parse remaining command line arguments */
402  wpips_parse_arguments(argc, argv);
403 
404  /* we create all frames */
405  create_frames();
406 
408 
410 
412 
414 
416 
417  if (! wpips_emacs_mode)
418  /* Create the edit/view windows only if we are not in the Emacs
419  mode: */
421 
422  /* In the Emacs mode, no XView log window but we need it to compute
423  the size of some other frames... */
425 
426  create_menus();
427 
429 
430  /* create_menus_end(); */
431 
432  create_icons();
433  /* create_icon();*/
434 
435  /* Call added. RK, 9/06/1993. */
436  place_frames();
437 
438  /* If we are in the emacs mode, initialize some things: */
440 
442 
451 
453 
455 
457 
459 
460  close_log_file();
461 
462  debug_off();
463 
464  exit(0);
465 }
void close_log_file(void)
Definition: message.c:162
void user_log(const char *format,...)
Definition: message.c:234
void(* pips_log_handler)(const char *fmt, va_list *args)
USER_LOG is a function that should be called to log the current PIPS request, as soon as it is releva...
Definition: message.c:216
string(* pips_request_handler)(const char *, va_list *)
default assignment of pips_request_handler is default_user_request.
Definition: message.c:139
void(* pips_error_handler)(const char *, const char *, va_list *)
PROMPT_USER schould be implemented.
Definition: message.c:455
void set_pips_meta_informations(const char *revs, const char *date, const char *comp)
Definition: message.c:102
void(* pips_warning_handler)(const char *, const char *, va_list *)
default assignment of pips_warning_handler is default_user_warning.
Definition: message.c:325
void const char const char const int
void set_exception_callbacks(exception_callback_t, exception_callback_t)
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void gen_array_append(gen_array_t a, void *what)
Definition: array.c:105
void gen_array_free(gen_array_t a)
Definition: array.c:70
void set_pipsmake_callback(pipsmake_callback_handler_type p)
callback.c
Definition: callback.c:43
void reset_pipsmake_callback()
Definition: callback.c:51
bool create_workspace(gen_array_t files)
FI: should be called "initialize_workspace()"; a previous call to db_create_workspace() is useful to ...
Definition: dbm.c:180
void(* pips_update_props_handler)()=default_update_props
default assignment of pips_update_props_handler is default_update_props.
Definition: dbm.c:53
bool open_workspace(const char *name)
should be: success (cf wpips.h)
Definition: dbm.c:309
void initialize_emacs_mode()
The function to initialize some things in the emacs mode:
Definition: emacs.c:511
bool wpips_emacs_mode
Here are all the stuff to interface Pips with Emacs.
Definition: emacs.c:65
void push_pips_context(char const *file, char const *function, int line)
exception.c
Definition: exception.c:43
void pop_pips_context(char const *file, char const *function, int line)
Definition: exception.c:50
void create_icons()
include "logo_pips_small.xpm"
Definition: xv_icons.c:72
void disable_compile_selection()
Definition: gtk_compile.c:74
void create_compile_menu()
Definition: gtk_compile.c:190
void create_edit_menu()
Definition: gtk_edit2.c:563
void create_edit_window()
Definition: gtk_edit2.c:513
void disable_view_selection()
Definition: gtk_edit2.c:505
void create_help_menu()
Definition: gtk_help.c:132
void create_help_window()
Definition: gtk_help.c:78
void create_log_menu()
Definition: gtk_log.c:178
void create_log_window()
This works but it is cleaner to use textsw_reset() instead...
Definition: gtk_log.c:215
void create_mchoose_window()
Definition: gtk_mchoose.c:242
void create_options_menu_and_window()
Definition: gtk_props.c:516
void update_options()
Definition: gtk_props.c:138
void disable_option_selection()
Definition: gtk_props.c:130
void create_query_window()
Definition: gtk_query.c:163
void create_quit_button()
Definition: gtk_quit.c:108
void create_schoose_window()
Definition: gtk_schoose2.c:189
void disable_module_selection()
Definition: gtk_select.c:253
void enable_module_selection()
Definition: gtk_select.c:262
void enable_workspace_create_or_open()
Definition: gtk_select.c:213
void disable_change_directory()
Definition: gtk_select.c:186
void enable_workspace_close()
Definition: gtk_select.c:242
void create_select_menu()
Definition: gtk_select.c:788
void enable_change_directory()
Definition: gtk_select.c:173
void disable_workspace_close()
Definition: gtk_select.c:234
void show_workspace()
Definition: gtk_status.c:123
void display_memory_usage()
Definition: gtk_status.c:84
void show_module()
Definition: gtk_status.c:134
void create_status_subwindow()
Definition: gtk_status.c:331
void create_transform_menu()
void disable_transform_selection()
Definition: gtk_transform.c:91
void pips_checks(void)
add checkings here (FI: why in help.c?) SG : PIPS_ROOT should not be required :)
Definition: help.c:100
#define debug_on(env)
Definition: misc-local.h:157
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
#define exit(code)
Definition: misc-local.h:54
#define abort()
Definition: misc-local.h:53
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
void initialize_newgen()
cproto-generated files
Definition: newgen.c:48
#define same_string_p(s1, s2)
char * soft_revisions
could be shared somewhere?
Definition: revisions.c:33
char * cc_version
Definition: revisions.c:41
char * soft_date
Definition: revisions.c:39
void interrupt_pipsmake_asap()
misc.c
Definition: misc.c:48
bool db_create_workspace(const char *)
Definition: workspace.c:282
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
void initialize_sc(char *(*var_to_string)(Variable))
Definition: sc_debug.c:253
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
int optind
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
#define MAX_NUMBER_OF_WPIPS_WINDOWS
How many display wondows can be opened :
Definition: wpips-local.h:30
wpips_main_loop_command_type
The type to describe the command to execute outside the notifyer:
Definition: wpips-local.h:66
@ WPIPS_EXIT
Definition: wpips-local.h:67
@ WPIPS_EXECUTE_AND_DISPLAY
Definition: wpips-local.h:69
@ WPIPS_SAFE_APPLY
Definition: wpips-local.h:68
void wpips_user_warning(const char *calling_function_name, const char *format, va_list *args)
Definition: vararg.c:56
void wpips_user_error(const char *calling_function_name, const char *format, va_list *args)
Definition: vararg.c:37
void execute_main_loop_command(wpips_main_loop_command_type command)
Exit the notify loop to execute a WPips command:
Definition: wpips.c:333
Panel query_panel
Definition: wpips.c:65
Frame mchoose_frame
Definition: wpips.c:56
Frame options_frame
Definition: wpips.c:61
static unsigned short pips_bits[]
Definition: wpips.c:153
static string module_name_given_to_wpips
Definition: wpips.c:79
void create_icon()
Definition: wpips.c:157
Frame query_frame
Definition: wpips.c:60
static int wpips_xview_error(Xv_object object, Attr_avlist avlist)
Try to inform the user about an XView error.
Definition: wpips.c:311
Frame log_frame
Definition: wpips.c:57
static gen_array_t files_given_to_wpips
Definition: wpips.c:80
Frame schoose_frame
Definition: wpips.c:55
static void wpips_parse_arguments(int argc, char *argv[])
Try to parse the WPips arguments.
Definition: wpips.c:192
void main_event_proc(Xv_Window window, Event *event)
Definition: wpips.c:115
Frame main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: wpips.c:54
int wpips_main(int argc, char *argv[])
Definition: wpips.c:378
void create_main_window()
Definition: wpips.c:129
@ WPIPS_NUMBER_OF_EVENT_TO_DEAL_DURING_PIPSMAKE_INTERPHASE
Definition: wpips.c:273
static bool deal_with_wpips_events_during_pipsmake()
Since XView is not called while pipsmake is running, explicitly run a hook from pipsmake to run the n...
Definition: wpips.c:279
Panel status_panel
Definition: wpips.c:64
Panel help_panel
Definition: wpips.c:68
void wpips_interrupt_pipsmake(Panel_item item, Event *event)
To ask pipsmake to stop as soon as possible:
Definition: wpips.c:299
Frame edit_frame[MAX_NUMBER_OF_WPIPS_WINDOWS]
Definition: wpips.c:58
Panel mchoose_panel
Definition: wpips.c:66
static wpips_main_loop_command_type wpips_main_loop_command
The variables to pass information between inside and outside the XView notifyer:
Definition: wpips.c:75
static int first_mapping
Definition: wpips.c:113
static void execute_workspace_creation_and_so_on_given_with_options(void)
Execute some actions asked as option after XView initialization:
Definition: wpips.c:236
Panel main_panel
Definition: wpips.c:63
Panel schoose_panel
Definition: wpips.c:67
static void create_menus()
Definition: wpips.c:85
Frame help_frame
Definition: wpips.c:59
static void wpips_main_loop(Frame frame_to_map_first)
The main loop that deals with command outside the XView notifyer:
Definition: wpips.c:343
static string workspace_name_given_to_wpips
To deal with argument parsing:
Definition: wpips.c:78
void execute_wpips_execute_and_display_something_outside_the_notifyer()
To execute something and display some Pips output with wpips or epips, called outside the notifyer:
Definition: xv_edit2.c:438
void create_frames()
Definition: xv_frames.c:91
void place_frames()
Definition: xv_frames.c:177
void wpips_user_log(string fmt, va_list args)
Definition: xv_log.c:183
string wpips_user_request(char *a_printf_format, va_list args)
Definition: xv_query.c:197
void end_select_module_notify(string name)
Definition: xv_select.c:882
void wpips_interrupt_button_restore()
Definition: xv_status.c:179
void wpips_interrupt_button_blink()
Definition: xv_status.c:163
void execute_safe_apply_outside_the_notifyer()
Definition: xv_transform.c:111