Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathplot.c
More file actions
1830 lines (1740 loc) · 56.9 KB
/
Copy pathplot.c
File metadata and controls
1830 lines (1740 loc) · 56.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file is part of the GNU plotutils package. Copyright (C) 1989,
1990, 1991, 1995, 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free
Software Foundation, Inc.
The GNU plotutils package is free software. You may redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software foundation; either version 2, or (at your
option) any later version.
The GNU plotutils package is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with the GNU plotutils package; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
Boston, MA 02110-1301, USA. */
/* This file is the driving routine for the GNU `plot' program. It
includes code to read a stream of commands, in GNU metafile format, and
call libplot functions to draw the graphics. */
#include "sys-defines.h"
#include "libcommon.h"
#include "getopt.h"
#include "fontlist.h"
#include "plot.h"
/* Obsolete op codes (no longer listed in plot.h) */
#define O_COLOR 'C'
#define O_FROTATE 'V'
#define O_FSCALE 'X'
#define O_FTRANSLATE 'Q'
/* The six input formats we recognize */
typedef enum
{
/* There are two GNU metafile formats: binary and portable (ascii). */
GNU_BINARY, GNU_PORTABLE,
/* PLOT5_HIGH and PLOT5_LOW are the two distinct versions of Unix plot(5)
format (high/low byte first), which we also support. They are
requested by the -h and -l options respectively. The user may not
need to specify either of those options explicitly, since if
sizeof(short int)=2 then plot(5) input format is subsumed by
GNU_OLD_BINARY format (see below). */
PLOT5_HIGH, PLOT5_LOW,
/* GNU_OLD_BINARY [obsolete] is the binary format used in pre-2.0
releases, with no initial magic string, short ints instead of ints,
and no OPENPL or CLOSEPL directives. By default, we assume that the
input format is GNU_OLD_BINARY, and we switch to GNU_BINARY or
GNU_PORTABLE if we see the appropriate magic header string.
GNU_OLD_PORTABLE [obsolete] is the ascii format used in pre-2.0
releases, with no initial magic string, and no OPENPL or CLOSEPL
directives. It subsumes the ascii version of plot(5) format, found on
some Unix systems. If the user wishes to parse GNU_OLD_PORTABLE
format, he/she should use the -A option. */
GNU_OLD_BINARY, GNU_OLD_PORTABLE
} plot_format;
const char *progname = "plot"; /* name of this program */
const char *written = "Written by Robert S. Maier.";
const char *copyright = "Copyright (C) 2009 Free Software Foundation, Inc.";
const char *usage_appendage = " [FILE]...\n\
With no FILE, or when FILE is -, read standard input.\n";
bool single_page_is_requested = false; /* set if user uses -p option */
char *bg_color = NULL; /* initial bg color, can be spec'd by user */
char *font_name = NULL; /* initial font name, can be spec'd by user */
char *pen_color = NULL; /* initial pen color, can be spec'd by user */
double font_size = -1.0; /* initial fractional size, <0 means default */
double line_width = -1.0; /* initial line width, <0 means default */
int requested_page = 0; /* user sets this via -p option */
/* Default input file format (see list of supported formats above). Don't
change this (GNU_OLD_BINARY is an obsolete format, but it subsumes
plot(5) format on many operating systems). We'll switch to the
appropriate modern format by peeking at the first line of the input file. */
plot_format user_specified_input_format = GNU_OLD_BINARY;
plot_format input_format = GNU_OLD_BINARY;
/* Whether to remove all page breaks and frame breaks (i.e. invocations
of erase()) from the output */
bool merge_pages = false;
/* options */
#define ARG_NONE 0
#define ARG_REQUIRED 1
#define ARG_OPTIONAL 2
const char *optstring = "shlAIOp:F:f:W:T:";
struct option long_options[] =
{
/* The most important option ("--display-type" is an obsolete variant) */
{ "output-format", ARG_REQUIRED, NULL, 'T'},
{ "display-type", ARG_REQUIRED, NULL, 'T' << 8 }, /* hidden */
/* Other frequently used options */
{ "font-name", ARG_REQUIRED, NULL, 'F' },
{ "font-size", ARG_REQUIRED, NULL, 'f' },
{ "line-width", ARG_REQUIRED, NULL, 'W' },
/* Long options with (mostly) no equivalent short option alias */
{ "bg-color", ARG_REQUIRED, NULL, 'q' << 8 },
{ "bitmap-size", ARG_REQUIRED, NULL, 'B' << 8 },
{ "emulate-color", ARG_REQUIRED, NULL, 'e' << 8},
{ "max-line-length", ARG_REQUIRED, NULL, 'M' << 8 },
{ "merge-pages", ARG_NONE, NULL, 's' },
{ "page-number", ARG_REQUIRED, NULL, 'p' },
{ "page-size", ARG_REQUIRED, NULL, 'P' << 8 },
{ "pen-color", ARG_REQUIRED, NULL, 'C' << 8 },
{ "rotation", ARG_REQUIRED, NULL, 'r' << 8},
/* Options relevant only to raw plot (refers to metafile output) */
{ "portable-output", ARG_NONE, NULL, 'O' },
/* Old input formats, for backward compatibility */
{ "high-byte-first-input", ARG_NONE, NULL, 'h' },
{ "low-byte-first-input", ARG_NONE, NULL, 'l' },
{ "ascii-input", ARG_NONE, NULL, 'A' },
/* obsolete hidden option [same as 'A'] */
{ "ascii-input", ARG_NONE, NULL, 'I' },
/* Documentation options */
{ "help-fonts", ARG_NONE, NULL, 'f' << 8 },
{ "list-fonts", ARG_NONE, NULL, 'l' << 8 },
{ "version", ARG_NONE, NULL, 'V' << 8 },
{ "help", ARG_NONE, NULL, 'h' << 8 },
{ NULL, 0, NULL, 0}
};
/* null-terminated list of options, such as obsolete-but-still-maintained
options or undocumented options, which we don't show to the user */
const int hidden_options[] = { (int)'I', (int)('T' << 8), 0 };
/* forward references */
bool read_plot (plPlotter *plotter, FILE *in_stream);
char *read_string (FILE *input, bool *badstatus);
double read_float (FILE *input, bool *badstatus);
double read_int (FILE *input, bool *badstatus);
int maybe_closepl (plPlotter *plotter);
int maybe_openpl (plPlotter *plotter);
int read_true_int (FILE *input, bool *badstatus);
unsigned char read_byte_as_unsigned_char (FILE *input, bool *badstatus);
unsigned int read_byte_as_unsigned_int (FILE *input, bool *badstatus);
int
main (int argc, char *argv[])
{
plPlotter *plotter;
plPlotterParams *plotter_params;
bool do_list_fonts = false; /* show a list of fonts? */
bool show_fonts = false; /* supply help on fonts? */
bool show_usage = false; /* show usage message? */
bool show_version = false; /* show version message? */
char *output_format = (char *)"meta"; /* default libplot output format */
int errcnt = 0; /* errors encountered */
int local_page_number; /* temporary storage */
int opt_index; /* long option index */
int option; /* option character */
int retval; /* return value */
plotter_params = pl_newplparams ();
while ((option = getopt_long (argc, argv, optstring, long_options, &opt_index)) != EOF)
{
if (option == 0)
option = long_options[opt_index].val;
switch (option)
{
case 'T': /* Output format, ARG REQUIRED */
case 'T' << 8:
output_format = (char *)xmalloc (strlen (optarg) + 1);
strcpy (output_format, optarg);
break;
case 'O': /* Ascii output */
pl_setplparam (plotter_params, "META_PORTABLE", (void *)"yes");
break;
case 'F': /* set the initial font */
font_name = (char *)xmalloc (strlen (optarg) + 1);
strcpy (font_name, optarg);
break;
case 'e' << 8: /* emulate color by grayscale */
pl_setplparam (plotter_params, "EMULATE_COLOR", (void *)optarg);
break;
case 'C' << 8: /* set the initial pen color */
pen_color = (char *)xmalloc (strlen (optarg) + 1);
strcpy (pen_color, optarg);
break;
case 'q' << 8: /* set the initial background color */
bg_color = (char *)xmalloc (strlen (optarg) + 1);
strcpy (bg_color, optarg);
break;
case 'B' << 8: /* Bitmap size */
pl_setplparam (plotter_params, "BITMAPSIZE", (void *)optarg);
break;
case 'P' << 8: /* Page size */
pl_setplparam (plotter_params, "PAGESIZE", (void *)optarg);
break;
case 'f': /* set the initial fontsize */
{
double local_font_size;
if (sscanf (optarg, "%lf", &local_font_size) <= 0)
{
fprintf (stderr,
"%s: error: the initial font size `%s' is bad (it should be a number)\n",
progname, optarg);
errcnt++;
break;
}
if (local_font_size > 1.0)
fprintf (stderr, "%s: the too-large initial font size `%f' is disregarded (it should be less than 1.0)\n",
progname, local_font_size);
else if (local_font_size < 0.0)
fprintf (stderr, "%s: the negative initial font size `%f' is disregarded\n",
progname, local_font_size);
else
font_size = local_font_size;
break;
}
case 'p': /* page number */
if (sscanf (optarg, "%d", &local_page_number) <= 0
|| local_page_number < 1)
{
fprintf (stderr,
"%s: error: the page number `%s' is bad (it should be a positive integer)\n",
progname, optarg);
errcnt++;
}
else
{
requested_page = local_page_number;
single_page_is_requested = true;
}
break;
case 'W': /* set the initial line width */
{
double local_line_width;
if (sscanf (optarg, "%lf", &local_line_width) <= 0)
{
fprintf (stderr,
"%s: error: the initial line thickness `%s' is bad (it should be a number)\n",
progname, optarg);
errcnt++;
break;
}
if (local_line_width < 0.0)
fprintf (stderr, "%s: the negative initial line thickness `%f' is ignored\n",
progname, local_line_width);
else
line_width = local_line_width;
break;
}
case 'h': /* High-byte-first plot(5) metafile(s) */
user_specified_input_format = PLOT5_HIGH;
break;
case 'l': /* Low-byte-first plot(5) metafile(s) */
user_specified_input_format = PLOT5_LOW;
break;
case 'A': /* Old ascii metafile(s) */
case 'I':
user_specified_input_format = GNU_OLD_PORTABLE;
break;
case 'r' << 8: /* Plot rotation angle, ARG REQUIRED */
pl_setplparam (plotter_params, "ROTATION", (void *)optarg);
break;
case 'M' << 8: /* Max line length */
pl_setplparam (plotter_params, "MAX_LINE_LENGTH", (void *)optarg);
break;
case 's': /* Merge pages */
merge_pages = true;
break;
case 'V' << 8: /* Version */
show_version = true;
break;
case 'f' << 8: /* Fonts */
show_fonts = true;
break;
case 'h' << 8: /* Help */
show_usage = true;
break;
case 'l' << 8: /* Fonts */
do_list_fonts = true;
break;
default:
errcnt++;
break;
}
}
if (errcnt > 0)
{
fprintf (stderr, "Try `%s --help' for more information\n", progname);
return EXIT_FAILURE;
}
if (show_version)
{
display_version (progname, written, copyright);
return EXIT_SUCCESS;
}
if (do_list_fonts)
{
int success;
success = list_fonts (output_format, progname);
if (success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
if (show_fonts)
{
int success;
success = display_fonts (output_format, progname);
if (success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
if (show_usage)
{
display_usage (progname, hidden_options, usage_appendage, 2);
return EXIT_SUCCESS;
}
if (bg_color)
/* select user-specified background color */
pl_setplparam (plotter_params, "BG_COLOR", (void *)bg_color);
if ((plotter = pl_newpl_r (output_format, NULL, stdout, stderr,
plotter_params)) == NULL)
{
fprintf (stderr, "%s: error: the plot device could not be created\n", progname);
return EXIT_FAILURE;
}
if (merge_pages)
/* we do just one openpl..closepl, wrapped around everything */
if (pl_openpl_r (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be opened\n",
progname);
return EXIT_FAILURE;
}
retval = EXIT_SUCCESS;
if (optind < argc)
/* input files (or stdin) named explicitly on the command line */
{
for (; optind < argc; optind++)
{
FILE *data_file;
if (strcmp (argv[optind], "-") == 0)
data_file = stdin;
else
{
data_file = fopen (argv[optind], "r");
if (data_file == NULL)
{
fprintf (stderr, "%s: %s: %s\n", progname, argv[optind], strerror(errno));
fprintf (stderr, "%s: ignoring this file\n", progname);
errno = 0; /* not quite fatal */
retval = EXIT_FAILURE;
continue; /* back to top of for loop */
}
}
if (read_plot (plotter, data_file) == false)
{
fprintf (stderr, "%s: the input file `%s' could not be parsed\n",
progname, argv[optind]);
retval = EXIT_FAILURE;
break; /* break out of for loop */
}
if (data_file != stdin) /* Don't close stdin */
if (fclose (data_file) < 0)
{
fprintf (stderr,
"%s: the input file `%s' could not be closed\n",
progname, argv[optind]);
retval = EXIT_FAILURE;
continue; /* back to top of for loop */
}
} /* endfor */
}
else
/* no files/streams spec'd on the command line, just read stdin */
{
if (read_plot (plotter, stdin) == false)
{
fprintf (stderr, "%s: the input could not be parsed\n", progname);
retval = EXIT_FAILURE;
}
}
if (merge_pages)
/* we do just one openpl..closepl, wrapped around everything */
if (pl_closepl_r (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be closed\n",
progname);
return EXIT_FAILURE;
}
if (pl_deletepl_r (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be deleted\n", progname);
retval = EXIT_FAILURE;
}
pl_deleteplparams (plotter_params);
return retval;
}
/* read_plot() reads a file in GNU metafile format or plot(5) format from a
stream, and calls a plot function according to each instruction found in
the file. Return value indicates whether stream was parsed
successfully. */
bool
read_plot (plPlotter *plotter, FILE *in_stream)
{
bool argerr = false; /* error occurred while reading argument? */
bool display_open = false; /* display device open? */
bool first_command = true; /* first command of file? */
bool in_page = false; /* within an openpl..closepl? */
bool parameters_initted = false; /* user-specified parameters initted? */
bool unrec = false; /* unrecognized command seen? */
char *s;
double x0, y0, x1, y1, x2, y2, x3, y3;
int i0, i1, i2;
int instruction;
static int current_page = 1; /* page count is continued from file to file */
/* User may specify one of the formats PLOT5_HIGH, PLOT5_LOW, and
GNU_OLD_PORTABLE on the command line. If user doesn't specify a
format, this is by default set to GNU_OLD_BINARY [obsolete], and we'll
figure out whether the file is in a modern format, and if so,
which one. */
input_format = user_specified_input_format;
/* peek at first instruction in file */
instruction = getc (in_stream);
/* Switch away from GNU_OLD_BINARY to GNU_BINARY if a GNU metafile magic
string, interpreted here as a comment, is seen at top of file. See
also parsing of the COMMENT instruction below (we further switch to
GNU_PORTABLE if the header line indicates we should). */
if (input_format == GNU_OLD_BINARY && instruction == (int)O_COMMENT)
input_format = GNU_BINARY;
/* Note: we use `input_format' as a way of working around a problem:
absurdly large font size requests, which can crash X servers. (You used
to be able to crash an X server by piping any EPS file to `plot -TX',
since the `S' on the first line was interepreted as an op code for a
font size request!) We no longer process the `S' op code unless we've
seen a modern GNU metafile magic string at the beginning of the file.
This is a kludge but adds a little safety. */
while (instruction != EOF)
{
/* If a pre-modern format, OPENPL directive is not supported. So
open display device if it hasn't already been opened, and
we're on the right page. */
if (input_format != GNU_BINARY && input_format != GNU_PORTABLE)
if ((!single_page_is_requested || current_page == requested_page)
&& instruction != (int)O_COMMENT && display_open == false)
{
if (maybe_openpl (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be opened\n",
progname);
exit (EXIT_FAILURE);
}
else
display_open = true;
}
switch (instruction)
{
case (int)O_ALABEL:
{
char x_adjust, y_adjust;
x_adjust = (char)read_byte_as_unsigned_char (in_stream, &argerr);
y_adjust = (char)read_byte_as_unsigned_char (in_stream, &argerr);
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_alabel_r (plotter, x_adjust, y_adjust, s);
free (s);
}
}
break;
case (int)O_ARC:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_farc_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_ARCREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_farcrel_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_BEZIER2:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fbezier2_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_BEZIER2REL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fbezier2rel_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_BEZIER3:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
x3 = read_int (in_stream, &argerr);
y3 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fbezier3_r (plotter, x0, y0, x1, y1, x2, y2, x3, y3);
break;
case (int)O_BEZIER3REL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
x3 = read_int (in_stream, &argerr);
y3 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fbezier3rel_r (plotter, x0, y0, x1, y1, x2, y2, x3, y3);
break;
case (int)O_BGCOLOR:
/* parse args as unsigned ints rather than ints */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
i1 = read_true_int (in_stream, &argerr)&0xFFFF;
i2 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_bgcolor_r (plotter, i0, i1, i2);
break;
case (int)O_BOX:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fbox_r (plotter, x0, y0, x1, y1);
break;
case (int)O_BOXREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fboxrel_r (plotter, x0, y0, x1, y1);
break;
case (int)O_CAPMOD:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_capmod_r (plotter, s);
free (s);
}
break;
case (int)O_CIRCLE:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fcircle_r (plotter, x0, y0, x1);
break;
case (int)O_CIRCLEREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fcirclerel_r (plotter, x0, y0, x1);
break;
case (int)O_COLOR: /* obsolete op code, to be removed */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
i1 = read_true_int (in_stream, &argerr)&0xFFFF;
i2 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_color_r (plotter, i0, i1, i2);
break;
case (int)O_CLOSEPATH:
if (!single_page_is_requested || current_page == requested_page)
pl_closepath_r (plotter);
break;
case (int)O_CLOSEPL:
if (input_format != GNU_BINARY && input_format != GNU_PORTABLE)
/* shouldn't be seeing a CLOSEPL */
{
if (display_open && maybe_closepl (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be closed\n",
progname);
exit (EXIT_FAILURE);
}
current_page++;
return false; /* signal a parse error */
}
else
/* GNU_BINARY or GNU_PORTABLE format, so this may be legitimate */
{
if (in_page == false)
/* shouldn't be seeing a CLOSEPL */
{
current_page++;
return false; /* signal a parse error */
}
else
/* the CLOSEPL is legitimate */
{
if (!single_page_is_requested
|| current_page == requested_page)
{
if (maybe_closepl (plotter) < 0)
{
fprintf (stderr,
"%s: error: the plot device could not be closed\n",
progname);
exit (EXIT_FAILURE);
}
display_open = false;
}
in_page = false;
current_page++; /* `page' is an OPENPL..CLOSEPL */
}
}
break;
case (int)O_COMMENT:
s = read_string (in_stream, &argerr);
if (!argerr)
{
/* if a header line, switch to appropriate modern format */
if (first_command
&& input_format != PLOT5_HIGH
&& input_format != PLOT5_LOW
&& (strlen (s) >= 6)
/* check magic number */
&& strncmp (s, "PLOT ", 5) == 0)
switch (s[5])
{
case '1':
input_format = GNU_BINARY;
break;
case '2':
input_format = GNU_PORTABLE;
break;
default:
fprintf (stderr,
"%s: the input file is of an unrecognized metafile type\n",
progname);
break;
}
free (s);
}
break;
case (int)O_CONT:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fcont_r (plotter, x0, y0);
break;
case (int)O_CONTREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fcontrel_r (plotter, x0, y0);
break;
case (int)O_ELLARC:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fellarc_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_ELLARCREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
y2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fellarcrel_r (plotter, x0, y0, x1, y1, x2, y2);
break;
case (int)O_ELLIPSE:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fellipse_r (plotter, x0, y0, x1, y1, x2);
break;
case (int)O_ELLIPSEREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
x2 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fellipserel_r (plotter, x0, y0, x1, y1, x2);
break;
case (int)O_ENDPATH:
if (!single_page_is_requested || current_page == requested_page)
pl_endpath_r (plotter);
break;
case (int)O_ENDSUBPATH:
if (!single_page_is_requested || current_page == requested_page)
pl_endsubpath_r (plotter);
break;
case (int)O_ERASE:
if (!single_page_is_requested || current_page == requested_page)
if (merge_pages == false) /* i.e. not merging frames */
pl_erase_r (plotter);
break;
case (int)O_FILLCOLOR:
/* parse args as unsigned ints rather than ints */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
i1 = read_true_int (in_stream, &argerr)&0xFFFF;
i2 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fillcolor_r (plotter, i0, i1, i2);
break;
case (int)O_FILLMOD:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_fillmod_r (plotter, s);
free (s);
}
break;
case (int)O_FILLTYPE:
/* parse args as unsigned ints rather than ints */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_filltype_r (plotter, i0);
break;
case (int)O_FONTNAME:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_fontname_r (plotter, s);
free (s);
}
break;
case (int)O_FONTSIZE:
x0 = read_int (in_stream, &argerr);
if (input_format == GNU_BINARY || input_format == GNU_PORTABLE)
/* workaround, see comment above */
{
if (!argerr)
if (!single_page_is_requested
|| current_page == requested_page)
pl_ffontsize_r (plotter, x0);
}
break;
case (int)O_JOINMOD:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_joinmod_r (plotter, s);
free (s);
}
break;
case (int)O_LABEL:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_label_r (plotter, s);
free (s);
}
break;
case (int)O_LINE:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fline_r (plotter, x0, y0, x1, y1);
break;
case (int)O_LINEDASH:
{
int n, i;
double *dash_array, phase;
n = read_true_int (in_stream, &argerr);
if (n > 0)
dash_array = (double *)xmalloc((unsigned int)n * sizeof(double));
else
dash_array = NULL;
for (i = 0; i < n; i++)
dash_array[i] = read_int (in_stream, &argerr);
phase = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_flinedash_r (plotter, n, dash_array, phase);
free (dash_array);
break;
}
case (int)O_LINEREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
x1 = read_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_flinerel_r (plotter, x0, y0, x1, y1);
break;
case (int)O_LINEMOD:
s = read_string (in_stream, &argerr);
if (!argerr)
{
if (!single_page_is_requested || current_page == requested_page)
pl_linemod_r (plotter, s);
free (s);
}
break;
case (int)O_LINEWIDTH:
x0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_flinewidth_r (plotter, x0);
break;
case (int)O_MARKER:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
i0 = read_true_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fmarker_r (plotter, x0, y0, i0, y1);
break;
case (int)O_MARKERREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
i0 = read_true_int (in_stream, &argerr);
y1 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fmarkerrel_r (plotter, x0, y0, i0, y1);
break;
case (int)O_MOVE:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fmove_r (plotter, x0, y0);
break;
case (int)O_MOVEREL:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fmoverel_r (plotter, x0, y0);
break;
case (int)O_OPENPL:
if (input_format != GNU_BINARY && input_format != GNU_PORTABLE)
/* shouldn't be seeing an OPENPL */
{
if (display_open && maybe_closepl (plotter) < 0)
{
fprintf (stderr, "%s: error: the plot device could not be closed\n",
progname);
exit (EXIT_FAILURE);
}
current_page++;
return false; /* signal a parse error */
}
else
/* GNU_BINARY or GNU_PORTABLE format, so may be legitimate */
{
if (in_page)
/* shouldn't be seeing another OPENPL */
{
if (display_open && maybe_closepl (plotter) < 0)
{
fprintf (stderr,
"%s: error: the plot device could not be closed\n",
progname);
exit (EXIT_FAILURE);
}
current_page++;
return false; /* signal a parse error */
}
/* this OPENPL is legitimate */
if (!single_page_is_requested || current_page == requested_page)
{
if (maybe_openpl (plotter) < 0)
{
fprintf (stderr,
"%s: error: the plot device could not be opened\n",
progname);
exit (EXIT_FAILURE);
}
else
display_open = true;
}
/* we're now in an openpl..closepl pair */
in_page = true;
}
break;
case (int)O_ORIENTATION:
i0 = read_true_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_orientation_r (plotter, i0);
break;
case (int)O_PENCOLOR:
/* parse args as unsigned ints rather than ints */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
i1 = read_true_int (in_stream, &argerr)&0xFFFF;
i2 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_pencolor_r (plotter, i0, i1, i2);
break;
case (int)O_PENTYPE:
/* parse args as unsigned ints rather than ints */
i0 = read_true_int (in_stream, &argerr)&0xFFFF;
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_pentype_r (plotter, i0);
break;
case (int)O_POINT:
x0 = read_int (in_stream, &argerr);
y0 = read_int (in_stream, &argerr);
if (!argerr)
if (!single_page_is_requested || current_page == requested_page)
pl_fpoint_r (plotter, x0, y0);
You can’t perform that action at this time.
