version 1.1, 2000/01/09 17:01:17 |
version 1.1.1.2, 2000/01/22 14:16:31 |
Line 73 TERM_PUBLIC void X11_fillbox __PROTO((int style, unsig |
|
Line 73 TERM_PUBLIC void X11_fillbox __PROTO((int style, unsig |
|
#ifndef TERM_PROTO_ONLY |
#ifndef TERM_PROTO_ONLY |
|
|
#ifdef TERM_BODY |
#ifdef TERM_BODY |
int X11_Display = 0; /* non-zero if '-display' found on command line */ |
|
|
|
|
/* non-zero if '-display' found on command line */ |
|
int X11_Display = 0; |
|
|
|
|
/* sunos 4 uses on_exit() in place of atexit(). If both are missing, |
/* sunos 4 uses on_exit() in place of atexit(). If both are missing, |
* we can probably survive since gnuplot_x11 should detect EOF on |
* we can probably survive since gnuplot_x11 should detect EOF on |
* the pipe. Unfortunately, the handlers take different parameters. |
* the pipe. Unfortunately, the handlers take different parameters. |
Line 98 int X11_Display = 0; /* non-zero if '-display' found |
|
Line 100 int X11_Display = 0; /* non-zero if '-display' found |
|
|
|
static void X11_atexit HANDLER_PROTO; |
static void X11_atexit HANDLER_PROTO; |
|
|
static char X11_opts[][20] = |
/* Merged the old char X11_opts[] and int X11_optarg[] |
|
* into one array of structs. |
|
* Loosely based on XrmOptionDescRec, the use of which |
|
* would probably be overkill here. */ |
|
typedef enum { hasNoArg, hasArg } OptionArg; |
|
|
|
static struct x11opt { |
|
const char *option; /* Name of option */ |
|
OptionArg arg; /* Whether option has argument */ |
|
} X11_opts[] = |
{ |
{ |
"-mono", "-gray", "-clear", "-tvtwm", "-pointsize", |
{ "-mono", hasNoArg }, { "-gray", hasNoArg }, { "-clear", hasNoArg }, |
"-iconic", "-rv", "-reverse", "+rv", "-synchronous", |
{ "-tvtwm", hasNoArg }, { "-pointsize", hasArg }, |
"-display", "-geometry", "-bg", "-background", "-bd", "-bordercolor", "-bw", |
{ "-iconic", hasNoArg }, { "-rv", hasNoArg }, |
"-borderwidth", "-fg", "-foreground", "-fn", "-font", "-name", |
{ "-reverse", hasNoArg }, { "+rv", hasNoArg }, |
"-selectionTimeout", "-title", "-xnllanguage", "-xrm", |
{ "-synchronous", hasNoArg }, |
"-raise", "-noraise", "-persist" |
{ "-display", hasArg }, { "-geometry", hasArg }, { "-bg", hasArg }, |
|
{ "-background", hasArg }, { "-bd", hasArg }, |
|
{ "-bordercolor", hasArg }, { "-bw", hasArg }, |
|
{ "-borderwidth", hasArg }, { "-fg", hasArg }, |
|
{ "-foreground", hasArg }, { "-fn", hasArg }, { "-font", hasArg }, |
|
{ "-name", hasArg }, |
|
{ "-selectionTimeout", hasArg }, { "-title", hasArg }, |
|
{ "-xnllanguage", hasArg }, { "-xrm", hasArg }, |
|
{ "-raise", hasNoArg }, { "-noraise", hasNoArg }, |
|
{ "-persist", hasNoArg } |
}; |
}; |
|
|
#define X11_nopts (sizeof(X11_opts) / sizeof(X11_opts[0])) |
#define X11_nopts (sizeof(X11_opts) / sizeof(X11_opts[0])) |
|
|
static int X11_optarg[X11_nopts] = |
|
{ |
|
0, 0, 0, 0, 1, |
|
0, 0, 0, 0, 0, |
|
1, 1, 1, 1, 1, 1, 1, |
|
1, 1, 1, 1, 1, 1, |
|
1, 1, 1, 1, |
|
0, 0, 0 |
|
}; |
|
|
|
static FILE *X11_ipc; |
static FILE *X11_ipc; |
#ifdef OS2 |
|
static char X11_command[1024] = "gnuplot_x11.exe"; |
|
#else |
|
static char X11_command[1024] = "gnuplot_x11"; |
|
#endif |
|
|
|
|
static char **xargv = (char **)NULL; |
|
static char *optvec[2*X11_nopts+1]; |
|
# ifdef OS2 |
|
static char X11_command[] = "gnuplot_x11.exe"; |
|
# else |
|
static char X11_command[] = "gnuplot_x11"; |
|
# endif /* !OS/2 */ |
|
|
/* X11_args - scan gnuplot command line for standard X Toolkit options |
/* X11_args - scan gnuplot command line for standard X Toolkit options |
* called from plot.c so must not be TERM_PUBLIC (which may be static) |
* called from plot.c so must not be TERM_PUBLIC (which may be static) |
*/ |
*/ |
|
|
int X11_args(argc, argv) |
int |
|
X11_args(argc, argv) |
int argc; |
int argc; |
char *argv[]; |
char *argv[]; |
{ |
{ |
int nx11 = 0, n; |
int nx11 = 0, i = 0, n; |
|
|
while (++argv, --argc > 0) { |
xargv = (char **) gp_alloc (argc*sizeof(char *), "<xargv>"); |
|
|
|
if (!xargv) { |
|
fputs ("not enough memory to copy argv - quitting\n", stderr); |
|
exit (EXIT_FAILURE); |
|
} |
|
|
|
/* We make a copy of the argument vector because |
|
* argv is modified later. */ |
|
memcpy (xargv, argv, argc*sizeof(char *)); |
|
optvec[i++] = X11_command; |
|
|
|
while (++argv, ++xargv, --argc > 0) { |
for (n = 0; n < X11_nopts; n++) { |
for (n = 0; n < X11_nopts; n++) { |
if (!strcmp(*argv, X11_opts[n])) { |
if (strcmp(*argv, X11_opts[n].option) == 0) { |
strcat(X11_command, " "); |
optvec[i++] = *xargv; |
strcat(X11_command, *argv); |
|
if (strcmp(*argv, "-display") == 0) |
if (strcmp(*argv, "-display") == 0) |
X11_Display++; |
X11_Display++; |
if (X11_optarg[n]) { |
if (X11_opts[n].arg == hasArg) { |
if (--argc <= 0) |
if (--argc <= 0) |
return (nx11); |
return nx11; |
strcat(X11_command, " \""); |
optvec[i++] = *++xargv, ++argv; |
strcat(X11_command, *++argv); |
|
strcat(X11_command, "\""); |
|
nx11++; |
nx11++; |
} |
} |
nx11++; |
nx11++; |
|
|
if (n == X11_nopts) |
if (n == X11_nopts) |
break; |
break; |
} |
} |
|
|
return (nx11); |
return (nx11); |
} |
} |
|
|
|
|
static unsigned int X11_plot_number; |
static unsigned int X11_plot_number; |
|
|
TERM_PUBLIC void X11_options() |
TERM_PUBLIC void |
|
X11_options() |
{ |
{ |
if (almost_equals(c_token, "res$et")) { |
if (almost_equals(c_token, "res$et")) { |
X11_atexit HANDLER_PARAMS; /* tell gnuplot_x11 to shut down */ |
X11_atexit HANDLER_PARAMS; /* tell gnuplot_x11 to shut down */ |
Line 194 TERM_PUBLIC void X11_options() |
|
Line 219 TERM_PUBLIC void X11_options() |
|
|
|
#define DEFAULT_X11 |
#define DEFAULT_X11 |
#if defined(VMS) || defined(CRIPPLED_SELECT) |
#if defined(VMS) || defined(CRIPPLED_SELECT) |
#undef DEFAULT_X11 |
# undef DEFAULT_X11 |
#endif |
#endif |
#if defined(VMS) && defined(CRIPPLED_SELECT) |
#if defined(VMS) && defined(CRIPPLED_SELECT) |
Error.Incompatible options. |
Error.Incompatible options. |
Line 212 Error.Incompatible options. |
|
Line 237 Error.Incompatible options. |
|
* DEFAULT_X11 popen() pipe IPC |
* DEFAULT_X11 popen() pipe IPC |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
|
|
static void X11_atexit HANDLER_DECL { if (X11_ipc) { |
static void |
|
X11_atexit HANDLER_DECL |
|
{ |
|
if (X11_ipc) { |
fputs("R\n", X11_ipc); |
fputs("R\n", X11_ipc); |
fclose(X11_ipc); |
fclose(X11_ipc); |
/* dont wait(), since they might be -persist */ |
/* dont wait(), since they might be -persist */ |
X11_ipc = NULL; |
X11_ipc = NULL; |
} |
} |
} TERM_PUBLIC void X11_init() |
} |
|
|
|
TERM_PUBLIC void |
|
X11_init() |
{ |
{ |
|
static int been_here = 0; |
|
|
if (!X11_ipc) { |
if (!X11_ipc) { |
/* first time through or after a reset */ |
/* first time through or after a reset */ |
#if defined(OSK) || defined(OS2) |
#if defined(OSK) || defined(OS2) |
Line 227 Error.Incompatible options. |
|
Line 260 Error.Incompatible options. |
|
* we can safely use it here |
* we can safely use it here |
*/ |
*/ |
X11_ipc = popen(X11_command, "w"); |
X11_ipc = popen(X11_command, "w"); |
#else |
#else /* !(OSK || OS/2) */ |
int fdes[2]; |
int fdes[2]; |
pipe(fdes); |
|
|
if (pipe(fdes)) perror("pipe() failed:"); |
|
|
if (fork() == 0) { |
if (fork() == 0) { |
/* child */ |
/* child */ |
close(fdes[1]); |
close(fdes[1]); |
dup2(fdes[0], 0); /* stdin from pipe */ |
dup2(fdes[0], 0); /* stdin from pipe */ |
execl("/bin/sh", "sh", "-c", X11_command, NULL); |
execvp(X11_command, optvec); |
/* if we get here, something went wrong */ |
/* if we get here, something went wrong */ |
perror("exec failed"); |
perror("exec failed"); |
exit(1); |
exit(EXIT_FAILURE); |
} |
} |
/* parent */ |
/* parent */ |
close(fdes[0]); /* read end of pipe */ |
close(fdes[0]); /* read end of pipe */ |
X11_ipc = fdopen(fdes[1], "w"); |
X11_ipc = fdopen(fdes[1], "w"); |
#endif |
#endif /* !(OSK || OS/2) */ |
} { |
|
static int been_here = 0; |
|
if (!been_here) { |
|
atexit(X11_atexit); |
|
been_here = 1; |
|
} |
|
} |
} |
|
|
|
if (!been_here) { |
|
atexit(X11_atexit); |
|
been_here++; |
|
} |
} |
} |
|
|
TERM_PUBLIC void X11_reset() |
TERM_PUBLIC void |
|
X11_reset() |
{ |
{ |
/* leave the pipe alone, until exit or set term x11 reset */ |
/* leave the pipe alone, until exit or set term x11 reset */ |
} |
} |
Line 269 TERM_PUBLIC void X11_reset() |
|
Line 303 TERM_PUBLIC void X11_reset() |
|
|
|
#define BEFORE_GRAPHICS /* nowt */ |
#define BEFORE_GRAPHICS /* nowt */ |
#define AFTER_TEXT /* nowt */ |
#define AFTER_TEXT /* nowt */ |
#endif /* DEFAULT_X11 */ |
|
|
|
|
|
#ifdef CRIPPLED_SELECT |
#elif defined(CRIPPLED_SELECT) |
|
|
/* PLEASE CAN SOMEONE CHECK THAT THIS STILL WORKS !!! */ |
/* PLEASE CAN SOMEONE CHECK THAT THIS STILL WORKS !!! */ |
|
|
Line 283 TERM_PUBLIC void X11_reset() |
|
Line 316 TERM_PUBLIC void X11_reset() |
|
static char X11_tmp[32], X11_tmp0[32], X11_shutdown[32]; |
static char X11_tmp[32], X11_tmp0[32], X11_shutdown[32]; |
static int X11_pid; |
static int X11_pid; |
|
|
TERM_PUBLIC void X11_init() |
TERM_PUBLIC void |
|
X11_init() |
{ |
{ |
if (!(X11_pid = fork())) { |
if (!(X11_pid = fork())) { |
execl("/bin/sh", "sh", "-c", X11_command, NULL); |
execvp(X11_command, optvec); |
_exit(1); |
_exit(1); |
} |
} |
sprintf(X11_tmp, "/tmp/Gnuplot_%d", X11_pid); |
sprintf(X11_tmp, "/tmp/Gnuplot_%d", X11_pid); |
Line 294 TERM_PUBLIC void X11_init() |
|
Line 328 TERM_PUBLIC void X11_init() |
|
sprintf(X11_shutdown, "echo R >%s", X11_tmp); |
sprintf(X11_shutdown, "echo R >%s", X11_tmp); |
} |
} |
|
|
TERM_PUBLIC void X11_reset() |
TERM_PUBLIC void |
|
X11_reset() |
{ |
{ |
system(X11_shutdown); |
system(X11_shutdown); |
} |
} |
Line 315 TERM_PUBLIC void X11_reset() |
|
Line 350 TERM_PUBLIC void X11_reset() |
|
#define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5) |
#define PRINT5(fmt,p1,p2,p3,p4,p5) fprintf(X11_ipc, fmt,p1,p2,p3,p4,p5) |
#define FFLUSH() fflush(X11_ipc) |
#define FFLUSH() fflush(X11_ipc) |
|
|
static void X11_atexit HANDLER_DECL { /* WHAT SHOULD I DO ? */ |
static void |
|
X11_atexit HANDLER_DECL { /* WHAT SHOULD I DO ? */ |
} |
} |
|
|
#endif /* CRIPPLED_SELECT */ |
#elif defined(VMS) |
#ifdef VMS |
|
/*----------------------------------------------------------------------------- |
/*----------------------------------------------------------------------------- |
* VMS mailbox/spawn IPC - Yehavi Bourvine - YEHAVI@VMS.HUJI.AC.IL |
* VMS mailbox/spawn IPC - Yehavi Bourvine - YEHAVI@VMS.HUJI.AC.IL |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
|
|
}; |
}; |
|
|
|
|
TERM_PUBLIC void X11_init() |
TERM_PUBLIC void |
|
X11_init() |
{ |
{ |
|
|
struct iosb iosb; |
struct iosb iosb; |
Line 368 TERM_PUBLIC void X11_init() |
|
Line 404 TERM_PUBLIC void X11_init() |
|
devnam.dsc$a_pointer, |
devnam.dsc$a_pointer, |
&devnam.dsc$w_length, 0 |
&devnam.dsc$w_length, 0 |
}; |
}; |
|
#define CMDLEN 1024 |
|
char cmdline[CMDLEN], *cmdp; |
|
int optindex; |
|
|
|
|
if (!X11_channel) { |
if (!X11_channel) { |
int one = 1; |
int one = 1; |
|
|
/* Create a descriptor for the command line that starts |
/* Create a descriptor for the command line that starts |
GNUPLOT_X11. $DESCRIP doesn't work in this context... */ |
GNUPLOT_X11. $DESCRIP doesn't work in this context... */ |
|
|
|
/* FIXME! |
|
* This does not work anymore since X11 option passing has been |
|
* changed to use execvp() in the DEFAULT_X11 case |
|
*/ |
struct dsc$descriptor_s pgmdsc = |
struct dsc$descriptor_s pgmdsc = |
{0, DSC$K_DTYPE_T, |
{0, DSC$K_DTYPE_T, |
DSC$K_CLASS_S, 0}; |
DSC$K_CLASS_S, 0}; |
pgmdsc.dsc$w_length = strlen(X11_command); |
optindex = 0; |
pgmdsc.dsc$a_pointer = X11_command; |
strcpy (cmdline, optvec[optindex]); |
|
cmdp = cmdline + strlen (optvec[optindex]); |
|
while (optvec[++optindex] != NULL) { |
|
*cmdp++ = ' '; |
|
*cmdp++ = '\"'; |
|
strcpy (cmdp, optvec[optindex]); |
|
cmdp += strlen (optvec[optindex]); |
|
*cmdp++ = '\"'; |
|
} |
|
pgmdsc.dsc$w_length = cmdp-cmdline; |
|
pgmdsc.dsc$a_pointer = cmdline; |
|
|
|
|
/* Create a mailbox which will be used as a pipe for commands to the |
/* Create a mailbox which will be used as a pipe for commands to the |
subprocess. What we'll write to it will be read by the subprocess as |
* subprocess. What we'll write to it will be read by the subprocess |
its STDIN. Use an unnamed mailbox and refer to it by its device |
* as its STDIN. Use an unnamed mailbox and refer to it by its device |
number */ |
* number */ |
|
|
vaxc$errno = sys$crembx(0, &X11_channel, MBXMXMSG, MBXMXMSG, 0, 0, 0, 0); |
vaxc$errno = sys$crembx(0, &X11_channel, MBXMXMSG, MBXMXMSG, 0, 0, 0, 0); |
if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) { |
if ((vaxc$errno & SS$_NORMAL) != SS$_NORMAL) { |
Line 450 TERM_PUBLIC void X11_init() |
|
Line 501 TERM_PUBLIC void X11_init() |
|
#define BEFORE_GRAPHICS /* nowt */ |
#define BEFORE_GRAPHICS /* nowt */ |
#define AFTER_TEXT /* nowt */ |
#define AFTER_TEXT /* nowt */ |
|
|
static void X11_atexit HANDLER_DECL { if (X11_channel) { |
static void |
|
X11_atexit HANDLER_DECL |
|
{ |
|
if (X11_channel) { |
PRINT0("R\n"); |
PRINT0("R\n"); |
sleep(2); /* Wait for subprocess to finish */ |
sleep(2); /* Wait for subprocess to finish */ |
sys$dassgn(X11_channel); |
sys$dassgn(X11_channel); |
X11_channel = 0; |
X11_channel = 0; |
} |
} |
} TERM_PUBLIC void X11_reset() |
} |
|
|
|
TERM_PUBLIC void |
|
X11_reset() |
{ |
{ |
/* do nothing until exit */ |
/* do nothing until exit */ |
} |
} |
|
|
#endif /* VMS */ |
#else /* !VMS */ |
|
You lose. |
|
#endif /* !VMS */ |
|
|
|
|
|
|
|
|
|
|
/* common stuff, using macros defined above */ |
/* common stuff, using macros defined above */ |
|
|
|
|
|
TERM_PUBLIC void |
TERM_PUBLIC void X11_graphics() |
X11_graphics() |
{ |
{ |
BEFORE_GRAPHICS; /* kludge for crippled select */ |
BEFORE_GRAPHICS; /* kludge for crippled select */ |
|
|
PRINT1("G%d\n", X11_plot_number); /* for VMS sake, keep as separate prints */ |
/* for VMS sake, keep as separate prints */ |
|
PRINT1("G%d\n", X11_plot_number); |
|
|
#ifdef ULTRIX_KLUDGE |
#ifdef ULTRIX_KLUDGE |
fflush(X11_ipc); |
fflush(X11_ipc); |
Line 483 TERM_PUBLIC void X11_graphics() |
|
Line 540 TERM_PUBLIC void X11_graphics() |
|
|
|
} |
} |
|
|
TERM_PUBLIC void X11_text() |
TERM_PUBLIC void |
|
X11_text() |
{ |
{ |
PRINT0("E\n"); |
PRINT0("E\n"); |
FFLUSH(); |
FFLUSH(); |
Line 496 TERM_PUBLIC void X11_text() |
|
Line 554 TERM_PUBLIC void X11_text() |
|
} |
} |
|
|
|
|
TERM_PUBLIC void X11_move(x, y) |
TERM_PUBLIC void |
|
X11_move(x, y) |
unsigned int x, y; |
unsigned int x, y; |
{ |
{ |
PRINT2("M%04d%04d\n", x, y); |
PRINT2("M%04d%04d\n", x, y); |
} |
} |
|
|
TERM_PUBLIC void X11_vector(x, y) |
TERM_PUBLIC void |
|
X11_vector(x, y) |
unsigned int x, y; |
unsigned int x, y; |
{ |
{ |
PRINT2("V%04d%04d\n", x, y); |
PRINT2("V%04d%04d\n", x, y); |
} |
} |
|
|
TERM_PUBLIC void X11_pointsize(ps) |
TERM_PUBLIC void |
|
X11_pointsize(ps) |
double ps; |
double ps; |
{ |
{ |
PRINT2("P7%04d%04d\n", /* size of point symbols */ |
PRINT2("P7%04d%04d\n", /* size of point symbols */ |
(int) (term->h_tic * ps * 0.5), (int) (term->v_tic * ps * 0.5)); |
(int) (term->h_tic * ps * 0.5), (int) (term->v_tic * ps * 0.5)); |
} |
} |
|
|
TERM_PUBLIC void X11_linewidth(lw) |
TERM_PUBLIC void |
|
X11_linewidth(lw) |
double lw; |
double lw; |
{ |
{ |
PRINT1("W%04d\n", (int) lw); |
PRINT1("W%04d\n", (int) lw); |
} |
} |
|
|
TERM_PUBLIC void X11_linetype(lt) |
TERM_PUBLIC void |
|
X11_linetype(lt) |
int lt; |
int lt; |
{ |
{ |
PRINT1("L%04d\n", lt); |
PRINT1("L%04d\n", lt); |
} |
} |
|
|
TERM_PUBLIC void X11_put_text(x, y, str) |
TERM_PUBLIC void |
|
X11_put_text(x, y, str) |
unsigned int x, y; |
unsigned int x, y; |
char str[]; |
char str[]; |
{ |
{ |
|
|
} |
} |
} |
} |
|
|
TERM_PUBLIC int X11_justify_text(mode) |
TERM_PUBLIC int |
|
X11_justify_text(mode) |
enum JUSTIFY mode; |
enum JUSTIFY mode; |
{ |
{ |
PRINT1("J%04d\n", mode); |
PRINT1("J%04d\n", mode); |
return (TRUE); |
return (TRUE); |
} |
} |
|
|
TERM_PUBLIC void X11_point(x, y, number) |
TERM_PUBLIC void |
|
X11_point(x, y, number) |
unsigned int x, y; |
unsigned int x, y; |
int number; |
int number; |
{ |
{ |
|
|
PRINT3("P%01d%04d%04d\n", number, x, y); |
PRINT3("P%01d%04d%04d\n", number, x, y); |
} |
} |
|
|
TERM_PUBLIC void X11_fillbox(style, x, y, w, h) |
TERM_PUBLIC void |
|
X11_fillbox(style, x, y, w, h) |
int style; |
int style; |
unsigned int x, y, w, h; |
unsigned int x, y, w, h; |
{ |
{ |