Move md2html utility to a standalone dir.
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e71960..455e4cf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,4 +56,4 @@ endif()
include(GNUInstallDirs)
add_subdirectory(src)
-
+add_subdirectory(md2html)
diff --git a/md2html/CMakeLists.txt b/md2html/CMakeLists.txt
new file mode 100644
index 0000000..14de671
--- /dev/null
+++ b/md2html/CMakeLists.txt
@@ -0,0 +1,22 @@
+
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DDEBUG")
+
+
+# Build rules for md2html command line utility
+
+include_directories("${PROJECT_SOURCE_DIR}/src")
+add_executable(md2html cmdline.c cmdline.h md2html.c)
+target_link_libraries(md2html md4c-html)
+
+
+# Install rules
+
+install(
+ TARGETS md2html
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+install(FILES "md2html.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
+
diff --git a/md2html/cmdline.c b/md2html/cmdline.c
new file mode 100644
index 0000000..c3fddfa
--- /dev/null
+++ b/md2html/cmdline.c
@@ -0,0 +1,205 @@
+/*
+ * C Reusables
+ * <http://github.com/mity/c-reusables>
+ *
+ * Copyright (c) 2017-2020 Martin Mitas
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "cmdline.h"
+
+#include <stdio.h>
+#include <string.h>
+
+
+#ifdef _WIN32
+ #define snprintf _snprintf
+#endif
+
+
+#define CMDLINE_AUXBUF_SIZE 32
+
+
+
+static int
+cmdline_handle_short_opt_group(const CMDLINE_OPTION* options, const char* arggroup,
+ int (*callback)(int /*optval*/, const char* /*arg*/, void* /*userdata*/),
+ void* userdata)
+{
+ const CMDLINE_OPTION* opt;
+ int i;
+ int ret = 0;
+
+ for(i = 0; arggroup[i] != '\0'; i++) {
+ for(opt = options; opt->id != 0; opt++) {
+ if(arggroup[i] == opt->shortname)
+ break;
+ }
+
+ if(opt->id != 0 && !(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG)) {
+ ret = callback(opt->id, NULL, userdata);
+ } else {
+ /* Unknown option. */
+ char badoptname[3];
+ badoptname[0] = '-';
+ badoptname[1] = arggroup[i];
+ badoptname[2] = '\0';
+ ret = callback((opt->id != 0 ? CMDLINE_OPTID_MISSINGARG : CMDLINE_OPTID_UNKNOWN),
+ badoptname, userdata);
+ }
+
+ if(ret != 0)
+ break;
+ }
+
+ return ret;
+}
+
+int
+cmdline_read(const CMDLINE_OPTION* options, int argc, char** argv,
+ int (*callback)(int /*optval*/, const char* /*arg*/, void* /*userdata*/),
+ void* userdata)
+{
+ const CMDLINE_OPTION* opt;
+ char auxbuf[CMDLINE_AUXBUF_SIZE+1];
+ int fast_optarg_decision = 1;
+ int after_doubledash = 0;
+ int i = 1;
+ int ret = 0;
+
+ auxbuf[CMDLINE_AUXBUF_SIZE] = '\0';
+
+ /* Check whether there is any CMDLINE_OPTFLAG_COMPILERLIKE option with
+ * a name not starting with '-'. That would imply we can to check for
+ * non-option arguments only after refusing all such options. */
+ for(opt = options; opt->id != 0; opt++) {
+ if((opt->flags & CMDLINE_OPTFLAG_COMPILERLIKE) && opt->longname[0] != '-')
+ fast_optarg_decision = 0;
+ }
+
+ while(i < argc) {
+ if(after_doubledash || strcmp(argv[i], "-") == 0) {
+ /* Non-option argument.
+ * Standalone "-" usually means "read from stdin" or "write to
+ * stdout" so treat it always as a non-option. */
+ ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
+ } else if(strcmp(argv[i], "--") == 0) {
+ /* End of options. All the remaining tokens are non-options
+ * even if they start with a dash. */
+ after_doubledash = 1;
+ } else if(fast_optarg_decision && argv[i][0] != '-') {
+ /* Non-option argument. */
+ ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
+ } else {
+ for(opt = options; opt->id != 0; opt++) {
+ if(opt->flags & CMDLINE_OPTFLAG_COMPILERLIKE) {
+ size_t len = strlen(opt->longname);
+ if(strncmp(argv[i], opt->longname, len) == 0) {
+ /* Compiler-like option. */
+ if(argv[i][len] != '\0')
+ ret = callback(opt->id, argv[i] + len, userdata);
+ else if(i+1 < argc)
+ ret = callback(opt->id, argv[++i], userdata);
+ else
+ ret = callback(CMDLINE_OPTID_MISSINGARG, opt->longname, userdata);
+ break;
+ }
+ } else if(opt->longname != NULL && strncmp(argv[i], "--", 2) == 0) {
+ size_t len = strlen(opt->longname);
+ if(strncmp(argv[i]+2, opt->longname, len) == 0) {
+ /* Regular long option. */
+ if(argv[i][2+len] == '\0') {
+ /* with no argument provided. */
+ if(!(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG))
+ ret = callback(opt->id, NULL, userdata);
+ else
+ ret = callback(CMDLINE_OPTID_MISSINGARG, argv[i], userdata);
+ break;
+ } else if(argv[i][2+len] == '=') {
+ /* with an argument provided. */
+ if(opt->flags & (CMDLINE_OPTFLAG_OPTIONALARG | CMDLINE_OPTFLAG_REQUIREDARG)) {
+ ret = callback(opt->id, argv[i]+2+len+1, userdata);
+ } else {
+ snprintf(auxbuf, CMDLINE_AUXBUF_SIZE, "--%s", opt->longname);
+ ret = callback(CMDLINE_OPTID_BOGUSARG, auxbuf, userdata);
+ }
+ break;
+ } else {
+ continue;
+ }
+ }
+ } else if(opt->shortname != '\0' && argv[i][0] == '-') {
+ if(argv[i][1] == opt->shortname) {
+ /* Regular short option. */
+ if(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG) {
+ if(argv[i][2] != '\0')
+ ret = callback(opt->id, argv[i]+2, userdata);
+ else if(i+1 < argc)
+ ret = callback(opt->id, argv[++i], userdata);
+ else
+ ret = callback(CMDLINE_OPTID_MISSINGARG, argv[i], userdata);
+ break;
+ } else {
+ ret = callback(opt->id, NULL, userdata);
+
+ /* There might be more (argument-less) short options
+ * grouped together. */
+ if(ret == 0 && argv[i][2] != '\0')
+ ret = cmdline_handle_short_opt_group(options, argv[i]+2, callback, userdata);
+ break;
+ }
+ }
+ }
+ }
+
+ if(opt->id == 0) { /* still not handled? */
+ if(argv[i][0] != '-') {
+ /* Non-option argument. */
+ ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
+ } else {
+ /* Unknown option. */
+ char* badoptname = argv[i];
+
+ if(strncmp(badoptname, "--", 2) == 0) {
+ /* Strip any argument from the long option. */
+ char* assignment = strchr(badoptname, '=');
+ if(assignment != NULL) {
+ size_t len = assignment - badoptname;
+ if(len > CMDLINE_AUXBUF_SIZE)
+ len = CMDLINE_AUXBUF_SIZE;
+ strncpy(auxbuf, badoptname, len);
+ auxbuf[len] = '\0';
+ badoptname = auxbuf;
+ }
+ }
+
+ ret = callback(CMDLINE_OPTID_UNKNOWN, badoptname, userdata);
+ }
+ }
+ }
+
+ if(ret != 0)
+ return ret;
+ i++;
+ }
+
+ return ret;
+}
+
diff --git a/md2html/cmdline.h b/md2html/cmdline.h
new file mode 100644
index 0000000..5bbde47
--- /dev/null
+++ b/md2html/cmdline.h
@@ -0,0 +1,153 @@
+/*
+ * C Reusables
+ * <http://github.com/mity/c-reusables>
+ *
+ * Copyright (c) 2017 Martin Mitas
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef CRE_CMDLINE_H
+#define CRE_CMDLINE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* The option may have an argument. (Affects only long option.) */
+#define CMDLINE_OPTFLAG_OPTIONALARG 0x0001
+
+/* The option must have an argument.
+ * Such short option cannot be grouped within single '-abc'. */
+#define CMDLINE_OPTFLAG_REQUIREDARG 0x0002
+
+/* Enable special compiler-like mode for the long option.
+ *
+ * Note ::shortname is not supported with this flag. CMDLINE_OPTION::shortname
+ * is silently ignored if the flag is used.
+ *
+ * With this flag, CMDLINE_OPTION::longname is treated differently as follows:
+ *
+ * 1. The option matches if the CMDLINE_OPTION::longname is the exact prefix
+ * of the argv[i] from commandline.
+ *
+ * 2. Double dash ("--") is not automatically prepended to
+ * CMDLINE_OPTION::longname. (If you desire any leading dash, include it
+ * explicitly in CMDLINE_OPTION initialization.)
+ *
+ * 3. An argument (optionally after a whitespace) is required (the flag
+ * CMDLINE_OPTFLAG_COMPILERLIKE implicitly implies also the flag
+ * CMDLINE_OPTFLAG_REQUIREDARG).
+ *
+ * But there is no delimiter expected (no "=" between the option and its
+ * argument). Whitespace is optional between the option and its argument.
+ *
+ * Intended use is for options similar to what many compilers accept.
+ * For example:
+ * -DDEBUG=0 (-D is the option, DEBUG=0 is the argument).
+ * -Isrc/include (-I is the option, src/include is the argument).
+ * -isystem /usr/include (-isystem is the option, /usr/include is the argument).
+ * -lmath (-l is the option, math is the argument).
+ */
+#define CMDLINE_OPTFLAG_COMPILERLIKE 0x0004
+
+
+/* Special (reserved) option IDs. Do not use these for any CMDLINE_OPTION::id.
+ * See documentation of cmdline_read() to get info about their meaning.
+ */
+#define CMDLINE_OPTID_NONE 0
+#define CMDLINE_OPTID_UNKNOWN (-0x7fffffff + 0)
+#define CMDLINE_OPTID_MISSINGARG (-0x7fffffff + 1)
+#define CMDLINE_OPTID_BOGUSARG (-0x7fffffff + 2)
+
+
+typedef struct CMDLINE_OPTION {
+ char shortname; /* Short (single char) option or 0. */
+ const char* longname; /* Long name (after "--") or NULL. */
+ int id; /* Non-zero ID to identify the option in the callback; or zero to denote end of options list. */
+ unsigned flags; /* Bitmask of CMDLINE_OPTFLAG_xxxx flags. */
+} CMDLINE_OPTION;
+
+
+/* Parses all options and their arguments as specified by argc, argv accordingly
+ * with the given options (except argv[0] which is ignored).
+ *
+ * The caller must specify the list of supported options in the 1st parameter
+ * of the function. The array must end with a record whose CMDLINE_OPTION::id
+ * is zero to zero.
+ *
+ * The provided callback function is called for each option on the command
+ * line so that:
+ *
+ * -- the "id" refers to the id of the option as specified in options[].
+ *
+ * -- the "arg" specifies an argument of the option or NULL if none is
+ * provided.
+ *
+ * -- the "userdata" just allows to pass in some caller's context into
+ * the callback.
+ *
+ * Special cases (recognized via special "id" value) are reported to the
+ * callback as follows:
+ *
+ * -- If id is CMDLINE_OPTID_NONE, the callback informs about a non-option
+ * also known as a positional argument.
+ *
+ * All argv[] tokens which are not interpreted as an options or an argument
+ * of any option fall into this category.
+ *
+ * Usually, programs interpret these as paths to file to process.
+ *
+ * -- If id is CMDLINE_OPTID_UNKNOWN, the corresponding argv[] looks like an
+ * option but it is not found in the options[] passed to cmdline_read().
+ *
+ * The callback's parameter arg specifies the guilty command line token.
+ * Usually, program writes down an error message and exits.
+ *
+ * -- If id is CMDLINE_OPTID_MISSINGARG, the given option is valid but its
+ * flag in options[] requires an argument; yet there is none on the
+ * command line.
+ *
+ * The callback's parameter arg specifies the guilty option name.
+ * Usually, program writes down an error message and exits.
+ *
+ * -- If id is CMDLINE_OPTID_BOGUSARG, the given option is valid but its
+ * flag in options[] does not expect an argument; yet the command line
+ * does provide one.
+ *
+ * The callback's parameter arg specifies the guilty option name.
+ * Usually, program writes down an error message and exits.
+ *
+ * On success, zero is returned.
+ *
+ * If the callback returns a non-zero, cmdline_read() aborts immediately and
+ * cmdline_read() propagates the same return value to the caller.
+ */
+
+int cmdline_read(const CMDLINE_OPTION* options, int argc, char** argv,
+ int (*callback)(int /*id*/, const char* /*arg*/, void* /*userdata*/),
+ void* userdata);
+
+
+#ifdef __cplusplus
+} /* extern "C" { */
+#endif
+
+#endif /* CRE_CMDLINE_H */
diff --git a/md2html/md2html.1 b/md2html/md2html.1
new file mode 100644
index 0000000..cffaee8
--- /dev/null
+++ b/md2html/md2html.1
@@ -0,0 +1,113 @@
+.TH MD2HTML 1 "June 2019" "" "General Commands Manual"
+.nh
+.ad l
+.
+.SH NAME
+.
+md2html \- convert Markdown to HTML
+.
+.SH SYNOPSIS
+.
+.B md2html
+.RI [ OPTION ]...\&
+.RI [ FILE ]
+.
+.SH OPTIONS
+.
+.SS General options:
+.
+.TP
+.BR -o ", " --output= \fIOUTFILE\fR
+Write output to \fIOUTFILE\fR instead of \fBstdout\fR(3)
+.
+.TP
+.BR -f ", " --full-html
+Generate full HTML document, including header
+.
+.TP
+.BR -s ", " --stat
+Measure time of input parsing
+.
+.TP
+.BR -h ", " --help
+Display help and exit
+.
+.TP
+.BR -v ", " --version
+Display version and exit
+.
+.SS Markdown dialect options:
+.
+.TP
+.B --commonmark
+CommonMark (the default)
+.
+.TP
+.B --github
+Github Flavored Markdown
+.
+.PP
+Note: dialect options are equivalent to some combination of flags below.
+.
+.SS Markdown extension options:
+.
+.TP
+.B --fcollapse-whitespace
+Collapse non-trivial whitespace
+.
+.TP
+.B --fverbatim-entities
+Do not translate entities
+.
+.TP
+.B --fpermissive-atx-headers
+Allow ATX headers without delimiting space
+.
+.TP
+.B --fpermissive-url-autolinks
+Allow URL autolinks without "<" and ">" delimiters
+.
+.TP
+.B --fpermissive-www-autolinks
+Allow WWW autolinks without any scheme (e.g. "www.example.com")
+.
+.TP
+.B --fpermissive-email-autolinks
+Allow e-mail autolinks without "<", ">" and "mailto:"
+.
+.TP
+.B --fpermissive-autolinks
+Enable all 3 of the above permissive autolinks options
+.
+.TP
+.B --fno-indented-code
+Disable indented code blocks
+.
+.TP
+.B --fno-html-blocks
+Disable raw HTML blocks
+.
+.TP
+.B --fno-html-spans
+Disable raw HTML spans
+.
+.TP
+.B --fno-html
+Same as \fB--fno-html-blocks --fno-html-spans\fR
+.
+.TP
+.B --ftables
+Enable tables
+.
+.TP
+.B --fstrikethrough
+Enable strikethrough spans
+.
+.TP
+.B --ftasklists
+Enable task lists
+.
+.SH SEE ALSO
+.
+https://github.com/mity/md4c
+.
diff --git a/md2html/md2html.c b/md2html/md2html.c
new file mode 100644
index 0000000..f2f2eb6
--- /dev/null
+++ b/md2html/md2html.c
@@ -0,0 +1,371 @@
+/*
+ * MD4C: Markdown parser for C
+ * (http://github.com/mity/md4c)
+ *
+ * Copyright (c) 2016-2020 Martin Mitas
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "md4c-html.h"
+#include "cmdline.h"
+
+
+
+/* Global options. */
+static unsigned parser_flags = 0;
+#ifndef MD4C_USE_ASCII
+ static unsigned renderer_flags = MD_HTML_FLAG_DEBUG | MD_HTML_FLAG_SKIP_UTF8_BOM;
+#else
+ static unsigned renderer_flags = MD_HTML_FLAG_DEBUG;
+#endif
+static int want_fullhtml = 0;
+static int want_stat = 0;
+
+
+/*********************************
+ *** Simple grow-able buffer ***
+ *********************************/
+
+/* We render to a memory buffer instead of directly outputting the rendered
+ * documents, as this allows using this utility for evaluating performance
+ * of MD4C (--stat option). This allows us to measure just time of the parser,
+ * without the I/O.
+ */
+
+struct membuffer {
+ char* data;
+ size_t asize;
+ size_t size;
+};
+
+static void
+membuf_init(struct membuffer* buf, MD_SIZE new_asize)
+{
+ buf->size = 0;
+ buf->asize = new_asize;
+ buf->data = malloc(buf->asize);
+ if(buf->data == NULL) {
+ fprintf(stderr, "membuf_init: malloc() failed.\n");
+ exit(1);
+ }
+}
+
+static void
+membuf_fini(struct membuffer* buf)
+{
+ if(buf->data)
+ free(buf->data);
+}
+
+static void
+membuf_grow(struct membuffer* buf, size_t new_asize)
+{
+ buf->data = realloc(buf->data, new_asize);
+ if(buf->data == NULL) {
+ fprintf(stderr, "membuf_grow: realloc() failed.\n");
+ exit(1);
+ }
+ buf->asize = new_asize;
+}
+
+static void
+membuf_append(struct membuffer* buf, const char* data, MD_SIZE size)
+{
+ if(buf->asize < buf->size + size)
+ membuf_grow(buf, buf->size + buf->size / 2 + size);
+ memcpy(buf->data + buf->size, data, size);
+ buf->size += size;
+}
+
+
+/**********************
+ *** Main program ***
+ **********************/
+
+static void
+process_output(const MD_CHAR* text, MD_SIZE size, void* userdata)
+{
+ membuf_append((struct membuffer*) userdata, text, size);
+}
+
+static int
+process_file(FILE* in, FILE* out)
+{
+ MD_SIZE n;
+ struct membuffer buf_in = {0};
+ struct membuffer buf_out = {0};
+ int ret = -1;
+ clock_t t0, t1;
+
+ membuf_init(&buf_in, 32 * 1024);
+
+ /* Read the input file into a buffer. */
+ while(1) {
+ if(buf_in.size >= buf_in.asize)
+ membuf_grow(&buf_in, buf_in.asize + buf_in.asize / 2);
+
+ n = fread(buf_in.data + buf_in.size, 1, buf_in.asize - buf_in.size, in);
+ if(n == 0)
+ break;
+ buf_in.size += n;
+ }
+
+ /* Input size is good estimation of output size. Add some more reserve to
+ * deal with the HTML header/footer and tags. */
+ membuf_init(&buf_out, buf_in.size + buf_in.size/8 + 64);
+
+ /* Parse the document. This shall call our callbacks provided via the
+ * md_renderer_t structure. */
+ t0 = clock();
+
+ ret = md_html(buf_in.data, buf_in.size, process_output, (void*) &buf_out,
+ parser_flags, renderer_flags);
+
+ t1 = clock();
+ if(ret != 0) {
+ fprintf(stderr, "Parsing failed.\n");
+ goto out;
+ }
+
+ /* Write down the document in the HTML format. */
+ if(want_fullhtml) {
+ fprintf(out, "<html>\n");
+ fprintf(out, "<head>\n");
+ fprintf(out, "<title></title>\n");
+ fprintf(out, "<meta name=\"generator\" content=\"md2html\">\n");
+ fprintf(out, "</head>\n");
+ fprintf(out, "<body>\n");
+ }
+
+ fwrite(buf_out.data, 1, buf_out.size, out);
+
+ if(want_fullhtml) {
+ fprintf(out, "</body>\n");
+ fprintf(out, "</html>\n");
+ }
+
+ if(want_stat) {
+ if(t0 != (clock_t)-1 && t1 != (clock_t)-1) {
+ double elapsed = (double)(t1 - t0) / CLOCKS_PER_SEC;
+ if (elapsed < 1)
+ fprintf(stderr, "Time spent on parsing: %7.2f ms.\n", elapsed*1e3);
+ else
+ fprintf(stderr, "Time spent on parsing: %6.3f s.\n", elapsed);
+ }
+ }
+
+ /* Success if we have reached here. */
+ ret = 0;
+
+out:
+ membuf_fini(&buf_in);
+ membuf_fini(&buf_out);
+
+ return ret;
+}
+
+
+static const CMDLINE_OPTION cmdline_options[] = {
+ { 'o', "output", 'o', CMDLINE_OPTFLAG_REQUIREDARG },
+ { 'f', "full-html", 'f', 0 },
+ { 's', "stat", 's', 0 },
+ { 'h', "help", 'h', 0 },
+ { 'v', "version", 'v', 0 },
+
+ { 0, "commonmark", 'c', 0 },
+ { 0, "github", 'g', 0 },
+
+ { 0, "fcollapse-whitespace", 'W', 0 },
+ { 0, "flatex-math", 'L', 0 },
+ { 0, "fpermissive-atx-headers", 'A', 0 },
+ { 0, "fpermissive-autolinks", 'V', 0 },
+ { 0, "fpermissive-email-autolinks", '@', 0 },
+ { 0, "fpermissive-url-autolinks", 'U', 0 },
+ { 0, "fpermissive-www-autolinks", '.', 0 },
+ { 0, "fstrikethrough", 'S', 0 },
+ { 0, "ftables", 'T', 0 },
+ { 0, "ftasklists", 'X', 0 },
+ { 0, "funderline", '_', 0 },
+ { 0, "fverbatim-entities", 'E', 0 },
+ { 0, "fwiki-links", 'K', 0 },
+
+ { 0, "fno-html-blocks", 'F', 0 },
+ { 0, "fno-html-spans", 'G', 0 },
+ { 0, "fno-html", 'H', 0 },
+ { 0, "fno-indented-code", 'I', 0 },
+
+ { 0, NULL, 0, 0 }
+};
+
+static void
+usage(void)
+{
+ printf(
+ "Usage: md2html [OPTION]... [FILE]\n"
+ "Convert input FILE (or standard input) in Markdown format to HTML.\n"
+ "\n"
+ "General options:\n"
+ " -o --output=FILE Output file (default is standard output)\n"
+ " -f, --full-html Generate full HTML document, including header\n"
+ " -s, --stat Measure time of input parsing\n"
+ " -h, --help Display this help and exit\n"
+ " -v, --version Display version and exit\n"
+ "\n"
+ "Markdown dialect options:\n"
+ "(note these are equivalent to some combinations of the flags below)\n"
+ " --commonmark CommonMark (this is default)\n"
+ " --github Github Flavored Markdown\n"
+ "\n"
+ "Markdown extension options:\n"
+ " --fcollapse-whitespace\n"
+ " Collapse non-trivial whitespace\n"
+ " --flatex-math Enable LaTeX style mathematics spans\n"
+ " --fpermissive-atx-headers\n"
+ " Allow ATX headers without delimiting space\n"
+ " --fpermissive-url-autolinks\n"
+ " Allow URL autolinks without '<', '>'\n"
+ " --fpermissive-www-autolinks\n"
+ " Allow WWW autolinks without any scheme (e.g. 'www.example.com')\n"
+ " --fpermissive-email-autolinks \n"
+ " Allow e-mail autolinks without '<', '>' and 'mailto:'\n"
+ " --fpermissive-autolinks\n"
+ " Same as --fpermissive-url-autolinks --fpermissive-www-autolinks\n"
+ " --fpermissive-email-autolinks\n"
+ " --fstrikethrough Enable strike-through spans\n"
+ " --ftables Enable tables\n"
+ " --ftasklists Enable task lists\n"
+ " --funderline Enable underline spans\n"
+ " --fwiki-links Enable wiki links\n"
+ "\n"
+ "Markdown suppression options:\n"
+ " --fno-html-blocks\n"
+ " Disable raw HTML blocks\n"
+ " --fno-html-spans\n"
+ " Disable raw HTML spans\n"
+ " --fno-html Same as --fno-html-blocks --fno-html-spans\n"
+ " --fno-indented-code\n"
+ " Disable indented code blocks\n"
+ "\n"
+ "HTML generator options:\n"
+ " --fverbatim-entities\n"
+ " Do not translate entities\n"
+ "\n"
+ );
+}
+
+static void
+version(void)
+{
+ printf("%d.%d.%d\n", MD_VERSION_MAJOR, MD_VERSION_MINOR, MD_VERSION_RELEASE);
+}
+
+static const char* input_path = NULL;
+static const char* output_path = NULL;
+
+static int
+cmdline_callback(int opt, char const* value, void* data)
+{
+ switch(opt) {
+ case 0:
+ if(input_path) {
+ fprintf(stderr, "Too many arguments. Only one input file can be specified.\n");
+ fprintf(stderr, "Use --help for more info.\n");
+ exit(1);
+ }
+ input_path = value;
+ break;
+
+ case 'o': output_path = value; break;
+ case 'f': want_fullhtml = 1; break;
+ case 's': want_stat = 1; break;
+ case 'h': usage(); exit(0); break;
+ case 'v': version(); exit(0); break;
+
+ case 'c': parser_flags = MD_DIALECT_COMMONMARK; break;
+ case 'g': parser_flags = MD_DIALECT_GITHUB; break;
+
+ case 'E': renderer_flags |= MD_HTML_FLAG_VERBATIM_ENTITIES; break;
+ case 'A': parser_flags |= MD_FLAG_PERMISSIVEATXHEADERS; break;
+ case 'I': parser_flags |= MD_FLAG_NOINDENTEDCODEBLOCKS; break;
+ case 'F': parser_flags |= MD_FLAG_NOHTMLBLOCKS; break;
+ case 'G': parser_flags |= MD_FLAG_NOHTMLSPANS; break;
+ case 'H': parser_flags |= MD_FLAG_NOHTML; break;
+ case 'W': parser_flags |= MD_FLAG_COLLAPSEWHITESPACE; break;
+ case 'U': parser_flags |= MD_FLAG_PERMISSIVEURLAUTOLINKS; break;
+ case '.': parser_flags |= MD_FLAG_PERMISSIVEWWWAUTOLINKS; break;
+ case '@': parser_flags |= MD_FLAG_PERMISSIVEEMAILAUTOLINKS; break;
+ case 'V': parser_flags |= MD_FLAG_PERMISSIVEAUTOLINKS; break;
+ case 'T': parser_flags |= MD_FLAG_TABLES; break;
+ case 'S': parser_flags |= MD_FLAG_STRIKETHROUGH; break;
+ case 'L': parser_flags |= MD_FLAG_LATEXMATHSPANS; break;
+ case 'K': parser_flags |= MD_FLAG_WIKILINKS; break;
+ case 'X': parser_flags |= MD_FLAG_TASKLISTS; break;
+ case '_': parser_flags |= MD_FLAG_UNDERLINE; break;
+
+ default:
+ fprintf(stderr, "Illegal option: %s\n", value);
+ fprintf(stderr, "Use --help for more info.\n");
+ exit(1);
+ break;
+ }
+
+ return 0;
+}
+
+int
+main(int argc, char** argv)
+{
+ FILE* in = stdin;
+ FILE* out = stdout;
+ int ret = 0;
+
+ if(cmdline_read(cmdline_options, argc, argv, cmdline_callback, NULL) != 0) {
+ usage();
+ exit(1);
+ }
+
+ if(input_path != NULL && strcmp(input_path, "-") != 0) {
+ in = fopen(input_path, "rb");
+ if(in == NULL) {
+ fprintf(stderr, "Cannot open %s.\n", input_path);
+ exit(1);
+ }
+ }
+ if(output_path != NULL && strcmp(output_path, "-") != 0) {
+ out = fopen(output_path, "wt");
+ if(out == NULL) {
+ fprintf(stderr, "Cannot open %s.\n", output_path);
+ exit(1);
+ }
+ }
+
+ ret = process_file(in, out);
+ if(in != stdin)
+ fclose(in);
+ if(out != stdout)
+ fclose(out);
+
+ return ret;
+}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f84849c..05f86ad 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -27,12 +27,6 @@ set_target_properties(md4c-html PROPERTIES
target_link_libraries(md4c-html md4c)
-# Build rules for md2html command line utility
-
-add_executable(md2html cmdline.c cmdline.h md2html.c)
-target_link_libraries(md2html md4c-html)
-
-
# Install rules
install(
@@ -57,12 +51,3 @@ install(
install(FILES ${CMAKE_BINARY_DIR}/src/md4c-html.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(EXPORT md4cHtmlConfig DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/md4c-html/)
-install(
- TARGETS md2html
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
-)
-install(FILES "md2html.1" DESTINATION "${CMAKE_INSTALL_MANDIR}/man1")
-
diff --git a/src/cmdline.c b/src/cmdline.c
deleted file mode 100644
index c3fddfa..0000000
--- a/src/cmdline.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * C Reusables
- * <http://github.com/mity/c-reusables>
- *
- * Copyright (c) 2017-2020 Martin Mitas
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include "cmdline.h"
-
-#include <stdio.h>
-#include <string.h>
-
-
-#ifdef _WIN32
- #define snprintf _snprintf
-#endif
-
-
-#define CMDLINE_AUXBUF_SIZE 32
-
-
-
-static int
-cmdline_handle_short_opt_group(const CMDLINE_OPTION* options, const char* arggroup,
- int (*callback)(int /*optval*/, const char* /*arg*/, void* /*userdata*/),
- void* userdata)
-{
- const CMDLINE_OPTION* opt;
- int i;
- int ret = 0;
-
- for(i = 0; arggroup[i] != '\0'; i++) {
- for(opt = options; opt->id != 0; opt++) {
- if(arggroup[i] == opt->shortname)
- break;
- }
-
- if(opt->id != 0 && !(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG)) {
- ret = callback(opt->id, NULL, userdata);
- } else {
- /* Unknown option. */
- char badoptname[3];
- badoptname[0] = '-';
- badoptname[1] = arggroup[i];
- badoptname[2] = '\0';
- ret = callback((opt->id != 0 ? CMDLINE_OPTID_MISSINGARG : CMDLINE_OPTID_UNKNOWN),
- badoptname, userdata);
- }
-
- if(ret != 0)
- break;
- }
-
- return ret;
-}
-
-int
-cmdline_read(const CMDLINE_OPTION* options, int argc, char** argv,
- int (*callback)(int /*optval*/, const char* /*arg*/, void* /*userdata*/),
- void* userdata)
-{
- const CMDLINE_OPTION* opt;
- char auxbuf[CMDLINE_AUXBUF_SIZE+1];
- int fast_optarg_decision = 1;
- int after_doubledash = 0;
- int i = 1;
- int ret = 0;
-
- auxbuf[CMDLINE_AUXBUF_SIZE] = '\0';
-
- /* Check whether there is any CMDLINE_OPTFLAG_COMPILERLIKE option with
- * a name not starting with '-'. That would imply we can to check for
- * non-option arguments only after refusing all such options. */
- for(opt = options; opt->id != 0; opt++) {
- if((opt->flags & CMDLINE_OPTFLAG_COMPILERLIKE) && opt->longname[0] != '-')
- fast_optarg_decision = 0;
- }
-
- while(i < argc) {
- if(after_doubledash || strcmp(argv[i], "-") == 0) {
- /* Non-option argument.
- * Standalone "-" usually means "read from stdin" or "write to
- * stdout" so treat it always as a non-option. */
- ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
- } else if(strcmp(argv[i], "--") == 0) {
- /* End of options. All the remaining tokens are non-options
- * even if they start with a dash. */
- after_doubledash = 1;
- } else if(fast_optarg_decision && argv[i][0] != '-') {
- /* Non-option argument. */
- ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
- } else {
- for(opt = options; opt->id != 0; opt++) {
- if(opt->flags & CMDLINE_OPTFLAG_COMPILERLIKE) {
- size_t len = strlen(opt->longname);
- if(strncmp(argv[i], opt->longname, len) == 0) {
- /* Compiler-like option. */
- if(argv[i][len] != '\0')
- ret = callback(opt->id, argv[i] + len, userdata);
- else if(i+1 < argc)
- ret = callback(opt->id, argv[++i], userdata);
- else
- ret = callback(CMDLINE_OPTID_MISSINGARG, opt->longname, userdata);
- break;
- }
- } else if(opt->longname != NULL && strncmp(argv[i], "--", 2) == 0) {
- size_t len = strlen(opt->longname);
- if(strncmp(argv[i]+2, opt->longname, len) == 0) {
- /* Regular long option. */
- if(argv[i][2+len] == '\0') {
- /* with no argument provided. */
- if(!(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG))
- ret = callback(opt->id, NULL, userdata);
- else
- ret = callback(CMDLINE_OPTID_MISSINGARG, argv[i], userdata);
- break;
- } else if(argv[i][2+len] == '=') {
- /* with an argument provided. */
- if(opt->flags & (CMDLINE_OPTFLAG_OPTIONALARG | CMDLINE_OPTFLAG_REQUIREDARG)) {
- ret = callback(opt->id, argv[i]+2+len+1, userdata);
- } else {
- snprintf(auxbuf, CMDLINE_AUXBUF_SIZE, "--%s", opt->longname);
- ret = callback(CMDLINE_OPTID_BOGUSARG, auxbuf, userdata);
- }
- break;
- } else {
- continue;
- }
- }
- } else if(opt->shortname != '\0' && argv[i][0] == '-') {
- if(argv[i][1] == opt->shortname) {
- /* Regular short option. */
- if(opt->flags & CMDLINE_OPTFLAG_REQUIREDARG) {
- if(argv[i][2] != '\0')
- ret = callback(opt->id, argv[i]+2, userdata);
- else if(i+1 < argc)
- ret = callback(opt->id, argv[++i], userdata);
- else
- ret = callback(CMDLINE_OPTID_MISSINGARG, argv[i], userdata);
- break;
- } else {
- ret = callback(opt->id, NULL, userdata);
-
- /* There might be more (argument-less) short options
- * grouped together. */
- if(ret == 0 && argv[i][2] != '\0')
- ret = cmdline_handle_short_opt_group(options, argv[i]+2, callback, userdata);
- break;
- }
- }
- }
- }
-
- if(opt->id == 0) { /* still not handled? */
- if(argv[i][0] != '-') {
- /* Non-option argument. */
- ret = callback(CMDLINE_OPTID_NONE, argv[i], userdata);
- } else {
- /* Unknown option. */
- char* badoptname = argv[i];
-
- if(strncmp(badoptname, "--", 2) == 0) {
- /* Strip any argument from the long option. */
- char* assignment = strchr(badoptname, '=');
- if(assignment != NULL) {
- size_t len = assignment - badoptname;
- if(len > CMDLINE_AUXBUF_SIZE)
- len = CMDLINE_AUXBUF_SIZE;
- strncpy(auxbuf, badoptname, len);
- auxbuf[len] = '\0';
- badoptname = auxbuf;
- }
- }
-
- ret = callback(CMDLINE_OPTID_UNKNOWN, badoptname, userdata);
- }
- }
- }
-
- if(ret != 0)
- return ret;
- i++;
- }
-
- return ret;
-}
-
diff --git a/src/cmdline.h b/src/cmdline.h
deleted file mode 100644
index 5bbde47..0000000
--- a/src/cmdline.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * C Reusables
- * <http://github.com/mity/c-reusables>
- *
- * Copyright (c) 2017 Martin Mitas
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#ifndef CRE_CMDLINE_H
-#define CRE_CMDLINE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-/* The option may have an argument. (Affects only long option.) */
-#define CMDLINE_OPTFLAG_OPTIONALARG 0x0001
-
-/* The option must have an argument.
- * Such short option cannot be grouped within single '-abc'. */
-#define CMDLINE_OPTFLAG_REQUIREDARG 0x0002
-
-/* Enable special compiler-like mode for the long option.
- *
- * Note ::shortname is not supported with this flag. CMDLINE_OPTION::shortname
- * is silently ignored if the flag is used.
- *
- * With this flag, CMDLINE_OPTION::longname is treated differently as follows:
- *
- * 1. The option matches if the CMDLINE_OPTION::longname is the exact prefix
- * of the argv[i] from commandline.
- *
- * 2. Double dash ("--") is not automatically prepended to
- * CMDLINE_OPTION::longname. (If you desire any leading dash, include it
- * explicitly in CMDLINE_OPTION initialization.)
- *
- * 3. An argument (optionally after a whitespace) is required (the flag
- * CMDLINE_OPTFLAG_COMPILERLIKE implicitly implies also the flag
- * CMDLINE_OPTFLAG_REQUIREDARG).
- *
- * But there is no delimiter expected (no "=" between the option and its
- * argument). Whitespace is optional between the option and its argument.
- *
- * Intended use is for options similar to what many compilers accept.
- * For example:
- * -DDEBUG=0 (-D is the option, DEBUG=0 is the argument).
- * -Isrc/include (-I is the option, src/include is the argument).
- * -isystem /usr/include (-isystem is the option, /usr/include is the argument).
- * -lmath (-l is the option, math is the argument).
- */
-#define CMDLINE_OPTFLAG_COMPILERLIKE 0x0004
-
-
-/* Special (reserved) option IDs. Do not use these for any CMDLINE_OPTION::id.
- * See documentation of cmdline_read() to get info about their meaning.
- */
-#define CMDLINE_OPTID_NONE 0
-#define CMDLINE_OPTID_UNKNOWN (-0x7fffffff + 0)
-#define CMDLINE_OPTID_MISSINGARG (-0x7fffffff + 1)
-#define CMDLINE_OPTID_BOGUSARG (-0x7fffffff + 2)
-
-
-typedef struct CMDLINE_OPTION {
- char shortname; /* Short (single char) option or 0. */
- const char* longname; /* Long name (after "--") or NULL. */
- int id; /* Non-zero ID to identify the option in the callback; or zero to denote end of options list. */
- unsigned flags; /* Bitmask of CMDLINE_OPTFLAG_xxxx flags. */
-} CMDLINE_OPTION;
-
-
-/* Parses all options and their arguments as specified by argc, argv accordingly
- * with the given options (except argv[0] which is ignored).
- *
- * The caller must specify the list of supported options in the 1st parameter
- * of the function. The array must end with a record whose CMDLINE_OPTION::id
- * is zero to zero.
- *
- * The provided callback function is called for each option on the command
- * line so that:
- *
- * -- the "id" refers to the id of the option as specified in options[].
- *
- * -- the "arg" specifies an argument of the option or NULL if none is
- * provided.
- *
- * -- the "userdata" just allows to pass in some caller's context into
- * the callback.
- *
- * Special cases (recognized via special "id" value) are reported to the
- * callback as follows:
- *
- * -- If id is CMDLINE_OPTID_NONE, the callback informs about a non-option
- * also known as a positional argument.
- *
- * All argv[] tokens which are not interpreted as an options or an argument
- * of any option fall into this category.
- *
- * Usually, programs interpret these as paths to file to process.
- *
- * -- If id is CMDLINE_OPTID_UNKNOWN, the corresponding argv[] looks like an
- * option but it is not found in the options[] passed to cmdline_read().
- *
- * The callback's parameter arg specifies the guilty command line token.
- * Usually, program writes down an error message and exits.
- *
- * -- If id is CMDLINE_OPTID_MISSINGARG, the given option is valid but its
- * flag in options[] requires an argument; yet there is none on the
- * command line.
- *
- * The callback's parameter arg specifies the guilty option name.
- * Usually, program writes down an error message and exits.
- *
- * -- If id is CMDLINE_OPTID_BOGUSARG, the given option is valid but its
- * flag in options[] does not expect an argument; yet the command line
- * does provide one.
- *
- * The callback's parameter arg specifies the guilty option name.
- * Usually, program writes down an error message and exits.
- *
- * On success, zero is returned.
- *
- * If the callback returns a non-zero, cmdline_read() aborts immediately and
- * cmdline_read() propagates the same return value to the caller.
- */
-
-int cmdline_read(const CMDLINE_OPTION* options, int argc, char** argv,
- int (*callback)(int /*id*/, const char* /*arg*/, void* /*userdata*/),
- void* userdata);
-
-
-#ifdef __cplusplus
-} /* extern "C" { */
-#endif
-
-#endif /* CRE_CMDLINE_H */
diff --git a/src/md2html.1 b/src/md2html.1
deleted file mode 100644
index cffaee8..0000000
--- a/src/md2html.1
+++ /dev/null
@@ -1,113 +0,0 @@
-.TH MD2HTML 1 "June 2019" "" "General Commands Manual"
-.nh
-.ad l
-.
-.SH NAME
-.
-md2html \- convert Markdown to HTML
-.
-.SH SYNOPSIS
-.
-.B md2html
-.RI [ OPTION ]...\&
-.RI [ FILE ]
-.
-.SH OPTIONS
-.
-.SS General options:
-.
-.TP
-.BR -o ", " --output= \fIOUTFILE\fR
-Write output to \fIOUTFILE\fR instead of \fBstdout\fR(3)
-.
-.TP
-.BR -f ", " --full-html
-Generate full HTML document, including header
-.
-.TP
-.BR -s ", " --stat
-Measure time of input parsing
-.
-.TP
-.BR -h ", " --help
-Display help and exit
-.
-.TP
-.BR -v ", " --version
-Display version and exit
-.
-.SS Markdown dialect options:
-.
-.TP
-.B --commonmark
-CommonMark (the default)
-.
-.TP
-.B --github
-Github Flavored Markdown
-.
-.PP
-Note: dialect options are equivalent to some combination of flags below.
-.
-.SS Markdown extension options:
-.
-.TP
-.B --fcollapse-whitespace
-Collapse non-trivial whitespace
-.
-.TP
-.B --fverbatim-entities
-Do not translate entities
-.
-.TP
-.B --fpermissive-atx-headers
-Allow ATX headers without delimiting space
-.
-.TP
-.B --fpermissive-url-autolinks
-Allow URL autolinks without "<" and ">" delimiters
-.
-.TP
-.B --fpermissive-www-autolinks
-Allow WWW autolinks without any scheme (e.g. "www.example.com")
-.
-.TP
-.B --fpermissive-email-autolinks
-Allow e-mail autolinks without "<", ">" and "mailto:"
-.
-.TP
-.B --fpermissive-autolinks
-Enable all 3 of the above permissive autolinks options
-.
-.TP
-.B --fno-indented-code
-Disable indented code blocks
-.
-.TP
-.B --fno-html-blocks
-Disable raw HTML blocks
-.
-.TP
-.B --fno-html-spans
-Disable raw HTML spans
-.
-.TP
-.B --fno-html
-Same as \fB--fno-html-blocks --fno-html-spans\fR
-.
-.TP
-.B --ftables
-Enable tables
-.
-.TP
-.B --fstrikethrough
-Enable strikethrough spans
-.
-.TP
-.B --ftasklists
-Enable task lists
-.
-.SH SEE ALSO
-.
-https://github.com/mity/md4c
-.
diff --git a/src/md2html.c b/src/md2html.c
deleted file mode 100644
index f2f2eb6..0000000
--- a/src/md2html.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * MD4C: Markdown parser for C
- * (http://github.com/mity/md4c)
- *
- * Copyright (c) 2016-2020 Martin Mitas
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include "md4c-html.h"
-#include "cmdline.h"
-
-
-
-/* Global options. */
-static unsigned parser_flags = 0;
-#ifndef MD4C_USE_ASCII
- static unsigned renderer_flags = MD_HTML_FLAG_DEBUG | MD_HTML_FLAG_SKIP_UTF8_BOM;
-#else
- static unsigned renderer_flags = MD_HTML_FLAG_DEBUG;
-#endif
-static int want_fullhtml = 0;
-static int want_stat = 0;
-
-
-/*********************************
- *** Simple grow-able buffer ***
- *********************************/
-
-/* We render to a memory buffer instead of directly outputting the rendered
- * documents, as this allows using this utility for evaluating performance
- * of MD4C (--stat option). This allows us to measure just time of the parser,
- * without the I/O.
- */
-
-struct membuffer {
- char* data;
- size_t asize;
- size_t size;
-};
-
-static void
-membuf_init(struct membuffer* buf, MD_SIZE new_asize)
-{
- buf->size = 0;
- buf->asize = new_asize;
- buf->data = malloc(buf->asize);
- if(buf->data == NULL) {
- fprintf(stderr, "membuf_init: malloc() failed.\n");
- exit(1);
- }
-}
-
-static void
-membuf_fini(struct membuffer* buf)
-{
- if(buf->data)
- free(buf->data);
-}
-
-static void
-membuf_grow(struct membuffer* buf, size_t new_asize)
-{
- buf->data = realloc(buf->data, new_asize);
- if(buf->data == NULL) {
- fprintf(stderr, "membuf_grow: realloc() failed.\n");
- exit(1);
- }
- buf->asize = new_asize;
-}
-
-static void
-membuf_append(struct membuffer* buf, const char* data, MD_SIZE size)
-{
- if(buf->asize < buf->size + size)
- membuf_grow(buf, buf->size + buf->size / 2 + size);
- memcpy(buf->data + buf->size, data, size);
- buf->size += size;
-}
-
-
-/**********************
- *** Main program ***
- **********************/
-
-static void
-process_output(const MD_CHAR* text, MD_SIZE size, void* userdata)
-{
- membuf_append((struct membuffer*) userdata, text, size);
-}
-
-static int
-process_file(FILE* in, FILE* out)
-{
- MD_SIZE n;
- struct membuffer buf_in = {0};
- struct membuffer buf_out = {0};
- int ret = -1;
- clock_t t0, t1;
-
- membuf_init(&buf_in, 32 * 1024);
-
- /* Read the input file into a buffer. */
- while(1) {
- if(buf_in.size >= buf_in.asize)
- membuf_grow(&buf_in, buf_in.asize + buf_in.asize / 2);
-
- n = fread(buf_in.data + buf_in.size, 1, buf_in.asize - buf_in.size, in);
- if(n == 0)
- break;
- buf_in.size += n;
- }
-
- /* Input size is good estimation of output size. Add some more reserve to
- * deal with the HTML header/footer and tags. */
- membuf_init(&buf_out, buf_in.size + buf_in.size/8 + 64);
-
- /* Parse the document. This shall call our callbacks provided via the
- * md_renderer_t structure. */
- t0 = clock();
-
- ret = md_html(buf_in.data, buf_in.size, process_output, (void*) &buf_out,
- parser_flags, renderer_flags);
-
- t1 = clock();
- if(ret != 0) {
- fprintf(stderr, "Parsing failed.\n");
- goto out;
- }
-
- /* Write down the document in the HTML format. */
- if(want_fullhtml) {
- fprintf(out, "<html>\n");
- fprintf(out, "<head>\n");
- fprintf(out, "<title></title>\n");
- fprintf(out, "<meta name=\"generator\" content=\"md2html\">\n");
- fprintf(out, "</head>\n");
- fprintf(out, "<body>\n");
- }
-
- fwrite(buf_out.data, 1, buf_out.size, out);
-
- if(want_fullhtml) {
- fprintf(out, "</body>\n");
- fprintf(out, "</html>\n");
- }
-
- if(want_stat) {
- if(t0 != (clock_t)-1 && t1 != (clock_t)-1) {
- double elapsed = (double)(t1 - t0) / CLOCKS_PER_SEC;
- if (elapsed < 1)
- fprintf(stderr, "Time spent on parsing: %7.2f ms.\n", elapsed*1e3);
- else
- fprintf(stderr, "Time spent on parsing: %6.3f s.\n", elapsed);
- }
- }
-
- /* Success if we have reached here. */
- ret = 0;
-
-out:
- membuf_fini(&buf_in);
- membuf_fini(&buf_out);
-
- return ret;
-}
-
-
-static const CMDLINE_OPTION cmdline_options[] = {
- { 'o', "output", 'o', CMDLINE_OPTFLAG_REQUIREDARG },
- { 'f', "full-html", 'f', 0 },
- { 's', "stat", 's', 0 },
- { 'h', "help", 'h', 0 },
- { 'v', "version", 'v', 0 },
-
- { 0, "commonmark", 'c', 0 },
- { 0, "github", 'g', 0 },
-
- { 0, "fcollapse-whitespace", 'W', 0 },
- { 0, "flatex-math", 'L', 0 },
- { 0, "fpermissive-atx-headers", 'A', 0 },
- { 0, "fpermissive-autolinks", 'V', 0 },
- { 0, "fpermissive-email-autolinks", '@', 0 },
- { 0, "fpermissive-url-autolinks", 'U', 0 },
- { 0, "fpermissive-www-autolinks", '.', 0 },
- { 0, "fstrikethrough", 'S', 0 },
- { 0, "ftables", 'T', 0 },
- { 0, "ftasklists", 'X', 0 },
- { 0, "funderline", '_', 0 },
- { 0, "fverbatim-entities", 'E', 0 },
- { 0, "fwiki-links", 'K', 0 },
-
- { 0, "fno-html-blocks", 'F', 0 },
- { 0, "fno-html-spans", 'G', 0 },
- { 0, "fno-html", 'H', 0 },
- { 0, "fno-indented-code", 'I', 0 },
-
- { 0, NULL, 0, 0 }
-};
-
-static void
-usage(void)
-{
- printf(
- "Usage: md2html [OPTION]... [FILE]\n"
- "Convert input FILE (or standard input) in Markdown format to HTML.\n"
- "\n"
- "General options:\n"
- " -o --output=FILE Output file (default is standard output)\n"
- " -f, --full-html Generate full HTML document, including header\n"
- " -s, --stat Measure time of input parsing\n"
- " -h, --help Display this help and exit\n"
- " -v, --version Display version and exit\n"
- "\n"
- "Markdown dialect options:\n"
- "(note these are equivalent to some combinations of the flags below)\n"
- " --commonmark CommonMark (this is default)\n"
- " --github Github Flavored Markdown\n"
- "\n"
- "Markdown extension options:\n"
- " --fcollapse-whitespace\n"
- " Collapse non-trivial whitespace\n"
- " --flatex-math Enable LaTeX style mathematics spans\n"
- " --fpermissive-atx-headers\n"
- " Allow ATX headers without delimiting space\n"
- " --fpermissive-url-autolinks\n"
- " Allow URL autolinks without '<', '>'\n"
- " --fpermissive-www-autolinks\n"
- " Allow WWW autolinks without any scheme (e.g. 'www.example.com')\n"
- " --fpermissive-email-autolinks \n"
- " Allow e-mail autolinks without '<', '>' and 'mailto:'\n"
- " --fpermissive-autolinks\n"
- " Same as --fpermissive-url-autolinks --fpermissive-www-autolinks\n"
- " --fpermissive-email-autolinks\n"
- " --fstrikethrough Enable strike-through spans\n"
- " --ftables Enable tables\n"
- " --ftasklists Enable task lists\n"
- " --funderline Enable underline spans\n"
- " --fwiki-links Enable wiki links\n"
- "\n"
- "Markdown suppression options:\n"
- " --fno-html-blocks\n"
- " Disable raw HTML blocks\n"
- " --fno-html-spans\n"
- " Disable raw HTML spans\n"
- " --fno-html Same as --fno-html-blocks --fno-html-spans\n"
- " --fno-indented-code\n"
- " Disable indented code blocks\n"
- "\n"
- "HTML generator options:\n"
- " --fverbatim-entities\n"
- " Do not translate entities\n"
- "\n"
- );
-}
-
-static void
-version(void)
-{
- printf("%d.%d.%d\n", MD_VERSION_MAJOR, MD_VERSION_MINOR, MD_VERSION_RELEASE);
-}
-
-static const char* input_path = NULL;
-static const char* output_path = NULL;
-
-static int
-cmdline_callback(int opt, char const* value, void* data)
-{
- switch(opt) {
- case 0:
- if(input_path) {
- fprintf(stderr, "Too many arguments. Only one input file can be specified.\n");
- fprintf(stderr, "Use --help for more info.\n");
- exit(1);
- }
- input_path = value;
- break;
-
- case 'o': output_path = value; break;
- case 'f': want_fullhtml = 1; break;
- case 's': want_stat = 1; break;
- case 'h': usage(); exit(0); break;
- case 'v': version(); exit(0); break;
-
- case 'c': parser_flags = MD_DIALECT_COMMONMARK; break;
- case 'g': parser_flags = MD_DIALECT_GITHUB; break;
-
- case 'E': renderer_flags |= MD_HTML_FLAG_VERBATIM_ENTITIES; break;
- case 'A': parser_flags |= MD_FLAG_PERMISSIVEATXHEADERS; break;
- case 'I': parser_flags |= MD_FLAG_NOINDENTEDCODEBLOCKS; break;
- case 'F': parser_flags |= MD_FLAG_NOHTMLBLOCKS; break;
- case 'G': parser_flags |= MD_FLAG_NOHTMLSPANS; break;
- case 'H': parser_flags |= MD_FLAG_NOHTML; break;
- case 'W': parser_flags |= MD_FLAG_COLLAPSEWHITESPACE; break;
- case 'U': parser_flags |= MD_FLAG_PERMISSIVEURLAUTOLINKS; break;
- case '.': parser_flags |= MD_FLAG_PERMISSIVEWWWAUTOLINKS; break;
- case '@': parser_flags |= MD_FLAG_PERMISSIVEEMAILAUTOLINKS; break;
- case 'V': parser_flags |= MD_FLAG_PERMISSIVEAUTOLINKS; break;
- case 'T': parser_flags |= MD_FLAG_TABLES; break;
- case 'S': parser_flags |= MD_FLAG_STRIKETHROUGH; break;
- case 'L': parser_flags |= MD_FLAG_LATEXMATHSPANS; break;
- case 'K': parser_flags |= MD_FLAG_WIKILINKS; break;
- case 'X': parser_flags |= MD_FLAG_TASKLISTS; break;
- case '_': parser_flags |= MD_FLAG_UNDERLINE; break;
-
- default:
- fprintf(stderr, "Illegal option: %s\n", value);
- fprintf(stderr, "Use --help for more info.\n");
- exit(1);
- break;
- }
-
- return 0;
-}
-
-int
-main(int argc, char** argv)
-{
- FILE* in = stdin;
- FILE* out = stdout;
- int ret = 0;
-
- if(cmdline_read(cmdline_options, argc, argv, cmdline_callback, NULL) != 0) {
- usage();
- exit(1);
- }
-
- if(input_path != NULL && strcmp(input_path, "-") != 0) {
- in = fopen(input_path, "rb");
- if(in == NULL) {
- fprintf(stderr, "Cannot open %s.\n", input_path);
- exit(1);
- }
- }
- if(output_path != NULL && strcmp(output_path, "-") != 0) {
- out = fopen(output_path, "wt");
- if(out == NULL) {
- fprintf(stderr, "Cannot open %s.\n", output_path);
- exit(1);
- }
- }
-
- ret = process_file(in, out);
- if(in != stdin)
- fclose(in);
- if(out != stdout)
- fclose(out);
-
- return ret;
-}