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 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
|
/*
Quickplot - an interactive 2D plotter
Copyright (C) 1998-2011 Lance Arsenault
This file is part of Quickplot.
Quickplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
Quickplot 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 Quickplot. If not, see <http://www.gnu.org/licenses/>.
*/
/* Quickplot is turning out to have so many command
* line options that we are automating the coding and
* documenting of them using this C code.
* This code is not compiled into Quickplot. The
* executable from this code is used to generate code
* that goes into Quickplot.
* We will try to make this the only place with these
* argument option strings are listed, so that we can
* change them in one place, or better yet, not change
* them.
*
* One negative to this method is that many other source
* files depend on this one file and so when you edit
* this one file many other files will need to be
* recompiled. Reminds me of using the QT moc
* preprocessor and why I do not like QT. This is not
* that bad. */
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include "config.h"
#include "debug.h"
#ifdef DMALLOC
# include "dmalloc.h"
#endif
struct qp_option
{
/* 0 = do not call function 1 or 2 = call function 2 = function will exit */
int pass[2]; /* pass[0] == 1st pass pass[1] == 2nd pass */
char *long_op; /* initialization code is generated based this string */
char *short_op;
char *arg; /* if arg == "[STRING]" then it is optional */
char *description; /* you can put @CONFIG_STUFF@ in this string */
/* Set these two to make code that initializes and declares a
* struct qp_app variable. */
char *op_init_value; /* like "0" for app->op_my_long_option = 0; */
char *op_type; /* like "int" for int op_my_long_option; in the struct qp_app */
};
/* description special sequences that make HTML markup
*
* "**" = start list <ul>
* "##" = <li>
* "&&" = end list </ul>
*
* " " = " "
*
* "--*" = "<a href="#name">--*</a>" where --* is a long_op
*
* "::" = "<span class=code>" and will not add '\n' until @@
* "@@" = "</span>"
*/
/* int tri values are auto = -1 on or yes = 1 no or off = 0 */
static
struct qp_option options[] =
{
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "", 0, "FILE", "read data from file FILE. If FILE is - (dash) then "
"standard input will be read. See also ::--file@@ and "
"::--pipe@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--about", "-a", 0, "display introductory information about Quickplot in a "
"browser and exit", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--auto-scale", "-A", 0, "automatically select the X and Y scales for graphs "
"containing more than one plot. This is the default. "
"See also ::--same-x-scale@@, ::--same-y-scale@@, "
"::--same-scale@@ ::--different-scale@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--background-color", "-C", "RGBA", "set the color of the graph background. RGBA may be any "
"string that GTK+ can parse into a RGB or RGBA color. "
"For examples ::--background-color='rgba(0,0,255,0.5)'@@ "
"will make translucent blue, and ::-C '#050'@@ will make "
"a dark green.", 0, "struct "
"qp_colora" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--border", "-b", 0, "add a border to main window. This is the default. See "
"also ::--no-border@@.", "TRUE", "gboolean" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--buttons", 0, 0, "show the button bar in the main window. This is the "
"default. See also ::--no-buttons@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--cairo-draw", "-c", 0, "draw graphs using the Cairo API. Cairo drawing may be "
"slower, but you get translucent colors and "
"anti-aliasing in all aspects of the graph and in saved "
"image files. See also ::--x11-draw@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--default-graph", "-D", 0, "create the default graph for the current file and turn "
"default graphing for future files read. "
"If you give a ::--graph@@ or ::--graph-file@@ "
"after this option you will generate an additional "
"graph. A default graph will be made each "
"time this option is encountered, so this can be used to "
"control when, in the sequence of command line options, "
"graphs are made. See also ::--no-default-graph@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--different-scale", "-d", 0, "graphs with more than one plot will have different "
"scales if the extreme values in each plot are not all "
"the same. See also ::--same-scale@@, ::--same-x-scale@@ "
"and ::--same-y-scale@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--file", "-f", "FILE", "read data from file FILE. If FILE is - (dash) then "
"standard input will be read. See also ::--pipe@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--fullscreen", "-F", 0, "make the main window fullscreen. See also "
"::--no-fullscreen@@ and ::--maximize@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--gaps", 0, 0, "interpret NAN, -NAN, INF, -INF, and double overflow "
"numbers as a gap in the plot, and don't draw a "
"connecting line to adjacent non-gap points. "
"This is the default. See also ::--no-gaps@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--geometry", 0, "GEO", "specify the position and size of the main window. To "
"set the geometry back to the default just set GEO to "
"NONE. Example ::--geometry=1000x300-0+30@@", 0, "cairo_rec"
"tangle_in"
"t_t" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--graph", "-g", "LIST", "make a graph with plots ::LIST@@. "
"The ::LIST@@ is of the form ::\"x0 y0 x1 y1 x2 "
"y2 ...\"@@. For example: ::--graph \"0 1 3 4\"@@ will "
"make two plots in a graph. It will plot channel 1 vs "
"channel 0 and channel 4 vs channel 3 in the same graph. "
" Data channels are numbered, starting at 0, in the "
"order that they are created as files are read. A "
"separate graph tab will be created for each ::--graph@@ "
"option given. This ::--graph@@ option must be after "
"the file loading options that load the channels that it "
"lists to plot. See also ::--graph-file@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--graph-file", "-G", "LIST", "make a graph with plots ::LIST@@. "
"The ::LIST@@ is of the form ::\"x0 y0 x1 y1 x2 "
"y2 ...\"@@. Example: ::--graph-file \"0 1 3 4\"@@ will "
"make two plots in a graph. It will plot channel 1 vs "
"channel 0 and channel 4 vs channel 3 in the same graph. "
" A separate graph tab will be created for each "
"::--graph-file@@ option given. This is like the "
"::--graph@@ option except that the channel numbers "
"start at zero for the last file read. "
"They are relative channel numbers. So channel numbers "
"for ::---graph-file@@ may be negative to refer to "
"channels that came from files before the last file. "
"This is handy if you load a lots of files and lose count "
"of the number of channels loaded in each file.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid", 0, 0, "draw a grid with the graph. This is the default. See "
"also ::--no-grid@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid-font", "-T", "FONT", "set the font used to in the grid label numbers. "
"Example: ::--grid-font='Sans Bold 12'@@. The default "
"grid font is \"Sans 10\".", "qp_strdu"
"p(\"Sans"
" 10\")", "char *" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--grid-line-color", 0, "RGBA", "set the graph grid lines color. RGBA may be any string "
"that GTK+ can parse into a RGB or RGBA color. For "
"example ::--grid_line_color='rgba(255,0,0,0.5)'@@ will "
"make a translucent red.", 0, "struct "
"qp_colora" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid-line-width", "-W", "PIXELS", "set the width of the grid lines if there are any", "4", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid-numbers", 0, 0, "show grid numbers. This is the default. The grid must "
"be showing to show grid numbers too. See also "
"::--no-grid-numbers@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--grid-text-color", 0, "RGBA", "set the graph grid text color. RGBA may be any string "
"that GTK+ can parse into a RGB or RGBA color. For "
"example ::--grid_text_color='rgba(0,255,0,0.5)'@@ will "
"make translucent green.", 0, "struct "
"qp_colora" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid-x-space", "-X", "PIXELS", "set the maximum x space between vertical grid lines. "
"The minimum will be about half this. This distance "
"varies as the scale changes due to zooming. This "
"distance cannot be fixed due to the way Quickplot "
"scales your graphs and always picks reasonable grid "
"line spacing. See also ::--grid-x-space@@.", "220", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--grid-y-space", "-Y", "PIXELS", "set the maximum y space between horizontal grid lines. "
"See also ::--grid-x-space@@ above.", "190", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--gtk-version", 0, 0, "print the version of GTK+ that Quickplot was built with "
"and then exit", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--gui", 0, 0, "show the menu bar, button bar, tabs bar, and the status "
"bar. This is the default. See also ::--no-gui@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--help", "-h", 0, "display help in a browser and exit", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--label-separator", "-p", "STR", "specifies the label separator string STR if labels are "
"read in from the top of a text data plot file. The "
"default value of ::STR@@ is ::\" \"@@ (a single space). "
" See option: ::--labels@@.", "qp_strdup"
"(\" \")", "char *" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--labels", "-L", 0, "read labels from the first line of a text file that "
"is not skipped. See also: ::--skip-lines@@, "
"::--label-separator@@ and ::--no-labels@@.", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--libsndfile-version", 0, 0, "print the version of libsndfile that Quickplot was "
"built with and then exit", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--line-width", "-I", "PIXELS", "specify the plot line widths in pixels. May be set to "
"AUTO to let Quickplot select the line width based on "
"the plot point density. AUTO is the default.", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--linear-channel", "-l", "[OPTS]", "::OPTS@@ are ::START|[STEP]@@. "
"This option prepends a linear series channel to the "
"file being read. ** ## ::START@@ "
"set the first value in the sequence to ::START@@. The "
"default ::START@@ value is ::0@@. ## ::STEP@@ "
"set the sequence step size to ::STEP@@. "
"The default ::STEP@@ is 1. && "
"There must be a ::START@@ before ::STEP@@. "
"For example: ::--linear-channel='100 0.2'@@ will make "
"a linear channel that starts at 100 and steps 0.2. "
"Sound files will always have a "
"linear channel that contains the time prepended. Using "
"this option with a sound file would prepend an "
"additional channel. Any file loaded that contains just "
"a single channel will automatically have a channel "
"prepended. Using this option with a single channel file "
"will not prepend an additional channel, but will let you "
"set the start and step values for that prepended "
"channel. See also ::--no-linear-channel@@.", "NULL", "struct "
"qp_channe"
"l *" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--lines", "-j", "Y|N|A", " ** ## ::Y@@ yes show lines ## ::N@@ no don't show lines. "
"Same as ::--no-lines@@. ## ::A@@ auto, be smart about "
"it. This is the default. &&", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--maximize", "-m", 0, "maximize the main window. See also ::--no-maximize@@ "
"and ::--fullscreen@@.", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--menubar", 0, 0, "show the menu bar. This is the default. See also "
"::--menubar@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--new-window", "-w", 0, "make a new main window for each graph", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-border", "-B", 0, "display graphs main windows with no borders", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-buttons", 0, 0, "hide the button bar in the main window. See also "
"::--buttons@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-default-graph", "-U", 0, "stop making the default graph for each file loaded. See "
"also ::--default-graph@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-fullscreen", 0, 0, "don't make the main window fullscreen. This is the "
"default. See also ::--fullscreen@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-gaps", "-J", 0, "draw a line across NAN (-NAN, INF, -INF and overflow "
"double) values if there are finite values on both "
"sides. See also ::--gaps@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-grid", "-H", 0, "don't draw graph grid lines in the graph. See also "
"::--grid@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-grid-numbers", 0, 0, "don't show grid numbers. See also ::--grid-numbers@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-gui", "-z", 0, "don't show the menu bar, button bar, tabs bar, and "
"status bar. See also ::--gui@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-labels", "-Q", 0, "don't read channel labels from the file. This is "
"the deafult. See also ::--labels@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-linear-channel", "-k", 0, "turn off adding a linear channel for up coming files. "
"See also ::--linear-channel@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-lines", "-i", 0, "plot without drawing lines in the graph. See also "
"--lines.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-maximize", 0, 0, "don't maximize the main window. This is the default. "
"See also ::--maximize@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-menubar", "-M", 0, "don't display the menu bar in the main window. See "
"also ::--menubar@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-new-window", "-Z", 0, "don't make a new main window for the graph. This is "
"the default. See also ::--new-window@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,0}, "--no-pipe", "-N", 0, "don't read data in from standard input even if there is "
"input to read. See also ::--pipe@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-points", "-o", 0, "plot without drawing points in the graph. See also "
"--points.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,0}, "--no-readline", 0, 0, "don't use GNU readline with the Quickplot command "
"shell if you run with the ::--shell@@ option. This "
"will disable the use of line editing, shell "
"history, and tab command completion. This "
"option has no effect if Quickplot is not built with "
"GNU readline.", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-shape", 0, 0, "turn off the use of the X11 shape extension. See also "
"::--shape@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-statusbar", 0, 0, "hide the status bar in the main window. See also "
"::--statusbar@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--no-tabs", 0, 0, "don't show the graph tabs in the main window. See also "
"::--tabs@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--number-of-plots", "-n", "NUM", "set the default maximum number of plots for each graph "
"to NUM", 0, "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--pipe", "-P", 0, "read graph data from standard input. By default "
"Quickplot "
"looks for data from standard input and stops looking if "
"no data is found in some short amount of time. This "
"option will cause Quickplot to wait for standard input "
"indefinitely. If you would like to type data in from "
"the terminal use ::--pipe@@. This option is the same "
"as ::--file=-@@.", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--point-size", "-O", "PIXELS", "start Quickplot using plot point size ::PIXELS@@ wide "
"in pixels. This may be set to ::AUTO@@ to have "
"quickplot automatically set the point size depending on "
"the point density that is in graph. ::AUTO@@ is the "
"default.", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--points", 0, 0, "show points in the plots in the graph. This is the "
"default.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--print-about", 0, 0, "prints the About document to standard output andthen "
"exits. Use option ::--about@@ to display an HTML "
"version of the Quickplot About information.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--print-help", 0, 0, "prints this Help document as ASCII text to standard "
"output and then exits. Use option ::--help@@ for "
"displaying an HTML version of this help.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,1}, "--read-pipe-here", "-R", 0, "this is a place holder that tells Quickplot when to "
"read the data from standard input. This is intended to "
"give the option of telling Quickplot when to read "
"standard input when Quickplot automatically determines "
"whether to read standard input or not. See options "
"::--file@@, ::--pipe@@ and ::--no-pipe@@.", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--same-scale", "-s", 0, "plot all plots in the same graph scale. See also "
"::--different-scale@@, ::--same-x-scale@@ and "
"::--same-y-scale@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--same-x-scale", "-x", "Y|N|A", "use in place of ::--same-scale@@ or ::--auto-scale@@ "
"for finer control over how the x values of the plots "
"are scaled when you have more than one plot on a graph "
"** ## ::Y@@ yes same x scale ## ::N@@ no different x "
"scales ## ::A@@ auto, be smart about it. This is the "
"default. && See also ::--same-y-scale@@.", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--same-y-scale", "-y", "Y|N|A", "use in place of ::--same-scale@@ or ::--auto-scale@@ "
"for finer control over how the x values of the plots "
"are scaled when you have more than one plot on a graph "
"** ## ::Y@@ yes same y scale ## ::N@@ no different y "
"scales ## ::A@@ auto, be smart about it. This is the "
"default. && See also ::--same-x-scale@@. ", "-1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--shape", 0, 0, "make graphs see through. It "
"uses the X11 shape extension which was made famous by "
"xeyes. The X11 shape extension may be a little flashy "
"on some systems. Try using ::--shape@@ with the "
"::--no-gui@@, ::--no-grid@@, and ::--no-border@@ "
"options to make a floating graph on your display. "
"The use of the X11 shape extension is a property of the "
"main window, not each graph tab. This option may not "
"work well with fullscreen view. This will slow down "
"graph drawing considerably. You can toggle this on and "
"off with the ::x@@ key. See option ::--no-shape@@.", "0", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--shell", "-e", 0, "run a Quickplot command shell that reads commands from "
"standard input and writes out to standard output. The "
"default is no shell and standard input will be read as "
"graph data. You may use ::--no-pipe@@ to stop standard "
"input from being read as graph data. The shell can do "
"most all the things that command-line options can do and "
"a lot more. Run an interactive shell with ::quickplot "
"--shell@@ and use the help and tab completion to see how "
"it works. You can also "
"connect a Quickplot command shell to a "
"running Quickplot program with the program "
"::quickplot_shell@@.", "NULL", "struct "
"qp_shell"
" *" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--signal", 0, "PID", "signal SIGUSR1 to process PID after Quickplot is "
"running.", "0", "pid_t" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,0}, "--silent", 0, 0, "don't spew even on error. The ::--silent@@ option will "
"override the effect of the ::--verbose@@ option.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--skip-lines", "-S", "NUM", "skip the first ::NUM@@ lines when reading the file. "
"This applies of all types of files that quickplot can "
"read. Set ::NUM@@ to zero to stop skipping lines.",
/* TODO: make skip list not just n lines */ "0", "size_t" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--statusbar", 0, 0, "show the status bar below the graph. This is the "
"default. See also ::--no-statusbar@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--tabs", 0, 0, "show the graph tabs. This is the default. See also "
"::--no-tabs@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {1,0}, "--verbose", "-v", 0, "spew more to standard output. See also ::--silent@@.", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {2,0}, "--version", "-V", 0, "print the Quickplot version number and then exit "
"returning 0 exit status", 0, 0 },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,1}, "--x11-draw", "-q", 0, "draw points and lines using the X11 API. This is the "
"default. Drawing may be much faster than with Cairo, "
"but there will be no translucent colors and no "
"anti-aliasing in the drawing of the plot lines and "
"points. There will be translucent colors and "
"anti-aliasing in the background and grid. Also, saved "
"images will not have translucent colors like they do with "
"the Cairo draw mode. You can "
"start drawing with X11 and switch to drawing with Cairo "
"when you want to save an image. Use the ::r@@ key or "
"the View menu to switch back and forth between drawing "
"with X11 and Cairo. See also ::--cairo-draw@@.", "1", "int" },
/*------------------------------------------------------------------------------------------------------------------------------------*/
{ {0,0}, 0, 0, 0, 0, 0, 0 }
};
/* the length of the array of options */
static size_t length = 0;
/* the sorted array of options */
static struct qp_option **opt;
static inline
void *Malloc(size_t s)
{
void *p;
errno = 0;
p = malloc(s);
if(!p)
{
printf("malloc(%zu)\n", s);
perror("malloc()");
while(1) sleep(100);
}
return p;
}
static const char *prefix[2] = { "parse_1st_", "parse_2nd_" };
static char *func = NULL;
static inline
char *get_func(const char *prefix, const char *str)
{
char *s;
if(!str || !str[0])
str = "File";
if(func)
free(func);
s = (char *) str;
while(*s == '-') ++s;
func = Malloc(strlen(prefix) + strlen(s) + 1);
sprintf(func, "%s%s", prefix, s);
s = func;
while(*s)
{
if(*s == '-')
*s = '_';
++s;
}
return func;
}
static
int not_short_op_switch_case(struct qp_option *op, int pass)
{
if(pass == 1 && op->pass[0] == 2)
/* We do not need to parse options that would
* exit in the 1st pass */
return 1;
return (
(op->arg && op->arg[0] != '[')
|| !op->short_op
|| (strlen(op->short_op) != 2)
);
}
static
void print_arg_parsing_code(int p)
{
size_t i;
int got_one = 0;
int got_two = 0;
printf(
"{\n"
" int i = 1;\n"
"\n"
" while(i < argc)\n"
" {\n"
" char *s;\n"
"\n"
);
for(i=1;i<length;++i)
{
if(!opt[i]->pass[p] || opt[i]->arg)
continue;
func = get_func(prefix[p], opt[i]->long_op);
printf(" %sif(!strcmp(\"%s\", argv[i]))\n"
" {\n"
" %s();\n%s"
" }\n",
(got_one)?"else ":"",
opt[i]->long_op, func,
(opt[i]->pass[p] == 1)?" ++i;\n":"");
++got_one;
}
for(i=1;i<length;++i)
{
if(!opt[i]->arg)
continue;
func = get_func(prefix[p], opt[i]->long_op);
printf(
" %sif((s = get_opt(",(got_one)?"else ":"");
if(opt[i]->short_op)
printf("\"%s\"", opt[i]->short_op);
else
printf("NULL");
printf(",\"%s\", argc, argv, &i)))\n"
" {\n", opt[i]->long_op);
if(opt[i]->pass[p])
printf(
" %s(s, argc, argv, &i);\n", func);
else
printf(
" /* do nothing this pass */\n");
printf(
" }\n");
if(opt[i]->arg[0] == '[')
{ /* again for case with no optional argument */
printf(
" %sif(!strcmp(\"%s\",argv[i])",
(got_one)?"else ":"", opt[i]->long_op);
if(opt[i]->short_op)
printf(" || !strcmp(\"%s\",argv[i])",
opt[i]->short_op);
printf(
")\n"
" {\n"
" /* this is to caught it when there is no optional arg */\n"
);
if(opt[i]->pass[p])
printf(
" %s(NULL, argc, argv, &i);\n", func);
else
printf(
" /* do nothing this pass */\n"
);
printf(
" ++i;\n"
" }\n");
}
++got_one;
}
for(i=1;i<length;++i)
{
if(!opt[i]->arg && !opt[i]->pass[p] &&
(p == 0 || opt[i]->pass[0] != 2))
{
printf(" %sif(!strcmp(\"%s\", argv[i])\n",
(got_one)?"else ":"",
opt[i]->long_op);
++got_one;
++got_two;
break;
}
}
for(++i;i<length;++i)
{
if(!opt[i]->arg && !opt[i]->pass[p] &&
(p == 0 || opt[i]->pass[0] != 2))
{
printf(" || !strcmp(\"%s\", argv[i])\n",
opt[i]->long_op);
continue;
}
}
if(got_two)
printf( " )\n"
" {\n"
" /* do nothing this pass */\n"
" ++i;\n"
" }\n");
got_two = 0;
for(i=1;i<length;++i)
{
if(not_short_op_switch_case(opt[i], p))
continue;
printf(" %sif(argv[i][0] == '-' && is_all_short_no_arg_options(&argv[i][1]))\n",
(got_one)?"else ":"");
++got_two;
++got_one;
break;
}
if(got_two)
{
printf(
" {\n"
" size_t j, len;\n"
" len = strlen(argv[i]);\n"
"\n"
" for(j=1;j<len;++j)\n"
" switch(argv[i][j])\n"
" {\n"
);
for(i=1;i<length;++i)
{
if(not_short_op_switch_case(opt[i], p) || !opt[i]->pass[p])
continue;
printf( " case '%c':\n", opt[i]->short_op[1]);
func = get_func(prefix[p], opt[i]->long_op);
if(!opt[i]->arg)
printf(" %s();\n", func);
else
printf(" %s(NULL, argc, argv, &i);\n", func);
printf(
" break;\n");
}
/* reuse dummy flag */
got_two = 0;
for(i=1;i<length;++i)
{
if(not_short_op_switch_case(opt[i], p) || opt[i]->pass[p])
continue;
printf( " case '%c':\n", opt[i]->short_op[1]);
got_two = 1;
}
if(got_two)
printf(
" /* do nothing this pass */\n"
" break;\n");
printf(" }\n"
"\n"
" ++i;\n"
"\n"
" }\n"
);
}
printf(" %s\n"
" {\n"
" /* option FILE */\n", (got_one)?"else":"");
if(opt[0]->pass[p])
printf(" %s(argv[i]);\n", get_func(prefix[p], opt[0]->long_op));
else
printf(" /* do nothing this pass */\n");
printf( " ++i;\n");
printf(
" }\n"
" }\n"
"\n"
"}\n"
"\n");
}
static
void print_argument_parsing_code(void)
{
char *s, *shorts;
size_t shorts_len;
int i;
/* Get a string with all the short options char
* with out a arg. */
s = (shorts = Malloc(length));
for(i=1;i<length;++i)
{
if(opt[i]->short_op && (!opt[i]->arg || opt[i]->arg[0] == '[') &&
strlen(opt[i]->short_op) == 2 && opt[i]->short_op[0] == '-'
)
{
*s = (opt[i]->short_op)[1];
++s;
}
}
*s = '\0';
shorts_len = strlen(shorts);
printf("\n"
"static inline\n"
"int is_all_short_no_arg_options(const char *str)\n"
"{\n"
" const char *shorts = \"%s\";\n"
" const size_t shorts_len = %zu;\n"
" size_t i;\n"
"\n"
" if(!str || !*str)\n"
" return 0; /* none */\n"
"\n"
" while(*str)\n"
" {\n"
" for(i=0;i<shorts_len;++i)\n"
" if(shorts[i] == *str)\n"
" break;\n"
" if(i == shorts_len)\n"
" return 0;/* no it is not just short options */\n"
" ++str;\n"
" }\n"
"\n"
" return 1; /* yes it is all short options */\n"
"}\n"
"\n",
shorts, shorts_len);
free(shorts);
printf("\nstatic\n"
"void parse_args_1st_pass(int argc, char **argv)\n");
print_arg_parsing_code(0);
printf("\nstatic\n"
"void parse_args_2nd_pass(int argc, char **argv)\n");
print_arg_parsing_code(1);
}
static
void print_pass_functions(int p)
{
int i;
printf("\n");
/* FILE is a argument with an long option flag */
if(opt[0]->pass[p])
printf("static inline\n"
"void %s(const char *file)\n"
"{\n"
"\n"
"}\n"
"\n",
get_func(prefix[p], opt[0]->long_op));
for(i=1;i<length;++i)
{
if(!opt[i]->pass[p] || opt[i]->arg)
continue;
func = get_func(prefix[p], opt[i]->long_op);
printf("static inline\n"
"void %s(void)\n"
"{\n"
"\n"
"}\n"
"\n", func);
}
printf("\n");
for(i=1;i<length;++i)
{
if(!opt[i]->pass[p] || !opt[i]->arg)
continue;
func = get_func(prefix[p], opt[i]->long_op);
printf("static inline\n"
"void %s(char *arg, int argc, char **argv, int *i)\n"
"{\n"
"\n"
"}\n"
"\n", func);
}
printf("\n");
}
static
void print_1st_pass_functions(void)
{
print_pass_functions(0);
}
static
void print_2nd_pass_functions(void)
{
print_pass_functions(1);
}
static
void print_app_ops_declare_code()
{
int i;
for(i=1;i<length;++i)
{
if(!opt[i]->op_type)
continue;
printf("%s %s;\n", opt[i]->op_type,
get_func("op_", opt[i]->long_op));
}
}
static
void print_app_ops_init_code()
{
int i;
for(i=1;i<length;++i)
{
if(!opt[i]->op_init_value)
continue;
printf(" app->%s = %s;\n",
get_func("op_", opt[i]->long_op),
opt[i]->op_init_value);
}
}
static
int get_string_len(char *str)
{
if(!str)
return 1;
{
size_t len;
char *s;
len = strlen(str);
for(s=str;*s;++s)
if(*s == '"')
++len;
return len;
}
}
/* adds space to the end to make the size you print be n */
/* returns the number of chars printed not including '\0' */
static
int Nprintf(int n, const char *format, ...)
{
va_list ap;
char *fmt, *str;
int i, j, len;
j = strlen(format);
len = n + j + 1;
fmt = Malloc(len + 1);
str = Malloc(len + 1);
strcpy(fmt, format);
for(i=j;i<len;++i)
fmt[i] = ' ';
fmt[i] = '\0';
va_start(ap, format);
vsnprintf(str, n+1, fmt, ap);
va_end(ap);
printf("%s", str);
len = strlen(str);
free(fmt);
free(str);
return n;
}
/* replaces " with \"
* Returns allocated memory */
static
char *fix_quotes(char *str)
{
size_t str_len, out_len, i;
char *s, *ret;
if(!str)
return str;
str_len = (out_len = strlen(str));
for(s=str;*s;++s)
if(*s == '"')
++out_len;
ret = (s = Malloc(out_len + 1));
for(i=0;i<str_len;++i)
{
if(str[i] == '"')
{
*s = '\\';
++s;
*s = '"';
}
else
*s = str[i];
++s;
}
*s = '\0';
return ret;
}
/* a snprintf() wrapper that I can get my head around. */
static inline
int Snprintf(char *str, size_t size, const char *format, ...)
{
va_list ap;
int ret;
va_start(ap, format);
vsnprintf(str, size+1, format, ap);
va_end(ap);
ret = strlen(str);
return ret;
}
/* the str="0" or str="hi aldnfa sdfkl" and so on */
/* str ="---------------------------------------------------"
* start len
* prints
* "-----------------------"
* "-----------------------"
* "-------------",
* */
static
void kick_it_print(char *str, int start, int len, int add_comma)
{
int slen;
char *comma;
if(add_comma)
add_comma = 1;
if(add_comma)
comma = ",";
else
comma = "";
if(!str)
{
Nprintf(len, "0%s", comma);
return;
}
slen = strlen(str);
add_comma += 2;
--len;
while(1)
{
int i;
if(slen <= len - add_comma)
{
Nprintf(len+1, "\"%s\"%s ", str, comma);
return;
}
for(i = len - add_comma; i> len/2 ; --i)
if(str[i-1] == ' ')
break;
if(i == len/2)
i = len - add_comma;
printf("\"");
slen -= i;
Nprintf(i, "%s", str);
str += i;
printf("\"\n");
Nprintf(start, " ");
}
}
static
void print_tidy_struct(void)
{
int i;
int count[7] = {0,0,0,0,0,0,0};
printf("static\n"
"struct qp_option options[] =\n"
"{\n");
for(i=0;i<length;++i)
{
int len;
len = get_string_len(opt[i]->long_op) + 4;
if(len > count[1])
count[1] = len;
len = get_string_len(opt[i]->short_op) + 4;
if(len > count[2])
count[2] = len;
len = get_string_len(opt[i]->arg) + 4;
if(len > count[3])
count[3] = len;
len = get_string_len(opt[i]->op_init_value) + 4;
if(len > count[5])
count[5] = len;
len = get_string_len(opt[i]->op_type) + 4;
if(len > count[6])
count[6] = len;
}
for(i=1;i<7;i++)
if(count[i] > 26)
count[i] = 26;
if(count[3] > 15)
count[3] = 15;
if(count[5] > 12)
count[5] = 12;
if(count[6] > 12)
count[6] = 12;
count[0] = strlen("{ {1,1}, ");
count[4] = 60;
/* change the counts to absolute distance */
for(i=1;i<7;i++)
count[i] += count[i-1];
printf("/*");
for(i=0;i<count[6]-2;++i)
putchar('-');
printf("*/\n");
for(i=0;i<length;++i)
{
char *s[6];
int j;
s[0] = fix_quotes(opt[i]->long_op);
s[1] = fix_quotes(opt[i]->short_op);
s[2] = fix_quotes(opt[i]->arg);
s[3] = fix_quotes(opt[i]->description);
s[4] = fix_quotes(opt[i]->op_init_value);
s[5] = fix_quotes(opt[i]->op_type);
Nprintf(count[0], "{ {%d,%d},", opt[i]->pass[0], opt[i]->pass[1]);
for(j=0;j<6;++j)
{
kick_it_print(s[j], count[j], count[j+1] - count[j], (j!=5)?1:0);
if(s[j])
free(s[j]);
}
printf("},\n/*");
for(j=0;j<count[6]-2;++j)
putchar('-');
printf("*/\n");
}
Nprintf(count[0], "{ {0,0},");
for(i=0;i<6;++i)
{
kick_it_print(NULL, count[i], count[i+1] - count[i], (i!=5)?1:0);
}
printf("}\n");
printf("};\n");
}
static
void print_help_text(void)
{
}
static
void print_html_options_list(void)
{
}
/* returns length printed
* adds <a href=#LONG_OPT_NAME>
* if the str have a --long-opt in it.
* Or returns 0 is none is found. */
int check_print_long_option_link(const char *str, size_t skip_i)
{
size_t i;
for(i=1;i<length;++i)
{
size_t len_opt, len_str;
if(i == skip_i)
continue;
len_str = strlen(str);
len_opt = strlen(opt[i]->long_op);
if(!strncmp(opt[i]->long_op, str, len_opt) && len_str >= len_opt + 2 &&
(
(str[len_opt] == '@' && str[len_opt+1] == '@') ||
str[len_opt] == ' ' || str[len_opt] == '='
)
)
return printf("<a class=opt href=\"#%s\">", get_func("op_", opt[i]->long_op));
}
return 0;
}
static
void print_text2html(const char *str, size_t opt_i)
{
char *s, *t;
int w_count = 0;
if(!str || !(*str) || !*(str +1))
{
printf("%s\n", str);
return;
}
s = (char *) str;
t = s + 1;
while(*s && *t)
{
if(*s == '*' && *t == '*') // <ul>
{
if(w_count)
putchar('\n');
printf(" <ul>\n");
s += 2;
while(*s == ' ')
++s;
t = s + 1;
w_count = 0;
continue;
}
if(*s == '#' && *t == '#') // <li>
{
if(w_count)
putchar('\n');
printf(" <li>");
s += 2;
while(*s == ' ')
++s;
t = s + 1;
w_count = 10;
continue;
}
if(*s == ' ' && *t == ' ')
{
w_count += printf(" ");
s += 2;
t += 2;
continue;
}
if(*s == ':' && *t == ':') // <span>
{
int do_ancher;
if(w_count)
{
putchar('\n');
w_count = 0;
}
w_count += printf(" <span class=code>");
s += 2;
t += 2;
w_count += (do_ancher = check_print_long_option_link(s, opt_i));
while(*s && !(*s == '@' && *t == '@'))
{
putchar(*(s++));
t = s + 1;
++w_count;
}
if(do_ancher)
w_count += printf("</a>");
w_count += printf("</span>");
s += 2;
if(*s == ' ' && *(s+1) != ' ')
{
putchar('\n');
w_count = 0;
++s;
}
t = s + 1;
continue;
}
if(*s == '&' && *t == '&') // </ul>
{
if(w_count)
putchar('\n');
printf(" </ul>\n");
s += 2;
while(*s == ' ')
++s;
t = s + 1;
w_count = 0;
continue;
}
if(w_count > 50 && *s == ' ')
{
putchar('\n');
w_count = 0;
}
else
{
++w_count;
putchar(*s);
}
++t;
++s;
}
if(*s)
putchar(*s);
putchar('\n');
}
static inline
void put_man_char(char c)
{
if(c == '-')
putchar('\\');
putchar(c);
}
static inline
int check_for_span_man(char **str, int *w_count, char *last_char)
{
char *s = *str;
if(!(*s) || !(*(s+1)))
return 0;
if(*s == ':' && *(s+1) == ':') // <span>
{
s += 2;
if(*last_char != '\n')
/* This is what last_char was for:
* to see if we need a '\n' printed here. */
putchar('\n');
while(isspace(*s)) ++s;
*w_count = 0;
printf("\\fB");
while(*s && !(*s == '@' && *(s+1) == '@')) // </span>
{
put_man_char(*s);
*last_char = *s;
++(*w_count);
++s;
}
if(*s == '@' && *(s+1) == '@')
s +=2;
printf("\\fR");
*str = s;
return 1;
}
return 0;
}
static
void print_text2man(char *str)
{
char *s;
int w_count = 0;
char last_char = '\n';
if(!str || !(*str) || !*(str+1))
{
printf("%s\n", str);
return;
}
s = str;
while(*s && *(s+1))
{
if(check_for_span_man(&s, &w_count, &last_char)) // <span>
continue;
if(*s == '*' && *(s+1) == '*') // <ul>
{
s += 2;
while(isspace(*s)) ++s;
while(*s && !(*s == '&' && *(s+1) == '&')) // </ul>
{
if(*s == '#' && *(s+1) == '#') // <li>
{
if(last_char != '\n')
putchar('\n');
printf(".sp\n");
s += 2;
while(isspace(*s)) ++s;
last_char = '\n';
}
else if(check_for_span_man(&s, &w_count, &last_char)) // <span>
continue;
else
{
put_man_char(*s);
last_char = *s;
++s;
}
}
if(*s == '&' && *(s+1) == '&')
s += 2;
if(last_char != '\n')
putchar('\n');
last_char = '\n';
w_count = 0;
continue;
}
if(w_count > 60 && isspace(*s))
{
putchar('\n');
while(isspace(*s)) ++s;
last_char = '\n';
w_count = 0;
continue;
}
if(w_count == 0 && isspace(*s))
{
while(isspace(*s)) ++s;
continue;
}
put_man_char(*s);
last_char = *s;
++w_count;
++s;
}
if(*s)
{
putchar(*s);
last_char = *s;
}
if(last_char != '\n')
putchar('\n');
}
static inline
char *remove_dashes(char *str)
{
char *s = str;
while(*s == '-') ++s;
return s;
}
static
void print_man_page_options(void)
{
int i;
printf(".SH OPTIONS\n.PP\n");
printf(".TP\n\\fBFILE\\fR\n");
print_text2man(opt[0]->description);
for(i=1; i<length; ++i)
{
char arg[128];
if(opt[i]->arg)
snprintf(arg, 128, " \\fB%s\\fR", opt[i]->arg);
else
arg[0] = '\0';
if(opt[i]->short_op && strlen(opt[i]->short_op) == 2)
printf(".TP\n\\fB\\-\\-%s\\fR%s or \\fB\\-%s\\fR%s\n",
remove_dashes(opt[i]->long_op), arg,
remove_dashes(opt[i]->short_op), arg);
else
printf(".TP\n\\fB\\-\\-%s\\fR%s\n",
remove_dashes(opt[i]->long_op), arg);
print_text2man(opt[i]->description);
}
}
static
void print_html_options_table(void)
{
int i;
char class[2] = { 'a', 'b' };
printf(
"<table class=options summary=\"Quickplot argument options\">\n"
);
printf(
" <tr>\n"
" <th class=opt>long option</th>\n"
" <th class=opt title=\"short options\" style=\"%s\">short</th>\n"
" <th class=opt title=\"option arguments\">arg</th>\n"
" <th class=opt>description</th>\n"
" </tr>\n"
"\n", "font-size:50%;"
);
for(i=0;i<length;++i)
{
printf(
" <tr class=%c>\n",
class[i%2]);
printf(
" <td class=opt style=\"white-space:nowrap;\">\n"
" <a name=\"%s%s\">%s</a>\n"
" </td>\n", i?"":"FILE",
get_func("op_", opt[i]->long_op), opt[i]->long_op);
printf(
" <td class=opt style=\"white-space:nowrap;\">\n"
" %s\n"
" </td>\n",
opt[i]->short_op?opt[i]->short_op:"");
printf(
" <td class=opt>\n"
" %s\n"
" </td>\n",
opt[i]->arg?opt[i]->arg:"");
printf(
" <td class=opt>\n");
print_text2html(opt[i]->description, i);
printf(
" </td>\n");
printf(
" </tr>\n");
}
printf("</table>\n");
}
int main(int argc, char **argv)
{
{
ssize_t n = 2;
if(argc > 1)
n = strlen(argv[1]);
if(argc < 2 || argc > 3 || n != 2 ||
argv[1][0] != '-' ||
(argv[1][1] != 't' && argv[1][1] != 'l' && argv[1][1] != 'h' &&
argv[1][1] != 'a' && argv[1][1] != '1' && argv[1][1] != '2' &&
argv[1][1] != 'i' && argv[1][1] != 'I' && argv[1][1] != 'T' &&
argv[1][1] != 'p' && argv[1][1] != 's' && argv[1][1] != 'm')
)
{
printf("Usage: %s [ -a | -h | -i | -I | -l | -p | -t | -1 | -2 ]\n"
"\n"
" Generate HTML and C code that is"
" related to Quickplot command line options\n"
" Returns 0 on success and 1 on error.\n"
"\n"
" -a print C code for argument parsing\n"
" -h print C code for OPTIONS help text\n"
" -i print C code for app->op_ initialization\n"
" -I print C code for declaring app\n"
" -l print html options list\n"
" -m print OPTIONS part of man page\n"
" -p print the options\n"
" -s print the short options sorted\n"
" -t print html options table\n"
" -T print C code of the big qp_options array\n"
" -1 print 1st pass parsing C code template\n"
" -2 print 2nd pass parsing C code template\n"
"\n", argv[0]);
return 1;
}
}
{
int err = 0;
/* make an array that we can sort */
struct qp_option *o;
/* Test that the options do not have duplicates */
for(o=(struct qp_option *)options;o->long_op;++o)
{
struct qp_option *oc;
for(oc=(o+1);oc->long_op;++oc)
{
if(!strcmp(oc->long_op, o->long_op))
{
printf("There are at least two long options: %s\n", o->long_op);
err = 1;
}
if(oc->short_op && o->short_op && !strcmp(oc->short_op, o->short_op))
{
printf("There are at least two short options: %s\n", o->short_op);
printf("one for: %s\n", o->long_op);
printf("one for: %s\n", oc->long_op);
err = 1;
}
}
++length;
}
if(err)
return 1;
}
{
/* sort the array */
ssize_t i, end;
opt = Malloc(sizeof(*opt)*length);
/* sort the options in order of long option */
for(i=0;i<length;++i)
opt[i] = (struct qp_option *) &options[i];
/* bubble sort for this small list */
end = length - 2;
while(end >= 0)
{
for(i=0;i<end;++i)
{
if(strcmp(opt[i]->long_op, opt[i+1]->long_op) > 0)
{
struct qp_option *o;
o = opt[i];
opt[i] = opt[i+1];
opt[i+1] = o;
}
}
--end;
}
}
#if 0
if(argv[1][1] == 'a')
{
size_t i;
printf("---- OLD SORT -----\n");
for(i=0;i<length;++i)
printf("%s\n", options[i].long_op);
printf("---- NEW SORT ----\n");
for(i=0;i<length;++i)
printf("%s\n", opt[i]->long_op);
}
#endif
if(opt[0]->long_op[0])
{
printf("FILE is not the first option listed\n");
return 1;
}
if(argv[1][1] == 'p')
{
size_t i;
for(i=0;i<length;++i)
printf("%s %s %s\n", opt[i]->long_op, opt[i]->short_op, opt[i]->arg);
return 0;
}
if(argv[1][1] == 'm')
{
printf(".\\\" This OPTIONS part of this file was generated by running: "
"%s %s\n", argv[0], argv[1]);
print_man_page_options();
return 0;
}
if(argv[1][1] == 's')
{
int i, L = 1, end;
char *shorts, *s;
for(i=0;i<length;++i)
{
char *o;
o = opt[i]->short_op;
if(o)
{
if(strlen(o) == 2 && o[0] == '-')
L += 1;
else
L += strlen(o);
}
}
s = (shorts = Malloc(L));
for(i=0;i<length;++i)
{
char *o;
o = opt[i]->short_op;
if(o)
{
int l;
l = strlen(o);
if(l == 2 && o[0] == '-')
{
*s = o[1];
++s;
}
else
{
snprintf(s, l+1, "%s", o);
s += l;
}
}
}
*s = '\0';
/* bubble sort for this small list */
end = L - 2;
while(end >= 0)
{
for(i=0;i<end;++i)
{
if(shorts[i] > shorts[i+1])
{
char c;
c = shorts[i];
shorts[i] = shorts[i+1];
shorts[i+1] = c;
}
}
--end;
}
printf("%s\n", shorts);
return 0;
}
if(argv[1][1] == 'T')
{
print_tidy_struct();
return 0;
}
if(argv[1][1] == 'I')
{
printf("/* This file was auto-generated by running: `%s %s' */\n",
argv[0], argv[1]);
print_app_ops_declare_code();
return 0;
}
if(argv[1][1] == 'i')
{
printf("/* This file was auto-generated by running: `%s %s' */\n",
argv[0], argv[1]);
print_app_ops_init_code();
return 0;
}
if(argv[1][1] == 'a')
{
printf("/* This file was auto-generated by running: `%s %s' */\n",
argv[0], argv[1]);
print_argument_parsing_code();
return 0;
}
if(argv[1][1] == 'h')
{
print_help_text();
return 0;
}
if(argv[1][1] == 'l')
{
print_html_options_list();
return 0;
}
if(argv[1][1] == 't')
{
printf("<!-- This table was auto-generated by running: `%s %s' -->\n",
argv[0], argv[1]);
print_html_options_table();
return 0;
}
if(argv[1][1] == '1')
{
printf("/* This file was auto-generated by running: `%s %s' */\n",
argv[0], argv[1]);
print_1st_pass_functions();
return 0;
}
if(argv[1][1] == '2')
{
printf("/* This file was auto-generated by running: `%s %s' */\n",
argv[0], argv[1]);
print_2nd_pass_functions();
return 0;
}
return 0;
}
|