1
/* This file is part of the GNU plotutils package. Copyright (C) 1995,
2
1996, 1997, 1998, 1999, 2000, 2005, Free Software Foundation, Inc.
4
The GNU plotutils package is free software. You may redistribute it
5
and/or modify it under the terms of the GNU General Public License as
6
published by the Free Software foundation; either version 2, or (at your
7
option) any later version.
9
The GNU plotutils package is distributed in the hope that it will be
10
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
General Public License for more details.
14
You should have received a copy of the GNU General Public License along
15
with the GNU plotutils package; see the file COPYING. If not, write to
16
the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
17
Boston, MA 02110-1301, USA. */
23
#include "libcommon.h"
4
26
#include "plot.h" // libplot header file
6
28
const char *progname = "pic2plot"; // name of this program
29
const char *written = "Written by Robert S. Maier.";
30
const char *copyright = "Copyright (C) 2005 Free Software Foundation, Inc.";
8
32
const char *usage_appendage = " FILE...\n";
16
40
// is derived from the output class. Any instance of the plot_output
17
41
// class looks at the following global variables, which the user
18
42
// can set on the command line.
19
char *display_type = (char *)"meta"; // libplot output format
43
char *output_format = (char *)"meta"; // libplot output format
20
44
char *font_name = NULL; // initial font name (if set)
21
45
char *pen_color_name = NULL; // initial pen color (if set)
22
46
double font_size = 10.0/(8.0*72.); // font size as width of graphics display
43
67
static int had_parse_error = 0; // parse error?
44
68
static int lf_flag = 1; // non-zero -> try to parse `.lf' lines
46
/* Long options we recognize */
49
73
#define ARG_REQUIRED 1
50
74
#define ARG_OPTIONAL 2
76
const char *optstring = "T:OndF:f:W:";
52
78
struct option long_options[] =
54
/* The most important option */
55
{ "display-type", ARG_REQUIRED, NULL, 'T'},
80
/* The most important option ("--display-type" is an obsolete variant) */
81
{ "output-format", ARG_REQUIRED, NULL, 'T'},
82
{ "display-type", ARG_REQUIRED, NULL, 'T' << 8 }, /* hidden */
56
83
/* Long options, most with no equivalent short option alias */
57
84
{ "bg-color", ARG_REQUIRED, NULL, 'q' << 8 },
58
85
{ "bitmap-size", ARG_REQUIRED, NULL, 'B' << 8 },
76
103
{ NULL, 0, NULL, 0}
79
/* null-terminated list of options that we don't show to the user */
80
int hidden_options[] = { 0 };
106
/* null-terminated list of options, such as obsolete-but-still-maintained
107
options or undocumented options, which we don't show to the user */
108
const int hidden_options[] = { (int)('T' << 8), 0 };
82
110
// forward references
83
111
void do_file (const char *filename);
84
112
void do_picture (FILE *fp);
87
extern "C" int display_fonts (const char *display_type, const char *progname);
88
extern "C" int list_fonts (const char *display_type, const char *progname);
89
extern "C" void display_usage (const char *progname, const int *omit_vals, const char *appendage, bool fonts);
90
extern "C" void display_version (const char *progname);
91
extern "C" voidptr_t xcalloc (size_t nmemb, size_t size);
92
extern "C" voidptr_t xmalloc (size_t size);
93
extern "C" voidptr_t xrealloc (voidptr_t p, size_t length);
94
extern "C" char *xstrdup (const char *s);
96
114
//////////////////////////////////////////////////////////////////////
97
115
// TOP_INPUT class.
98
116
//////////////////////////////////////////////////////////////////////
330
348
plotter_params = pl_newplparams ();
331
while ((option = getopt_long (argc, argv, "T:OndF:f:W:", long_options, &opt_index)) != EOF)
349
while ((option = getopt_long (argc, argv, optstring, long_options, &opt_index)) != EOF)
334
352
option = long_options[opt_index].val;
338
case 'T': /* Display type, ARG REQUIRED */
339
display_type = (char *)xmalloc (strlen (optarg) + 1);
340
strcpy (display_type, optarg);
356
case 'T': /* Output format, ARG REQUIRED */
358
output_format = (char *)xmalloc (strlen (optarg) + 1);
359
strcpy (output_format, optarg);
342
361
case 'O': /* Ascii output */
343
pl_setplparam (plotter_params, "META_PORTABLE", (voidptr_t)"yes");
362
pl_setplparam (plotter_params, "META_PORTABLE", (void *)"yes");
345
364
case 'n': /* No centering */
346
365
no_centering_flag = 1;
411
430
case 'e' << 8: /* Emulate color via grayscale */
412
pl_setplparam (plotter_params, "EMULATE_COLOR", (voidptr_t)optarg);
431
pl_setplparam (plotter_params, "EMULATE_COLOR", (void *)optarg);
414
433
case 'C' << 8: /* set the initial pen color */
415
434
pen_color_name = (char *)xmalloc (strlen (optarg) + 1);
416
435
strcpy (pen_color_name, optarg);
418
437
case 'q' << 8: /* set the initial background color */
419
pl_setplparam (plotter_params, "BG_COLOR", (voidptr_t)optarg);
438
pl_setplparam (plotter_params, "BG_COLOR", (void *)optarg);
421
440
case 'B' << 8: /* Bitmap size */
422
pl_setplparam (plotter_params, "BITMAPSIZE", (voidptr_t)optarg);
441
pl_setplparam (plotter_params, "BITMAPSIZE", (void *)optarg);
424
443
case 'M' << 8: /* Max line length */
425
pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (voidptr_t)optarg);
444
pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (void *)optarg);
427
446
case 'P' << 8: /* Page size */
428
pl_setplparam (plotter_params, "PAGESIZE", (voidptr_t)optarg);
447
pl_setplparam (plotter_params, "PAGESIZE", (void *)optarg);
430
449
case 'r' << 8: /* Rotation angle */
431
pl_setplparam (plotter_params, "ROTATION", (voidptr_t)optarg);
450
pl_setplparam (plotter_params, "ROTATION", (void *)optarg);
433
452
case 'V' << 8: /* Version */
434
453
show_version = true;
457
476
if (show_version)
459
display_version (progname);
478
display_version (progname, written, copyright);
460
479
return EXIT_SUCCESS;
462
481
if (do_list_fonts)
464
483
int success = true;
466
success = list_fonts (display_type, progname);
485
success = list_fonts (output_format, progname);
468
487
return EXIT_SUCCESS;