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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609
|
/* This file contains the main routine, and a few support subroutines, for
GNU graph.
Copyright (C) 1989-1999 Free Software Foundation, Inc. */
#include "sys-defines.h"
#include "extern.h"
#include "getopt.h"
#define ARG_NONE 0
#define ARG_REQUIRED 1
#define ARG_OPTIONAL 2
struct option long_options[] =
{
/* The most important option */
{"display-type", ARG_REQUIRED, NULL, 'T'},
/* Other frequently used options */
{"auto-abscissa", ARG_OPTIONAL, NULL, 'a'}, /* 0 or 1 or 2 */
{"clip-mode", ARG_REQUIRED, NULL, 'K'},
{"fill-fraction", ARG_REQUIRED, NULL, 'q'},
{"font-name", ARG_REQUIRED, NULL, 'F'},
{"font-size", ARG_REQUIRED, NULL, 'f'},
{"grid-style", ARG_REQUIRED, NULL, 'g'},
{"height-of-plot", ARG_REQUIRED, NULL, 'h'},
{"input-format", ARG_REQUIRED, NULL, 'I'},
{"line-mode", ARG_REQUIRED, NULL, 'm'},
{"line-width", ARG_REQUIRED, NULL, 'W'},
{"right-shift", ARG_REQUIRED, NULL, 'r'},
{"save-screen", ARG_NONE, NULL, 's'},
{"symbol", ARG_OPTIONAL, NULL, 'S'}, /* 0 or 1 or 2 */
{"tick-size", ARG_REQUIRED, NULL, 'k'},
{"toggle-auto-bump", ARG_NONE, NULL, 'B'},
{"toggle-axis-end", ARG_REQUIRED, NULL, 'E'},
{"toggle-frame-on-top", ARG_NONE, NULL, 'H'},
{"toggle-log-axis", ARG_REQUIRED, NULL, 'l'},
{"toggle-no-ticks", ARG_REQUIRED, NULL, 'N'},
{"toggle-round-to-next-tick", ARG_REQUIRED, NULL, 'R'},
{"toggle-transpose-axes", ARG_NONE, NULL, 't'},
{"toggle-use-color", ARG_NONE, NULL, 'C'},
{"top-label", ARG_REQUIRED, NULL, 'L'},
{"upward-shift", ARG_REQUIRED, NULL, 'u'},
{"width-of-plot", ARG_REQUIRED, NULL, 'w'},
{"x-label", ARG_REQUIRED, NULL, 'X'},
{"x-limits", ARG_OPTIONAL, NULL, 'x'}, /* 0, 1, 2, or 3 */
{"y-label", ARG_REQUIRED, NULL, 'Y'},
{"y-limits", ARG_OPTIONAL, NULL, 'y'}, /* 0, 1, 2, or 3 */
/* Long options with no equivalent short option alias */
{"bg-color", ARG_REQUIRED, NULL, 'q' << 8},
{"bitmap-size", ARG_REQUIRED, NULL, 'B' << 8},
{"blankout", ARG_REQUIRED, NULL, 'b' << 8},
{"emulate-color", ARG_REQUIRED, NULL, 'e' << 8},
{"frame-line-width", ARG_REQUIRED, NULL, 'W' << 8},
{"frame-color", ARG_REQUIRED, NULL, 'C' << 8},
{"max-line-length", ARG_REQUIRED, NULL, 'M' << 8},
{"pen-colors", ARG_REQUIRED, NULL, 'p' << 8},
{"reposition", ARG_REQUIRED, NULL, 'R' << 8}, /* 3 */
{"rotation", ARG_REQUIRED, NULL, 'r' << 8},
{"symbol-font-name", ARG_REQUIRED, NULL, 'G' << 8},
{"title-font-name", ARG_REQUIRED, NULL, 'Z' << 8},
{"title-font-size", ARG_REQUIRED, NULL, 'F' << 8},
{"toggle-rotate-y-label", ARG_NONE, NULL, 'N' << 8},
{"page-size", ARG_REQUIRED, NULL, 'P' << 8},
/* Options relevant only to raw graph (refers to plot(5) output) */
{"portable-output", ARG_NONE, NULL, 'O'},
/* 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, 0, 0}
};
/* null-terminated list of options that we don't show to the user */
int hidden_options[] = { 0 };
const char *progname = "graph"; /* name of this program */
const char *usage_appendage = " [FILE]...\n\
With no FILE, or when FILE is -, read standard input.\n";
/* forward references */
static void close_file ____P ((char *filename, FILE *stream));
static void open_file_for_reading ____P ((char *filename, FILE **input));
static bool parse_pen_string ____P ((const char *pen_s));
int
#ifdef _HAVE_PROTOS
main (int argc, char *argv[])
#else
main (argc, argv)
int argc;
char *argv[];
#endif
{
/* Variables related to getopt parsing */
int option;
int opt_index;
int errcnt = 0; /* errors encountered in getopt parsing */
int matched;
bool using_getopt = true; /* true until end of command-line options */
bool continue_parse = true; /* reset e.g. when --help or --version seen */
bool show_version = false; /* show version message? */
bool show_usage = false; /* show usage message? */
bool show_fonts = false; /* supply help on fonts? */
bool do_list_fonts = false; /* show a list of fonts? */
bool filter = false; /* will we act as a filter? */
bool new_symbol = false;
bool new_symbol_size = false;
bool new_symbol_font_name = false;
bool new_linemode = false;
bool new_plot_line_width = false;
bool new_fill_fraction = false;
bool new_use_color = false;
bool first_file_of_graph = true;
bool first_graph_of_multigraph = true;
FILE *data_file = NULL;
/* Variables related to the point reader */
Reader *reader = NULL;
data_type input_type = T_ASCII; /* by default we read ascii data */
bool auto_bump = true; /* auto-bump linemode between polylines? */
bool auto_abscissa = false; /* generate abscissa values automatically? */
double x_start = 0.; /* start and increment, for auto-abscissa */
double delta_x = 1.;
/* polyline attributes */
int linemode_index = 1; /* linemode for polylines, 1=solid, etc. */
double plot_line_width = -0.001; /* polyline width (as frac. of display width), negative means default provided by libplot) */
int symbol_index = 0; /* 0=none, 1=dot, 2=plus, 3=asterisk, etc. */
double symbol_size = .03; /* symbol size (frac. of plotting box size) */
double fill_fraction = -1.0; /* negative means regions aren't filled */
bool use_color = false; /* color / monochrome */
/* Variables related to both the point reader and the point plotter */
bool transpose_axes = false; /* true means -x applies to y axis, etc. */
/* Variables related to the multigrapher, i.e. point plotter */
Multigrapher *multigrapher = NULL;
/* command-line parameters (constant over multigrapher operation) */
const char *display_type = "meta";/* libplot output format */
const char *bg_color = NULL; /* color of background, if non-NULL */
const char *bitmap_size = NULL;
const char *emulate_color = NULL;
const char *max_line_length = NULL;
const char *meta_portable = NULL;
const char *page_size = NULL;
const char *rotation_angle = NULL;
bool save_screen = false; /* save screen, i.e. no erase before plot? */
/* graph-specific parameters (may change from graph to graph) */
grid_type grid_spec = AXES_AND_BOX; /* frame type for current graph */
bool no_rotate_y_label = false; /* used for pre-X11R6 servers */
const char *frame_color = "black"; /* color of frame (and graph, if no -C)*/
int clip_mode = 1; /* clipping mode (cf. gnuplot) */
/* following variables are portmanteau: x and y are included as bitfields*/
int log_axis = 0; /* log axes or linear axes? */
int round_to_next_tick = 0; /* round axis limits to nearest tick? */
int switch_axis_end = 0; /* axis at top/right instead of bottom/left? */
int omit_ticks = 0; /* omit ticks and tick labels from an axis? */
/* graph dimensions, expressed as fractions of the width of the libplot
graphics display [by convention square]; <0.0 means use libplot default */
double frame_line_width = -0.001; /* width of lines in the graph frame */
/* dimensions of graphing area, expressed as fractions of the width of
the libplot graphics display [by convention square] */
double margin_below = .2; /* margin below the plot */
double margin_left = .2; /* margin left of the plot */
double plot_height = .6; /* height of the plot */
double plot_width = .6; /* width of the plot */
/* dimensions, expressed as fractions of the size of the plotting area */
double tick_size = .02; /* size of tick marks (< 0.0 allowed) */
double font_size = 0.0525; /* fontsize */
double title_font_size = 0.07; /* title fontsize */
double blankout_fraction = 1.3; /* this fraction of size of plotting box
is erased before the plot is drawn */
/* text-related */
const char *font_name = NULL; /* font name, NULL -> device default */
const char *title_font_name = NULL; /* title font name, NULL -> default */
const char *symbol_font_name = "ZapfDingbats"; /* symbol font name, NULL -> default */
const char *x_label = NULL; /* label for the x axis, NULL -> no label */
const char *y_label = NULL; /* label for the y axis, NULL -> no label */
const char *top_label = NULL; /* title above the plot, NULL -> no title */
/* user-specified limits on the axes */
double min_x = 0.0, min_y = 0.0, max_x = 0.0, max_y = 0.0;
double spacing_x = 0.0, spacing_y = 0.0;
/* flags indicating which axis limits the user has specified */
bool spec_min_x = false, spec_min_y = false;
bool spec_max_x = false, spec_max_y = false;
bool spec_spacing_x = false, spec_spacing_y = false;
/* misc. local variables used in getopt parsing, counterparts to the above */
double local_x_start, local_delta_x;
int local_grid_style;
int local_symbol_index;
int local_clip_mode;
double local_symbol_size, local_font_size, local_title_font_size;
double local_frame_line_width, local_plot_line_width;
double local_min_x, local_min_y;
double local_max_x, local_max_y;
double local_spacing_x, local_spacing_y;
double local_fill_fraction;
/* `finalized' arguments to set_graph_parameters() (computed at the time
the first file of a graph is seen, and continuing in effect over the
duration of the graph) */
int final_log_axis = 0;
int final_round_to_next_tick = 0;
double final_min_x = 0.0, final_max_x = 0.0, final_spacing_x = 0.0;
double final_min_y = 0.0, final_max_y = 0.0, final_spacing_y = 0.0;
bool final_spec_min_x = false, final_spec_min_y = false;
bool final_spec_max_x = false, final_spec_max_y = false;
bool final_spec_spacing_x = false, final_spec_spacing_y = false;
bool final_transpose_axes = false;
/* for storage of data points (if we're not acting as a filter) */
Point *p; /* points array */
int points_length = 1024; /* length of the points array, in points */
int no_of_points = 0; /* number of points stored in it */
/* support for multigraphing */
double reposition_trans_x = 0.0, reposition_trans_y = 0.0;
double reposition_scale = 1.0;
double old_reposition_trans_x, old_reposition_trans_y;
double old_reposition_scale;
/* sui generis */
bool frame_on_top = false;
/* The main command-line parsing loop, which uses getopt to scan argv[]
without reordering, i.e. to process command-line arguments (options
and filenames) sequentially.
From a logical point of view, a multigraph consists of a sequence of
graphs, with a `--reposition' flag serving as a separator between
graphs. A graph is drawn from one or more files.
So this parsing loop invokes Multigrapher methods (1) when a file name
is seen, (2) when a `--reposition' directive is seen, and (3) at the
end of the scan over argv[].
If at the end of the scan no file names have been seen, stdin is used
instead as an input stream. (As a file name, `-' means stdin.) */
while (continue_parse)
{
if (using_getopt)
/* end of options not reached yet */
{
option = getopt_long (argc, argv,
/* initial hyphen requests no reordering */
"-BCHOVstE:F:f:g:h:k:K:I:l:L:m:N:q:R:r:T:u:w:W:X:Y:a::x::y::S::",
long_options, &opt_index);
if (option == EOF) /* end of options */
{
using_getopt = false;
continue; /* back to top of while loop */
}
if (option == 1) /* filename embedded among options */
{
if (strcmp (optarg, "-") == 0)
data_file = stdin; /* interpret "-" as stdin */
else
open_file_for_reading (optarg, &data_file);
}
}
else
/* end of options reached, processing filenames manually */
{
if (optind >= argc) /* all files processed */
{
if (first_graph_of_multigraph && first_file_of_graph)
/* no file appeared on command line, read stdin instead */
{
data_file = stdin;
option = 1; /* code for pseudo-option */
}
else
break; /* all files done, break out of while loop */
}
else /* have files yet to process */
{
if (strcmp (argv[optind], "-") == 0)
data_file = stdin;
else
open_file_for_reading (argv[optind], &data_file);
optarg = argv[optind]; /* keep track of name of opened file */
optind++;
option = 1; /* code for pseudo-option */
}
}
/* Parse an option flag, which may be a genuine option flag obtained
from getopt, or a fake (a `1', indicating that a filename has been
seen by getopt, or that filename has been seen on the command line
after all genuine options have been processed, or that stdin
should be read because no filenames have been seen). */
switch (option)
{
/* ----------- options with no argument --------------*/
case 's': /* Don't erase display before plot, ARG NONE */
save_screen = true;
break;
case 't': /* Toggle transposition of axes, ARG NONE */
transpose_axes = (transpose_axes == true ? false : true);
break;
case 'B': /* Toggle linemode auto-bumping, ARG NONE */
auto_bump = (auto_bump == true ? false : true);
break;
case 'C': /* Toggle color/monochrome, ARG NONE */
new_use_color = true;
use_color = (use_color == true ? false : true);
break;
case 'H': /* Toggle frame-on-top, ARG NONE */
frame_on_top = (frame_on_top == true ? false : true);
break;
case 'O': /* portable format, ARG NONE */
meta_portable = "yes";
break;
case 'e' << 8: /* emulate color, ARG NONE */
emulate_color = xstrdup (optarg);
break;
case 'V' << 8: /* Version, ARG NONE */
show_version = true;
continue_parse = false;
break;
case 'h' << 8: /* Help, ARG NONE */
show_usage = true;
continue_parse = false;
break;
case 'f' << 8: /* Help on fonts, ARG NONE */
show_fonts = true;
continue_parse = false;
break;
case 'l' << 8: /* List fonts, ARG NONE */
do_list_fonts = true;
continue_parse = false;
break;
case 'N' << 8: /* Toggle rotation of y-label, ARG NONE */
no_rotate_y_label = (no_rotate_y_label == true ? false : true);
break;
/*----------- options with a single argument --------------*/
case 'I': /* Input format, ARG REQUIRED */
switch (*optarg)
{
case 'a':
case 'A':
/* ASCII format, records and fields within records are
separated by whitespace, and datasets are separated by a
pair of newlines. Record length = 2. */
input_type = T_ASCII;
break;
case 'f':
case 'F':
/* Binary single precision, records and fields within records
are contiguous, and datasets are separated by a FLT_MAX.
Record length = 2. */
input_type = T_SINGLE;
break;
case 'd':
case 'D':
/* Binary double precision, records and fields within records
are contiguous, and datasets are separated by a DBL_MAX.
Record length = 2. */
input_type = T_DOUBLE;
break;
case 'i':
case 'I':
/* Binary integer, records and fields within records are
contiguous, and datasets are separated by an occurrence of
INT_MAX. Record length = 2. */
input_type = T_INTEGER;
break;
case 'e':
case 'E':
/* Same as T_ASCII, but record length = 3. */
input_type = T_ASCII_ERRORBAR;
break;
case 'g':
case 'G':
/* Sui generis. */
input_type = T_GNUPLOT; /* gnuplot `table' format */
break;
default:
fprintf (stderr,
"%s: error: unrecognized data option `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'f': /* Font size, ARG REQUIRED */
if (sscanf (optarg, "%lf", &local_font_size) <= 0)
{
fprintf (stderr,
"%s: error: font size must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
else
{
if (local_font_size >= 1.0)
fprintf (stderr, "%s: ignoring too-large font size `%f' (must be < 1.0)\n",
progname, local_font_size);
else if (local_font_size < 0.0)
fprintf (stderr, "%s: ignoring negative font size `%f'\n",
progname, local_font_size);
else
font_size = local_font_size;
}
break;
case 'g': /* Grid style, ARG REQUIRED */
if (sscanf (optarg, "%d", &local_grid_style) <= 0)
{
fprintf (stderr,
"%s: error: grid style must be a (small) integer, was `%s'\n",
progname, optarg);
errcnt++;
break;
}
switch (local_grid_style)
/* the subset ordering is: 0 < 1 < 2 < 3; 4 is different */
{
case 0:
/* no frame at all; just the plot */
grid_spec = NO_AXES;
break;
case 1:
/* box, ticks, gridlines, labels */
grid_spec = AXES;
break;
case 2:
/* box, ticks, no gridlines, labels */
grid_spec = AXES_AND_BOX;
break;
case 3:
/* `half-box', partial ticks, no gridlines, labels */
grid_spec = AXES_AND_BOX_AND_GRID;
break;
case 4:
/* no box, no gridlines; specially positioned axes, labels */
grid_spec = AXES_AT_ORIGIN;
break;
default:
fprintf (stderr,
"%s: error: grid style number `%s' out of bounds\n",
progname, optarg);
errcnt++;
}
break;
case 'h': /* Height of plot, ARG REQUIRED */
if (sscanf (optarg, "%lf", &plot_height) <= 0)
{
fprintf (stderr,
"%s: error: plot height must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'K': /* Clip mode, ARG REQUIRED */
if ((sscanf (optarg, "%d", &local_clip_mode) <= 0)
|| local_clip_mode < 0 || local_clip_mode > 2)
fprintf (stderr,
"%s: ignoring bad clip mode `%s' (must be 0, 1, or 2)\n",
progname, optarg);
else
clip_mode = local_clip_mode;
break;
case 'l': /* Toggle log/linear axis, ARG REQUIRED */
switch (*optarg)
{
case 'x':
case 'X':
log_axis ^= X_AXIS;
break;
case 'y':
case 'Y':
log_axis ^= Y_AXIS;
break;
default:
fprintf (stderr,
"%s: ignoring unrecognized axis specification `%s'\n",
progname, optarg);
break;
}
break;
case 'N': /* Toggle omission of labels, ARG REQUIRED */
switch (*optarg)
{
case 'x':
case 'X':
omit_ticks ^= X_AXIS;
break;
case 'y':
case 'Y':
omit_ticks ^= Y_AXIS;
break;
default:
fprintf (stderr,
"%s: ignoring unrecognized axis specification `%s'\n",
progname, optarg);
break;
}
break;
case 'm': /* Linemode, ARG REQUIRED */
new_linemode = true;
if (sscanf (optarg, "%d", &linemode_index) <= 0)
{
fprintf (stderr,
"%s: error: linemode must be a (small) integer, was `%s'.\n",
progname, optarg);
errcnt++;
}
break;
case 'q': /* Fill fraction, ARG REQUIRED */
if (sscanf (optarg, "%lf", &local_fill_fraction) <= 0)
{
fprintf (stderr,
"%s: error: fill fraction must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
else
{
if (local_fill_fraction > 1.0)
fprintf (stderr,
"%s: ignoring bad region fill fraction `%f' (must be <=1.0)\n",
progname, local_fill_fraction);
else
{
fill_fraction = local_fill_fraction;
new_fill_fraction = true;
}
}
break;
case 'r': /* Right shift, ARG REQUIRED */
if (sscanf (optarg, "%lf", &margin_left) <= 0)
{
fprintf (stderr,
"%s: error: plot rightward displacement must be a number, was `%s'.\n",
progname, optarg);
errcnt++;
}
break;
case 'u': /* Upward shift, ARG REQUIRED */
if (sscanf (optarg, "%lf", &margin_below) <= 0)
{
fprintf (stderr,
"%s: error: plot upward displacement must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'w': /* Width of plot, ARG REQUIRED */
if (sscanf (optarg, "%lf", &plot_width) <= 0)
{
fprintf (stderr,
"%s: error: plot width must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'T': /* Display type, ARG REQUIRED */
display_type = xstrdup (optarg);
break;
case 'F': /* Font name, ARG REQUIRED */
font_name = xstrdup (optarg);
break;
case 'r' << 8: /* Rotation angle, ARG REQUIRED */
rotation_angle = xstrdup (optarg);
break;
case 'Z' << 8: /* Title Font name, ARG REQUIRED */
title_font_name = xstrdup (optarg);
break;
case 'G' << 8: /* Symbol Font name, ARG REQUIRED */
symbol_font_name = xstrdup (optarg);
new_symbol_font_name = true;
break;
case 'R': /* Toggle rounding to next tick, ARG REQUIRED*/
switch (*optarg)
{
case 'x':
case 'X':
round_to_next_tick ^= X_AXIS;
break;
case 'y':
case 'Y':
round_to_next_tick ^= Y_AXIS;
break;
default:
fprintf (stderr,
"%s: ignoring unrecognized axis specification `%s'\n",
progname, optarg);
break;
}
break;
case 'L': /* Top title, ARG REQUIRED */
top_label = xstrdup (optarg);
break;
case 'k': /* Tick size, ARG REQUIRED */
if (sscanf (optarg, "%lf", &tick_size) <= 0)
{
fprintf (stderr,
"%s: error: tick size must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'W': /* Line width, ARG REQUIRED */
if (sscanf (optarg, "%lf", &local_plot_line_width) <= 0)
{
fprintf (stderr,
"%s: error: plot line thickness must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
if (local_plot_line_width < 0.0)
fprintf (stderr, "%s: ignoring negative plot line thickness `%f'\n",
progname, local_plot_line_width);
else
{
plot_line_width = local_plot_line_width;
new_plot_line_width = true;
}
break;
case 'X': /* X axis title, ARG REQUIRED */
x_label = xstrdup (optarg);
break;
case 'Y': /* Y axis title, ARG REQUIRED */
y_label = xstrdup (optarg);
break;
case 'E': /* Toggle switching of axis to other end,
ARG REQUIRED */
switch (*optarg)
{
case 'x':
case 'X':
switch_axis_end ^= Y_AXIS;
break;
case 'y':
case 'Y':
switch_axis_end ^= X_AXIS;
break;
default:
fprintf (stderr,
"%s: ignoring unrecognized axis specification `%s'\n",
progname, optarg);
break;
}
break;
case 'b' << 8: /* Blankout fraction, ARG REQUIRED */
if (sscanf (optarg, "%lf", &blankout_fraction) <= 0)
{
fprintf (stderr,
"%s: error: fractional blankout must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
break;
case 'B' << 8: /* Bitmap size, ARG REQUIRED */
bitmap_size = xstrdup (optarg);
break;
case 'F' << 8: /* Title font size, ARG REQUIRED */
if (sscanf (optarg, "%lf", &local_title_font_size) <= 0)
{
fprintf (stderr,
"%s: error: title font size must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
else if (local_title_font_size >= 1.0)
fprintf (stderr, "%s: ignoring too-large title font size `%f' (must be < 1.0)\n",
progname, local_title_font_size);
else if (local_title_font_size < 0.0)
fprintf (stderr, "%s: ignoring negative title font size `%f'\n",
progname, local_title_font_size);
if (local_title_font_size == 0.0)
fprintf (stderr, "%s: ignoring zero title font size\n",
progname);
else
title_font_size = local_title_font_size;
break;
case 'W' << 8: /* Frame line width, ARG REQUIRED */
if (sscanf (optarg, "%lf", &local_frame_line_width) <= 0)
{
fprintf (stderr,
"%s: error: frame line thickness must be a number, was `%s'\n",
progname, optarg);
errcnt++;
}
if (local_frame_line_width < 0.0)
fprintf (stderr, "%s: ignoring negative frame line thickness `%f'\n",
progname, local_frame_line_width);
else
frame_line_width = local_frame_line_width;
break;
case 'M' << 8: /* Max line length, ARG REQUIRED */
max_line_length = xstrdup (optarg);
break;
case 'P' << 8: /* Page size, ARG REQUIRED */
page_size = xstrdup (optarg);
break;
case 'p' << 8: /* Pen color string, ARG REQUIRED */
if (parse_pen_string (optarg) == false)
{
fprintf (stderr, "%s: ignoring unparseable pen string `%s'\n",
progname, optarg);
}
break;
case 'q' << 8: /* Background color, ARG REQUIRED */
bg_color = xstrdup (optarg);
break;
case 'C' << 8: /* Frame color, ARG REQUIRED */
frame_color = xstrdup (optarg);
break;
/*------ options with zero or more arguments ---------*/
case 'a': /* Auto-abscissa, ARG OPTIONAL [0,1,2] */
auto_abscissa = true;
if (optind >= argc)
break;
if (sscanf (argv[optind], "%lf", &local_delta_x) <= 0)
break;
optind++; /* tell getopt we recognized delta_x */
if (local_delta_x == 0.0)
/* "-a 0" turns off auto-abscissa for next file */
{
auto_abscissa = false;
break;
}
delta_x = local_delta_x;
if (optind >= argc)
break;
if (sscanf (argv[optind], "%lf", &local_x_start) <= 0)
break;
x_start = local_x_start;
optind++; /* tell getopt we recognized x_start */
break;
case 'x': /* X limits, ARG OPTIONAL [0,1,2,3] */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_min_x)) <= 0))
{
spec_min_x = spec_max_x = spec_spacing_x = false;
break;
}
if (matched > 0)
{
spec_min_x = true;
min_x = local_min_x;
}
else
spec_min_x = false;
optind++; /* tell getopt we recognized min_x */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_max_x)) <= 0))
{
spec_max_x = spec_spacing_x = false;
break;
}
if (matched > 0)
{
spec_max_x = true;
max_x = local_max_x;
}
else
spec_max_x = false;
optind++; /* tell getopt we recognized max_x */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_spacing_x)) <= 0))
{
spec_spacing_x = false;
break;
}
if (matched > 0)
{
spec_spacing_x = true;
spacing_x = local_spacing_x;
}
else
spec_spacing_x = false;
optind++; /* tell getopt we recognized spacing_x */
break;
case 'y': /* Y limits, ARG OPTIONAL [0,1,2,3] */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_min_y)) <= 0))
{
spec_min_y = spec_max_y = spec_spacing_y = false;
break;
}
if (matched > 0)
{
spec_min_y = true;
min_y = local_min_y;
}
else
spec_min_y = false;
optind++; /* tell getopt we recognized min_y */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_max_y)) <= 0))
{
spec_max_y = spec_spacing_y = false;
break;
}
if (matched > 0)
{
spec_max_y = true;
max_y = local_max_y;
}
else
spec_max_y = false;
optind++; /* tell getopt we recognized max_y */
matched = 0;
if (optind >= argc
|| ((strcmp (argv[optind], "-") != 0)
&& (matched
= sscanf (argv[optind], "%lf", &local_spacing_y)) <= 0))
{
spec_spacing_y = false;
break;
}
if (matched > 0)
{
spec_spacing_y = true;
spacing_y = local_spacing_y;
}
else
spec_spacing_y = false;
optind++; /* tell getopt we recognized spacing_y */
break;
case 'S': /* Symbol, ARG OPTIONAL [0,1,2] */
new_symbol = true;
symbol_index = 1; /* symbol # 1 is switched to by -S alone */
if (optind >= argc)
break;
if (sscanf (argv[optind], "%d", &local_symbol_index) <= 0)
break;
if (local_symbol_index < 0 || local_symbol_index > 255)
fprintf (stderr, "%s: ignoring symbol type `%d' (must be in range 0..255)\n",
progname, local_symbol_index);
else
symbol_index = local_symbol_index;
optind++; /* tell getopt we recognized symbol_index */
if (optind >= argc)
break;
if (sscanf (argv[optind], "%lf", &local_symbol_size) <= 0)
break;
if (local_symbol_size < 0.0)
fprintf (stderr, "%s: ignoring negative symbol size `%f'\n",
progname, local_symbol_size);
else if (local_symbol_size == 0.0)
fprintf (stderr, "%s: ignoring zero symbol size\n",
progname);
else
{
symbol_size = local_symbol_size;
new_symbol_size = true;
}
optind++; /* tell getopt we recognized symbol_size */
break;
/* ---------- options with one or more arguments ---------- */
case 'R' << 8: /* End graph and reposition, ARG REQUIRED [3]*/
old_reposition_trans_x = reposition_trans_x;
old_reposition_trans_y = reposition_trans_y;
old_reposition_scale = reposition_scale;
if (sscanf (optarg, "%lf", &reposition_trans_x) <= 0)
{
fprintf (stderr,
"%s: error: x repositioning must be a number, was `%s'\n",
progname, optarg);
return EXIT_FAILURE;
}
if (optind >= argc)
{
fprintf (stderr,
"%s: error: missing arg[s] to --reposition option\n",
progname);
return EXIT_FAILURE;
}
if (sscanf (argv[optind], "%lf", &reposition_trans_y) <= 0)
{
fprintf (stderr,
"%s: error: y repositioning must be a number, was `%s'\n",
progname, argv[optind]);
return EXIT_FAILURE;
}
optind++; /* tell getopt we recognized trans_y */
if (optind >= argc)
{
fprintf (stderr,
"%s: error: missing arg[s] to --reposition option\n",
progname);
return EXIT_FAILURE;
}
if (sscanf (argv[optind], "%lf", &reposition_scale) <= 0)
{
fprintf (stderr,
"%s: error: reposition scale factor must be a number, was `%s'\n",
progname, optarg);
return EXIT_FAILURE;
}
if (reposition_scale == 0.0)
{
fprintf (stderr,
"%s: error: reposition scale factor cannot be zero\n", progname);
return EXIT_FAILURE;
}
optind++; /* tell getopt we recognized trans_x */
if (!first_file_of_graph)
/* a graph is in progress (at least one file has been read), so
it must be ended before we begin the next one */
{
if (!filter)
/* We haven't been acting as a real-time filter for the
duration of this graph, so the graph isn't already drawn
on the display. Instead, we have a points array and we
need to plot it, after computing bounds. */
{
/* fill in any of min_? and max_? that user didn't
specify (the prefix "final_" means these arguments
were finalized at the time the first file of the plot
was processed) */
array_bounds (p, no_of_points,
final_transpose_axes, clip_mode,
&final_min_x, &final_min_y,
&final_max_x, &final_max_y,
final_spec_min_x, final_spec_min_y,
final_spec_max_x, final_spec_max_y);
if (first_graph_of_multigraph)
/* haven't created multigrapher yet, do so now */
{
if ((multigrapher = new_multigrapher (display_type, bg_color, bitmap_size, emulate_color, max_line_length, meta_portable, page_size, rotation_angle, save_screen)) == NULL)
{
fprintf (stderr,
"%s: error: couldn't open graphing device\n", progname);
return EXIT_FAILURE;
}
}
/* begin graph: push new libplot drawing state onto stack
of states; also concatenate the current transformation
matrix with a matrix formed from the repositioning
parameters (this will be in effect for duration of the
graph) */
begin_graph (multigrapher,
old_reposition_scale,
old_reposition_trans_x, old_reposition_trans_y);
/* font selection, saves typing */
if ((title_font_name == NULL) && (font_name != NULL))
title_font_name = font_name;
/* initialize, using (in part) finalized arguments */
set_graph_parameters (multigrapher,
frame_line_width,
frame_color,
top_label,
title_font_name, title_font_size, /* for title */
tick_size, grid_spec,
final_min_x, final_max_x, final_spacing_x,
final_min_y, final_max_y, final_spacing_y,
final_spec_spacing_x,
final_spec_spacing_y,
plot_width, plot_height, margin_below, margin_left,
font_name, font_size, /* for abs. label */
x_label,
font_name, font_size, /* for ord. label */
y_label,
no_rotate_y_label,
/* these args are portmanteaux */
final_log_axis,
final_round_to_next_tick,
switch_axis_end, omit_ticks,
/* more args */
clip_mode,
blankout_fraction,
final_transpose_axes);
/* draw the graph frame (grid, ticks, etc.); draw a
`canvas' (a background opaque white rectangle) only if
this isn't the first graph */
draw_frame_of_graph (multigrapher,
(first_graph_of_multigraph ? false : true));
/* plot the laboriously read-in array */
plot_point_array (multigrapher, p, no_of_points);
/* free points array */
free (p);
no_of_points = 0;
first_file_of_graph = false;
} /* end of not-filter case */
/* draw graph frame on top of graph, if user requested it */
if (frame_on_top)
{
end_polyline_and_flush (multigrapher);
draw_frame_of_graph (multigrapher, false);
}
/* end graph: pop the graph-specific libplot drawing state off
the stack of drawing states */
end_graph (multigrapher);
/* on to next graph */
first_graph_of_multigraph = false;
first_file_of_graph = true;
} /* end of not first-file-of-plot case */
break; /* end of `--reposition' option */
/* ---------------- pseudo-options -------------- */
/* File specified on command line, returned in order (along with
command-line options). The first time we reach this point in
any plot, we perform special initializations and in particular
determine whether or not, for the duration of this plot, we'll
be acting as a filter. We can do so if xmin, xmax, ymin, ymax
have all been specified, by this point, on the command line.
A plot may consist of many files. A plot in progress is
terminated if a --reposition option (which moves us to the
next plot of a multiplot) is seen, or when the last
command-line option is processed. */
case 1:
if (first_file_of_graph)
{
/* For plots with a logarithmic axis, compute logs of axis
limits, since coordinates along the axis, as obtained from
the reader, are stored in logarithmic form. */
if (log_axis & X_AXIS)
{
if (spec_min_x)
{
if (min_x > 0.0)
min_x = log10(min_x);
else
{
fprintf(stderr,
"%s: error: nonpositive limit %g on logarithmic axis\n",
progname, min_x);
return EXIT_FAILURE;
}
}
if (spec_max_x)
{
if (max_x > 0.0)
max_x = log10(max_x);
else
{
fprintf(stderr,
"%s: error: nonpositive limit %g on logarithmic axis\n",
progname, max_x);
return EXIT_FAILURE;
}
}
}
if (log_axis & Y_AXIS)
{
if (spec_min_y)
{
if (min_y > 0.0)
min_y = log10(min_y);
else
{
fprintf(stderr,
"%s: error: nonpositive limit %g on logarithmic axis\n",
progname, min_y);
return EXIT_FAILURE;
}
}
if (spec_max_y)
{
if (max_y > 0.0)
max_y = log10(max_y);
else
{
fprintf(stderr,
"%s: error: nonpositive limit %g on logarithmic axis\n",
progname, max_y);
return EXIT_FAILURE;
}
}
}
/* We now finalize the following parameters (arguments to
set_graph_parameters()), even though we won't call
set_graph_parameters() for a while yet, if it turns out we
need to act as a real-time filter. */
/* portmanteaux */
final_log_axis = log_axis;
final_round_to_next_tick = round_to_next_tick;
/* bool */
final_transpose_axes = transpose_axes;
/* x-axis specific */
final_min_x = min_x;
final_max_x = max_x;
final_spacing_x = spacing_x;
final_spec_min_x = spec_min_x;
final_spec_max_x = spec_max_x;
final_spec_spacing_x = spec_spacing_x;
/* y-axis specific */
final_min_y = min_y;
final_max_y = max_y;
final_spec_min_y = spec_min_y;
final_spec_max_y = spec_max_y;
final_spacing_y = spacing_y;
final_spec_spacing_y = spec_spacing_y;
/* If user didn't specify either the lower limit or the upper
limit for an axis, by default we'll round the axis limits
to the nearest tick, after computing them. (If either
limit was specified by the user, to request rounding the
user must specify the -R option as well.) */
if (!final_spec_min_x && !final_spec_max_x)
final_round_to_next_tick |= X_AXIS;
if (!final_spec_min_y && !final_spec_max_y)
final_round_to_next_tick |= Y_AXIS;
/* The case when x_min, x_max, y_min, y_max are all specified
by the luser is special: we set the `filter' flag for the
duration of this plot, to indicate that we can function as
a real-time filter, calling read_and_plot_file() on each
file, rather than calling read_file() on each one
separately to create an array of points, and then calling
plot_point_array(). */
filter = ((final_spec_min_x && final_spec_max_x
&& final_spec_min_y && final_spec_max_y)
? true : false);
} /* end of first-file-of-plot case */
if (filter)
/* filter flag is set, will call read_and_plot() on this file */
{
if (first_file_of_graph)
{
if (first_graph_of_multigraph)
/* need to create the multigrapher */
{
if ((multigrapher = new_multigrapher (display_type, bg_color, bitmap_size, emulate_color, max_line_length, meta_portable, page_size, rotation_angle, save_screen)) == NULL)
{
fprintf (stderr,
"%s: error: couldn't open graphing device\n",
progname);
return EXIT_FAILURE;
}
}
/* begin graph: push a graph-specific drawing state onto
libplot's stack of drawing states; also concatenate
the current transformation matrix with a matrix formed
from the repositioning parameters (this will take
effect for the duration of the graph) */
begin_graph (multigrapher,
reposition_scale,
reposition_trans_x, reposition_trans_y);
/* font selection, saves typing */
if ((title_font_name == NULL) && (font_name != NULL))
title_font_name = font_name;
/* following will be in effect for the entire plot */
set_graph_parameters (multigrapher,
frame_line_width,
frame_color,
top_label,
title_font_name, title_font_size, /* for title */
tick_size, grid_spec,
final_min_x, final_max_x, final_spacing_x,
final_min_y, final_max_y, final_spacing_y,
final_spec_spacing_x,
final_spec_spacing_y,
plot_width, plot_height,
margin_below, margin_left,
font_name, font_size, /* on abscissa */
x_label,
font_name, font_size, /* on ordinate */
y_label,
no_rotate_y_label,
/* these args are portmanteaux */
final_log_axis,
final_round_to_next_tick,
switch_axis_end,
omit_ticks,
/* more args */
clip_mode,
blankout_fraction,
final_transpose_axes);
/* draw the graph frame (grid, ticks, etc.); draw a
`canvas' (a background opaque white rectangle) only if
this isn't the first graph */
draw_frame_of_graph (multigrapher,
first_graph_of_multigraph ? false : true);
reader = new_reader (data_file, input_type,
auto_abscissa, delta_x, x_start,
/* following three are graph-specific */
final_transpose_axes,
final_log_axis, auto_bump,
/* following args are file-specific
(they set dataset attributes) */
symbol_index, symbol_size,
symbol_font_name,
linemode_index, plot_line_width,
fill_fraction, use_color);
new_symbol = new_symbol_size = new_symbol_font_name = false;
new_linemode = new_plot_line_width = false;
new_fill_fraction = new_use_color = false;
}
else
/* not first file of plot; do some things anyway */
{
/* set reader parameters that may change when we move
from file to file within a plot */
alter_reader_parameters (reader,
data_file, input_type,
auto_abscissa, delta_x, x_start,
/* following args set dataset
attributes */
symbol_index, symbol_size,
symbol_font_name,
linemode_index, plot_line_width,
fill_fraction, use_color,
/* following bools make up a mask*/
new_symbol, new_symbol_size,
new_symbol_font_name,
new_linemode, new_plot_line_width,
new_fill_fraction, new_use_color);
new_symbol = new_symbol_size = new_symbol_font_name = false;
new_linemode = new_plot_line_width = false;
new_fill_fraction = new_use_color = false;
}
/* call read_and_plot_file() on the file; each dataset in the
file yields a polyline */
read_and_plot_file (reader, multigrapher);
} /* end of filter case */
else
/* filter flag is set, will read and plot this file separately */
/* Luser didn't specify enough information for us to act as a
filter, so we do things the hard way: we call read_file() on
each file to create a points array, and at the end of the
plot we'll call plot_point_array() on the array. For now,
we don't even call set_graph_parameters(). */
{
if (first_file_of_graph) /* some additional initializations */
{
p = (Point *)xmalloc (points_length * sizeof (Point));
reader = new_reader (data_file, input_type,
auto_abscissa, delta_x, x_start,
/* following are graph-specific */
final_transpose_axes,
final_log_axis, auto_bump,
/* following args are file-specific
(they set dataset attributes) */
symbol_index, symbol_size,
symbol_font_name,
linemode_index, plot_line_width,
fill_fraction, use_color);
new_symbol = new_symbol_size = new_symbol_font_name = false;
new_linemode = new_plot_line_width = false;
new_fill_fraction = new_use_color = false;
}
else /* not first file of plot, but do some things anyway */
{
/* set reader parameters that may change when we move
from file to file within a plot */
alter_reader_parameters (reader,
data_file, input_type,
auto_abscissa, delta_x, x_start,
/* following args set dataset
attributes */
symbol_index, symbol_size,
symbol_font_name,
linemode_index, plot_line_width,
fill_fraction, use_color,
/* following bools make up a mask*/
new_symbol, new_symbol_size,
new_symbol_font_name,
new_linemode, new_plot_line_width,
new_fill_fraction, new_use_color);
new_symbol = new_symbol_size = new_symbol_font_name = false;
new_linemode = new_plot_line_width = false;
new_fill_fraction = new_use_color = false;
}
/* add points to points array by calling read_file() on file */
read_file (reader, &p, &points_length, &no_of_points);
} /* end of not-filter case */
/* close file */
if (data_file != stdin)
close_file (optarg, data_file);
first_file_of_graph = false;
break; /* end of `case 1' in switch() [i.e., filename seen] */
/*---------------- End of options ----------------*/
default: /* Default, unknown option */
errcnt++;
continue_parse = false;
break;
} /* end of switch() */
if (errcnt > 0)
continue_parse = false;
} /* end of while loop */
if (errcnt > 0)
{
fprintf (stderr, "Try `%s --help' for more information\n", progname);
return EXIT_FAILURE;
}
if (show_version)
{
display_version (progname);
return EXIT_SUCCESS;
}
if (do_list_fonts)
{
int success;
success = list_fonts (display_type, progname);
if (success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
if (show_fonts)
{
int success;
success = display_fonts (display_type, progname);
if (success)
return EXIT_SUCCESS;
else
return EXIT_FAILURE;
}
if (show_usage)
{
display_usage (progname, hidden_options, usage_appendage, true);
return EXIT_SUCCESS;
}
/* End of command-line parse. At this point, we need to terminate the
graph currently in progress, if it's nonempty (i.e. if one or more
files have been read). */
if (first_file_of_graph == false)
{
/* At least one file was read. If we're acting as a real-time
filter, then the graph is already drawn on the display and there's
nothing for us to do. Instead, we have a points array and we need
to plot it, after computing bounds. */
if (!filter)
{
/* fill in any of min_? and max_? that user didn't specify (the
prefix "final_" means these arguments were finalized at the
time the first file of the plot was processed) */
array_bounds (p, no_of_points,
final_transpose_axes, clip_mode,
&final_min_x, &final_min_y,
&final_max_x, &final_max_y,
final_spec_min_x, final_spec_min_y,
final_spec_max_x, final_spec_max_y);
if (first_graph_of_multigraph)
/* still haven't created multigrapher, do so now */
{
if ((multigrapher = new_multigrapher (display_type, bg_color, bitmap_size, emulate_color, max_line_length, meta_portable, page_size, rotation_angle, save_screen)) == NULL)
{
fprintf (stderr,
"%s: error: couldn't open graphing device\n", progname);
return EXIT_FAILURE;
}
}
/* begin graph: push new libplot drawing state onto stack of
states; also concatenate the current transformation matrix
with a matrix formed from the repositioning parameters (this
will take effect for the duration of the graph) */
begin_graph (multigrapher,
reposition_scale,
reposition_trans_x, reposition_trans_y);
/* font selection, saves typing */
if ((title_font_name == NULL) && (font_name != NULL))
title_font_name = font_name;
set_graph_parameters (multigrapher,
frame_line_width,
frame_color,
top_label,
title_font_name, title_font_size, /*for title*/
tick_size, grid_spec,
final_min_x, final_max_x, final_spacing_x,
final_min_y, final_max_y, final_spacing_y,
final_spec_spacing_x,
final_spec_spacing_y,
plot_width, plot_height,
margin_below, margin_left,
font_name, font_size, /* for abscissa label */
x_label,
font_name, font_size, /* for ordinate label */
y_label,
no_rotate_y_label,
/* these args are portmanteaux */
final_log_axis,
final_round_to_next_tick,
switch_axis_end, omit_ticks,
/* more args */
clip_mode,
blankout_fraction,
final_transpose_axes);
/* draw the graph frame (grid, ticks, etc.); draw a `canvas' (a
background opaque white rectangle) only if this isn't the
first graph */
draw_frame_of_graph (multigrapher,
first_graph_of_multigraph ? false : true);
/* plot the laboriously read-in array */
plot_point_array (multigrapher, p, no_of_points);
/* free points array */
free (p);
no_of_points = 0;
} /* end of not-filter case */
/* draw graph frame on top of graph, if user requested it */
if (frame_on_top)
{
end_polyline_and_flush (multigrapher);
draw_frame_of_graph (multigrapher, false);
}
/* end graph: pop drawing state off the stack of drawing states */
end_graph (multigrapher);
} /* end of nonempty-graph case */
/* finish up by deleting our multigrapher (one must have been created,
since we always read at least stdin) */
if (delete_multigrapher (multigrapher) < 0)
{
fprintf (stderr, "%s: error: could not close graphing device\n",
progname);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
static void
#ifdef _HAVE_PROTOS
open_file_for_reading (char *filename, FILE **input)
#else
open_file_for_reading (filename, input)
char *filename;
FILE **input;
#endif
{
FILE *data_file;
data_file = fopen (filename, "r");
if (data_file == NULL)
{
fprintf (stderr, "%s: %s: %s\n", progname, filename, strerror(errno));
exit (EXIT_FAILURE);
}
else
*input = data_file;
}
static void
#ifdef _HAVE_PROTOS
close_file (char *filename, FILE *stream)
#else
close_file (filename, stream)
char *filename;
FILE *stream;
#endif
{
if (fclose (stream) < 0)
fprintf (stderr,
"%s: could not close input file `%s'\n",
progname, filename);
}
static bool
#ifdef _HAVE_PROTOS
parse_pen_string (const char *pen_s)
#else
parse_pen_string (pen_s)
const char *pen_s;
#endif
{
const char *charp;
char name[MAX_COLOR_NAME_LEN];
int i;
charp = pen_s;
while (*charp)
{
int pen_num;
bool got_digit;
const char *tmp;
if (*charp == ':') /* skip any ':' */
{
charp++;
continue; /* back to top of while loop */
}
pen_num = 0;
got_digit = false;
while (*charp >= '0' && *charp <= '9')
{
pen_num = 10 * pen_num + (int)*charp - (int)'0';
got_digit = true;
charp++;
}
if (!got_digit || pen_num < 1 || pen_num > NO_OF_LINEMODES)
return false;
if (*charp != '=')
return false;
charp++;
for (tmp = charp, i = 0; i < MAX_COLOR_NAME_LEN; tmp++, i++)
{
if (*tmp == ':') /* end of color name string */
{
name[i] = '\0';
charp = tmp + 1;
break;
}
else if (*tmp == '\0') /* end of name string */
{
name[i] = '\0';
charp = tmp;
break;
}
else
name[i] = *tmp;
}
/* replace pen color name by user-specified color name */
colorstyle[pen_num - 1] = xstrdup (name);
}
return true;
}
|