PIPS
gpips.c
Go to the documentation of this file.
1 /*
2 
3  $Id: gpips.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 
33 #include "genC.h"
34 #include "linear.h"
35 #include "ri.h"
36 #include "database.h"
37 
38 #include "misc.h"
39 #include "ri-util.h"
40 #include "pipsdbm.h"
41 #include "constants.h"
42 #include "resources.h"
43 #include "pipsmake.h"
44 
45 #include "top-level.h"
46 
47 // imports gtk
48 #undef test_undefined // also defined in glib included from gtk
49 #include <gtk/gtk.h>
50 
51 #include "gpips.h"
52 
53 // Gtk Windows (XV Frame -> GTK Window)
57 GtkWidget * main_window_vbox;
58 
59 // Gtk Frames (XV Panel -> GTK Frame)
61 
63 
64 /* The variables to pass information between inside and outside the
65  XView notifyer: */
66 
67 /* By default, exiting the notifyer is to exit gpips: */
69 
70 /* To deal with argument parsing: */
71 static string workspace_name_given_to_gpips = NULL;
72 static string module_name_given_to_gpips = NULL;
74 
76  main_window_menu_bar = gtk_menu_bar_new();
77  gtk_box_pack_start(GTK_BOX(main_window_vbox), main_window_menu_bar, FALSE,
78  FALSE, 0);
79  gtk_widget_show_all(main_window_menu_bar);
80 }
81 
82 static void create_menus() {
84  // create_select_menu();
86  /* create_analyze_menu();*/
89  /* The option panel use the definition of the edit menu and so
90  needs to be create after it: */
92  /* Gone in create_menus_end(): ...No ! */
96 }
97 
98 /*
99  static void
100  create_menus_end()
101  {
102  create_help_menu();
103  }
104  */
105 
106 //static int first_mapping = TRUE;
107 
108 //void main_event_proc(window, event)
109 // Xv_Window window;Event *event; {
110 // if (first_mapping == TRUE && event_id(event) == 32526) {
111 // first_mapping = FALSE;
112 //
113 // // /* we place all frames */
114 // // place_frames();
115 // };
116 //}
117 
119  // main_panel = xv_create(main_frame, PANEL, NULL);
120  main_frame = gtk_frame_new(NULL);
121  main_window_vbox = gtk_vbox_new(FALSE, 0);
122  gtk_container_add(GTK_CONTAINER(main_window), main_window_vbox);
123  gtk_box_pack_start(GTK_BOX(main_window_vbox), main_frame, TRUE, FALSE, 0);
124  gtk_widget_show_all(main_frame);
125 }
126 
127 /*
128 static unsigned short pips_bits[] = {
129 #include "pips.icon"
130  };
131 */
132 //void create_icon() {
133 // Server_image pips_image;
134 // Icon icon;
135 // Rect rect;
136 //
137 // pips_image = (Server_image) xv_create(NULL, SERVER_IMAGE, XV_WIDTH, 64,
138 // XV_HEIGHT, 64, SERVER_IMAGE_BITS, pips_bits, NULL);
139 // icon = (Icon) xv_create(XV_NULL, ICON, ICON_IMAGE, pips_image, NULL);
140 // rect.r_width = (int) xv_get(icon, XV_WIDTH);
141 // rect.r_height = (int) xv_get(icon, XV_HEIGHT);
142 // rect.r_left = 0;
143 // rect.r_top = 0;
144 //
145 // xv_set(main_frame, FRAME_ICON, icon, FRAME_CLOSED_RECT, &rect, NULL);
146 //}
147 
148 /* Try to parse the gpips arguments.
149 
150  Should add a help and version option.
151  */
152 
153 static void gpips_parse_arguments(int argc, char * argv[]) {
154  extern int optind; /* the one of getopt (3) */
155  int iarg = optind;
156 
157  while (iarg < argc) {
158  if (same_string_p(argv[iarg], "-workspace")) {
159  argv[iarg] = NULL;
160  workspace_name_given_to_gpips = argv[++iarg];
161  } else if (same_string_p(argv[iarg], "-module")) {
162  argv[iarg] = NULL;
163  module_name_given_to_gpips = argv[++iarg];
164  } else if (same_string_p(argv[iarg], "-files")) {
165  argv[iarg] = NULL;
166 
167  if (!files_given_to_gpips) /* lazy init */
169  gen_array_append(files_given_to_gpips, argv[++iarg]);
170  } else {
171  if (argv[iarg][0] == '-') {
172  fprintf(stderr, "Usage: %s ", argv[0]);
173  fprintf(stderr, "[ X-Window options ]");
174  fprintf(stderr, "[ -workspace name [ -module name ] ");
175  fprintf(stderr, "[ -files file1.f file2.f ... ] ]\n");
176  exit(1);
177  }
178  }
179  iarg += 1;
180  }
181 }
182 
183 /* Execute some actions asked as option after XView initialization: */
185  if (workspace_name_given_to_gpips != NULL) {
186  if (files_given_to_gpips != NULL) {
188  /* It fails, Go on with the normal gpips behaviour... */
189  return;
190 
192  /* It fails, Go on with the normal gpips behaviour... */
193  return;
194 
196  } else {
198  /* It fails, Go on with the normal gpips behaviour... */
199  return;
200  }
201 
202  if (module_name_given_to_gpips != NULL) {
204  }
206  show_workspace();
211  show_module();
212  }
213 }
214 
215 /* How much to call the notifyer between each pipsmake phase: */
216 enum {
218 };
219 
220 /* Since XView is not called while pipsmake is running, explicitly run
221  a hook from pipsmake to run the notifier such as to stop pipsmake: */
223  int i;
224 
225  /* First, try to show we are working :-) */
227 
229  /* Ask the XView notifier to deal with one event. */
230  // notify_dispatch();
231  gtk_main_iteration_do(FALSE);
232 
233  /* Refresh the main frame: */
234  // XFlush((Display *) xv_get(main_frame, XV_DISPLAY));
235  /* pipsmake not interrupted by default: */
236  return TRUE;
237 }
238 
239 /* To ask pipsmake to stop as soon as possible: */
240 //void gpips_interrupt_pipsmake(Panel_item item, Event * event) {
241 // interrupt_pipsmake_asap();
242 // user_log("PIPS interruption requested...\n");
243 //}
244 
245 /* Try to inform the user about an XView error. For debug, use the
246  GPIPS_DEBUG_LEVEL to have an abort on this kind
247  of error. */
248 //static int gpips_xview_error(Xv_object object, Attr_avlist avlist) {
249 // debug_on("GPIPS_DEBUG_LEVEL");
250 //
251 // fprintf(stderr, "gpips_xview_error caught an error:\n%s\n",
252 // xv_error_format(object, avlist));
253 // /* Cannot use pips_assert since it uses XView, neither
254 // get_bool_property for the same reason: */
255 // if (get_debug_level() > 0) {
256 // fprintf(stderr,
257 // "gpips_xview_error is aborting as requested since GPIPS_DEBUG_LEVEL > 0...\n");
258 // abort();
259 // }
260 //
261 // debug_off();
262 //
263 // return XV_OK;
264 //}
265 
266 /* Exit the notify loop to execute a gpips command: */
268  gpips_main_loop_command = command;
269  // notify_stop();
270  gtk_main_quit();
271  /* I guess the function above does not return... */
272 }
273 
274 /* The main loop that deals with command outside the XView notifier: */
275 static void gpips_main_loop() {
276  // xv_main_loop(frame_to_map_first);
277  gtk_main();
278 
279  /* The loop to execute commands: */
281  debug(1, "gpips_main_loop", "gpips_main_loop_command = %d\n",
283 
284  switch ((int) gpips_main_loop_command) {
285  case GPIPS_SAFE_APPLY:
287  break;
288 
291  break;
292 
293  default:
294  pips_assert(
295  "gpips_main_loop does not understand the gpips_main_loop_command",
296  0);
297  }
298 
299  /* If the notifier happen to exit without a specified command,
300  just exit: */
302 
303  /* Restore the initial state of the blinking pips icon: */
305 
306  /* Wait again for something from X11 */
307  // notify_start();
308  gtk_main();
309  }
310 }
311 
312 int gpips_main(int argc, char * argv[]) {
313  pips_checks();
314  //FIXME: set_pips_meta_informations(soft_revisions, soft_date, cc_version);
315  set_pips_meta_informations("<unknown>", "<unknown>", "<unknown>");
316 
322 
326 
327  debug_on("GPIPS_DEBUG_LEVEL");
328 
329  /* we parse command line arguments */
330  /* XV_ERROR_PROC unset as we shifted to xview.3, Apr. 92 */
331  // xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, XV_ERROR_PROC,
332  // gpips_xview_error, 0);
333  gtk_init(&argc, &argv);
334 
335  /* we parse remaining command line arguments */
336  gpips_parse_arguments(argc, argv);
337 
338  /* we create all windows */
339  create_windows();
347  create_menus();
349  //create_icons(); TODO: icon mangement
350  // place_frames();
351  gtk_widget_show_all(main_window);
352 
354 
363 
365 
367 
368  gpips_main_loop();
369 
371 
372  close_log_file();
373 
374  debug_off();
375 
376  exit(0);
377 }
void close_log_file(void)
Definition: message.c:162
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 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 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
#define MAX_NUMBER_OF_GPIPS_WINDOWS
How many display wondows can be opened :
Definition: gpips-local.h:30
gpips_main_loop_command_type
The type to describe the command to execute outside the notifyer:
Definition: gpips-local.h:62
@ GPIPS_SAFE_APPLY
Definition: gpips-local.h:63
@ GPIPS_EXECUTE_AND_DISPLAY
Definition: gpips-local.h:63
@ GPIPS_EXIT
Definition: gpips-local.h:63
void gpips_user_warning(const char *calling_function_name, const char *format, va_list *args)
Definition: vararg.c:56
void gpips_user_error(const char *calling_function_name, const char *format, va_list *args)
Definition: vararg.c:37
GtkWidget * edit_window[MAX_NUMBER_OF_GPIPS_WINDOWS]
Definition: gpips.c:55
GtkWidget * options_window
Definition: gpips.c:56
GtkWidget * status_frame
Definition: gpips.c:60
GtkWidget * main_window_vbox
Definition: gpips.c:57
GtkWidget * query_dialog
Definition: gpips.c:55
GtkWidget * main_window
Definition: gpips.c:54
GtkWidget * schoose_window
Definition: gpips.c:54
static void gpips_parse_arguments(int argc, char *argv[])
Try to parse the gpips arguments.
Definition: gpips.c:153
static gen_array_t files_given_to_gpips
Definition: gpips.c:73
static bool deal_with_gpips_events_during_pipsmake()
Since XView is not called while pipsmake is running, explicitly run a hook from pipsmake to run the n...
Definition: gpips.c:222
static void create_main_window_menu_bar()
Definition: gpips.c:75
GtkWidget * main_frame
If we are in the Emacs mode, the log_frame is no longer really used:
Definition: gpips.c:60
void create_main_window()
Definition: gpips.c:118
GtkWidget * log_window
Definition: gpips.c:54
@ GPIPS_NUMBER_OF_EVENT_TO_DEAL_DURING_PIPSMAKE_INTERPHASE
Definition: gpips.c:217
int gpips_main(int argc, char *argv[])
Definition: gpips.c:312
GtkWidget * mchoose_frame
Definition: gpips.c:60
void execute_main_loop_command(gpips_main_loop_command_type command)
To ask pipsmake to stop as soon as possible:
Definition: gpips.c:267
GtkWidget * help_frame
Definition: gpips.c:60
static string module_name_given_to_gpips
Definition: gpips.c:72
static void execute_workspace_creation_and_so_on_given_with_options(void)
Execute some actions asked as option after XView initialization:
Definition: gpips.c:184
GtkWidget * main_window_menu_bar
Definition: gpips.c:62
GtkWidget * mchoose_window
Definition: gpips.c:54
static void create_menus()
Definition: gpips.c:82
static void gpips_main_loop()
The main loop that deals with command outside the XView notifier:
Definition: gpips.c:275
static string workspace_name_given_to_gpips
To deal with argument parsing:
Definition: gpips.c:71
static gpips_main_loop_command_type gpips_main_loop_command
The variables to pass information between inside and outside the XView notifyer:
Definition: gpips.c:68
GtkWidget * help_window
Definition: gpips.c:55
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 execute_gpips_execute_and_display_something_outside_the_notifier()
To execute something and display some Pips output with gpips, called outside the notifyer:
Definition: gtk_edit2.c:367
void create_help_menu()
Definition: gtk_help.c:132
void create_help_window()
Definition: gtk_help.c:78
void gpips_user_log(const char *fmt, va_list *args)
Definition: gtk_log.c:136
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
string gpips_user_request(const char *a_printf_format, va_list *args)
Definition: gtk_query.c:136
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 end_select_module_callback(const char *name)
Definition: gtk_select.c:691
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 gpips_interrupt_button_restore()
Definition: gtk_status.c:156
void display_memory_usage()
Definition: gtk_status.c:84
void gpips_interrupt_button_blink()
Definition: gtk_status.c:145
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 execute_safe_apply_outside_the_notifier()
Definition: gtk_transform.c:99
void create_windows()
Definition: gtk_windows.c:86
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
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)
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