123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- #include "sys-defines.h"
- #include <signal.h>
- #include "extern.h"
- XPlotter **_xplotters = NULL;
- int _xplotters_len = 0;
- #define INITIAL_XPLOTTERS_LEN 4
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
- pthread_mutex_t _xplotters_mutex = PTHREAD_MUTEX_INITIALIZER;
- #endif
- #endif
- #ifndef LIBPLOTTER
- const Plotter _pl_y_default_plotter =
- {
-
- _pl_y_initialize, _pl_y_terminate,
-
- _pl_y_begin_page, _pl_y_erase_page, _pl_y_end_page,
-
- _pl_x_push_state, _pl_x_pop_state,
-
- _pl_x_paint_path, _pl_x_paint_paths, _pl_x_path_is_flushable, _pl_x_maybe_prepaint_segments,
-
- _pl_g_paint_marker, _pl_x_paint_point,
-
- _pl_g_paint_text_string_with_escapes, _pl_x_paint_text_string,
- _pl_x_get_text_width,
-
- _pl_x_retrieve_font,
-
- _pl_x_flush_output,
-
- _pl_g_warning,
- _pl_g_error,
- };
- #endif
- void
- _pl_y_initialize (S___(Plotter *_plotter))
- {
- bool open_slot = false;
- int i, j;
- #ifndef LIBPLOTTER
-
- _pl_x_initialize (S___(_plotter));
- #endif
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
-
- pthread_mutex_lock (&_xplotters_mutex);
- #endif
- #endif
-
- if (_xplotters_len == 0)
- {
-
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
- #ifdef X_THREAD_SUPPORT
- XInitThreads ();
- XtToolkitThreadInitialize ();
- #endif
- #endif
- #endif
-
- XtToolkitInitialize ();
- }
-
- if (_xplotters_len == 0)
- {
- _xplotters = (XPlotter **)_pl_xmalloc (INITIAL_XPLOTTERS_LEN * sizeof(XPlotter *));
- for (i = 0; i < INITIAL_XPLOTTERS_LEN; i++)
- _xplotters[i] = (XPlotter *)NULL;
- _xplotters_len = INITIAL_XPLOTTERS_LEN;
- }
-
-
- for (i = 0; i < _xplotters_len; i++)
- if (_xplotters[i] == NULL)
- {
- open_slot = true;
- break;
- }
- if (!open_slot)
-
- {
- i = _xplotters_len;
- _xplotters =
- (XPlotter **)_pl_xrealloc (_xplotters,
- 2 * _xplotters_len * sizeof (XPlotter *));
- for (j = _xplotters_len; j < 2 * _xplotters_len; j++)
- _xplotters[j] = (XPlotter *)NULL;
- _xplotters_len *= 2;
- }
-
-
- _xplotters[i] = _plotter;
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
-
- pthread_mutex_unlock (&_xplotters_mutex);
- #endif
- #endif
-
- #ifndef LIBPLOTTER
-
- _plotter->data->type = PL_X11;
- #endif
-
- _plotter->data->output_model = PL_OUTPUT_VIA_CUSTOM_ROUTINES_TO_NON_STREAM;
-
- _plotter->y_app_con = (XtAppContext)NULL;
- _plotter->y_toplevel = (Widget)NULL;
- _plotter->y_canvas = (Widget)NULL;
- _plotter->y_drawable4 = (Drawable)0;
- _plotter->y_auto_flush = true;
- _plotter->y_vanish_on_delete = false;
- _plotter->y_pids = (pid_t *)NULL;
- _plotter->y_num_pids = 0;
- _plotter->y_event_handler_count = 0;
-
-
- {
- const char *vanish_s;
- vanish_s = (const char *)_get_plot_param (_plotter->data,
- "X_AUTO_FLUSH");
- if (strcasecmp (vanish_s, "no") == 0)
- _plotter->y_auto_flush = false;
- else
- _plotter->y_auto_flush = true;
- }
-
- {
- const char *vanish_s;
- vanish_s = (const char *)_get_plot_param (_plotter->data,
- "VANISH_ON_DELETE");
- if (strcasecmp (vanish_s, "yes") == 0)
- _plotter->y_vanish_on_delete = true;
- else
- _plotter->y_vanish_on_delete = false;
- }
- }
- void
- _pl_y_terminate (S___(Plotter *_plotter))
- {
- int i, j;
-
- if (_plotter->y_vanish_on_delete)
- {
- for (j = 0; j < _plotter->y_num_pids; j++)
- kill (_plotter->y_pids[j], SIGKILL);
- if (_plotter->y_num_pids > 0)
- {
- free (_plotter->y_pids);
- _plotter->y_pids = (pid_t *)NULL;
- }
- }
-
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
-
- pthread_mutex_lock (&_xplotters_mutex);
- #endif
- #endif
- for (i = 0; i < _xplotters_len; i++)
- if (_xplotters[i] == _plotter)
- {
- _xplotters[i] = (XPlotter *)NULL;
- break;
- }
- #ifdef PTHREAD_SUPPORT
- #ifdef HAVE_PTHREAD_H
-
- pthread_mutex_unlock (&_xplotters_mutex);
- #endif
- #endif
- #ifndef LIBPLOTTER
-
- _pl_x_terminate (S___(_plotter));
- #endif
- }
- #ifdef LIBPLOTTER
- XPlotter::XPlotter (FILE *infile, FILE *outfile, FILE *errfile)
- :XDrawablePlotter (infile, outfile, errfile)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (FILE *outfile)
- :XDrawablePlotter (outfile)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (istream& in, ostream& out, ostream& err)
- : XDrawablePlotter (in, out, err)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (ostream& out)
- : XDrawablePlotter (out)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter ()
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (FILE *infile, FILE *outfile, FILE *errfile, PlotterParams ¶meters)
- :XDrawablePlotter (infile, outfile, errfile, parameters)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (FILE *outfile, PlotterParams ¶meters)
- :XDrawablePlotter (outfile, parameters)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (istream& in, ostream& out, ostream& err, PlotterParams ¶meters)
- : XDrawablePlotter (in, out, err, parameters)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (ostream& out, PlotterParams ¶meters)
- : XDrawablePlotter (out, parameters)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::XPlotter (PlotterParams ¶meters)
- : XDrawablePlotter (parameters)
- {
- _pl_y_initialize ();
-
- }
- XPlotter::~XPlotter ()
- {
-
- if (_plotter->data->open)
- _API_closepl ();
- _pl_y_terminate ();
-
- }
- #endif
|