1
/* This file is part of the GNU plotutils package. Copyright (C) 1989,
2
1990, 1991, 1995, 1996, 1997, 1998, 1999, 2000, 2005, Free Software
5
The GNU plotutils package is free software. You may redistribute it
6
and/or modify it under the terms of the GNU General Public License as
7
published by the Free Software foundation; either version 2, or (at your
8
option) any later version.
10
The GNU plotutils package is distributed in the hope that it will be
11
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with the GNU plotutils package; see the file COPYING. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
18
Boston, MA 02110-1301, USA. */
1
20
/* This file is the driving routine for the GNU `plot' program. It
2
21
includes code to read a stream of commands, in GNU metafile format, and
3
call libplot functions to draw the graphics.
5
Copyright (C) 1989-2000 Free Software Foundation, Inc. */
22
call libplot functions to draw the graphics. */
7
24
#include "sys-defines.h"
25
#include "libcommon.h"
11
30
/* Obsolete op codes (no longer listed in plot.h) */
12
31
#define O_COLOR 'C'
46
65
const char *progname = "plot"; /* name of this program */
66
const char *written = "Written by Robert S. Maier.";
67
const char *copyright = "Copyright (C) 2005 Free Software Foundation, Inc.";
48
69
const char *usage_appendage = " [FILE]...\n\
49
70
With no FILE, or when FILE is -, read standard input.\n";
67
88
of erase()) from the output */
68
89
bool merge_pages = false;
70
/* Long options we recognize */
73
94
#define ARG_REQUIRED 1
74
95
#define ARG_OPTIONAL 2
97
const char *optstring = "shlAIOp:F:f:W:T:";
76
99
struct option long_options[] =
78
/* The most important option */
79
{ "display-type", ARG_REQUIRED, NULL, 'T'},
101
/* The most important option ("--display-type" is an obsolete variant) */
102
{ "output-format", ARG_REQUIRED, NULL, 'T'},
103
{ "display-type", ARG_REQUIRED, NULL, 'T' << 8 }, /* hidden */
80
104
/* Other frequently used options */
81
105
{ "font-name", ARG_REQUIRED, NULL, 'F' },
82
106
{ "font-size", ARG_REQUIRED, NULL, 'f' },
107
131
{ NULL, 0, NULL, 0}
110
/* null-terminated list of options that we don't show to the user */
111
int hidden_options[] = { (int)'I', 0 };
134
/* null-terminated list of options, such as obsolete-but-still-maintained
135
options or undocumented options, which we don't show to the user */
136
const int hidden_options[] = { (int)'I', (int)('T' << 8), 0 };
114
139
/* forward references */
115
bool read_plot ____P((plPlotter *plotter, FILE *in_stream));
116
char *read_string ____P((FILE *input, bool *badstatus));
117
double read_float ____P((FILE *input, bool *badstatus));
118
double read_int ____P((FILE *input, bool *badstatus));
119
int maybe_closepl ____P((plPlotter *plotter));
120
int maybe_openpl ____P((plPlotter *plotter));
121
int read_true_int ____P((FILE *input, bool *badstatus));
122
unsigned char read_byte_as_unsigned_char ____P((FILE *input, bool *badstatus));
123
unsigned int read_byte_as_unsigned_int ____P((FILE *input, bool *badstatus));
125
extern int display_fonts ____P((const char *display_type, const char *progname));
126
extern int list_fonts ____P((const char *display_type, const char *progname));
127
extern void display_usage ____P((const char *progname, const int *omit_vals, const char *appendage, bool fonts));
128
extern void display_version ____P((const char *progname));
129
extern voidptr_t xcalloc ____P ((size_t nmemb, size_t size));
130
extern voidptr_t xmalloc ____P ((size_t size));
131
extern voidptr_t xrealloc ____P ((voidptr_t p, size_t length));
132
extern char *xstrdup ____P ((const char *s));
140
bool read_plot (plPlotter *plotter, FILE *in_stream);
141
char *read_string (FILE *input, bool *badstatus);
142
double read_float (FILE *input, bool *badstatus);
143
double read_int (FILE *input, bool *badstatus);
144
int maybe_closepl (plPlotter *plotter);
145
int maybe_openpl (plPlotter *plotter);
146
int read_true_int (FILE *input, bool *badstatus);
147
unsigned char read_byte_as_unsigned_char (FILE *input, bool *badstatus);
148
unsigned int read_byte_as_unsigned_int (FILE *input, bool *badstatus);
137
152
main (int argc, char *argv[])
144
154
plPlotter *plotter;
145
155
plPlotterParams *plotter_params;
147
157
bool show_fonts = false; /* supply help on fonts? */
148
158
bool show_usage = false; /* show usage message? */
149
159
bool show_version = false; /* show version message? */
150
char *display_type = (char *)"meta"; /* default libplot output format */
160
char *output_format = (char *)"meta"; /* default libplot output format */
151
161
int errcnt = 0; /* errors encountered */
152
162
int local_page_number; /* temporary storage */
153
163
int opt_index; /* long option index */
155
165
int retval; /* return value */
157
167
plotter_params = pl_newplparams ();
158
while ((option = getopt_long (argc, argv, "shlAIOp:F:f:W:T:", long_options, &opt_index)) != EOF)
168
while ((option = getopt_long (argc, argv, optstring, long_options, &opt_index)) != EOF)
161
171
option = long_options[opt_index].val;
165
case 'T': /* Display type, ARG REQUIRED */
166
display_type = (char *)xmalloc (strlen (optarg) + 1);
167
strcpy (display_type, optarg);
175
case 'T': /* Output format, ARG REQUIRED */
177
output_format = (char *)xmalloc (strlen (optarg) + 1);
178
strcpy (output_format, optarg);
169
180
case 'O': /* Ascii output */
170
pl_setplparam (plotter_params, "META_PORTABLE", (voidptr_t)"yes");
181
pl_setplparam (plotter_params, "META_PORTABLE", (void *)"yes");
172
183
case 'F': /* set the initial font */
173
184
font_name = (char *)xmalloc (strlen (optarg) + 1);
174
185
strcpy (font_name, optarg);
176
187
case 'e' << 8: /* emulate color by grayscale */
177
pl_setplparam (plotter_params, "EMULATE_COLOR", (voidptr_t)optarg);
188
pl_setplparam (plotter_params, "EMULATE_COLOR", (void *)optarg);
179
190
case 'C' << 8: /* set the initial pen color */
180
191
pen_color = (char *)xmalloc (strlen (optarg) + 1);
185
196
strcpy (bg_color, optarg);
187
198
case 'B' << 8: /* Bitmap size */
188
pl_setplparam (plotter_params, "BITMAPSIZE", (voidptr_t)optarg);
199
pl_setplparam (plotter_params, "BITMAPSIZE", (void *)optarg);
190
201
case 'P' << 8: /* Page size */
191
pl_setplparam (plotter_params, "PAGESIZE", (voidptr_t)optarg);
202
pl_setplparam (plotter_params, "PAGESIZE", (void *)optarg);
193
204
case 'f': /* set the initial fontsize */
257
268
user_specified_input_format = GNU_OLD_PORTABLE;
259
270
case 'r' << 8: /* Plot rotation angle, ARG REQUIRED */
260
pl_setplparam (plotter_params, "ROTATION", (voidptr_t)optarg);
271
pl_setplparam (plotter_params, "ROTATION", (void *)optarg);
262
273
case 'M' << 8: /* Max line length */
263
pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (voidptr_t)optarg);
274
pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (void *)optarg);
265
276
case 's': /* Merge pages */
266
277
merge_pages = true;
325
336
/* select user-specified background color */
326
pl_setplparam (plotter_params, "BG_COLOR", (voidptr_t)bg_color);
337
pl_setplparam (plotter_params, "BG_COLOR", (void *)bg_color);
328
if ((plotter = pl_newpl_r (display_type, NULL, stdout, stderr,
339
if ((plotter = pl_newpl_r (output_format, NULL, stdout, stderr,
329
340
plotter_params)) == NULL)
331
342
fprintf (stderr, "%s: error: could not create plot device\n", progname);
417
428
the file. Return value indicates whether stream was parsed
421
431
read_plot (plPlotter *plotter, FILE *in_stream)
423
read_plot (plotter, in_stream)
428
433
bool argerr = false; /* error occurred while reading argument? */
429
434
bool display_open = false; /* display device open? */
1828
1793
string, with \0 replacing \n, is allocated on the heap and may be
1832
1796
read_string (FILE *input, bool *badstatus)
1834
read_string (input, badstatus)
1839
1798
int length = 0, buffer_length = 16; /* initial length */