Term-Gnuplot
view release on metacpan or search on metacpan
pm_exec/gpexecute.c view on Meta::CPAN
#ifdef WIN_IPC
# include <stdlib.h>
# include <assert.h>
# include "mouse.h" /* do_event() */
#endif
#if defined(PIPE_IPC) /* || defined(WIN_IPC) */
static gpe_fifo_t *gpe_init __PROTO((void));
static void gpe_push __PROTO((gpe_fifo_t ** base, struct gp_event_t * ge));
static struct gp_event_t *gpe_front __PROTO((gpe_fifo_t ** base));
static int gpe_pop __PROTO((gpe_fifo_t ** base));
#endif /* PIPE_IPC || WIN_IPC */
/*
* gp_execute functions
*/
#ifdef OS2
/* handle to event semaphore (post an event to gnuplot that the shared
memory contains a command to be executed) */
int pausing = 0;
/* avoid passing data back to gnuplot in `pause' mode */
/* gplt_x11.c */
unsigned long ppidGnu = 0;
#endif
#ifdef OS2_IPC
char mouseShareMemName[40];
PVOID input_from_PM_Terminal;
/* pointer to shared memory for storing the command to be executed */
HEV semInputReady = 0;
/*
* Let the command in the shared memory be executed.
*/
void
gp_post_shared_mem(void)
{
APIRET rc;
if (semInputReady == 0) { /* but it must be open for the first time */
char semInputReadyName[40];
sprintf(semInputReadyName, "\\SEM32\\GP%i_Input_Ready", (int) ppidGnu);
DosOpenEventSem(semInputReadyName, &semInputReady);
}
rc = DosPostEventSem(semInputReady);
DosSleep(10);
/* dirty trick: wait a little bit; otherwise problems to
* distinguish mouse button down and up, for instance
* (info sent to shared memory was too fast; maybe a blocking
* semaphore would help, but no fun to implement it...)
&*/
}
/* Copy the command (given by the input string) to the shared memory
* and let gnuplot execute it.
* If this routine is called during a 'pause', then the command is
* ignored (shared memory is cleared). Needed for actions launched by a
* hotkey.
* Firstly, the command is copied from shared memory to clipboard
* if this option is set on.
* Secondly, gnuplot is informed that shared memory contains a command
* by posting semInputReady event semaphore.
*
* OS/2 specific: if (!s), then the command has been already sprintf'ed to
* the shared memory.
*/
void
gp_execute(char *s)
{
if (input_from_PM_Terminal == NULL)
return;
if (s) /* copy the command to shared memory */
strcpy(input_from_PM_Terminal, s);
if (((char *) input_from_PM_Terminal)[0] == 0)
return;
if (pausing) { /* no communication during pause */
/* DosBeep(440,111); */
((char *) input_from_PM_Terminal)[0] = 0;
return;
}
#ifdef GNUPMDRV
/* write the command to clipboard */
if (bSend2gp == TRUE)
TextToClipboard(input_from_PM_Terminal);
#endif
gp_post_shared_mem();
}
#endif /* OS2_IPC */
#if defined(PIPE_IPC) /* || defined(WIN_IPC) */
int buffered_output_pending = 0;
static gpe_fifo_t *
gpe_init(void)
{
gpe_fifo_t *base = malloc(sizeof(gpe_fifo_t));
/* fprintf(stderr, "(gpe_init) \n"); */
assert(base);
base->next = (gpe_fifo_t *) 0;
base->prev = (gpe_fifo_t *) 0;
return base;
}
static void
gpe_push(gpe_fifo_t ** base, struct gp_event_t *ge)
{
buffered_output_pending++;
if ((*base)->prev) {
gpe_fifo_t *new = malloc(sizeof(gpe_fifo_t));
/* fprintf(stderr, "(gpe_push) \n"); */
assert(new);
(*base)->prev->next = new;
new->prev = (*base)->prev;
(*base)->prev = new;
new->next = (gpe_fifo_t *) 0;
} else {
/* first element, this is the case, if the pipe isn't clogged */
(*base)->next = (gpe_fifo_t *) 0; /* tail */
(*base)->prev = (*base); /* points to itself */
}
(*base)->prev->ge = *ge;
}
static struct gp_event_t *
gpe_front(gpe_fifo_t ** base)
{
return &((*base)->ge);
}
static int
gpe_pop(gpe_fifo_t ** base)
{
buffered_output_pending--;
if ((*base)->prev == (*base)) {
(*base)->prev = (gpe_fifo_t *) 0;
return 0;
} else {
gpe_fifo_t *save = *base;
/* fprintf(stderr, "(gpe_pop) \n"); */
(*base)->next->prev = (*base)->prev;
( run in 1.146 second using v1.01-cache-2.11-cpan-2398b32b56e )