Index: trunk/parsers/libmwparser/src/mwWikitextLexer.g |
— | — | @@ -152,6 +152,7 @@ |
153 | 153 | #include <mwlexercontext.h> |
154 | 154 | #include <mwutils.h> |
155 | 155 | #include <mwkeyvalue.h> |
| 156 | +#include <mwmedialinkoption.h> |
156 | 157 | } |
157 | 158 | |
158 | 159 | @lexer::members{ |
— | — | @@ -288,11 +289,19 @@ |
289 | 290 | { |
290 | 291 | MWLEXERCONTEXT *context = param; |
291 | 292 | speculationSuccess(context, &context->indentSpeculation); |
| 293 | + bool willFail = context->headingSpeculation.active |
| 294 | + || context->internalLinkSpeculation.active |
| 295 | + || context->mediaLinkSpeculation[0].active |
| 296 | + || context->mediaLinkSpeculation[1].active; |
292 | 297 | SPECULATION_FAILURE(context, |
293 | 298 | &context->headingSpeculation, |
294 | 299 | &context->internalLinkSpeculation, |
295 | 300 | &context->mediaLinkSpeculation[0], |
296 | 301 | &context->mediaLinkSpeculation[1]); |
| 302 | + |
| 303 | + if (!willFail) { |
| 304 | + context->resolveLinks(context); |
| 305 | + } |
297 | 306 | } |
298 | 307 | |
299 | 308 | |
— | — | @@ -302,8 +311,8 @@ |
303 | 312 | fragment |
304 | 313 | NOWIKI |
305 | 314 | @init{ |
306 | | - ANTLR3_MARKER nowikiStart; |
307 | | - ANTLR3_MARKER nowikiEnd; |
| 315 | + ANTLR3_MARKER nowikiStart = 0; |
| 316 | + ANTLR3_MARKER nowikiEnd = 0; |
308 | 317 | pANTLR3_VECTOR attrs = NULL; |
309 | 318 | }: |
310 | 319 | N O W I K I (SPACE_TAB ATTRIBUTE_LIST_HTML[&attrs]? )? '>' |
— | — | @@ -333,8 +342,8 @@ |
334 | 343 | fragment |
335 | 344 | HTML_PRE |
336 | 345 | @init{ |
337 | | - ANTLR3_MARKER preStart; |
338 | | - ANTLR3_MARKER preEnd; |
| 346 | + ANTLR3_MARKER preStart = 0; |
| 347 | + ANTLR3_MARKER preEnd = 0; |
339 | 348 | pANTLR3_VECTOR attrs = NULL; |
340 | 349 | }: |
341 | 350 | {!CX->htmlPreDisabled}?=> P R E (SPACE_TAB ATTRIBUTE_LIST_HTML[&attrs]? )? '>' |
— | — | @@ -385,8 +394,8 @@ |
386 | 395 | |
387 | 396 | END_HEADING |
388 | 397 | @init { |
389 | | - ANTLR3_MARKER mark; |
390 | | - ANTLR3_MARKER endHeadingText; |
| 398 | + ANTLR3_MARKER mark = 0; |
| 399 | + ANTLR3_MARKER endHeadingText = 0; |
391 | 400 | }: |
392 | 401 | {!CX->wikitextHeadingCloseDisabled}?=> '=' {mark = MARK();endHeadingText = GETCHARINDEX();} |
393 | 402 | ( ({CX->headingLevel == 1}?=> END_HEADING_EOL[mark]) |
— | — | @@ -416,9 +425,9 @@ |
417 | 426 | |
418 | 427 | INDENTED_LIST_TABLE |
419 | 428 | @init{ |
420 | | - ANTLR3_MARKER listStart; |
421 | | - ANTLR3_MARKER tableStart; |
422 | | - ANTLR3_MARKER spaceStart; |
| 429 | + ANTLR3_MARKER listStart = 0; |
| 430 | + ANTLR3_MARKER tableStart = 0; |
| 431 | + ANTLR3_MARKER spaceStart = 0; |
423 | 432 | }: |
424 | 433 | {BOL}?=> |
425 | 434 | { |
— | — | @@ -543,14 +552,15 @@ |
544 | 553 | */ |
545 | 554 | INTERNAL_LINK |
546 | 555 | @init{ |
547 | | - ANTLR3_MARKER mark; |
| 556 | + ANTLR3_MARKER mark = 0; |
548 | 557 | pANTLR3_STRING linkTitle; |
549 | 558 | pANTLR3_STRING linkAnchor=NULL; |
550 | 559 | bool isCompleteLink = false; |
551 | 560 | bool success = true; |
552 | | - bool alreadyInInternalLink; |
553 | | - bool isMediaLink; |
| 561 | + bool alreadyInInternalLink = false; |
| 562 | + bool isMediaLink = false; |
554 | 563 | pANTLR3_VECTOR attr = NULL; |
| 564 | + MEDIALINKOPTION *mlOption = NULL; |
555 | 565 | pANTLR3_STRING attrLink = NULL; |
556 | 566 | }: {!CX->mediaLinkOpenDisabled && !alreadyTried(CX, &CX->internalLinkSpeculation) |
557 | 567 | /* |
— | — | @@ -592,7 +602,7 @@ |
593 | 603 | ('#' INTERNAL_LINK_ANCHOR[&linkAnchor])? |
594 | 604 | ( |
595 | 605 | ']]' {isCompleteLink=true;} |
596 | | - | '|' ({isMediaLink}?=> MEDIA_LINK_ATTRIBUTES[&attr, &attrLink] | ) |
| 606 | + | '|' ({isMediaLink}?=> MEDIA_LINK_OPTIONS[&mlOption, &attrLink] | ) |
597 | 607 | | {success = false;} |
598 | 608 | ) |
599 | 609 | ) |
— | — | @@ -621,8 +631,17 @@ |
622 | 632 | * We'll pack the link title in the attribute vector. |
623 | 633 | * The parser will unpack it and send it as a separate |
624 | 634 | * parameter to the client. |
| 635 | + * |
| 636 | + * Argument convention: |
| 637 | + * |
| 638 | + * options, linkTitle, linkAnchor, linkResolution, attributeLinkResolution |
625 | 639 | */ |
| 640 | + |
| 641 | + attr->add(attr, mlOption, MWMediaLinkOptionFree); |
626 | 642 | attr->add(attr, linkTitle, NULL); |
| 643 | + attr->add(attr, linkAnchor, NULL); |
| 644 | + attr->add(attr, NULL, NULL); |
| 645 | + attr->add(attr, NULL, NULL); |
627 | 646 | token->custom = attr; |
628 | 647 | if (isCompleteLink) { |
629 | 648 | token->setType(token, MEDIA_LINK); |
— | — | @@ -634,7 +653,16 @@ |
635 | 654 | } else if (CX->isLegalTitle(CX, linkTitle)) { |
636 | 655 | MWLinkCollectionAdd(CX->linkCollection, MWLT_INTERNAL, linkTitle, token); |
637 | 656 | speculationAbort(CX, &CX->mediaLinkSpeculation[CX->mediaLinkOpenNestingLevel]); |
638 | | - token->custom = linkTitle; |
| 657 | + /* |
| 658 | + * Convention for passing attributes to internal link: |
| 659 | + * |
| 660 | + * linkTitle, linkAnchor, linkResolution |
| 661 | + */ |
| 662 | + pANTLR3_VECTOR v = CX->vectorFactory->newVector(CX->vectorFactory); |
| 663 | + v->add(v, linkTitle, NULL); |
| 664 | + v->add(v, linkAnchor, NULL); |
| 665 | + v->add(v, NULL, NULL); |
| 666 | + token->custom = v; |
639 | 667 | if (isCompleteLink) { |
640 | 668 | speculationAbort(CX, &CX->internalLinkSpeculation); |
641 | 669 | } else { |
— | — | @@ -674,94 +702,90 @@ |
675 | 703 | ; |
676 | 704 | |
677 | 705 | fragment |
678 | | -MEDIA_LINK_ATTRIBUTES[pANTLR3_VECTOR *attr, pANTLR3_STRING *link]: |
679 | | - ((MEDIA_LINK_ATTRIBUTE[NULL]|MEDIA_LINK_ATTRIBUTE_WITH_VALUE[NULL, NULL])=> |
680 | | - (MEDIA_LINK_ATTRIBUTE[attr]|MEDIA_LINK_ATTRIBUTE_WITH_VALUE[attr, link]) |
681 | | - SKIP_SPACE) |
682 | | - ( |
683 | | - ('|' MEDIA_LINK_ATTRIBUTE[NULL]|MEDIA_LINK_ATTRIBUTE_WITH_VALUE[NULL, NULL])=> |
684 | | - '|' (MEDIA_LINK_ATTRIBUTE[attr]|MEDIA_LINK_ATTRIBUTE_WITH_VALUE[attr, link]) |
685 | | - )* |
| 706 | +MEDIA_LINK_OPTIONS[MEDIALINKOPTION **mlOption, pANTLR3_STRING *link]: |
| 707 | + |
| 708 | + ( |
| 709 | + (SKIP_SPACE (MEDIA_LINK_OPTION[NULL] |MEDIA_LINK_OPTION_WITH_VALUE[NULL, NULL]) |
| 710 | + SKIP_SPACE ('|'|{PEEK(1, ']') && PEEK(2, ']')}?=>) )=> |
| 711 | + SKIP_SPACE (MEDIA_LINK_OPTION[mlOption]|MEDIA_LINK_OPTION_WITH_VALUE[mlOption, link]) |
| 712 | + SKIP_SPACE ('|'|{PEEK(1, ']') && PEEK(2, ']')}?=>) |
| 713 | + )* |
686 | 714 | ; |
687 | 715 | |
688 | 716 | fragment |
689 | | -MEDIA_LINK_ATTRIBUTE[pANTLR3_VECTOR *attrs] |
| 717 | +MEDIA_LINK_OPTION[MEDIALINKOPTION **mlOption] |
690 | 718 | @init{ |
691 | | - ANTLR3_MARKER start; |
| 719 | + ANTLR3_MARKER start = 0; |
692 | 720 | }: |
693 | 721 | { |
694 | | - start = GETCHARINDEX(); |
| 722 | + if (*mlOption == NULL) { |
| 723 | + *mlOption = MWMediaLinkOptionNew(); |
| 724 | + } |
695 | 725 | } |
696 | | - ( 'thumbnail' |
697 | | - |'left' |
698 | | - |'right' |
699 | | - |'none' |
700 | | - |'center' |
701 | | - |'frame' |
702 | | - |'framed' |
703 | | - |'frameless' |
704 | | - |'upright' |
705 | | - |'border' |
706 | | - |'baseline' |
707 | | - |'sub' |
708 | | - |'super' |
709 | | - |'top' |
710 | | - |'text-top' |
711 | | - |'middle' |
712 | | - |'bottom') |
713 | | - { |
714 | | - MWKEYVALUE kv = { SUBSTR1(start), NULL }; |
715 | | - addAttribute(CX, attrs, kv); |
716 | | - } |
| 726 | + ( ('thumbnail' { (*mlOption)->frame = LOF_THUMBNAIL; }) |
| 727 | + |('left' { (*mlOption)->halign = LOHA_LEFT; }) |
| 728 | + |('right' { (*mlOption)->halign = LOHA_RIGHT; }) |
| 729 | + |('none' { (*mlOption)->halign = LOHA_NONE; }) |
| 730 | + |('center' { (*mlOption)->halign = LOHA_CENTER; }) |
| 731 | + |('frame' { (*mlOption)->frame = LOF_FRAME; }) |
| 732 | + |('framed' { (*mlOption)->frame = LOF_FRAME; }) |
| 733 | + |('frameless' { (*mlOption)->frame = LOF_FRAMELESS; }) |
| 734 | + |('upright' { (*mlOption)->upright = true; }) |
| 735 | + |('border' { (*mlOption)->border = true; }) |
| 736 | + |('baseline' { (*mlOption)->valign = LOVA_BASELINE; }) |
| 737 | + |('sub' { (*mlOption)->valign = LOVA_SUB; }) |
| 738 | + |('super' { (*mlOption)->valign = LOVA_SUPER; }) |
| 739 | + |('top' { (*mlOption)->valign = LOVA_TOP; }) |
| 740 | + |('text-top' { (*mlOption)->valign = LOVA_TEXT_TOP; }) |
| 741 | + |('middle' { (*mlOption)->valign = LOVA_MIDDLE; }) |
| 742 | + |('bottom' { (*mlOption)->valign = LOVA_BOTTOM; }) |
| 743 | + |('text-bottom' { (*mlOption)->valign = LOVA_TEXT_BOTTOM; })) |
717 | 744 | ; |
718 | 745 | |
719 | 746 | fragment |
720 | | -MEDIA_LINK_ATTRIBUTE_WITH_VALUE[pANTLR3_VECTOR *attrs, pANTLR3_STRING *link] |
| 747 | +MEDIA_LINK_OPTION_WITH_VALUE[MEDIALINKOPTION **mlOption, pANTLR3_STRING *link] |
721 | 748 | @init{ |
722 | | - ANTLR3_MARKER startKey; |
723 | | - ANTLR3_MARKER endKey; |
724 | | - ANTLR3_MARKER startVal; |
| 749 | + ANTLR3_MARKER startVal = 0; |
725 | 750 | bool hasHeight = false; |
726 | 751 | bool hasWidth = false; |
727 | 752 | bool isLink = false; |
728 | | - ANTLR3_MARKER startVal1; |
729 | | - ANTLR3_MARKER endVal1; |
730 | | - ANTLR3_MARKER startVal2; |
731 | | - ANTLR3_MARKER endVal2; |
| 753 | + ANTLR3_MARKER startVal1 = 0; |
| 754 | + ANTLR3_MARKER endVal1 = 0; |
| 755 | + ANTLR3_MARKER startVal2 = 0; |
| 756 | + ANTLR3_MARKER endVal2 = 0; |
732 | 757 | }: |
733 | 758 | { |
734 | | - startKey = GETCHARINDEX(); |
| 759 | + if (*mlOption == NULL) { |
| 760 | + *mlOption = MWMediaLinkOptionNew(); |
| 761 | + } |
735 | 762 | } |
736 | | - ((( 'al' { endKey = GETCHARINDEX(); } 't=' |
737 | | - | 'lin' { endKey = GETCHARINDEX(); isLink = true; } 'k=') |
738 | | - { startVal = GETCHARINDEX(); } (MEDIA_LINK_ATTRIBUTE_VALUE_CHAR | {PEEK(1, ']') && !PEEK(2, ']')}?=> ']')*) |
| 763 | + (((( 'alt=' |
| 764 | + | ('link=' { isLink = true; }) ) |
| 765 | + { startVal = GETCHARINDEX(); } (MEDIA_LINK_OPTION_VALUE_CHAR | {PEEK(1, ']') && !PEEK(2, ']')}?=> ']')*) |
739 | 766 | { |
740 | 767 | pANTLR3_STRING val = SUBSTR1(startVal); |
741 | | - MWKEYVALUE kv = { SUBSTR2(startKey, endKey), val }; |
742 | | - addAttribute(CX, attrs, kv); |
743 | 768 | if (isLink) { |
744 | 769 | *link = val; |
| 770 | + } else { |
| 771 | + (*mlOption)->alt = val; |
745 | 772 | } |
746 | 773 | } |
747 | 774 | ) |
748 | 775 | | (({startVal1 = GETCHARINDEX(); } (({hasWidth=true; endVal1 = GETCHARINDEX();} DECIMAL_DIGIT)* 'x' {hasHeight=true;})? |
749 | 776 | {startVal2 = GETCHARINDEX(); } ({ endVal2 = GETCHARINDEX(); } DECIMAL_DIGIT)+ 'px') |
750 | 777 | { |
751 | | - pANTLR3_STRING width = CX->stringFactory->newStr8(CX->stringFactory, "width"); |
752 | 778 | if (hasHeight) { |
753 | | - pANTLR3_STRING height = CX->stringFactory->newStr8(CX->stringFactory, "height"); |
754 | | - MWKEYVALUE h = { height, SUBSTR2(startVal2, endVal2) }; |
755 | 779 | if (hasWidth) { |
756 | | - MWKEYVALUE w = { width, SUBSTR2(startVal1, endVal1) }; |
757 | | - addAttribute(CX, attrs, w); |
| 780 | + (*mlOption)->width = SUBSTR2(startVal1, endVal1); |
758 | 781 | } |
759 | | - addAttribute(CX, attrs, h); |
| 782 | + (*mlOption)->height = SUBSTR2(startVal2, endVal2); |
760 | 783 | } else { |
761 | | - MWKEYVALUE w = { width, SUBSTR2(startVal2, endVal2) }; |
762 | | - addAttribute(CX, attrs, w); |
| 784 | + |
| 785 | + (*mlOption)->width = SUBSTR2(startVal2, endVal2); |
763 | 786 | } |
764 | 787 | } |
765 | 788 | ) |
| 789 | + ) |
766 | 790 | ; |
767 | 791 | |
768 | 792 | END_INTERNAL_LINK: {!CX->internalLinkCloseDisabled}?=> ']]' |
— | — | @@ -783,8 +807,8 @@ |
784 | 808 | @init{ |
785 | 809 | bool success = true; |
786 | 810 | bool complete = true; |
787 | | - ANTLR3_MARKER urlStart; |
788 | | - ANTLR3_MARKER urlEnd; |
| 811 | + ANTLR3_MARKER urlStart = 0; |
| 812 | + ANTLR3_MARKER urlEnd = 0; |
789 | 813 | }: {!CX->externalLinkOpenDisabled && !alreadyTried(CX, &CX->externalLinkSpeculation)}?=> |
790 | 814 | { |
791 | 815 | speculationInitiate(CX, &CX->externalLinkSpeculation); |
— | — | @@ -798,7 +822,7 @@ |
799 | 823 | pANTLR3_STRING url = SUBSTR2(urlStart, urlEnd); |
800 | 824 | pANTLR3_COMMON_TOKEN token = NEW_TOK(EXTERNAL_LINK, url); |
801 | 825 | token->custom = url; |
802 | | - MWLinkCollectionAdd(CX->linkCollection, MWLT_EXTERNAL, url, token); |
| 826 | + //MWLinkCollectionAdd(CX->linkCollection, MWLT_EXTERNAL, url, token); |
803 | 827 | if (!complete) { |
804 | 828 | token->setType(token, BEGIN_EXTERNAL_LINK); |
805 | 829 | onExternalLinkOpen(CX); |
— | — | @@ -854,7 +878,7 @@ |
855 | 879 | fragment |
856 | 880 | INTERNAL_LINK_TITLE[pANTLR3_STRING *linkTitle] |
857 | 881 | @init{ |
858 | | - ANTLR3_MARKER start; |
| 882 | + ANTLR3_MARKER start = 0; |
859 | 883 | }: |
860 | 884 | { |
861 | 885 | start = GETCHARINDEX(); |
— | — | @@ -868,7 +892,7 @@ |
869 | 893 | fragment |
870 | 894 | INTERNAL_LINK_ANCHOR[pANTLR3_STRING *linkAnchor] |
871 | 895 | @init{ |
872 | | - ANTLR3_MARKER start; |
| 896 | + ANTLR3_MARKER start = 0; |
873 | 897 | }: |
874 | 898 | { |
875 | 899 | start = GETCHARINDEX(); |
— | — | @@ -881,7 +905,7 @@ |
882 | 906 | |
883 | 907 | HTML_ENTITY |
884 | 908 | @init{ |
885 | | - ANTLR3_MARKER mark; |
| 909 | + ANTLR3_MARKER mark = 0; |
886 | 910 | bool success = false; |
887 | 911 | }: |
888 | 912 | '&' |
— | — | @@ -940,8 +964,8 @@ |
941 | 965 | |
942 | 966 | HTML_OPEN_TAG |
943 | 967 | @init{ |
944 | | - ANTLR3_MARKER bodyStart; |
945 | | - ANTLR3_MARKER bodyEnd; |
| 968 | + ANTLR3_MARKER bodyStart = 0; |
| 969 | + ANTLR3_MARKER bodyEnd = 0; |
946 | 970 | CX->inHtmlPre = false; |
947 | 971 | CX->inNowiki = false; |
948 | 972 | pANTLR3_VECTOR attrs = NULL; |
— | — | @@ -978,17 +1002,17 @@ |
979 | 1003 | fragment |
980 | 1004 | TAG_EXTENSION |
981 | 1005 | @init{ |
982 | | - ANTLR3_MARKER mark; |
983 | | - ANTLR3_MARKER nameStart; |
984 | | - ANTLR3_MARKER nameEnd; |
985 | | - ANTLR3_MARKER bodyStart; |
986 | | - ANTLR3_MARKER bodyEnd; |
| 1006 | + ANTLR3_MARKER mark = 0; |
| 1007 | + ANTLR3_MARKER nameStart = 0; |
| 1008 | + ANTLR3_MARKER nameEnd = 0; |
| 1009 | + ANTLR3_MARKER bodyStart = 0; |
| 1010 | + ANTLR3_MARKER bodyEnd = 0; |
987 | 1011 | bool success = true; |
988 | 1012 | bool empty = false; |
989 | 1013 | pANTLR3_STRING name; |
990 | 1014 | pANTLR3_VECTOR attr = NULL; |
991 | 1015 | pANTLR3_STRING body = NULL; |
992 | | - MWPARSER_TAGEXT *tagExt; |
| 1016 | + MWPARSER_TAGEXT *tagExt = NULL; |
993 | 1017 | }: |
994 | 1018 | { |
995 | 1019 | mark = MARK(); |
— | — | @@ -1031,9 +1055,9 @@ |
1032 | 1056 | fragment |
1033 | 1057 | TAG_EXTENSION_BODY[pANTLR3_STRING name, ANTLR3_MARKER *bodyEnd] |
1034 | 1058 | @init{ |
1035 | | - ANTLR3_MARKER start; |
1036 | | - ANTLR3_MARKER end; |
1037 | | - ANTLR3_MARKER tmpBodyEnd; |
| 1059 | + ANTLR3_MARKER start = 0; |
| 1060 | + ANTLR3_MARKER end = 0; |
| 1061 | + ANTLR3_MARKER tmpBodyEnd = 0; |
1038 | 1062 | }: |
1039 | 1063 | (('</' ((LETTER)=> LETTER)+)=> '</' {start = GETCHARINDEX();} ((LETTER)=> {tmpBodyEnd = end = GETCHARINDEX();} LETTER)+ ((SPACE_TAB_CHAR)=> {tmpBodyEnd = GETCHARINDEX();} SPACE_TAB_CHAR)* |
1040 | 1064 | (('>')=> '>' ({name->compareS(name, SUBSTR2(start, end)) == 0}?=> | {*bodyEnd = tmpBodyEnd;} TAG_EXTENSION_BODY[name, bodyEnd]) |
— | — | @@ -1131,7 +1155,7 @@ |
1132 | 1156 | |
1133 | 1157 | HTML_CLOSE_TAG |
1134 | 1158 | @init{ |
1135 | | - ANTLR3_MARKER endHeadingText; |
| 1159 | + ANTLR3_MARKER endHeadingText = 0; |
1136 | 1160 | }: |
1137 | 1161 | { |
1138 | 1162 | endHeadingText = GETCHARINDEX(); |
— | — | @@ -1239,7 +1263,7 @@ |
1240 | 1264 | ATTRIBUTE_LIST_TABLE[pANTLR3_VECTOR *attrs] |
1241 | 1265 | @init{ |
1242 | 1266 | MWKEYVALUE attr; |
1243 | | - bool success; |
| 1267 | + bool success = false; |
1244 | 1268 | }: |
1245 | 1269 | SKIP_SPACE |
1246 | 1270 | ( |
— | — | @@ -1264,8 +1288,8 @@ |
1265 | 1289 | ATTRIBUTE_LIST_TABLE_CELL[pANTLR3_VECTOR *attrs] |
1266 | 1290 | @init{ |
1267 | 1291 | MWKEYVALUE attr; |
1268 | | - bool success; |
1269 | | - ANTLR3_MARKER mark; |
| 1292 | + bool success = false; |
| 1293 | + ANTLR3_MARKER mark = 0; |
1270 | 1294 | }: |
1271 | 1295 | { |
1272 | 1296 | mark = MARK(); |
— | — | @@ -1304,7 +1328,7 @@ |
1305 | 1329 | ATTRIBUTE_LIST_HTML[pANTLR3_VECTOR *attrs] |
1306 | 1330 | @init{ |
1307 | 1331 | MWKEYVALUE attr; |
1308 | | - bool success; |
| 1332 | + bool success = false; |
1309 | 1333 | }: |
1310 | 1334 | ( |
1311 | 1335 | ( |
— | — | @@ -1340,7 +1364,7 @@ |
1341 | 1365 | fragment |
1342 | 1366 | ATTRIBUTE_NAME[pANTLR3_STRING *name] |
1343 | 1367 | @init{ |
1344 | | - ANTLR3_MARKER start; |
| 1368 | + ANTLR3_MARKER start = 0; |
1345 | 1369 | }: |
1346 | 1370 | { start = GETCHARINDEX(); } |
1347 | 1371 | (('xml:')=>'xml:'|('xmlns:')=>'xmlns:')? (LETTER|DECIMAL_DIGIT)+ |
— | — | @@ -1348,7 +1372,10 @@ |
1349 | 1373 | ; |
1350 | 1374 | |
1351 | 1375 | fragment |
1352 | | -ATTRIBUTE_VALUE[pANTLR3_STRING *value] @init{ ANTLR3_MARKER start; }: |
| 1376 | +ATTRIBUTE_VALUE[pANTLR3_STRING *value] |
| 1377 | +@init{ |
| 1378 | + ANTLR3_MARKER start = 0; |
| 1379 | +}: |
1353 | 1380 | ( |
1354 | 1381 | ('"' |
1355 | 1382 | { start = GETCHARINDEX(); } |
— | — | @@ -1420,7 +1447,7 @@ |
1421 | 1448 | fragment NON_WHITESPACE_OR_BAR_OR_OPEN_BRACKET_CHAR: ~(SPACE_TAB_CHAR | NEWLINE_CHAR | '|' | '[' |'!'| |
1422 | 1449 | '-'| |
1423 | 1450 | '}'); |
1424 | | -fragment MEDIA_LINK_ATTRIBUTE_VALUE_CHAR: ~(NON_PRINTABLE_CHAR|'|'|']'); |
| 1451 | +fragment MEDIA_LINK_OPTION_VALUE_CHAR: ~(NON_PRINTABLE_CHAR|'|'|']'); |
1425 | 1452 | fragment SKIP_SPACE: ((SPACE_TAB_CHAR)=> SPACE_TAB_CHAR)*; |
1426 | 1453 | fragment LETTER: UCASE_LETTER | LCASE_LETTER; |
1427 | 1454 | fragment HTML_ENTITY_CHARS: HTML_ENTITY_CHAR+; |
Index: trunk/parsers/libmwparser/src/mwlistener.template |
— | — | @@ -2,6 +2,7 @@ |
3 | 3 | #include <mwkeyvalue.h> |
4 | 4 | #include <mwlistener.h> |
5 | 5 | #include <wchar.h> |
| 6 | +#include <mwlinkresolution.h> |
6 | 7 | |
7 | 8 | /* |
8 | 9 | * A note on memory management: All parameters of type pANTLR3_STRING |
— | — | @@ -73,15 +74,15 @@ |
74 | 75 | static void PREFIX`EndHtmlBlockquote'(MWLISTENER *listener); |
75 | 76 | static void PREFIX`BeginHtmlCenter'(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
76 | 77 | static void PREFIX`EndHtmlCenter'(MWLISTENER *listener); |
77 | | -static void PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 78 | +static void PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
78 | 79 | static void PREFIX`EndInternalLink'(MWLISTENER *listener); |
79 | | -static void PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 80 | +static void PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
80 | 81 | static void PREFIX`BeginExternalLink'(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
81 | 82 | static void PREFIX`EndExternalLink'(MWLISTENER *listener); |
82 | 83 | static void PREFIX`OnExternalLink'(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
83 | | -static void PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 84 | +static void PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr); |
84 | 85 | static void PREFIX`EndMediaLink'(MWLISTENER *listener); |
85 | | -static void PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 86 | +static void PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr); |
86 | 87 | static void PREFIX`OnTagExtension'(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr); |
87 | 88 | static void PREFIX`BeginHtmlU'(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
88 | 89 | static void PREFIX`EndHtmlU'(MWLISTENER *listener); |
— | — | @@ -142,6 +143,19 @@ |
143 | 144 | .newData = PREFIX`New', |
144 | 145 | .freeData = PREFIX`Free', |
145 | 146 | .resetData = PREFIX`Reset', |
| 147 | + /** |
| 148 | + * If the listener provides a link resolver implementation, |
| 149 | + * it will be called after the lexer is done, before the parser |
| 150 | + * runs. |
| 151 | + * |
| 152 | + * The link resolver should use the link collection API to walk |
| 153 | + * the link collection and fill out the missing information |
| 154 | + * about the links. If this is done, the listener will directly obtain |
| 155 | + * the information about the links in the relevant methods. (I.e., |
| 156 | + * beginInternalLink, onInternalLink, beginMediaLink, and onMediaLink). |
| 157 | + */ |
| 158 | + .linkResolver = NULL, |
| 159 | + .setLinkResolverData = NULL, |
146 | 160 | .getResult = PREFIX`GetResult', |
147 | 161 | .onWord = PREFIX`OnWord', |
148 | 162 | .onSpecial = PREFIX`OnSpecial', |
— | — | @@ -506,11 +520,19 @@ |
507 | 521 | * link targetting the page with the given title. |
508 | 522 | * |
509 | 523 | * @param listener |
510 | | - * @param linkTitle |
| 524 | + * @param attr The link does not take any actual attributes, but |
| 525 | + * the ordinary arguments are packed into the attribute vector |
| 526 | + * in the order linkTitle, linkAnchor, linkTitle |
511 | 527 | */ |
512 | 528 | static void |
513 | | -PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 529 | +PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attr) |
514 | 530 | { |
| 531 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 532 | + attr->remove(attr, attr->count - 1); |
| 533 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 534 | + attr->remove(attr, attr->count - 1); |
| 535 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 536 | + attr->remove(attr, attr->count - 1); |
515 | 537 | } |
516 | 538 | |
517 | 539 | /** |
— | — | @@ -530,11 +552,19 @@ |
531 | 553 | * TODO: pass link trail and prefix as arguments to this method. |
532 | 554 | * |
533 | 555 | * @param listener |
534 | | - * @param linkTitle |
| 556 | + * @param attr The link does not take any actual attributes, but |
| 557 | + * the ordinary arguments are packed into the attribute vector |
| 558 | + * in the order linkTitle, linkAnchor, linkTitle |
535 | 559 | */ |
536 | 560 | static void |
537 | | -PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 561 | +PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attr) |
538 | 562 | { |
| 563 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 564 | + attr->remove(attr, attr->count - 1); |
| 565 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 566 | + attr->remove(attr, attr->count - 1); |
| 567 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 568 | + attr->remove(attr, attr->count - 1); |
539 | 569 | } |
540 | 570 | |
541 | 571 | /** |
— | — | @@ -581,12 +611,21 @@ |
582 | 612 | * Also, note that media links may nest one level. |
583 | 613 | * |
584 | 614 | * @param listener |
585 | | - * @param linkTitle |
586 | | - * @param attr |
| 615 | + * @param attr In the attribute vector additional parameters are |
| 616 | + * packed in the order attributes, linkTitle, linkAnchor, |
| 617 | + * linkResolution, attributeLinkResolution. |
587 | 618 | */ |
588 | 619 | static void |
589 | | -PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr) |
| 620 | +PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr) |
590 | 621 | { |
| 622 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 623 | + attr->remove(attr, attr->count - 1); |
| 624 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 625 | + attr->remove(attr, attr->count - 1); |
| 626 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 627 | + attr->remove(attr, attr->count - 1); |
| 628 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 629 | + attr->remove(attr, attr->count - 1); |
591 | 630 | } |
592 | 631 | |
593 | 632 | /** |
— | — | @@ -606,12 +645,21 @@ |
607 | 646 | * for PREFIX`BeginMediaLink'. |
608 | 647 | * |
609 | 648 | * @param listener |
610 | | - * @param linkTitle |
611 | | - * @param attr |
| 649 | + * @param attr In the attribute vector additional parameters are |
| 650 | + * packed in the order attributes, linkTitle, linkAnchor, |
| 651 | + * linkResolution, attributeLinkResolution. |
612 | 652 | */ |
613 | 653 | static void |
614 | | -PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr) |
| 654 | +PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr) |
615 | 655 | { |
| 656 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 657 | + attr->remove(attr, attr->count - 1); |
| 658 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 659 | + attr->remove(attr, attr->count - 1); |
| 660 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 661 | + attr->remove(attr, attr->count - 1); |
| 662 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 663 | + attr->remove(attr, attr->count - 1); |
616 | 664 | } |
617 | 665 | |
618 | 666 | /** |
Index: trunk/parsers/libmwparser/src/mwlinks.c |
— | — | @@ -1,10 +1,11 @@ |
2 | 2 | #include <antlr3.h> |
3 | 3 | #include <mwparsercontext.h> |
4 | 4 | #include <mwlinks.h> |
| 5 | +#include <mwlinkresolution.h> |
5 | 6 | |
6 | | -static void beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle); |
| 7 | +static void beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr); |
7 | 8 | static void endInternalLink(MWPARSERCONTEXT *context); |
8 | | -static void onInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle); |
| 9 | +static void onInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr); |
9 | 10 | static void beginExternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkUrl); |
10 | 11 | static void endExternalLink(MWPARSERCONTEXT *context); |
11 | 12 | static void onExternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkUrl); |
— | — | @@ -13,12 +14,22 @@ |
14 | 15 | static void onMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr); |
15 | 16 | |
16 | 17 | static void |
17 | | -beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle) |
| 18 | +beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr) |
18 | 19 | { |
19 | | - MW_DELAYED_CALL( context, beginInternalLink, endInternalLink, linkTitle, false); |
20 | | - MW_BEGIN_ORDERED_FORMAT(context, beginInternalLink, endInternalLink, linkTitle, false); |
| 20 | + MW_DELAYED_CALL( context, beginInternalLink, endInternalLink, attr, false); |
| 21 | + MW_BEGIN_ORDERED_FORMAT(context, beginInternalLink, endInternalLink, attr, false); |
21 | 22 | MWLISTENER *l = &context->listener; |
22 | | - l->beginInternalLink(l, linkTitle); |
| 23 | + /* |
| 24 | + * Since this is a long term format, this call may be repeated |
| 25 | + * several times. Since the client will want to unpack the |
| 26 | + * attribute vector, we'll make a copy of it. |
| 27 | + */ |
| 28 | + pANTLR3_VECTOR v = context->vectorFactory->newVector(context->vectorFactory); |
| 29 | + int i; |
| 30 | + for (i = 0; i < attr->count ; i++) { |
| 31 | + v->add(v, attr->get(attr, i), NULL); |
| 32 | + } |
| 33 | + l->beginInternalLink(l, v); |
23 | 34 | } |
24 | 35 | |
25 | 36 | static void |
— | — | @@ -31,11 +42,16 @@ |
32 | 43 | } |
33 | 44 | |
34 | 45 | static void |
35 | | -onInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle) |
| 46 | +onInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr) |
36 | 47 | { |
37 | 48 | MW_TRIGGER_DELAYED_CALLS(context); |
| 49 | + pANTLR3_VECTOR v = context->vectorFactory->newVector(context->vectorFactory); |
| 50 | + int i; |
| 51 | + for (i = 0; i < attr->count ; i++) { |
| 52 | + v->add(v, attr->get(attr, i), NULL); |
| 53 | + } |
38 | 54 | MWLISTENER *l = &context->listener; |
39 | | - l->onInternalLink(l, linkTitle); |
| 55 | + l->onInternalLink(l, v); |
40 | 56 | } |
41 | 57 | |
42 | 58 | static void |
— | — | @@ -67,11 +83,9 @@ |
68 | 84 | static void |
69 | 85 | beginMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr) |
70 | 86 | { |
71 | | - context->tempCloseFormats(context); |
72 | | - pANTLR3_STRING linkUrl = attr->get(attr, attr->count - 1); |
73 | | - attr->remove(attr, attr->count - 1); |
| 87 | + MW_TRIGGER_DELAYED_CALLS(context); |
74 | 88 | MWLISTENER *l = &context->listener; |
75 | | - l->beginMediaLink(l, linkUrl, attr); |
| 89 | + l->beginMediaLink(l, attr); |
76 | 90 | context->tempReopenFormats(context); |
77 | 91 | } |
78 | 92 | |
— | — | @@ -88,10 +102,8 @@ |
89 | 103 | onMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr) |
90 | 104 | { |
91 | 105 | MW_TRIGGER_DELAYED_CALLS(context); |
92 | | - pANTLR3_STRING linkUrl = attr->get(attr, attr->count - 1); |
93 | | - attr->remove(attr, attr->count - 1); |
94 | 106 | MWLISTENER *l = &context->listener; |
95 | | - l->onMediaLink(l, linkUrl, attr); |
| 107 | + l->onMediaLink(l, attr); |
96 | 108 | } |
97 | 109 | |
98 | 110 | |
Index: trunk/parsers/libmwparser/src/mwlinkresolution.c |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +#include <stdlib.h> |
| 3 | +#include <mwlinkresolution.h> |
| 4 | + |
| 5 | +void MWLinkResolutionFree(void *linkResolution) |
| 6 | +{ |
| 7 | + MWLINKRESOLUTION *lr = linkResolution; |
| 8 | + lr->free(lr->freeData); |
| 9 | +} |
Index: trunk/parsers/libmwparser/src/mwlexercontext.c |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | static void mwFreeStringConversionState(void *state); |
41 | 41 | static bool setLegalTitleRegexp(MWLEXERCONTEXT *context, const char *perlRegexp); |
42 | 42 | static bool setMediaLinkTitleRegexp(MWLEXERCONTEXT *context, const char *perlRegexp); |
| 43 | +static void resolveLinks(MWLEXERCONTEXT *context); |
43 | 44 | |
44 | 45 | MWLEXERCONTEXT *MWLexerContextNew(pANTLR3_LEXER lexer) |
45 | 46 | { |
— | — | @@ -122,6 +123,9 @@ |
123 | 124 | context->registerTagExtension = registerTagExtension; |
124 | 125 | context->setLegalTitleRegexp = setLegalTitleRegexp; |
125 | 126 | context->setMediaLinkTitleRegexp = setMediaLinkTitleRegexp; |
| 127 | + context->resolveLinks = resolveLinks; |
| 128 | + context->linkResolver = NULL; |
| 129 | + context->linkResolverData = NULL; |
126 | 130 | |
127 | 131 | if (!context->reset(context)) { |
128 | 132 | context->free(context); |
— | — | @@ -448,3 +452,12 @@ |
449 | 453 | |
450 | 454 | return true; |
451 | 455 | } |
| 456 | + |
| 457 | +static void |
| 458 | +resolveLinks(MWLEXERCONTEXT *context) |
| 459 | +{ |
| 460 | + if (context->linkResolver != NULL |
| 461 | + && MWLinkCollectionNumLinks(context->linkCollection) > 0) { |
| 462 | + context->linkResolver(context->linkCollection, context->linkResolverData); |
| 463 | + } |
| 464 | +} |
Index: trunk/parsers/libmwparser/src/mwmedialinkoption.c |
— | — | @@ -0,0 +1,28 @@ |
| 2 | +#include <antlr3.h> |
| 3 | +#include <mwmedialinkoption.h> |
| 4 | + |
| 5 | +MEDIALINKOPTION * MWMediaLinkOptionNew(void) |
| 6 | +{ |
| 7 | + MEDIALINKOPTION *option = ANTLR3_MALLOC(sizeof(*option)); |
| 8 | + if (option == NULL) { |
| 9 | + return NULL; |
| 10 | + } |
| 11 | + |
| 12 | + option->frame = LOF_NONE; |
| 13 | + option->halign = LOHA_NONE; |
| 14 | + option->valign = LOVA_NONE; |
| 15 | + option->upright = false; |
| 16 | + option->border = false; |
| 17 | + option->alt = NULL; |
| 18 | + option->width = NULL; |
| 19 | + option->height = NULL; |
| 20 | + |
| 21 | + return option; |
| 22 | +} |
| 23 | + |
| 24 | +void MWMediaLinkOptionFree(void *mediaLinkOption) |
| 25 | +{ |
| 26 | + if (mediaLinkOption != NULL) { |
| 27 | + ANTLR3_FREE(mediaLinkOption); |
| 28 | + } |
| 29 | +} |
Index: trunk/parsers/libmwparser/src/tracingcontext.c |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | #include <tracingcontext.h> |
23 | 23 | #include <mwkeyvalue.h> |
24 | 24 | #include <wchar.h> |
| 25 | +#include <mwlinkresolution.h> |
| 26 | +#include <mwmedialinkoption.h> |
25 | 27 | |
26 | 28 | static const int INDENT_SPACES = 4; |
27 | 29 | |
— | — | @@ -81,15 +83,15 @@ |
82 | 84 | static void TCEndHtmlBlockquote(MWLISTENER *listener); |
83 | 85 | static void TCBeginHtmlCenter(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
84 | 86 | static void TCEndHtmlCenter(MWLISTENER *listener); |
85 | | -static void TCBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 87 | +static void TCBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
86 | 88 | static void TCEndInternalLink(MWLISTENER *listener); |
87 | | -static void TCOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 89 | +static void TCOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
88 | 90 | static void TCBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
89 | 91 | static void TCEndExternalLink(MWLISTENER *listener); |
90 | 92 | static void TCOnExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
91 | | -static void TCBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 93 | +static void TCBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
92 | 94 | static void TCEndMediaLink(MWLISTENER *listener); |
93 | | -static void TCOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 95 | +static void TCOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
94 | 96 | static void TCOnTagExtension(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr); |
95 | 97 | static void TCBeginHtmlU(MWLISTENER *listener, pANTLR3_VECTOR attributes); |
96 | 98 | static void TCEndHtmlU(MWLISTENER *listener); |
— | — | @@ -129,6 +131,7 @@ |
130 | 132 | static void TCFree(void *tcontext); |
131 | 133 | |
132 | 134 | static void TCPrintAttributes(pANTLR3_VECTOR attributes); |
| 135 | +static void TCPrintMediaLinkOptions(MEDIALINKOPTION *mlOption); |
133 | 136 | static void TCPrintIndent(MWLISTENER *listener); |
134 | 137 | static void TCIncreaseIndent(MWLISTENER *listener); |
135 | 138 | static void TCDecreaseIndent(MWLISTENER *listener); |
— | — | @@ -153,6 +156,8 @@ |
154 | 157 | .newData = TCNew, |
155 | 158 | .freeData = TCFree, |
156 | 159 | .resetData = NULL, |
| 160 | + .linkResolver = NULL, |
| 161 | + .setLinkResolverData = NULL, |
157 | 162 | .onWord = TCOnWord, |
158 | 163 | .onSpecial = TCOnSpecial, |
159 | 164 | .onSpace = TCOnSpace, |
— | — | @@ -416,8 +421,14 @@ |
417 | 422 | } |
418 | 423 | |
419 | 424 | static void |
420 | | -TCBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 425 | +TCBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
421 | 426 | { |
| 427 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 428 | + attr->remove(attr, attr->count - 1); |
| 429 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 430 | + attr->remove(attr, attr->count - 1); |
| 431 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 432 | + attr->remove(attr, attr->count - 1); |
422 | 433 | TCPrintIndent(listener); |
423 | 434 | printf("BEGIN INTERNAL LINK[%s]\n", linkTitle->chars); |
424 | 435 | TCIncreaseIndent(listener); |
— | — | @@ -432,8 +443,14 @@ |
433 | 444 | } |
434 | 445 | |
435 | 446 | static void |
436 | | -TCOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 447 | +TCOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
437 | 448 | { |
| 449 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 450 | + attr->remove(attr, attr->count - 1); |
| 451 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 452 | + attr->remove(attr, attr->count - 1); |
| 453 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 454 | + attr->remove(attr, attr->count - 1); |
438 | 455 | TCPrintIndent(listener); |
439 | 456 | printf("INTERNAL LINK[%s]\n", linkTitle->chars); |
440 | 457 | } |
— | — | @@ -462,11 +479,20 @@ |
463 | 480 | } |
464 | 481 | |
465 | 482 | static void |
466 | | -TCBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr) |
| 483 | +TCBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
467 | 484 | { |
| 485 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 486 | + attr->remove(attr, attr->count - 1); |
| 487 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 488 | + attr->remove(attr, attr->count - 1); |
| 489 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 490 | + attr->remove(attr, attr->count - 1); |
| 491 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 492 | + attr->remove(attr, attr->count - 1); |
| 493 | + MEDIALINKOPTION *mlOption = attr->get(attr, attr->count - 1); |
468 | 494 | TCPrintIndent(listener); |
469 | | - printf("BEGIN MEDIA LINK[%s]", linkUrl->chars); |
470 | | - TCPrintAttributes(attr); |
| 495 | + printf("BEGIN MEDIA LINK[%s]", linkTitle->chars); |
| 496 | + TCPrintMediaLinkOptions(mlOption); |
471 | 497 | printf("\n"); |
472 | 498 | TCIncreaseIndent(listener); |
473 | 499 | } |
— | — | @@ -480,10 +506,18 @@ |
481 | 507 | } |
482 | 508 | |
483 | 509 | static void |
484 | | -TCOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr) |
| 510 | +TCOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
485 | 511 | { |
| 512 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 513 | + attr->remove(attr, attr->count - 1); |
| 514 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 515 | + attr->remove(attr, attr->count - 1); |
| 516 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 517 | + attr->remove(attr, attr->count - 1); |
| 518 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 519 | + attr->remove(attr, attr->count - 1); |
486 | 520 | TCPrintIndent(listener); |
487 | | - printf("MEDIA LINK[%s]", linkUrl->chars); |
| 521 | + printf("MEDIA LINK[%s]", linkTitle->chars); |
488 | 522 | TCPrintAttributes(attr); |
489 | 523 | printf("\n"); |
490 | 524 | } |
— | — | @@ -685,6 +719,101 @@ |
686 | 720 | } |
687 | 721 | |
688 | 722 | static void |
| 723 | +TCPrintMediaLinkOptions(MEDIALINKOPTION *mlOption) |
| 724 | +{ |
| 725 | + if (mlOption != NULL) { |
| 726 | + const char *frame; |
| 727 | + switch (mlOption->frame) { |
| 728 | + case LOF_NONE: |
| 729 | + frame = "none"; |
| 730 | + break; |
| 731 | + case LOF_FRAME: |
| 732 | + frame = "frame"; |
| 733 | + break; |
| 734 | + case LOF_FRAMELESS: |
| 735 | + frame = "frameless"; |
| 736 | + break; |
| 737 | + case LOF_THUMBNAIL: |
| 738 | + frame = "thumbnail"; |
| 739 | + break; |
| 740 | + default: |
| 741 | + frame = "invalid"; |
| 742 | + break; |
| 743 | + } |
| 744 | + |
| 745 | + const char *halign; |
| 746 | + switch(mlOption->halign) { |
| 747 | + case LOHA_NONE: |
| 748 | + halign = "none"; |
| 749 | + break; |
| 750 | + case LOHA_LEFT: |
| 751 | + halign = "left"; |
| 752 | + break; |
| 753 | + case LOHA_RIGHT: |
| 754 | + halign = "right"; |
| 755 | + break; |
| 756 | + case LOHA_CENTER: |
| 757 | + halign = "center"; |
| 758 | + break; |
| 759 | + default: |
| 760 | + halign = "illegal"; |
| 761 | + break; |
| 762 | + } |
| 763 | + |
| 764 | + const char *valign; |
| 765 | + switch (mlOption->valign) { |
| 766 | + case LOVA_NONE: |
| 767 | + valign = "none"; |
| 768 | + break; |
| 769 | + case LOVA_BASELINE: |
| 770 | + valign = "baseline"; |
| 771 | + break; |
| 772 | + case LOVA_SUB: |
| 773 | + valign = "sub"; |
| 774 | + break; |
| 775 | + case LOVA_SUPER: |
| 776 | + valign = "super"; |
| 777 | + break; |
| 778 | + case LOVA_TOP: |
| 779 | + valign = "top"; |
| 780 | + break; |
| 781 | + case LOVA_TEXT_TOP: |
| 782 | + valign = "text-top"; |
| 783 | + break; |
| 784 | + case LOVA_MIDDLE: |
| 785 | + valign = "middle"; |
| 786 | + break; |
| 787 | + case LOVA_BOTTOM: |
| 788 | + valign = "bottom"; |
| 789 | + break; |
| 790 | + case LOVA_TEXT_BOTTOM: |
| 791 | + valign = "text-bottom"; |
| 792 | + break; |
| 793 | + default: |
| 794 | + valign = "illegal"; |
| 795 | + break; |
| 796 | + } |
| 797 | + |
| 798 | + printf("frame: %s, halign: %s, valign: %s", frame, halign, valign); |
| 799 | + if (mlOption->upright) { |
| 800 | + printf(", upright"); |
| 801 | + } |
| 802 | + if (mlOption->border) { |
| 803 | + printf(", border"); |
| 804 | + } |
| 805 | + if (mlOption->alt != NULL) { |
| 806 | + printf(", alt='%s'", mlOption->alt->chars); |
| 807 | + } |
| 808 | + if (mlOption->width != NULL) { |
| 809 | + printf(", width: %s", mlOption->width->chars); |
| 810 | + } |
| 811 | + if (mlOption->height != NULL) { |
| 812 | + printf(", height: %s", mlOption->height->chars); |
| 813 | + } |
| 814 | + } |
| 815 | +} |
| 816 | + |
| 817 | +static void |
689 | 818 | TCBeginTable(MWLISTENER *listener, pANTLR3_VECTOR attributes) |
690 | 819 | { |
691 | 820 | TCPrintIndent(listener); |
— | — | @@ -1193,4 +1322,3 @@ |
1194 | 1323 | TC(listener)->indent -= INDENT_SPACES; |
1195 | 1324 | } |
1196 | 1325 | |
1197 | | - |
Index: trunk/parsers/libmwparser/src/mwWikitextParser.g |
— | — | @@ -556,22 +556,26 @@ |
557 | 557 | |
558 | 558 | begin_table_of_contents_item: |
559 | 559 | (h = BEGIN_HEADING { CX->beginTableOfContentsItem(CX, $h->HEADING_LEVEL, $h->getText($h)); }) |
| 560 | +/* |
560 | 561 | | (h = HTML_H1_OPEN { CX->beginTableOfContentsItem(CX, 1, $h->getText($h)); }) |
561 | 562 | | (h = HTML_H2_OPEN { CX->beginTableOfContentsItem(CX, 2, $h->getText($h)); }) |
562 | 563 | | (h = HTML_H3_OPEN { CX->beginTableOfContentsItem(CX, 3, $h->getText($h)); }) |
563 | 564 | | (h = HTML_H4_OPEN { CX->beginTableOfContentsItem(CX, 4, $h->getText($h)); }) |
564 | 565 | | (h = HTML_H5_OPEN { CX->beginTableOfContentsItem(CX, 5, $h->getText($h)); }) |
565 | 566 | | (h = HTML_H6_OPEN { CX->beginTableOfContentsItem(CX, 6, $h->getText($h)); }) |
| 567 | +*/ |
566 | 568 | ; |
567 | 569 | |
568 | 570 | end_table_of_contents_item: |
569 | 571 | (END_HEADING { CX->endTableOfContentsItem(CX); }) |
| 572 | +/* |
570 | 573 | |(((HTML_H1_CLOSE { CX->endTableOfContentsItem(CX); }) |
571 | 574 | | (HTML_H2_CLOSE { CX->endTableOfContentsItem(CX); }) |
572 | 575 | | (HTML_H3_CLOSE { CX->endTableOfContentsItem(CX); }) |
573 | 576 | | (HTML_H4_CLOSE { CX->endTableOfContentsItem(CX); }) |
574 | 577 | | (HTML_H5_CLOSE { CX->endTableOfContentsItem(CX); }) |
575 | 578 | | (HTML_H6_CLOSE { CX->endTableOfContentsItem(CX); }))|EOF) |
| 579 | +*/ |
576 | 580 | ; |
577 | 581 | |
578 | 582 | link_element: internal_link | external_link | media_link |
Index: trunk/parsers/libmwparser/src/mwparser.c |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | return NULL; |
60 | 60 | } |
61 | 61 | |
62 | | - mwparser->parserContext = MWParserContextNew(parser, listener); |
| 62 | + mwparser->parserContext = MWParserContextNew(parser, listener, mwparser->lexerContext); |
63 | 63 | if (mwparser->parserContext == NULL) { |
64 | 64 | MWParserFree(mwparser); |
65 | 65 | return NULL; |
Index: trunk/parsers/libmwparser/src/mwparsercontext.c |
— | — | @@ -26,6 +26,7 @@ |
27 | 27 | #include <mwheadings.h> |
28 | 28 | #include <mwhtml.h> |
29 | 29 | #include <mwlinks.h> |
| 30 | +#include <mwlexercontext.h> |
30 | 31 | #include <assert.h> |
31 | 32 | #include "mwWikitextParser.h" |
32 | 33 | |
— | — | @@ -130,7 +131,7 @@ |
131 | 132 | } |
132 | 133 | |
133 | 134 | |
134 | | -MWPARSERCONTEXT * MWParserContextNew(void * parser, const MWLISTENER *listener) |
| 135 | +MWPARSERCONTEXT * MWParserContextNew(void * parser, const MWLISTENER *listener, MWLEXERCONTEXT *lexerContext) |
135 | 136 | { |
136 | 137 | MWPARSERCONTEXT *context = ANTLR3_MALLOC(sizeof(*context)); |
137 | 138 | pmwWikitextParser psr = parser; |
— | — | @@ -214,6 +215,14 @@ |
215 | 216 | NULL_FAIL(context->listener.data); |
216 | 217 | } |
217 | 218 | |
| 219 | + if (context->listener.setLinkResolverData != NULL) { |
| 220 | + context->listener.setLinkResolverData(context->listener.data, &lexerContext->linkResolverData); |
| 221 | + } |
| 222 | + |
| 223 | + if (context->listener.linkResolver != NULL) { |
| 224 | + lexerContext->linkResolver = context->listener.linkResolver; |
| 225 | + } |
| 226 | + |
218 | 227 | context->reset(context); |
219 | 228 | |
220 | 229 | return context; |
Index: trunk/parsers/libmwparser/src/mwlinkcollection.c |
— | — | @@ -1,3 +1,22 @@ |
| 2 | +/* |
| 3 | + * Copyright 2010 Andreas Jonsson |
| 4 | + * |
| 5 | + * This file is part of libmwparser. |
| 6 | + * |
| 7 | + * Libmwparser is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
2 | 21 | #include <glib.h> |
3 | 22 | #include <antlr3.h> |
4 | 23 | #include <mwlinkcollection.h> |
— | — | @@ -10,7 +29,7 @@ |
11 | 30 | GList *tokens; |
12 | 31 | }; |
13 | 32 | |
14 | | -typedef struct { |
| 33 | +typedef struct LCKEY_struct { |
15 | 34 | MWLINKTYPE type; |
16 | 35 | pANTLR3_STRING linkTitle; |
17 | 36 | } LCKEY; |
— | — | @@ -52,7 +71,7 @@ |
53 | 72 | return strncmp((char *)k1->linkTitle->chars, (char *)k2->linkTitle->chars, k1->linkTitle->len); |
54 | 73 | } |
55 | 74 | |
56 | | -typedef struct { |
| 75 | +typedef struct LCVAL_struct { |
57 | 76 | GList *tokenList; |
58 | 77 | } LCVAL; |
59 | 78 | |
— | — | @@ -134,7 +153,7 @@ |
135 | 154 | lckeyFree(key); |
136 | 155 | key = origKey; |
137 | 156 | } |
138 | | - val->tokenList = g_list_prepend(val->tokenList, val); |
| 157 | + val->tokenList = g_list_prepend(val->tokenList, token); |
139 | 158 | collection->tokens = g_list_prepend(collection->tokens, val->tokenList); |
140 | 159 | g_tree_insert(collection->inverseTree, val->tokenList, key); |
141 | 160 | } |
— | — | @@ -166,3 +185,70 @@ |
167 | 186 | } while(!last); |
168 | 187 | } |
169 | 188 | |
| 189 | +struct CALLBACKDATA { |
| 190 | + int (*callback)(MWLCKEY *key, void *data); |
| 191 | + void *data; |
| 192 | +}; |
| 193 | + |
| 194 | +static gboolean |
| 195 | +callCallback(gpointer key, gpointer value, gpointer data) |
| 196 | +{ |
| 197 | + struct CALLBACKDATA *cb = data; |
| 198 | + return cb->callback(key, cb->data); |
| 199 | +} |
| 200 | + |
| 201 | +void |
| 202 | +MWLinkCollectionTraverse(MWLINKCOLLECTION *linkCollection, |
| 203 | + int (*callback)(MWLCKEY *key, void *data), |
| 204 | + void *callbackData) |
| 205 | +{ |
| 206 | + struct CALLBACKDATA cb = { callback, callbackData }; |
| 207 | + g_tree_traverse(linkCollection->tree, callCallback, G_IN_ORDER, &cb); |
| 208 | +} |
| 209 | + |
| 210 | +static void setMediaLinkResolution(gpointer data, gpointer userdata) |
| 211 | +{ |
| 212 | + pANTLR3_COMMON_TOKEN t = data; |
| 213 | + MWLINKRESOLUTION *resolution = userdata; |
| 214 | + pANTLR3_VECTOR attr = t->custom; |
| 215 | + attr->set(attr, attr->count - 2, resolution, MWLinkResolutionFree, true); |
| 216 | +} |
| 217 | + |
| 218 | +static void setLinkResolution(gpointer data, gpointer userdata) |
| 219 | +{ |
| 220 | + pANTLR3_COMMON_TOKEN t = data; |
| 221 | + MWLINKRESOLUTION *resolution = userdata; |
| 222 | + pANTLR3_VECTOR attr = t->custom; |
| 223 | + attr->set(attr, attr->count - 1, resolution, MWLinkResolutionFree, true); |
| 224 | +} |
| 225 | + |
| 226 | +void |
| 227 | +MWLinkCollectionResolve(MWLINKCOLLECTION *linkCollection, MWLCKEY *key, MWLINKRESOLUTION *resolution) |
| 228 | +{ |
| 229 | + LCVAL *val = g_tree_lookup(linkCollection->tree, key); |
| 230 | + if (val != NULL) { |
| 231 | + if (key->type == MWLT_MEDIA) { |
| 232 | + g_list_foreach(val->tokenList, setMediaLinkResolution, resolution); |
| 233 | + } else { |
| 234 | + g_list_foreach(val->tokenList, setLinkResolution, resolution); |
| 235 | + } |
| 236 | + } |
| 237 | +} |
| 238 | + |
| 239 | +const char * |
| 240 | +MWLCKeyGetLinkTitle(MWLCKEY *lckey) |
| 241 | +{ |
| 242 | + return (char*)lckey->linkTitle->chars; |
| 243 | +} |
| 244 | + |
| 245 | +MWLINKTYPE |
| 246 | +MWLCKeyGetLinkType(MWLCKEY *lckey) |
| 247 | +{ |
| 248 | + return lckey->type; |
| 249 | +} |
| 250 | + |
| 251 | +int |
| 252 | +MWLinkCollectionNumLinks(MWLINKCOLLECTION *collection) |
| 253 | +{ |
| 254 | + return g_tree_nnodes(collection->tree); |
| 255 | +} |
Index: trunk/parsers/libmwparser/tests/Makefile.in |
— | — | @@ -173,6 +173,7 @@ |
174 | 174 | SWIG_LIB = @SWIG_LIB@ |
175 | 175 | TARGET_LANGUAGE = @TARGET_LANGUAGE@ |
176 | 176 | TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@ |
| 177 | +TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@ |
177 | 178 | VERSION = @VERSION@ |
178 | 179 | abs_builddir = @abs_builddir@ |
179 | 180 | abs_srcdir = @abs_srcdir@ |
Index: trunk/parsers/libmwparser/configure.ac |
— | — | @@ -74,10 +74,11 @@ |
75 | 75 | TARGET_LANGUAGE_LDFLAGS='$(PERLXS_LDFLAGS)' |
76 | 76 | elif test "x$TARGET_LANGUAGE" == xphp; then |
77 | 77 | TARGET_LANGUAGE_CFLAGS='-DTARGET_LANGUAGE_PHP $(PHP_CFLAGS)' |
78 | | - TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS)' |
| 78 | + TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS) $(PHP_LIBS)' |
79 | 79 | fi |
80 | 80 | |
81 | 81 | AC_SUBST([TARGET_LANGUAGE_CFLAGS]) |
| 82 | +AC_SUBST([TARGET_LANGUAGE_LDFLAGS]) |
82 | 83 | |
83 | 84 | AM_PROG_LIBTOOL |
84 | 85 | AC_PROG_LIBTOOL |
Index: trunk/parsers/libmwparser/Makefile.am |
— | — | @@ -13,16 +13,13 @@ |
14 | 14 | |
15 | 15 | ANTLR_LEXER = mwWikitextLexer |
16 | 16 | ANTLR_PARSER = mwWikitextParser |
17 | | -ANTLR_LEXER_DELEGATES = |
18 | 17 | |
19 | 18 | ANTLR_GRAMMARS = $(ANTLR_LEXER:=.g) $(ANTLR_PARSER:=.g) |
20 | 19 | |
21 | 20 | ANTLR_SOURCES = $(ANTLR_LEXER:=.c) $(ANTLR_PARSER:=.c) $(ANTLR_LEXER:=.h) $(ANTLR_PARSER:=.h) |
22 | 21 | |
23 | | -ANTLR_LEXER_DELEGATE_SOURCES = |
| 22 | +CLEANFILES = $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc |
24 | 23 | |
25 | | -CLEANFILES = $(ANTLR_LEXER_DELEGATE_SOURCES) $(ANTLR_LEXER_DELEGATES:=.tokens) $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc |
26 | | - |
27 | 24 | lib_LTLIBRARIES = libmwparser.la |
28 | 25 | |
29 | 26 | nodist_libmwparser_la_SOURCES = $(ANTLR_SOURCES) $(ANTLR_LEXER_DELEGATE_SOURCES) |
— | — | @@ -51,9 +48,11 @@ |
52 | 49 | include/mwkeyvalue.h \ |
53 | 50 | include/mwlexercontext.h \ |
54 | 51 | include/mwlinkcollection.h \ |
| 52 | + include/mwlinkresolution.h \ |
55 | 53 | include/mwlinks.h \ |
56 | 54 | include/mwlistener.h \ |
57 | 55 | include/mwparser.h \ |
| 56 | + include/mwmedialinkoption.h \ |
58 | 57 | include/mwparsercontext.h \ |
59 | 58 | include/mwtables.h \ |
60 | 59 | include/mwtagext.h \ |
— | — | @@ -66,7 +65,9 @@ |
67 | 66 | src/mwhtml.c \ |
68 | 67 | src/mwlexercontext.c \ |
69 | 68 | src/mwlinks.c \ |
| 69 | + src/mwlinkresolution.c \ |
70 | 70 | src/mwlinkcollection.c \ |
| 71 | + src/mwmedialinkoption.c \ |
71 | 72 | src/mwparser.c \ |
72 | 73 | src/mwparsercontext.c \ |
73 | 74 | src/mwtagext.c \ |
— | — | @@ -82,12 +83,12 @@ |
83 | 84 | src/mwlexerpredicatedefs.php \ |
84 | 85 | antlr.patch |
85 | 86 | |
86 | | -libmwparser_la_LIBS = $(GLIB_LIBS) |
87 | | - |
88 | 87 | libmwparser_la_CFLAGS = $(GLIB_CFLAGS) -std=gnu99 -Wall -Wno-unused-variable |
89 | 88 | |
90 | 89 | libmwparser_la_LDFLAGS = -release $(PACKAGE_VERSION) |
91 | 90 | |
| 91 | +libmwparser_la_LIBADD = $(GLIB_LIBS) $(ANTLR3C_LIBS); |
| 92 | + |
92 | 93 | INCLUDES = -I$(top_srcdir)/include |
93 | 94 | |
94 | 95 | include_HEADERS = config.h |
Index: trunk/parsers/libmwparser/wrapper/Makefile.in |
— | — | @@ -72,10 +72,12 @@ |
73 | 73 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' |
74 | 74 | am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)" |
75 | 75 | LTLIBRARIES = $(lib_LTLIBRARIES) |
76 | | -libmwp_la_LIBADD = |
77 | | -am_libmwp_la_OBJECTS = libmwp_la-mwscriptbufferlistener.lo \ |
78 | | - libmwp_la-mwp_wrap.lo |
79 | | -libmwp_la_OBJECTS = $(am_libmwp_la_OBJECTS) |
| 76 | +libmwp_la_DEPENDENCIES = |
| 77 | +am_libmwp_la_OBJECTS = libmwp_la-mwlinkresolvercallback.lo \ |
| 78 | + libmwp_la-mwscriptbufferlistener.lo |
| 79 | +nodist_libmwp_la_OBJECTS = libmwp_la-mwp_wrap.lo |
| 80 | +libmwp_la_OBJECTS = $(am_libmwp_la_OBJECTS) \ |
| 81 | + $(nodist_libmwp_la_OBJECTS) |
80 | 82 | libmwp_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ |
81 | 83 | $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libmwp_la_CFLAGS) \ |
82 | 84 | $(CFLAGS) $(libmwp_la_LDFLAGS) $(LDFLAGS) -o $@ |
— | — | @@ -92,7 +94,7 @@ |
93 | 95 | LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ |
94 | 96 | --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ |
95 | 97 | $(LDFLAGS) -o $@ |
96 | | -SOURCES = $(libmwp_la_SOURCES) |
| 98 | +SOURCES = $(libmwp_la_SOURCES) $(nodist_libmwp_la_SOURCES) |
97 | 99 | DIST_SOURCES = $(libmwp_la_SOURCES) |
98 | 100 | HEADERS = $(include_HEADERS) |
99 | 101 | ETAGS = etags |
— | — | @@ -172,6 +174,7 @@ |
173 | 175 | SWIG_LIB = @SWIG_LIB@ |
174 | 176 | TARGET_LANGUAGE = @TARGET_LANGUAGE@ |
175 | 177 | TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@ |
| 178 | +TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@ |
176 | 179 | VERSION = @VERSION@ |
177 | 180 | abs_builddir = @abs_builddir@ |
178 | 181 | abs_srcdir = @abs_srcdir@ |
— | — | @@ -227,13 +230,20 @@ |
228 | 231 | top_srcdir = @top_srcdir@ |
229 | 232 | PHP_CFLAGS = `php-config --includes` |
230 | 233 | PHP_LDFLAGS = `php-config --ldflags` |
231 | | -CLEANFILES = mwp_wrap.c mwp.pm |
| 234 | +PHP_LIBS = `php-config --libs` |
| 235 | +CLEANFILES = mwp_wrap.c mwp.pm mwp.php php_mwp.h |
232 | 236 | lib_LTLIBRARIES = libmwp.la |
233 | | -libmwp_la_SOURCES = src/mwscriptbufferlistener.c \ |
234 | | - mwp_wrap.c |
| 237 | +libmwp_la_SOURCES = \ |
| 238 | + src/mwlinkresolvercallback.c \ |
| 239 | + src/mwscriptbufferlistener.c \ |
| 240 | + src/mwparser.i \ |
| 241 | + include/mwlinkresolvercallback.h \ |
| 242 | + include/mwscriptbuf.h |
235 | 243 | |
236 | | -libmwp_la_CFLAGS = $(TARGET_LANGUAGE_CFLAGS) $(GLIB_CFLAGS) -Wall |
237 | | -libmwp_la_LDFLAGS = $(TARGET_LANGUAGE_LDFLAGS) $(GLIB_LDFLAGS) |
| 244 | +nodist_libmwp_la_SOURCES = mwp_wrap.c |
| 245 | +libmwp_la_CFLAGS = $(TARGET_LANGUAGE_CFLAGS) $(GLIB_CFLAGS) -Wall -Wno-unused |
| 246 | +libmwp_la_LDFLAGS = $(TARGET_LANGUAGE_LDFLAGS) $(GLIB_LDFLAGS) -lmwparser |
| 247 | +libmwp_la_LIBADD = |
238 | 248 | INCLUDES = -I$(srcdir)/include -I$(top_srcdir)/include |
239 | 249 | include_HEADERS = $(top_builddir)/config.h |
240 | 250 | all: all-am |
— | — | @@ -310,6 +320,7 @@ |
311 | 321 | distclean-compile: |
312 | 322 | -rm -f *.tab.c |
313 | 323 | |
| 324 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwlinkresolvercallback.Plo@am__quote@ |
314 | 325 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwp_wrap.Plo@am__quote@ |
315 | 326 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwscriptbufferlistener.Plo@am__quote@ |
316 | 327 | |
— | — | @@ -334,6 +345,13 @@ |
335 | 346 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
336 | 347 | @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< |
337 | 348 | |
| 349 | +libmwp_la-mwlinkresolvercallback.lo: src/mwlinkresolvercallback.c |
| 350 | +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwp_la_CFLAGS) $(CFLAGS) -MT libmwp_la-mwlinkresolvercallback.lo -MD -MP -MF $(DEPDIR)/libmwp_la-mwlinkresolvercallback.Tpo -c -o libmwp_la-mwlinkresolvercallback.lo `test -f 'src/mwlinkresolvercallback.c' || echo '$(srcdir)/'`src/mwlinkresolvercallback.c |
| 351 | +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwp_la-mwlinkresolvercallback.Tpo $(DEPDIR)/libmwp_la-mwlinkresolvercallback.Plo |
| 352 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/mwlinkresolvercallback.c' object='libmwp_la-mwlinkresolvercallback.lo' libtool=yes @AMDEPBACKSLASH@ |
| 353 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
| 354 | +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwp_la_CFLAGS) $(CFLAGS) -c -o libmwp_la-mwlinkresolvercallback.lo `test -f 'src/mwlinkresolvercallback.c' || echo '$(srcdir)/'`src/mwlinkresolvercallback.c |
| 355 | + |
338 | 356 | libmwp_la-mwscriptbufferlistener.lo: src/mwscriptbufferlistener.c |
339 | 357 | @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwp_la_CFLAGS) $(CFLAGS) -MT libmwp_la-mwscriptbufferlistener.lo -MD -MP -MF $(DEPDIR)/libmwp_la-mwscriptbufferlistener.Tpo -c -o libmwp_la-mwscriptbufferlistener.lo `test -f 'src/mwscriptbufferlistener.c' || echo '$(srcdir)/'`src/mwscriptbufferlistener.c |
340 | 358 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwp_la-mwscriptbufferlistener.Tpo $(DEPDIR)/libmwp_la-mwscriptbufferlistener.Plo |
— | — | @@ -513,7 +531,8 @@ |
514 | 532 | info-am: |
515 | 533 | |
516 | 534 | install-data-am: install-includeHEADERS |
517 | | - |
| 535 | + @$(NORMAL_INSTALL) |
| 536 | + $(MAKE) $(AM_MAKEFLAGS) install-data-hook |
518 | 537 | install-dvi: install-dvi-am |
519 | 538 | |
520 | 539 | install-dvi-am: |
— | — | @@ -560,18 +579,19 @@ |
561 | 580 | |
562 | 581 | uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES |
563 | 582 | |
564 | | -.MAKE: install-am install-strip |
| 583 | +.MAKE: install-am install-data-am install-strip |
565 | 584 | |
566 | 585 | .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ |
567 | 586 | clean-libLTLIBRARIES clean-libtool ctags distclean \ |
568 | 587 | distclean-compile distclean-generic distclean-libtool \ |
569 | 588 | distclean-tags distdir dvi dvi-am html html-am info info-am \ |
570 | | - install install-am install-data install-data-am install-dvi \ |
571 | | - install-dvi-am install-exec install-exec-am install-html \ |
572 | | - install-html-am install-includeHEADERS install-info \ |
573 | | - install-info-am install-libLTLIBRARIES install-man install-pdf \ |
574 | | - install-pdf-am install-ps install-ps-am install-strip \ |
575 | | - installcheck installcheck-am installdirs maintainer-clean \ |
| 589 | + install install-am install-data install-data-am \ |
| 590 | + install-data-hook install-dvi install-dvi-am install-exec \ |
| 591 | + install-exec-am install-html install-html-am \ |
| 592 | + install-includeHEADERS install-info install-info-am \ |
| 593 | + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ |
| 594 | + install-ps install-ps-am install-strip installcheck \ |
| 595 | + installcheck-am installdirs maintainer-clean \ |
576 | 596 | maintainer-clean-generic mostlyclean mostlyclean-compile \ |
577 | 597 | mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ |
578 | 598 | tags uninstall uninstall-am uninstall-includeHEADERS \ |
— | — | @@ -580,8 +600,11 @@ |
581 | 601 | vpath %.i $(srcdir)/src |
582 | 602 | |
583 | 603 | mwp_wrap.c: mwparser.i |
584 | | - swig -$(TARGET_LANGUAGE) -Wall -o $@ $< |
| 604 | + swig -$(TARGET_LANGUAGE) $(INCLUDES) -Wall -o $@ $< |
585 | 605 | |
| 606 | +install-data-hook: |
| 607 | + if test x$(TARGET_LANGUAGE) = xphp ; then $(MKDIR_P) $(datarootdir)/php/MediaWiki && $(INSTALL_SCRIPT) mwp.php $(datarootdir)/php/MediaWiki; fi |
| 608 | + |
586 | 609 | # Tell versions [3.59,3.63) of GNU make to not export all variables. |
587 | 610 | # Otherwise a system limit (for SysV at least) may be exceeded. |
588 | 611 | .NOEXPORT: |
Index: trunk/parsers/libmwparser/wrapper/include/mwscriptbuf.h |
— | — | @@ -2,9 +2,21 @@ |
3 | 3 | #define _MWSCRIPT_BUF_H |
4 | 4 | |
5 | 5 | #include <mwattributes.h> |
| 6 | +#include <mwscriptmalloc.h> |
6 | 7 | |
| 8 | +struct MWSCRIPTBUF_struct; |
| 9 | + |
| 10 | +static inline void appendBytes(struct MWSCRIPTBUF_struct *buf, const char *bytes, size_t numBytes); |
| 11 | + |
7 | 12 | #define BUFSIZE 4096 |
8 | 13 | |
| 14 | +typedef struct MWSCRIPTBUF_INDEX_struct |
| 15 | +{ |
| 16 | + int row; |
| 17 | + int col; |
| 18 | +} |
| 19 | + MWSCRIPTBUF_INDEX; |
| 20 | + |
9 | 21 | #ifdef TARGET_LANGUAGE_PERL |
10 | 22 | |
11 | 23 | #include <EXTERN.h> |
— | — | @@ -21,7 +33,30 @@ |
22 | 34 | } |
23 | 35 | MWSCRIPTBUF; |
24 | 36 | |
| 37 | +static inline MWSCRIPTBUF_INDEX |
| 38 | +getIndex(MWSCRIPTBUF *buf) |
| 39 | +{ |
| 40 | + MWSCRIPTBUF_INDEX index = { |
| 41 | + /* av_len returns the highest _index_ in the array */ |
| 42 | + av_len(buf->av), |
| 43 | + buf->p - buf->buf, |
| 44 | + }; |
| 45 | + return index; |
| 46 | +} |
25 | 47 | |
| 48 | +static inline void |
| 49 | +copyAppendRegion(MWSCRIPTBUF *buf, MWSCRIPTBUF_INDEX start, MWSCRIPTBUF_INDEX end) |
| 50 | +{ |
| 51 | + int row; |
| 52 | + for (row = start.row; row <= end.row; row++) { |
| 53 | + SV *sv = *(av_fetch(buf->av, row, 0)); |
| 54 | + int startCol = row == start.row ? start.col : 0; |
| 55 | + int endCol = row == end.row ? end.col : SvCUR(sv); |
| 56 | + appendBytes(buf, SvPVX(sv) + startCol, endCol - startCol); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | + |
26 | 61 | static inline void * |
27 | 62 | scriptBufResult(MWSCRIPTBUF *buf) |
28 | 63 | { |
— | — | @@ -100,6 +135,30 @@ |
101 | 136 | } |
102 | 137 | MWSCRIPTBUF; |
103 | 138 | |
| 139 | +static inline MWSCRIPTBUF_INDEX |
| 140 | +getIndex(MWSCRIPTBUF *buf) |
| 141 | +{ |
| 142 | + MWSCRIPTBUF_INDEX index = { |
| 143 | + buf->av->value.ht->nNumOfElements - 1, |
| 144 | + buf->p - buf->buf, |
| 145 | + }; |
| 146 | + return index; |
| 147 | +} |
| 148 | + |
| 149 | +static inline void |
| 150 | +copyAppendRegion(MWSCRIPTBUF *buf, MWSCRIPTBUF_INDEX start, MWSCRIPTBUF_INDEX end) |
| 151 | +{ |
| 152 | + int row; |
| 153 | + for (row = start.row; row <= end.row; row++) { |
| 154 | + zval **tmp; |
| 155 | + int ret = zend_hash_index_find(buf->av->value.ht, row, (void **) &tmp); |
| 156 | + zval *sv = *tmp; |
| 157 | + int startCol = row == start.row ? start.col : 0; |
| 158 | + int endCol = row == end.row ? end.col : sv->value.str.len - 1; |
| 159 | + appendBytes(buf, sv->value.str.val + startCol, endCol - startCol); |
| 160 | + } |
| 161 | +} |
| 162 | + |
104 | 163 | static inline void * |
105 | 164 | scriptBufResult(MWSCRIPTBUF *buf) |
106 | 165 | { |
— | — | @@ -182,7 +241,7 @@ |
183 | 242 | static inline void |
184 | 243 | appendAntlr3String(MWSCRIPTBUF *buf, pANTLR3_STRING string) |
185 | 244 | { |
186 | | - appendBytes(buf, (char *)string->chars, string->size); |
| 245 | + appendBytes(buf, (char *)string->chars, string->size - 1); |
187 | 246 | } |
188 | 247 | |
189 | 248 | static inline void |
— | — | @@ -199,7 +258,7 @@ |
200 | 259 | |
201 | 260 | #define APPEND_ATTR_VECTOR(element, attr) (appendAttrVector(BUF, element, attr)) |
202 | 261 | |
203 | | -#define APPEND_CONST_STRING(string) (appendBytes(BUF, string, sizeof(string))) |
| 262 | +#define APPEND_CONST_STRING(string) (appendBytes(BUF, string, sizeof(string) - 1)) |
204 | 263 | |
205 | 264 | #define APPEND_STRING(string) (appendBytes(BUF, string, strlen(string))) |
206 | 265 | |
— | — | @@ -213,6 +272,8 @@ |
214 | 273 | } \ |
215 | 274 | } while (0) |
216 | 275 | |
| 276 | +struct MWLINKCOLLECTION_struct; |
217 | 277 | |
| 278 | +void MWScriptCallbackResolveLinks(struct MWLINKCOLLECTION_struct *linkCollection, void *data); |
218 | 279 | |
219 | 280 | #endif |
Index: trunk/parsers/libmwparser/wrapper/include/mwlinkresolvercallback.h |
— | — | @@ -0,0 +1,8 @@ |
| 2 | +#ifndef MWLINKRESOLVERCALLBACK_H_ |
| 3 | +#define MWLINKRESOLVERCALLBACK_H_ |
| 4 | + |
| 5 | +#include <mwlinkcollection.h> |
| 6 | + |
| 7 | +void MWLinkResolverCallback(MWLINKCOLLECTION *linkCollection, void *data); |
| 8 | + |
| 9 | +#endif |
Index: trunk/parsers/libmwparser/wrapper/src/mwlinkresolvercallback.c |
— | — | @@ -0,0 +1,55 @@ |
| 2 | +#include <antlr3.h> |
| 3 | +#include <mwlinkresolvercallback.h> |
| 4 | + |
| 5 | +#ifdef TARGET_LANGUAGE_PERL |
| 6 | +#include <EXTERN.h> |
| 7 | +#include <perl.h> |
| 8 | +#include <XSUB.h> |
| 9 | + |
| 10 | + |
| 11 | +void |
| 12 | +MWLinkResolverCallback(MWLINKCOLLECTION *linkCollection, void *data) |
| 13 | +{ |
| 14 | + SV *lc = sv_newmortal(); |
| 15 | + sv_setref_pv(lc, NULL, linkCollection); |
| 16 | + |
| 17 | + dSP; |
| 18 | + |
| 19 | + ENTER; |
| 20 | + SAVETMPS; |
| 21 | + |
| 22 | + PUSHMARK(SP); |
| 23 | + XPUSHs(lc); |
| 24 | + PUTBACK; |
| 25 | + |
| 26 | + call_pv("MWParserLinkResolverCallback", G_DISCARD); |
| 27 | + |
| 28 | + FREETMPS; |
| 29 | + LEAVE; |
| 30 | +} |
| 31 | + |
| 32 | +#elif (defined TARGET_LANGUAGE_PHP) |
| 33 | +#include <php.h> |
| 34 | + |
| 35 | +void |
| 36 | +MWLinkResolverCallback(MWLINKCOLLECTION *linkCollection, void *data) |
| 37 | +{ |
| 38 | + zval *name; |
| 39 | + zval *lc; |
| 40 | + zval *retval; |
| 41 | + MAKE_STD_ZVAL(name); |
| 42 | + MAKE_STD_ZVAL(retval); |
| 43 | + MAKE_STD_ZVAL(lc); |
| 44 | + ZVAL_RESOURCE(lc, (long) linkCollection); |
| 45 | + if (name == NULL) { |
| 46 | + zend_error(E_ERROR, "Function call failed"); |
| 47 | + } |
| 48 | + ZVAL_STRING(name, "MWParserLinkResolverCallback", 1); |
| 49 | + if(call_user_function(CG(function_table), NULL, name, retval, 1, &lc) != SUCCESS) { |
| 50 | + zend_error(E_ERROR, "Function call failed"); |
| 51 | + } |
| 52 | + Z_DELREF_P(name); |
| 53 | + Z_DELREF_P(lc); |
| 54 | + Z_DELREF_P(retval); |
| 55 | +} |
| 56 | +#endif |
Index: trunk/parsers/libmwparser/wrapper/src/mwscriptbuf.c |
— | — | @@ -1,3 +1,3 @@ |
2 | 2 | |
3 | | -#include <mwscriptbuf.h> |
4 | 3 | |
| 4 | + |
Index: trunk/parsers/libmwparser/wrapper/src/mwparser.i |
— | — | @@ -4,16 +4,38 @@ |
5 | 5 | #include <antlr3.h> |
6 | 6 | #include <mwparser.h> |
7 | 7 | #include <mwlistener.h> |
| 8 | +#include <mwlinkresolution.h> |
| 9 | +#include <mwlinkcollection.h> |
8 | 10 | extern MWLISTENER mwScriptBufferListener; |
9 | 11 | static MWPARSER_OPTIONS *null_options = NULL; |
10 | 12 | %} |
11 | 13 | |
| 14 | +%include <mwlinkresolution.h> |
| 15 | + |
12 | 16 | #ifdef SWIGPERL |
13 | 17 | %typemap(in) SV *string { |
14 | 18 | SvREFCNT_inc($input); |
15 | 19 | $1 = $input; |
16 | 20 | } |
17 | 21 | |
| 22 | +%typemap(in) SV *callback { |
| 23 | + $1 = $input; |
| 24 | +} |
| 25 | + |
| 26 | +%typemap(in) SV *callbackData { |
| 27 | + $1 = $input; |
| 28 | +} |
| 29 | + |
| 30 | +%typemap(in) MWLINKRESOLUTION *resolution { |
| 31 | + SvREFCNT_inc($input); |
| 32 | + if ((SWIG_ConvertPtr($input,(void **) &$1, $1_descriptor,0)) == -1) { |
| 33 | + SWIG_exception_fail(SWIG_ArgError(SWIG_ValueError), "Invalid class for link resolution pointer."); |
| 34 | + } |
| 35 | + $1->free = freeScriptVar; |
| 36 | + $1->freeData = $input; |
| 37 | + |
| 38 | +} |
| 39 | + |
18 | 40 | %{ |
19 | 41 | static SV *MWParseArticle(MWPARSER *parser) |
20 | 42 | { |
— | — | @@ -21,20 +43,59 @@ |
22 | 44 | return MWParserGetResult(parser); |
23 | 45 | } |
24 | 46 | |
25 | | - static void freeString(void *string) { |
26 | | - SV *sv = string; |
| 47 | + static void freeScriptVar(void *v) |
| 48 | + { |
| 49 | + SV *sv = v; |
27 | 50 | SvREFCNT_dec(sv); |
28 | 51 | } |
29 | 52 | |
30 | 53 | static MWPARSER_INPUT_STREAM * new_MWParserInput(SV *string) |
31 | 54 | { |
32 | | - return MWParserOpenStringWithCleanup("input", SvPVX(string), SvCUR(string), MWPARSER_UTF8, string, freeString); |
| 55 | + return MWParserOpenStringWithCleanup("input", SvPVX(string), SvCUR(string), MWPARSER_UTF8, string, freeScriptVar); |
33 | 56 | } |
| 57 | + |
| 58 | + static int addKey(MWLCKEY *key, void *data) |
| 59 | + { |
| 60 | + AV *av = data; |
| 61 | + SV *sv = newSV(0); |
| 62 | + SWIG_MakePtr(sv, SWIG_as_voidptr(key), SWIGTYPE_p_MWLCKEY, 0); |
| 63 | + av_push(av, sv); |
| 64 | + return 0; |
| 65 | + } |
| 66 | + |
| 67 | + static SV* MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection) |
| 68 | + { |
| 69 | + AV *av = newAV(); |
| 70 | + if (av == NULL) { |
| 71 | + return NULL; |
| 72 | + } |
| 73 | + |
| 74 | + MWLinkCollectionTraverse(linkCollection, addKey, av); |
| 75 | + |
| 76 | + SV *rv = newRV_noinc((SV*) av); |
| 77 | + if (rv == NULL) { |
| 78 | + av_undef(av); |
| 79 | + return NULL; |
| 80 | + } |
| 81 | + return rv; |
| 82 | + } |
34 | 83 | %} |
35 | 84 | |
36 | 85 | %typemap(out) SV * sv { |
37 | 86 | $result = $1; |
38 | 87 | } |
| 88 | + |
| 89 | +%typemap(in) MWLINKCOLLECTION * linkCollection { |
| 90 | + if (!SvOK($input)) { |
| 91 | + SWIG_exception_fail(SWIG_ArgError(SWIG_ValueError), "Link collection argument undefined."); |
| 92 | + } |
| 93 | + if (!SvROK($input)) { |
| 94 | + SWIG_exception_fail(SWIG_ArgError(SWIG_ValueError), "Link collection argument not a reference."); |
| 95 | + } |
| 96 | + |
| 97 | + $1 = INT2PTR(MWLINKCOLLECTION *, SvIV(SvRV($input))); |
| 98 | +} |
| 99 | + |
39 | 100 | #elif defined (SWIGPHP) |
40 | 101 | %{ |
41 | 102 | static zval *MWParseArticle(MWPARSER *parser) |
— | — | @@ -42,15 +103,44 @@ |
43 | 104 | MWParserParseArticle(parser, NULL); |
44 | 105 | return MWParserGetResult(parser); |
45 | 106 | } |
46 | | - static void freeString(void *string) { |
47 | | - zval *z = string; |
| 107 | + |
| 108 | + static void freeScriptVar(void *v) |
| 109 | + { |
| 110 | + zval *z = v; |
48 | 111 | Z_DELREF_P(z); |
49 | 112 | } |
50 | 113 | |
51 | 114 | static MWPARSER_INPUT_STREAM * new_MWParserInput(zval *string) |
52 | 115 | { |
53 | | - return MWParserOpenStringWithCleanup("input", string->value.str.val, string->value.str.len, MWPARSER_UTF8, string, freeString); |
| 116 | + return MWParserOpenStringWithCleanup("input", string->value.str.val, string->value.str.len, MWPARSER_UTF8, string, freeScriptVar); |
54 | 117 | } |
| 118 | + |
| 119 | + static int addKey(MWLCKEY *key, void *data) |
| 120 | + { |
| 121 | + zval *av = data; |
| 122 | + zval *sv; |
| 123 | + MAKE_STD_ZVAL(sv); |
| 124 | + |
| 125 | + SWIG_SetPointerZval(sv, (void *) key, SWIGTYPE_p_MWLCKEY, 0); |
| 126 | + |
| 127 | + add_next_index_zval(av, sv); |
| 128 | + return 0; |
| 129 | + } |
| 130 | + |
| 131 | + static zval* MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection) |
| 132 | + { |
| 133 | + zval *av; |
| 134 | + MAKE_STD_ZVAL(av); |
| 135 | + if (av == NULL) { |
| 136 | + return NULL; |
| 137 | + } |
| 138 | + array_init(av); |
| 139 | + |
| 140 | + MWLinkCollectionTraverse(linkCollection, addKey, av); |
| 141 | + |
| 142 | + return av; |
| 143 | + } |
| 144 | + |
55 | 145 | %} |
56 | 146 | |
57 | 147 | %typemap(out) zval * { |
— | — | @@ -64,8 +154,26 @@ |
65 | 155 | Z_ADDREF_P(*$input); |
66 | 156 | $1 = *$input; |
67 | 157 | } |
| 158 | + |
| 159 | +%typemap(in) MWLINKRESOLUTION *resolution { |
| 160 | + Z_ADDREF_P(*$input); |
| 161 | + if ((SWIG_ConvertPtr(*$input,(void **) &$1, $1_descriptor,0)) == -1) { |
| 162 | + SWIG_PHP_Error(E_ERROR, "Invalid class for link resolution pointer."); |
| 163 | + } |
| 164 | + $1->free = freeScriptVar; |
| 165 | + $1->freeData = $input; |
| 166 | + |
| 167 | +} |
| 168 | + |
| 169 | +%typemap(in) MWLINKCOLLECTION * linkCollection { |
| 170 | + $1 = (long) Z_LVAL_P(*$input); |
| 171 | +} |
| 172 | + |
68 | 173 | #endif |
69 | 174 | |
| 175 | +extern MWLCKEY * getMWLCKey(void); |
| 176 | + |
| 177 | + |
70 | 178 | %{ |
71 | 179 | static MWPARSER *new_MWParser(MWPARSER_INPUT_STREAM *inputStream) |
72 | 180 | { |
— | — | @@ -97,6 +205,11 @@ |
98 | 206 | |
99 | 207 | extern bool MWParserSetMediaLinkTitleRegexp(MWPARSER *parser, const char *perlRegexp); |
100 | 208 | |
| 209 | +extern void MWLinkCollectionResolve(MWLINKCOLLECTION *linkCollection, |
| 210 | + MWLCKEY *key, |
| 211 | + MWLINKRESOLUTION *resolution); |
| 212 | + |
| 213 | + |
101 | 214 | typedef struct MWPARSER_TAGEXT_struct { |
102 | 215 | char * name; |
103 | 216 | bool isBlock; |
— | — | @@ -107,9 +220,15 @@ |
108 | 221 | |
109 | 222 | #ifdef SWIGPERL |
110 | 223 | static SV *MWParseArticle(MWPARSER *parser); |
| 224 | +static SV *MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection); |
111 | 225 | static MWPARSER_INPUT_STREAM * new_MWParserInput(SV *string); |
112 | 226 | #elif defined(SWIGPHP) |
113 | 227 | static zval *MWParseArticle(MWPARSER *parser); |
114 | 228 | static MWPARSER_INPUT_STREAM * new_MWParserInput(zval *string); |
| 229 | +static zval* MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection); |
115 | 230 | #endif |
116 | 231 | |
| 232 | +typedef enum MWLINKTYPE { MWLT_INTERNAL, MWLT_EXTERNAL, MWLT_MEDIA, MWLT_LINKATTR } MWLINKTYPE; |
| 233 | + |
| 234 | +extern const char *MWLCKeyGetLinkTitle(MWLCKEY *lckey); |
| 235 | +extern MWLINKTYPE MWLCKeyGetLinkType(MWLCKEY *lckey); |
Index: trunk/parsers/libmwparser/wrapper/src/mwscriptbufferlistener.c |
— | — | @@ -4,8 +4,11 @@ |
5 | 5 | #include <assert.h> |
6 | 6 | #include <stdbool.h> |
7 | 7 | #include <mwscriptbuf.h> |
| 8 | +#include <mwlinkresolution.h> |
| 9 | +#include <mwlinkcollection.h> |
| 10 | +#include <mwlinkresolvercallback.h> |
| 11 | +#include <mwmedialinkoption.h> |
8 | 12 | |
9 | | - |
10 | 13 | /* |
11 | 14 | * A note on memory management: All parameters of type pANTLR3_STRING |
12 | 15 | * or pANTLR3_VECTOR have been allocated by the antlr runtime via |
— | — | @@ -76,15 +79,15 @@ |
77 | 80 | static void SBEndHtmlBlockquote(MWLISTENER *listener); |
78 | 81 | static void SBBeginHtmlCenter(MWLISTENER *listener, pANTLR3_VECTOR attr); |
79 | 82 | static void SBEndHtmlCenter(MWLISTENER *listener); |
80 | | -static void SBBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 83 | +static void SBBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
81 | 84 | static void SBEndInternalLink(MWLISTENER *listener); |
82 | | -static void SBOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle); |
| 85 | +static void SBOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
83 | 86 | static void SBBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
84 | 87 | static void SBEndExternalLink(MWLISTENER *listener); |
85 | 88 | static void SBOnExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl); |
86 | | -static void SBBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 89 | +static void SBBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
87 | 90 | static void SBEndMediaLink(MWLISTENER *listener); |
88 | | -static void SBOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 91 | +static void SBOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr); |
89 | 92 | static void SBOnTagExtension(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr); |
90 | 93 | static void SBBeginHtmlU(MWLISTENER *listener, pANTLR3_VECTOR attr); |
91 | 94 | static void SBEndHtmlU(MWLISTENER *listener); |
— | — | @@ -123,6 +126,8 @@ |
124 | 127 | static void SBReset(void *data); |
125 | 128 | static void SBFree(void *data); |
126 | 129 | static void * SBGetResult(MWLISTENER *listener); |
| 130 | +static void SBLinkResolver(MWLINKCOLLECTION *linkCollection, void *data); |
| 131 | +static void SBSetLinkResolverData(void *listenerData, void **linkResolverData); |
127 | 132 | |
128 | 133 | /** |
129 | 134 | * Data storage for the listener. |
— | — | @@ -132,6 +137,16 @@ |
133 | 138 | MWSCRIPTBUF buf; |
134 | 139 | pANTLR3_STRING_FACTORY stringFactory; |
135 | 140 | int headingLevel; |
| 141 | + void *scriptCallbackData; |
| 142 | + |
| 143 | + bool renderMarkup; |
| 144 | + const char *height; |
| 145 | + const char *width; |
| 146 | + const char *url; |
| 147 | + const char *imageUrl; |
| 148 | + const char *alt; |
| 149 | + int mediaLinkEndDivs; |
| 150 | + MWSCRIPTBUF_INDEX startCaption; |
136 | 151 | } |
137 | 152 | SCRIPT_BUF; |
138 | 153 | |
— | — | @@ -150,6 +165,8 @@ |
151 | 166 | .newData = SBNew, |
152 | 167 | .freeData = SBFree, |
153 | 168 | .resetData = SBReset, |
| 169 | + .linkResolver = SBLinkResolver, |
| 170 | + .setLinkResolverData = SBSetLinkResolverData, |
154 | 171 | .getResult = SBGetResult, |
155 | 172 | .onWord = SBOnWord, |
156 | 173 | .onSpecial = SBOnSpecial, |
— | — | @@ -281,6 +298,13 @@ |
282 | 299 | return NULL; |
283 | 300 | } |
284 | 301 | |
| 302 | + data->scriptCallbackData = NULL; |
| 303 | + data->renderMarkup = true; |
| 304 | + data->height = NULL; |
| 305 | + data->width = NULL; |
| 306 | + data->url = NULL; |
| 307 | + data->imageUrl = NULL; |
| 308 | + |
285 | 309 | return data; |
286 | 310 | } |
287 | 311 | |
— | — | @@ -321,6 +345,17 @@ |
322 | 346 | return scriptBufResult(BUF); |
323 | 347 | } |
324 | 348 | |
| 349 | +static void SBLinkResolver(MWLINKCOLLECTION *linkCollection, void *data) |
| 350 | +{ |
| 351 | + MWLinkResolverCallback(linkCollection, data); |
| 352 | +} |
| 353 | + |
| 354 | +static void SBSetLinkResolverData(void *listenerData, void **linkResolverData) |
| 355 | +{ |
| 356 | + SCRIPT_BUF *buf = listenerData; |
| 357 | + *linkResolverData = buf->scriptCallbackData; |
| 358 | +} |
| 359 | + |
325 | 360 | /** |
326 | 361 | * Method that will be called to indicate that a "word" should be |
327 | 362 | * rendered. |
— | — | @@ -423,16 +458,26 @@ |
424 | 459 | static void |
425 | 460 | SBOnBr(MWLISTENER *listener, pANTLR3_VECTOR attr) |
426 | 461 | { |
427 | | - APPEND_CONST_STRING("<br/>"); |
| 462 | + if (DATA->renderMarkup) { |
| 463 | + APPEND_CONST_STRING("<br/>"); |
| 464 | + } |
428 | 465 | } |
429 | 466 | |
430 | | -#define HTML_TAG(name) do { \ |
431 | | - if (attr == NULL) { \ |
432 | | - APPEND_CONST_STRING("<" name ">"); \ |
433 | | - } else { \ |
434 | | - APPEND_CONST_STRING("<" name); \ |
435 | | - APPEND_ATTR_VECTOR(name, attr); \ |
436 | | - APPEND_CONST_STRING(">"); \ |
| 467 | +#define HTML_TAG(name) do { \ |
| 468 | + if (DATA->renderMarkup) { \ |
| 469 | + if (attr == NULL) { \ |
| 470 | + APPEND_CONST_STRING("<" name ">"); \ |
| 471 | + } else { \ |
| 472 | + APPEND_CONST_STRING("<" name); \ |
| 473 | + APPEND_ATTR_VECTOR(name, attr); \ |
| 474 | + APPEND_CONST_STRING(">"); \ |
| 475 | + } \ |
| 476 | + } \ |
| 477 | +} while (0) |
| 478 | + |
| 479 | +#define HTML_END(name) do { \ |
| 480 | + if (DATA->renderMarkup) { \ |
| 481 | + APPEND_CONST_STRING("</" name ">"); \ |
437 | 482 | } \ |
438 | 483 | } while (0) |
439 | 484 | |
— | — | @@ -456,7 +501,7 @@ |
457 | 502 | static void |
458 | 503 | SBEndParagraph(MWLISTENER *listener) |
459 | 504 | { |
460 | | - APPEND_CONST_STRING("</p>"); |
| 505 | + HTML_END("p"); |
461 | 506 | } |
462 | 507 | |
463 | 508 | /** |
— | — | @@ -499,7 +544,7 @@ |
500 | 545 | static void |
501 | 546 | SBEndItalic(MWLISTENER *listener) |
502 | 547 | { |
503 | | - APPEND_CONST_STRING("</i>"); |
| 548 | + HTML_END("i"); |
504 | 549 | } |
505 | 550 | |
506 | 551 | /** |
— | — | @@ -522,7 +567,7 @@ |
523 | 568 | static void |
524 | 569 | SBEndBold(MWLISTENER *listener) |
525 | 570 | { |
526 | | - APPEND_CONST_STRING("</b>"); |
| 571 | + HTML_END("b"); |
527 | 572 | } |
528 | 573 | |
529 | 574 | /** |
— | — | @@ -533,7 +578,9 @@ |
534 | 579 | static void |
535 | 580 | SBBeginPre(MWLISTENER *listener) |
536 | 581 | { |
537 | | - APPEND_CONST_STRING("<pre>"); |
| 582 | + if (DATA->renderMarkup) { |
| 583 | + APPEND_CONST_STRING("<pre>"); |
| 584 | + } |
538 | 585 | } |
539 | 586 | |
540 | 587 | /** |
— | — | @@ -544,7 +591,7 @@ |
545 | 592 | static void |
546 | 593 | SBEndPre(MWLISTENER *listener) |
547 | 594 | { |
548 | | - APPEND_CONST_STRING("</pre>"); |
| 595 | + HTML_END("pre"); |
549 | 596 | } |
550 | 597 | |
551 | 598 | /** |
— | — | @@ -593,41 +640,80 @@ |
594 | 641 | { |
595 | 642 | switch (DATA->headingLevel) { |
596 | 643 | case 1: |
597 | | - APPEND_CONST_STRING("</h1>"); |
| 644 | + HTML_END("h1"); |
598 | 645 | break; |
599 | 646 | case 2: |
600 | | - APPEND_CONST_STRING("</h2>"); |
| 647 | + HTML_END("h2"); |
601 | 648 | break; |
602 | 649 | case 3: |
603 | | - APPEND_CONST_STRING("</h3>"); |
| 650 | + HTML_END("h3"); |
604 | 651 | break; |
605 | 652 | case 4: |
606 | | - APPEND_CONST_STRING("</h4>"); |
| 653 | + HTML_END("h4"); |
607 | 654 | break; |
608 | 655 | case 5: |
609 | | - APPEND_CONST_STRING("</h5>"); |
| 656 | + HTML_END("h5"); |
610 | 657 | break; |
611 | 658 | case 6: |
612 | | - APPEND_CONST_STRING("</h6>"); |
| 659 | + HTML_END("h6"); |
613 | 660 | break; |
614 | 661 | default: |
615 | 662 | assert(false); |
616 | 663 | } |
617 | 664 | } |
618 | 665 | |
| 666 | +static void |
| 667 | +renderInternalLinkOpen(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_STRING linkAnchor, MWLINKRESOLUTION *linkResolution) |
| 668 | +{ |
| 669 | + if (DATA->renderMarkup) { |
| 670 | +#ifndef NDEBUG |
| 671 | + if (linkResolution == NULL) { |
| 672 | + APPEND_CONST_STRING("<a style=\"color: pink;\" title=\"UNRESOLVED INTERNAL LINK ["); |
| 673 | + APPEND_ANTLR3_STRING(linkTitle); |
| 674 | + if (linkAnchor != NULL) { |
| 675 | + APPEND_CONST_STRING("#"); |
| 676 | + /* TODO verify anchor */ |
| 677 | + APPEND_ANTLR3_STRING(linkAnchor); |
| 678 | + } |
| 679 | + APPEND_CONST_STRING("]\">"); |
| 680 | + } else |
| 681 | +#endif |
| 682 | + { |
| 683 | + APPEND_CONST_STRING("<a href=\""); |
| 684 | + APPEND_STRING(linkResolution->url); |
| 685 | + if (linkAnchor != NULL) { |
| 686 | + APPEND_CONST_STRING("#"); |
| 687 | + APPEND_ANTLR3_STRING(linkAnchor); |
| 688 | + } |
| 689 | + APPEND_CONST_STRING("\""); |
| 690 | + if (linkResolution->color == MWLINKCOLOR_RED) { |
| 691 | + APPEND_CONST_STRING(" class=\"new\""); |
| 692 | + } |
| 693 | + APPEND_CONST_STRING(">"); |
| 694 | + } |
| 695 | + } |
| 696 | +} |
| 697 | + |
619 | 698 | /** |
620 | 699 | * Initiate formatting of the link text corresponding to an internal |
621 | 700 | * link targetting the page with the given title. |
622 | 701 | * |
623 | 702 | * @param listener |
624 | | - * @param linkTitle |
| 703 | + * @param attr The link does not take any actual attributes, but |
| 704 | + * the ordinary arguments are packed into the attribute vector |
| 705 | + * in the order linkTitle, linkAnchor, linkTitle |
625 | 706 | */ |
626 | 707 | static void |
627 | | -SBBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 708 | +SBBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
628 | 709 | { |
629 | | - APPEND_CONST_STRING("<!-- BEGIN INTERNAL LINK ["); |
630 | | - APPEND_ANTLR3_STRING(linkTitle); |
631 | | - APPEND_CONST_STRING("] -->"); |
| 710 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 711 | + attr->remove(attr, attr->count - 1); |
| 712 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 713 | + attr->remove(attr, attr->count - 1); |
| 714 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 715 | + attr->remove(attr, attr->count - 1); |
| 716 | + |
| 717 | + renderInternalLinkOpen(listener, linkTitle, linkAnchor, linkResolution); |
632 | 718 | } |
633 | 719 | |
634 | 720 | /** |
— | — | @@ -638,9 +724,10 @@ |
639 | 725 | static void |
640 | 726 | SBEndInternalLink(MWLISTENER *listener) |
641 | 727 | { |
642 | | - APPEND_CONST_STRING("<!-- END INTERNAL LINK -->"); |
| 728 | + HTML_END("a"); |
643 | 729 | } |
644 | 730 | |
| 731 | + |
645 | 732 | /** |
646 | 733 | * A complete internal link has been encountered. The link title |
647 | 734 | * should be used as the text contents of the link. |
— | — | @@ -648,14 +735,24 @@ |
649 | 736 | * TODO: pass link trail and prefix as arguments to this method. |
650 | 737 | * |
651 | 738 | * @param listener |
652 | | - * @param linkTitle |
| 739 | + * @param attr The link does not take any actual attributes, but |
| 740 | + * the ordinary arguments are packed into the attribute vector |
| 741 | + * in the order linkTitle, linkAnchor, linkTitle |
653 | 742 | */ |
654 | 743 | static void |
655 | | -SBOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle) |
| 744 | +SBOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
656 | 745 | { |
657 | | - APPEND_CONST_STRING("<!-- INTERNAL LINK ["); |
658 | | - APPEND_ANTLR3_STRING(linkTitle); |
659 | | - APPEND_CONST_STRING("] -->"); |
| 746 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 1); |
| 747 | + attr->remove(attr, attr->count - 1); |
| 748 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 1); |
| 749 | + attr->remove(attr, attr->count - 1); |
| 750 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 1); |
| 751 | + attr->remove(attr, attr->count - 1); |
| 752 | + if (DATA->renderMarkup) { |
| 753 | + renderInternalLinkOpen(listener, linkTitle, linkAnchor, linkResolution); |
| 754 | + } |
| 755 | + SBOnSpecial(listener, linkTitle); |
| 756 | + SBEndInternalLink(listener); |
660 | 757 | } |
661 | 758 | |
662 | 759 | /** |
— | — | @@ -668,10 +765,12 @@ |
669 | 766 | static void |
670 | 767 | SBBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl) |
671 | 768 | { |
672 | | - APPEND_CONST_STRING("<a href=\""); |
673 | | - /* TODO URL validation */ |
674 | | - APPEND_ANTLR3_STRING(linkUrl); |
675 | | - APPEND_CONST_STRING("\">"); |
| 769 | + if (DATA->renderMarkup) { |
| 770 | + APPEND_CONST_STRING("<a class=\"external text\" rel=\"nofollow\" href=\""); |
| 771 | + /* TODO URL validation */ |
| 772 | + APPEND_ANTLR3_STRING(linkUrl); |
| 773 | + APPEND_CONST_STRING("\">"); |
| 774 | + } |
676 | 775 | } |
677 | 776 | |
678 | 777 | /** |
— | — | @@ -682,7 +781,7 @@ |
683 | 782 | static void |
684 | 783 | SBEndExternalLink(MWLISTENER *listener) |
685 | 784 | { |
686 | | - APPEND_CONST_STRING("</a>"); |
| 785 | + HTML_END("a"); |
687 | 786 | } |
688 | 787 | |
689 | 788 | /** |
— | — | @@ -695,12 +794,135 @@ |
696 | 795 | static void |
697 | 796 | SBOnExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl) |
698 | 797 | { |
699 | | - APPEND_CONST_STRING("<a href=\""); |
700 | | - /* TODO URL validation */ |
701 | | - APPEND_ANTLR3_STRING(linkUrl); |
| 798 | + if (DATA->renderMarkup) { |
| 799 | + APPEND_CONST_STRING("<a class=\"external text\" rel=\"nofollow\" href=\""); |
| 800 | + /* TODO URL validation */ |
| 801 | + APPEND_ANTLR3_STRING(linkUrl); |
| 802 | + APPEND_CONST_STRING("\">"); |
| 803 | + } |
| 804 | + SBOnSpecial(listener, linkUrl); |
| 805 | + HTML_END("a"); |
| 806 | +} |
| 807 | + |
| 808 | +static void |
| 809 | +renderMediaLinkOpen(MWLISTENER *listener, |
| 810 | + MEDIALINKOPTION *mlOption, |
| 811 | + pANTLR3_STRING linkTitle, |
| 812 | + pANTLR3_STRING linkAnchor, |
| 813 | + MWLINKRESOLUTION *linkResolution, |
| 814 | + MWLINKRESOLUTION *attributeLinkResolution) |
| 815 | +{ |
| 816 | + if (linkResolution != NULL) { |
| 817 | + pANTLR3_STRING title = linkTitle; |
| 818 | + pANTLR3_STRING alt = linkTitle; |
| 819 | + const char *width; |
| 820 | + const char *height; |
| 821 | + bool renderFrame = mlOption != NULL && mlOption->frame != LOF_NONE; |
| 822 | + |
| 823 | + if (mlOption != NULL && mlOption->width != NULL) { |
| 824 | + width = (char *) mlOption->width->toUTF8(mlOption->width)->chars; |
| 825 | + } else { |
| 826 | + width = linkResolution->imageWidth; |
| 827 | + } |
| 828 | + |
| 829 | + if (mlOption != NULL && mlOption->height != NULL) { |
| 830 | + height = (char *) mlOption->height->toUTF8(mlOption->height)->chars; |
| 831 | + } else { |
| 832 | + height = linkResolution->imageHeight; |
| 833 | + } |
| 834 | + |
| 835 | + if (renderFrame) { |
| 836 | + DATA->mediaLinkEndDivs = 3; |
| 837 | + if (mlOption->halign == LOHA_CENTER) { |
| 838 | + DATA->mediaLinkEndDivs = 4; |
| 839 | + APPEND_CONST_STRING("<div class=\"center\"><div class=\"thumb none\">"); |
| 840 | + } else if (mlOption->halign == LOHA_LEFT) { |
| 841 | + APPEND_CONST_STRING("<div class=\"thumb tleft\">"); |
| 842 | + } else { |
| 843 | + APPEND_CONST_STRING("<div class=\"thumb tright\">"); |
| 844 | + } |
| 845 | + APPEND_CONST_STRING("<div class=\"thumbinner\">"); |
| 846 | + APPEND_CONST_STRING("<a class=\"image\" title=\""); |
| 847 | + APPEND_ANTLR3_STRING(title); |
| 848 | + APPEND_CONST_STRING("\" href=\""); |
| 849 | + APPEND_STRING(linkResolution->url); |
| 850 | + APPEND_CONST_STRING("\"><img "); |
| 851 | + if (width != NULL) { |
| 852 | + APPEND_CONST_STRING("width=\""); |
| 853 | + APPEND_STRING(width); |
| 854 | + APPEND_CONST_STRING("\" "); |
| 855 | + } |
| 856 | + if (height != NULL) { |
| 857 | + APPEND_CONST_STRING("height=\""); |
| 858 | + APPEND_STRING(height); |
| 859 | + APPEND_CONST_STRING("\" "); |
| 860 | + } |
| 861 | + // APPEND_CONST_STRING("\" border=\""); |
| 862 | + // APPEND_STRING(border); |
| 863 | + APPEND_CONST_STRING("src=\""); |
| 864 | + APPEND_STRING(linkResolution->imageUrl); |
| 865 | + APPEND_CONST_STRING("\" alt=\""); |
| 866 | + APPEND_ANTLR3_STRING(alt); |
| 867 | + APPEND_CONST_STRING("\"/></a>"); |
| 868 | + APPEND_CONST_STRING("<div class=\"thumbcaption\">"); |
| 869 | + } else { |
| 870 | + |
| 871 | + APPEND_CONST_STRING("<a title=\""); |
| 872 | + DATA->height = height; |
| 873 | + DATA->width = width; |
| 874 | + DATA->url = linkResolution->url; |
| 875 | + DATA->imageUrl = linkResolution->imageUrl; |
| 876 | + DATA->alt = mlOption == NULL ? NULL : mlOption->alt; |
| 877 | + DATA->renderMarkup = false; |
| 878 | + DATA->startCaption = getIndex(&DATA->buf); |
| 879 | + } |
| 880 | + } |
| 881 | +#ifndef NDEBUG |
| 882 | + else { |
| 883 | + APPEND_CONST_STRING("<a style=\"color: pink;\" title=\"UNRESOLVED MEDIA LINK ["); |
| 884 | + APPEND_ANTLR3_STRING(linkTitle); |
| 885 | + if (linkAnchor != NULL) { |
| 886 | + APPEND_CONST_STRING("#"); |
| 887 | + /* TODO verify anchor */ |
| 888 | + APPEND_ANTLR3_STRING(linkAnchor); |
| 889 | + } |
| 890 | + APPEND_CONST_STRING("]\">"); |
| 891 | + } |
| 892 | +#endif |
| 893 | +} |
| 894 | + |
| 895 | +static void |
| 896 | +renderCloseMediaLinkNoframe(MWLISTENER *listener) |
| 897 | +{ |
| 898 | + DATA->renderMarkup = true; |
| 899 | + MWSCRIPTBUF_INDEX endCaption = getIndex(&DATA->buf); |
| 900 | + APPEND_CONST_STRING("\" class=\"image\" href=\""); |
| 901 | + APPEND_STRING(DATA->url); |
702 | 902 | APPEND_CONST_STRING("\">"); |
703 | | - /* TODO escape URL */ |
704 | | - APPEND_ANTLR3_STRING(linkUrl); |
| 903 | + if (DATA->imageUrl != NULL) { |
| 904 | + APPEND_CONST_STRING("<img "); |
| 905 | + if (DATA->width != NULL) { |
| 906 | + APPEND_CONST_STRING("width=\""); |
| 907 | + APPEND_STRING(DATA->width); |
| 908 | + APPEND_CONST_STRING("\" "); |
| 909 | + } |
| 910 | + if (DATA->height != NULL) { |
| 911 | + APPEND_CONST_STRING("height=\""); |
| 912 | + APPEND_STRING(DATA->height); |
| 913 | + APPEND_CONST_STRING("\" "); |
| 914 | + } |
| 915 | + APPEND_CONST_STRING("src=\""); |
| 916 | + APPEND_STRING(DATA->imageUrl); |
| 917 | + APPEND_CONST_STRING("\" alt=\""); |
| 918 | + } |
| 919 | + if (DATA->alt != NULL) { |
| 920 | + APPEND_STRING(DATA->alt); |
| 921 | + } else { |
| 922 | + copyAppendRegion(&DATA->buf, DATA->startCaption, endCaption); |
| 923 | + } |
| 924 | + if (DATA->imageUrl != NULL) { |
| 925 | + APPEND_CONST_STRING("\"/>"); |
| 926 | + } |
705 | 927 | APPEND_CONST_STRING("</a>"); |
706 | 928 | } |
707 | 929 | |
— | — | @@ -714,12 +936,22 @@ |
715 | 937 | * Also, note that media links may nest one level. |
716 | 938 | * |
717 | 939 | * @param listener |
718 | | - * @param linkTitle |
719 | | - * @param attr |
| 940 | + * @param attr In the attribute vector additional parameters are |
| 941 | + * packed in the order options, linkTitle, linkAnchor, |
| 942 | + * linkResolution, attributeLinkResolution. |
720 | 943 | */ |
721 | 944 | static void |
722 | | -SBBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr) |
| 945 | +SBBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
723 | 946 | { |
| 947 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 948 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 2); |
| 949 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 3); |
| 950 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 4); |
| 951 | + MEDIALINKOPTION *mlOption = attr->get(attr, attr->count - 5); |
| 952 | + |
| 953 | + if (DATA->renderMarkup) { |
| 954 | + renderMediaLinkOpen(listener, mlOption, linkTitle, linkAnchor, linkResolution, attributeLinkResolution); |
| 955 | + } |
724 | 956 | } |
725 | 957 | |
726 | 958 | /** |
— | — | @@ -730,6 +962,14 @@ |
731 | 963 | static void |
732 | 964 | SBEndMediaLink(MWLISTENER *listener) |
733 | 965 | { |
| 966 | + if (!DATA->renderMarkup) { |
| 967 | + renderCloseMediaLinkNoframe(listener); |
| 968 | + } else { |
| 969 | + int i; |
| 970 | + for (i = 0; i < DATA->mediaLinkEndDivs; i++) { |
| 971 | + HTML_END("div"); |
| 972 | + } |
| 973 | + } |
734 | 974 | } |
735 | 975 | |
736 | 976 | /** |
— | — | @@ -739,12 +979,23 @@ |
740 | 980 | * for SBBeginMediaLink. |
741 | 981 | * |
742 | 982 | * @param listener |
743 | | - * @param linkTitle |
744 | | - * @param attr |
| 983 | + * @param attr In the attribute vector additional parameters are |
| 984 | + * packed in the order options, linkTitle, linkAnchor, |
| 985 | + * linkResolution, attributeLinkResolution. |
745 | 986 | */ |
746 | 987 | static void |
747 | | -SBOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr) |
| 988 | +SBOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr) |
748 | 989 | { |
| 990 | + MWLINKRESOLUTION *attributeLinkResolution = attr->get(attr, attr->count - 1); |
| 991 | + MWLINKRESOLUTION *linkResolution = attr->get(attr, attr->count - 2); |
| 992 | + pANTLR3_STRING linkAnchor = attr->get(attr, attr->count - 3); |
| 993 | + pANTLR3_STRING linkTitle = attr->get(attr, attr->count - 4); |
| 994 | + MEDIALINKOPTION *mlOption = attr->get(attr, attr->count - 5); |
| 995 | + |
| 996 | + if (DATA->renderMarkup) { |
| 997 | + renderMediaLinkOpen(listener, mlOption, linkTitle, linkAnchor, linkResolution, attributeLinkResolution); |
| 998 | + SBEndMediaLink(listener); |
| 999 | + } |
749 | 1000 | } |
750 | 1001 | |
751 | 1002 | /** |
— | — | @@ -761,12 +1012,13 @@ |
762 | 1013 | static void |
763 | 1014 | SBOnTagExtension(MWLISTENER *listener, const char *name, pANTLR3_STRING body, pANTLR3_VECTOR attr) |
764 | 1015 | { |
765 | | - APPEND_CONST_STRING("<!-- TAG EXTENSION["); |
766 | | - printf("name: %p, body: %p\n", name, body); |
767 | | - APPEND_STRING(name); |
768 | | - APPEND_CONST_STRING("] -->"); |
769 | | - SBOnSpecial(listener, body); |
770 | | - APPEND_CONST_STRING("<!-- END TAG EXTENSION -->"); |
| 1016 | + if (DATA->renderMarkup) { |
| 1017 | + APPEND_CONST_STRING("<!-- TAG EXTENSION["); |
| 1018 | + APPEND_STRING(name); |
| 1019 | + APPEND_CONST_STRING("] -->"); |
| 1020 | + SBOnSpecial(listener, body); |
| 1021 | + APPEND_CONST_STRING("<!-- END TAG EXTENSION -->"); |
| 1022 | + } |
771 | 1023 | } |
772 | 1024 | |
773 | 1025 | /** |
— | — | @@ -798,7 +1050,7 @@ |
799 | 1051 | static void |
800 | 1052 | SBEndBulletList(MWLISTENER *listener) |
801 | 1053 | { |
802 | | - APPEND_CONST_STRING("</ul>"); |
| 1054 | + HTML_END("ul"); |
803 | 1055 | } |
804 | 1056 | |
805 | 1057 | /** |
— | — | @@ -821,7 +1073,7 @@ |
822 | 1074 | static void |
823 | 1075 | SBEndBulletListItem(MWLISTENER *listener) |
824 | 1076 | { |
825 | | - APPEND_CONST_STRING("</li>"); |
| 1077 | + HTML_END("li"); |
826 | 1078 | } |
827 | 1079 | |
828 | 1080 | /** |
— | — | @@ -846,7 +1098,7 @@ |
847 | 1099 | static void |
848 | 1100 | SBEndEnumerationList(MWLISTENER *listener) |
849 | 1101 | { |
850 | | - APPEND_CONST_STRING("</ol>"); |
| 1102 | + HTML_END("ol"); |
851 | 1103 | } |
852 | 1104 | |
853 | 1105 | /** |
— | — | @@ -869,7 +1121,7 @@ |
870 | 1122 | static void |
871 | 1123 | SBEndEnumerationItem(MWLISTENER *listener) |
872 | 1124 | { |
873 | | - APPEND_CONST_STRING("</li>"); |
| 1125 | + HTML_END("li"); |
874 | 1126 | } |
875 | 1127 | |
876 | 1128 | /** |
— | — | @@ -894,7 +1146,7 @@ |
895 | 1147 | static void |
896 | 1148 | SBEndDefinitionList(MWLISTENER *listener) |
897 | 1149 | { |
898 | | - APPEND_CONST_STRING("</dl>"); |
| 1150 | + HTML_END("dl"); |
899 | 1151 | } |
900 | 1152 | |
901 | 1153 | /** |
— | — | @@ -917,7 +1169,7 @@ |
918 | 1170 | static void |
919 | 1171 | SBEndDefinedTermItem(MWLISTENER *listener) |
920 | 1172 | { |
921 | | - APPEND_CONST_STRING("</dt>"); |
| 1173 | + HTML_END("dt"); |
922 | 1174 | } |
923 | 1175 | |
924 | 1176 | /** |
— | — | @@ -940,7 +1192,7 @@ |
941 | 1193 | static void |
942 | 1194 | SBEndDefinitionItem(MWLISTENER *listener) |
943 | 1195 | { |
944 | | - APPEND_CONST_STRING("</dd>"); |
| 1196 | + HTML_END("dd"); |
945 | 1197 | } |
946 | 1198 | |
947 | 1199 | /** |
— | — | @@ -1014,7 +1266,7 @@ |
1015 | 1267 | static void |
1016 | 1268 | SBEndTable(MWLISTENER *listener) |
1017 | 1269 | { |
1018 | | - APPEND_CONST_STRING("</table>"); |
| 1270 | + HTML_END("table"); |
1019 | 1271 | } |
1020 | 1272 | |
1021 | 1273 | /** |
— | — | @@ -1037,7 +1289,7 @@ |
1038 | 1290 | static void |
1039 | 1291 | SBEndTableRow(MWLISTENER *listener) |
1040 | 1292 | { |
1041 | | - APPEND_CONST_STRING("</tr>"); |
| 1293 | + HTML_END("tr"); |
1042 | 1294 | } |
1043 | 1295 | |
1044 | 1296 | /** |
— | — | @@ -1060,7 +1312,7 @@ |
1061 | 1313 | static void |
1062 | 1314 | SBEndTableCell(MWLISTENER *listener) |
1063 | 1315 | { |
1064 | | - APPEND_CONST_STRING("</td>"); |
| 1316 | + HTML_END("td"); |
1065 | 1317 | } |
1066 | 1318 | |
1067 | 1319 | /** |
— | — | @@ -1083,7 +1335,7 @@ |
1084 | 1336 | static void |
1085 | 1337 | SBEndTableHeading(MWLISTENER *listener) |
1086 | 1338 | { |
1087 | | - APPEND_CONST_STRING("</th>"); |
| 1339 | + HTML_END("th"); |
1088 | 1340 | } |
1089 | 1341 | |
1090 | 1342 | /** |
— | — | @@ -1106,7 +1358,7 @@ |
1107 | 1359 | static void |
1108 | 1360 | SBEndTableCaption(MWLISTENER *listener) |
1109 | 1361 | { |
1110 | | - APPEND_CONST_STRING("</caption>"); |
| 1362 | + HTML_END("caption"); |
1111 | 1363 | } |
1112 | 1364 | |
1113 | 1365 | |
— | — | @@ -1130,7 +1382,7 @@ |
1131 | 1383 | static void |
1132 | 1384 | SBEndTableBody(MWLISTENER *listener) |
1133 | 1385 | { |
1134 | | - APPEND_CONST_STRING("</tbody>"); |
| 1386 | + HTML_END("tbody"); |
1135 | 1387 | } |
1136 | 1388 | |
1137 | 1389 | /** |
— | — | @@ -1192,7 +1444,7 @@ |
1193 | 1445 | static void |
1194 | 1446 | SBEndHtmlDiv(MWLISTENER *listener) |
1195 | 1447 | { |
1196 | | - APPEND_CONST_STRING("</div>"); |
| 1448 | + HTML_END("div"); |
1197 | 1449 | } |
1198 | 1450 | |
1199 | 1451 | /** |
— | — | @@ -1215,7 +1467,7 @@ |
1216 | 1468 | static void |
1217 | 1469 | SBEndHtmlBlockquote(MWLISTENER *listener) |
1218 | 1470 | { |
1219 | | - APPEND_CONST_STRING("</blockquote>"); |
| 1471 | + HTML_END("blockquote"); |
1220 | 1472 | } |
1221 | 1473 | |
1222 | 1474 | /** |
— | — | @@ -1238,7 +1490,7 @@ |
1239 | 1491 | static void |
1240 | 1492 | SBEndHtmlCenter(MWLISTENER *listener) |
1241 | 1493 | { |
1242 | | - APPEND_CONST_STRING("</center>"); |
| 1494 | + HTML_END("center"); |
1243 | 1495 | } |
1244 | 1496 | |
1245 | 1497 | /** |
— | — | @@ -1261,7 +1513,7 @@ |
1262 | 1514 | static void |
1263 | 1515 | SBEndHtmlU(MWLISTENER *listener) |
1264 | 1516 | { |
1265 | | - APPEND_CONST_STRING("</u>"); |
| 1517 | + HTML_END("u"); |
1266 | 1518 | } |
1267 | 1519 | |
1268 | 1520 | /** |
— | — | @@ -1284,7 +1536,7 @@ |
1285 | 1537 | static void |
1286 | 1538 | SBEndHtmlDel(MWLISTENER *listener) |
1287 | 1539 | { |
1288 | | - APPEND_CONST_STRING("</del>"); |
| 1540 | + HTML_END("del"); |
1289 | 1541 | } |
1290 | 1542 | |
1291 | 1543 | /** |
— | — | @@ -1307,7 +1559,7 @@ |
1308 | 1560 | static void |
1309 | 1561 | SBEndHtmlIns(MWLISTENER *listener) |
1310 | 1562 | { |
1311 | | - APPEND_CONST_STRING("</ins>"); |
| 1563 | + HTML_END("ins"); |
1312 | 1564 | } |
1313 | 1565 | |
1314 | 1566 | /** |
— | — | @@ -1330,7 +1582,7 @@ |
1331 | 1583 | static void |
1332 | 1584 | SBEndHtmlFont(MWLISTENER *listener) |
1333 | 1585 | { |
1334 | | - APPEND_CONST_STRING("</font>"); |
| 1586 | + HTML_END("font"); |
1335 | 1587 | } |
1336 | 1588 | |
1337 | 1589 | /** |
— | — | @@ -1353,7 +1605,7 @@ |
1354 | 1606 | static void |
1355 | 1607 | SBEndHtmlBig(MWLISTENER *listener) |
1356 | 1608 | { |
1357 | | - APPEND_CONST_STRING("</big>"); |
| 1609 | + HTML_END("big"); |
1358 | 1610 | } |
1359 | 1611 | |
1360 | 1612 | /** |
— | — | @@ -1376,7 +1628,7 @@ |
1377 | 1629 | static void |
1378 | 1630 | SBEndHtmlSmall(MWLISTENER *listener) |
1379 | 1631 | { |
1380 | | - APPEND_CONST_STRING("</small>"); |
| 1632 | + HTML_END("small"); |
1381 | 1633 | } |
1382 | 1634 | |
1383 | 1635 | /** |
— | — | @@ -1399,7 +1651,7 @@ |
1400 | 1652 | static void |
1401 | 1653 | SBEndHtmlSub(MWLISTENER *listener) |
1402 | 1654 | { |
1403 | | - APPEND_CONST_STRING("</sub>"); |
| 1655 | + HTML_END("sub"); |
1404 | 1656 | } |
1405 | 1657 | |
1406 | 1658 | /** |
— | — | @@ -1422,7 +1674,7 @@ |
1423 | 1675 | static void |
1424 | 1676 | SBEndHtmlSup(MWLISTENER *listener) |
1425 | 1677 | { |
1426 | | - APPEND_CONST_STRING("</sup>"); |
| 1678 | + HTML_END("sup"); |
1427 | 1679 | } |
1428 | 1680 | |
1429 | 1681 | /** |
— | — | @@ -1445,7 +1697,7 @@ |
1446 | 1698 | static void |
1447 | 1699 | SBEndHtmlCite(MWLISTENER *listener) |
1448 | 1700 | { |
1449 | | - APPEND_CONST_STRING("</cite>"); |
| 1701 | + HTML_END("cite"); |
1450 | 1702 | } |
1451 | 1703 | |
1452 | 1704 | /** |
— | — | @@ -1468,7 +1720,7 @@ |
1469 | 1721 | static void |
1470 | 1722 | SBEndHtmlCode(MWLISTENER *listener) |
1471 | 1723 | { |
1472 | | - APPEND_CONST_STRING("</code>"); |
| 1724 | + HTML_END("code"); |
1473 | 1725 | } |
1474 | 1726 | |
1475 | 1727 | /** |
— | — | @@ -1491,7 +1743,7 @@ |
1492 | 1744 | static void |
1493 | 1745 | SBEndHtmlStrike(MWLISTENER *listener) |
1494 | 1746 | { |
1495 | | - APPEND_CONST_STRING("</strike>"); |
| 1747 | + HTML_END("strike"); |
1496 | 1748 | } |
1497 | 1749 | |
1498 | 1750 | /** |
— | — | @@ -1514,7 +1766,7 @@ |
1515 | 1767 | static void |
1516 | 1768 | SBEndHtmlStrong(MWLISTENER *listener) |
1517 | 1769 | { |
1518 | | - APPEND_CONST_STRING("</strong>"); |
| 1770 | + HTML_END("strong"); |
1519 | 1771 | } |
1520 | 1772 | |
1521 | 1773 | /** |
— | — | @@ -1537,7 +1789,7 @@ |
1538 | 1790 | static void |
1539 | 1791 | SBEndHtmlSpan(MWLISTENER *listener) |
1540 | 1792 | { |
1541 | | - APPEND_CONST_STRING("</span>"); |
| 1793 | + HTML_END("span"); |
1542 | 1794 | } |
1543 | 1795 | |
1544 | 1796 | /** |
— | — | @@ -1560,7 +1812,7 @@ |
1561 | 1813 | static void |
1562 | 1814 | SBEndHtmlTt(MWLISTENER *listener) |
1563 | 1815 | { |
1564 | | - APPEND_CONST_STRING("</tt>"); |
| 1816 | + HTML_END("tt"); |
1565 | 1817 | } |
1566 | 1818 | |
1567 | 1819 | /** |
— | — | @@ -1583,7 +1835,7 @@ |
1584 | 1836 | static void |
1585 | 1837 | SBEndHtmlVar(MWLISTENER *listener) |
1586 | 1838 | { |
1587 | | - APPEND_CONST_STRING("</var>"); |
| 1839 | + HTML_END("var"); |
1588 | 1840 | } |
1589 | 1841 | |
1590 | 1842 | /** |
— | — | @@ -1606,7 +1858,7 @@ |
1607 | 1859 | static void |
1608 | 1860 | SBEndHtmlAbbr(MWLISTENER *listener) |
1609 | 1861 | { |
1610 | | - APPEND_CONST_STRING("</abbr>"); |
| 1862 | + HTML_END("abbr"); |
1611 | 1863 | } |
1612 | 1864 | |
1613 | 1865 | |
— | — | @@ -1623,5 +1875,5 @@ |
1624 | 1876 | { |
1625 | 1877 | HTML_TAG("pre"); |
1626 | 1878 | SBOnSpecial(listener, body); |
1627 | | - APPEND_CONST_STRING("</pre>"); |
| 1879 | + HTML_END("pre"); |
1628 | 1880 | } |
Index: trunk/parsers/libmwparser/wrapper/Makefile.am |
— | — | @@ -2,23 +2,35 @@ |
3 | 3 | |
4 | 4 | PHP_CFLAGS=`php-config --includes` |
5 | 5 | PHP_LDFLAGS=`php-config --ldflags` |
| 6 | +PHP_LIBS=`php-config --libs` |
6 | 7 | |
7 | | -CLEANFILES=mwp_wrap.c mwp.pm |
| 8 | +CLEANFILES=mwp_wrap.c mwp.pm mwp.php php_mwp.h |
8 | 9 | |
9 | 10 | lib_LTLIBRARIES = libmwp.la |
10 | 11 | |
11 | | -libmwp_la_SOURCES = src/mwscriptbufferlistener.c \ |
12 | | - mwp_wrap.c |
| 12 | +libmwp_la_SOURCES = \ |
| 13 | + src/mwlinkresolvercallback.c \ |
| 14 | + src/mwscriptbufferlistener.c \ |
| 15 | + src/mwparser.i \ |
| 16 | + include/mwlinkresolvercallback.h \ |
| 17 | + include/mwscriptbuf.h |
13 | 18 | |
14 | | -libmwp_la_CFLAGS = $(TARGET_LANGUAGE_CFLAGS) $(GLIB_CFLAGS) -Wall |
15 | 19 | |
16 | | -libmwp_la_LDFLAGS = $(TARGET_LANGUAGE_LDFLAGS) $(GLIB_LDFLAGS) |
| 20 | +nodist_libmwp_la_SOURCES = mwp_wrap.c |
17 | 21 | |
| 22 | +libmwp_la_CFLAGS = $(TARGET_LANGUAGE_CFLAGS) $(GLIB_CFLAGS) -Wall -Wno-unused |
| 23 | + |
| 24 | +libmwp_la_LDFLAGS = $(TARGET_LANGUAGE_LDFLAGS) $(GLIB_LDFLAGS) -lmwparser -release $(PACKAGE_VERSION) |
| 25 | + |
| 26 | +libmwp_la_LIBADD = |
| 27 | + |
18 | 28 | INCLUDES = -I$(srcdir)/include -I$(top_srcdir)/include |
19 | 29 | |
| 30 | + |
20 | 31 | include_HEADERS = $(top_builddir)/config.h |
21 | 32 | |
22 | 33 | mwp_wrap.c: mwparser.i |
23 | | - swig -$(TARGET_LANGUAGE) -Wall -o $@ $< |
| 34 | + swig -$(TARGET_LANGUAGE) $(INCLUDES) -Wall -o $@ $< |
24 | 35 | |
25 | | - |
| 36 | +install-data-hook: |
| 37 | + if test x$(TARGET_LANGUAGE) = xphp ; then $(MKDIR_P) $(datarootdir)/php/MediaWiki && $(INSTALL_SCRIPT) mwp.php $(datarootdir)/php/MediaWiki; fi |
Index: trunk/parsers/libmwparser/configure |
— | — | @@ -790,6 +790,7 @@ |
791 | 791 | build_cpu |
792 | 792 | build |
793 | 793 | LIBTOOL |
| 794 | +TARGET_LANGUAGE_LDFLAGS |
794 | 795 | TARGET_LANGUAGE_CFLAGS |
795 | 796 | TARGET_LANGUAGE |
796 | 797 | GLIB_LIBS |
— | — | @@ -5404,11 +5405,12 @@ |
5405 | 5406 | TARGET_LANGUAGE_LDFLAGS='$(PERLXS_LDFLAGS)' |
5406 | 5407 | elif test "x$TARGET_LANGUAGE" == xphp; then |
5407 | 5408 | TARGET_LANGUAGE_CFLAGS='-DTARGET_LANGUAGE_PHP $(PHP_CFLAGS)' |
5408 | | - TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS)' |
| 5409 | + TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS) $(PHP_LIBS)' |
5409 | 5410 | fi |
5410 | 5411 | |
5411 | 5412 | |
5412 | 5413 | |
| 5414 | + |
5413 | 5415 | case `pwd` in |
5414 | 5416 | *\ * | *\ *) |
5415 | 5417 | { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 |
— | — | @@ -5959,13 +5961,13 @@ |
5960 | 5962 | else |
5961 | 5963 | lt_cv_nm_interface="BSD nm" |
5962 | 5964 | echo "int some_variable = 0;" > conftest.$ac_ext |
5963 | | - (eval echo "\"\$as_me:5962: $ac_compile\"" >&5) |
| 5965 | + (eval echo "\"\$as_me:5964: $ac_compile\"" >&5) |
5964 | 5966 | (eval "$ac_compile" 2>conftest.err) |
5965 | 5967 | cat conftest.err >&5 |
5966 | | - (eval echo "\"\$as_me:5965: $NM \\\"conftest.$ac_objext\\\"\"" >&5) |
| 5968 | + (eval echo "\"\$as_me:5967: $NM \\\"conftest.$ac_objext\\\"\"" >&5) |
5967 | 5969 | (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) |
5968 | 5970 | cat conftest.err >&5 |
5969 | | - (eval echo "\"\$as_me:5968: output\"" >&5) |
| 5971 | + (eval echo "\"\$as_me:5970: output\"" >&5) |
5970 | 5972 | cat conftest.out >&5 |
5971 | 5973 | if $GREP 'External.*some_variable' conftest.out > /dev/null; then |
5972 | 5974 | lt_cv_nm_interface="MS dumpbin" |
— | — | @@ -7170,7 +7172,7 @@ |
7171 | 7173 | ;; |
7172 | 7174 | *-*-irix6*) |
7173 | 7175 | # Find out which ABI we are using. |
7174 | | - echo '#line 7173 "configure"' > conftest.$ac_ext |
| 7176 | + echo '#line 7175 "configure"' > conftest.$ac_ext |
7175 | 7177 | if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 |
7176 | 7178 | (eval $ac_compile) 2>&5 |
7177 | 7179 | ac_status=$? |
— | — | @@ -8432,11 +8434,11 @@ |
8433 | 8435 | -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ |
8434 | 8436 | -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ |
8435 | 8437 | -e 's:$: $lt_compiler_flag:'` |
8436 | | - (eval echo "\"\$as_me:8435: $lt_compile\"" >&5) |
| 8438 | + (eval echo "\"\$as_me:8437: $lt_compile\"" >&5) |
8437 | 8439 | (eval "$lt_compile" 2>conftest.err) |
8438 | 8440 | ac_status=$? |
8439 | 8441 | cat conftest.err >&5 |
8440 | | - echo "$as_me:8439: \$? = $ac_status" >&5 |
| 8442 | + echo "$as_me:8441: \$? = $ac_status" >&5 |
8441 | 8443 | if (exit $ac_status) && test -s "$ac_outfile"; then |
8442 | 8444 | # The compiler can only warn and ignore the option if not recognized |
8443 | 8445 | # So say no if there are warnings other than the usual output. |
— | — | @@ -8771,11 +8773,11 @@ |
8772 | 8774 | -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ |
8773 | 8775 | -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ |
8774 | 8776 | -e 's:$: $lt_compiler_flag:'` |
8775 | | - (eval echo "\"\$as_me:8774: $lt_compile\"" >&5) |
| 8777 | + (eval echo "\"\$as_me:8776: $lt_compile\"" >&5) |
8776 | 8778 | (eval "$lt_compile" 2>conftest.err) |
8777 | 8779 | ac_status=$? |
8778 | 8780 | cat conftest.err >&5 |
8779 | | - echo "$as_me:8778: \$? = $ac_status" >&5 |
| 8781 | + echo "$as_me:8780: \$? = $ac_status" >&5 |
8780 | 8782 | if (exit $ac_status) && test -s "$ac_outfile"; then |
8781 | 8783 | # The compiler can only warn and ignore the option if not recognized |
8782 | 8784 | # So say no if there are warnings other than the usual output. |
— | — | @@ -8876,11 +8878,11 @@ |
8877 | 8879 | -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ |
8878 | 8880 | -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ |
8879 | 8881 | -e 's:$: $lt_compiler_flag:'` |
8880 | | - (eval echo "\"\$as_me:8879: $lt_compile\"" >&5) |
| 8882 | + (eval echo "\"\$as_me:8881: $lt_compile\"" >&5) |
8881 | 8883 | (eval "$lt_compile" 2>out/conftest.err) |
8882 | 8884 | ac_status=$? |
8883 | 8885 | cat out/conftest.err >&5 |
8884 | | - echo "$as_me:8883: \$? = $ac_status" >&5 |
| 8886 | + echo "$as_me:8885: \$? = $ac_status" >&5 |
8885 | 8887 | if (exit $ac_status) && test -s out/conftest2.$ac_objext |
8886 | 8888 | then |
8887 | 8889 | # The compiler can only warn and ignore the option if not recognized |
— | — | @@ -8931,11 +8933,11 @@ |
8932 | 8934 | -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ |
8933 | 8935 | -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ |
8934 | 8936 | -e 's:$: $lt_compiler_flag:'` |
8935 | | - (eval echo "\"\$as_me:8934: $lt_compile\"" >&5) |
| 8937 | + (eval echo "\"\$as_me:8936: $lt_compile\"" >&5) |
8936 | 8938 | (eval "$lt_compile" 2>out/conftest.err) |
8937 | 8939 | ac_status=$? |
8938 | 8940 | cat out/conftest.err >&5 |
8939 | | - echo "$as_me:8938: \$? = $ac_status" >&5 |
| 8941 | + echo "$as_me:8940: \$? = $ac_status" >&5 |
8940 | 8942 | if (exit $ac_status) && test -s out/conftest2.$ac_objext |
8941 | 8943 | then |
8942 | 8944 | # The compiler can only warn and ignore the option if not recognized |
— | — | @@ -11315,7 +11317,7 @@ |
11316 | 11318 | lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 |
11317 | 11319 | lt_status=$lt_dlunknown |
11318 | 11320 | cat > conftest.$ac_ext <<_LT_EOF |
11319 | | -#line 11318 "configure" |
| 11321 | +#line 11320 "configure" |
11320 | 11322 | #include "confdefs.h" |
11321 | 11323 | |
11322 | 11324 | #if HAVE_DLFCN_H |
— | — | @@ -11411,7 +11413,7 @@ |
11412 | 11414 | lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 |
11413 | 11415 | lt_status=$lt_dlunknown |
11414 | 11416 | cat > conftest.$ac_ext <<_LT_EOF |
11415 | | -#line 11414 "configure" |
| 11417 | +#line 11416 "configure" |
11416 | 11418 | #include "confdefs.h" |
11417 | 11419 | |
11418 | 11420 | #if HAVE_DLFCN_H |
Index: trunk/parsers/libmwparser/Makefile.in |
— | — | @@ -77,12 +77,15 @@ |
78 | 78 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' |
79 | 79 | am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)" |
80 | 80 | LTLIBRARIES = $(lib_LTLIBRARIES) |
81 | | -libmwparser_la_LIBADD = |
| 81 | +am__DEPENDENCIES_1 = |
| 82 | +libmwparser_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(ANTLR3C_LIBS); |
82 | 83 | am_libmwparser_la_OBJECTS = libmwparser_la-mwattributes.lo \ |
83 | 84 | libmwparser_la-mwbasicevents.lo libmwparser_la-mwformats.lo \ |
84 | 85 | libmwparser_la-mwheadings.lo libmwparser_la-mwhtml.lo \ |
85 | 86 | libmwparser_la-mwlexercontext.lo libmwparser_la-mwlinks.lo \ |
86 | | - libmwparser_la-mwlinkcollection.lo libmwparser_la-mwparser.lo \ |
| 87 | + libmwparser_la-mwlinkresolution.lo \ |
| 88 | + libmwparser_la-mwlinkcollection.lo \ |
| 89 | + libmwparser_la-mwmedialinkoption.lo libmwparser_la-mwparser.lo \ |
87 | 90 | libmwparser_la-mwparsercontext.lo libmwparser_la-mwtagext.lo \ |
88 | 91 | libmwparser_la-mwtables.lo libmwparser_la-tracingcontext.lo |
89 | 92 | am__objects_1 = libmwparser_la-mwWikitextLexer.lo |
— | — | @@ -90,7 +93,7 @@ |
91 | 94 | am__objects_3 = |
92 | 95 | am__objects_4 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \ |
93 | 96 | $(am__objects_3) |
94 | | -nodist_libmwparser_la_OBJECTS = $(am__objects_4) $(am__objects_3) |
| 97 | +nodist_libmwparser_la_OBJECTS = $(am__objects_4) |
95 | 98 | libmwparser_la_OBJECTS = $(am_libmwparser_la_OBJECTS) \ |
96 | 99 | $(nodist_libmwparser_la_OBJECTS) |
97 | 100 | libmwparser_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ |
— | — | @@ -237,6 +240,7 @@ |
238 | 241 | SWIG_LIB = @SWIG_LIB@ |
239 | 242 | TARGET_LANGUAGE = @TARGET_LANGUAGE@ |
240 | 243 | TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@ |
| 244 | +TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@ |
241 | 245 | VERSION = @VERSION@ |
242 | 246 | abs_builddir = @abs_builddir@ |
243 | 247 | abs_srcdir = @abs_srcdir@ |
— | — | @@ -297,11 +301,9 @@ |
298 | 302 | SUBDIRS = tests wrapper |
299 | 303 | ANTLR_LEXER = mwWikitextLexer |
300 | 304 | ANTLR_PARSER = mwWikitextParser |
301 | | -ANTLR_LEXER_DELEGATES = |
302 | 305 | ANTLR_GRAMMARS = $(ANTLR_LEXER:=.g) $(ANTLR_PARSER:=.g) |
303 | 306 | ANTLR_SOURCES = $(ANTLR_LEXER:=.c) $(ANTLR_PARSER:=.c) $(ANTLR_LEXER:=.h) $(ANTLR_PARSER:=.h) |
304 | | -ANTLR_LEXER_DELEGATE_SOURCES = |
305 | | -CLEANFILES = $(ANTLR_LEXER_DELEGATE_SOURCES) $(ANTLR_LEXER_DELEGATES:=.tokens) $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc |
| 307 | +CLEANFILES = $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc |
306 | 308 | lib_LTLIBRARIES = libmwparser.la |
307 | 309 | nodist_libmwparser_la_SOURCES = $(ANTLR_SOURCES) $(ANTLR_LEXER_DELEGATE_SOURCES) |
308 | 310 | libmwparser_la_SOURCES = \ |
— | — | @@ -314,9 +316,11 @@ |
315 | 317 | include/mwkeyvalue.h \ |
316 | 318 | include/mwlexercontext.h \ |
317 | 319 | include/mwlinkcollection.h \ |
| 320 | + include/mwlinkresolution.h \ |
318 | 321 | include/mwlinks.h \ |
319 | 322 | include/mwlistener.h \ |
320 | 323 | include/mwparser.h \ |
| 324 | + include/mwmedialinkoption.h \ |
321 | 325 | include/mwparsercontext.h \ |
322 | 326 | include/mwtables.h \ |
323 | 327 | include/mwtagext.h \ |
— | — | @@ -329,7 +333,9 @@ |
330 | 334 | src/mwhtml.c \ |
331 | 335 | src/mwlexercontext.c \ |
332 | 336 | src/mwlinks.c \ |
| 337 | + src/mwlinkresolution.c \ |
333 | 338 | src/mwlinkcollection.c \ |
| 339 | + src/mwmedialinkoption.c \ |
334 | 340 | src/mwparser.c \ |
335 | 341 | src/mwparsercontext.c \ |
336 | 342 | src/mwtagext.c \ |
— | — | @@ -342,9 +348,9 @@ |
343 | 349 | src/mwlexerpredicatedefs.php \ |
344 | 350 | antlr.patch |
345 | 351 | |
346 | | -libmwparser_la_LIBS = $(GLIB_LIBS) |
347 | 352 | libmwparser_la_CFLAGS = $(GLIB_CFLAGS) -std=gnu99 -Wall -Wno-unused-variable |
348 | 353 | libmwparser_la_LDFLAGS = -release $(PACKAGE_VERSION) |
| 354 | +libmwparser_la_LIBADD = $(GLIB_LIBS) $(ANTLR3C_LIBS); |
349 | 355 | INCLUDES = -I$(top_srcdir)/include |
350 | 356 | include_HEADERS = config.h |
351 | 357 | ANTLR_PRODUCTS = |
— | — | @@ -455,7 +461,9 @@ |
456 | 462 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwhtml.Plo@am__quote@ |
457 | 463 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwlexercontext.Plo@am__quote@ |
458 | 464 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwlinkcollection.Plo@am__quote@ |
| 465 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwlinkresolution.Plo@am__quote@ |
459 | 466 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwlinks.Plo@am__quote@ |
| 467 | +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwmedialinkoption.Plo@am__quote@ |
460 | 468 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwparser.Plo@am__quote@ |
461 | 469 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwparsercontext.Plo@am__quote@ |
462 | 470 | @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwtables.Plo@am__quote@ |
— | — | @@ -532,6 +540,13 @@ |
533 | 541 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
534 | 542 | @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -c -o libmwparser_la-mwlinks.lo `test -f 'src/mwlinks.c' || echo '$(srcdir)/'`src/mwlinks.c |
535 | 543 | |
| 544 | +libmwparser_la-mwlinkresolution.lo: src/mwlinkresolution.c |
| 545 | +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -MT libmwparser_la-mwlinkresolution.lo -MD -MP -MF $(DEPDIR)/libmwparser_la-mwlinkresolution.Tpo -c -o libmwparser_la-mwlinkresolution.lo `test -f 'src/mwlinkresolution.c' || echo '$(srcdir)/'`src/mwlinkresolution.c |
| 546 | +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwparser_la-mwlinkresolution.Tpo $(DEPDIR)/libmwparser_la-mwlinkresolution.Plo |
| 547 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/mwlinkresolution.c' object='libmwparser_la-mwlinkresolution.lo' libtool=yes @AMDEPBACKSLASH@ |
| 548 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
| 549 | +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -c -o libmwparser_la-mwlinkresolution.lo `test -f 'src/mwlinkresolution.c' || echo '$(srcdir)/'`src/mwlinkresolution.c |
| 550 | + |
536 | 551 | libmwparser_la-mwlinkcollection.lo: src/mwlinkcollection.c |
537 | 552 | @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -MT libmwparser_la-mwlinkcollection.lo -MD -MP -MF $(DEPDIR)/libmwparser_la-mwlinkcollection.Tpo -c -o libmwparser_la-mwlinkcollection.lo `test -f 'src/mwlinkcollection.c' || echo '$(srcdir)/'`src/mwlinkcollection.c |
538 | 553 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwparser_la-mwlinkcollection.Tpo $(DEPDIR)/libmwparser_la-mwlinkcollection.Plo |
— | — | @@ -539,6 +554,13 @@ |
540 | 555 | @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
541 | 556 | @am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -c -o libmwparser_la-mwlinkcollection.lo `test -f 'src/mwlinkcollection.c' || echo '$(srcdir)/'`src/mwlinkcollection.c |
542 | 557 | |
| 558 | +libmwparser_la-mwmedialinkoption.lo: src/mwmedialinkoption.c |
| 559 | +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -MT libmwparser_la-mwmedialinkoption.lo -MD -MP -MF $(DEPDIR)/libmwparser_la-mwmedialinkoption.Tpo -c -o libmwparser_la-mwmedialinkoption.lo `test -f 'src/mwmedialinkoption.c' || echo '$(srcdir)/'`src/mwmedialinkoption.c |
| 560 | +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwparser_la-mwmedialinkoption.Tpo $(DEPDIR)/libmwparser_la-mwmedialinkoption.Plo |
| 561 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='src/mwmedialinkoption.c' object='libmwparser_la-mwmedialinkoption.lo' libtool=yes @AMDEPBACKSLASH@ |
| 562 | +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ |
| 563 | +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -c -o libmwparser_la-mwmedialinkoption.lo `test -f 'src/mwmedialinkoption.c' || echo '$(srcdir)/'`src/mwmedialinkoption.c |
| 564 | + |
543 | 565 | libmwparser_la-mwparser.lo: src/mwparser.c |
544 | 566 | @am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmwparser_la_CFLAGS) $(CFLAGS) -MT libmwparser_la-mwparser.lo -MD -MP -MF $(DEPDIR)/libmwparser_la-mwparser.Tpo -c -o libmwparser_la-mwparser.lo `test -f 'src/mwparser.c' || echo '$(srcdir)/'`src/mwparser.c |
545 | 567 | @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwparser_la-mwparser.Tpo $(DEPDIR)/libmwparser_la-mwparser.Plo |
Index: trunk/parsers/libmwparser/include/mwlinkcollection.h |
— | — | @@ -1,10 +1,14 @@ |
2 | 2 | #ifndef MWLINKCOLLECTION_H_ |
3 | 3 | #define MWLINKCOLLECTION_H_ |
4 | 4 | |
| 5 | +#include <mwlinkresolution.h> |
| 6 | + |
5 | 7 | typedef struct MWLINKCOLLECTION_struct MWLINKCOLLECTION; |
6 | 8 | |
7 | 9 | typedef void * MWLINKCOLLECTION_MARK; |
8 | 10 | |
| 11 | +typedef struct LCKEY_struct MWLCKEY; |
| 12 | + |
9 | 13 | typedef enum MWLINKTYPE { MWLT_INTERNAL, MWLT_EXTERNAL, MWLT_MEDIA, MWLT_LINKATTR } MWLINKTYPE; |
10 | 14 | |
11 | 15 | MWLINKCOLLECTION *MWLinkCollectionNew(void); |
— | — | @@ -13,8 +17,23 @@ |
14 | 18 | MWLINKTYPE type, |
15 | 19 | pANTLR3_STRING link, |
16 | 20 | pANTLR3_COMMON_TOKEN token); |
| 21 | +int MWLinkCollectionNumLinks(MWLINKCOLLECTION *collection); |
17 | 22 | |
18 | 23 | MWLINKCOLLECTION_MARK MWLinkCollectionMark(MWLINKCOLLECTION *collection); |
19 | 24 | void MWLinkCollectionRewind(MWLINKCOLLECTION *collection, MWLINKCOLLECTION_MARK mark); |
20 | 25 | |
| 26 | +void MWLinkCollectionTraverse(MWLINKCOLLECTION *linkCollection, |
| 27 | + int (*callback)(MWLCKEY *key, void *data), |
| 28 | + void *callbackData); |
| 29 | + |
| 30 | +void MWLinkCollectionResolve(MWLINKCOLLECTION *linkCollection, |
| 31 | + MWLCKEY *key, |
| 32 | + MWLINKRESOLUTION *resolution); |
| 33 | + |
| 34 | +const char *MWLCKeyGetLinkTitle(MWLCKEY *lckey); |
| 35 | +MWLINKTYPE MWLCKeyGetLinkType(MWLCKEY *lckey); |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
21 | 40 | #endif |
Index: trunk/parsers/libmwparser/include/mwlinkresolution.h |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +#ifndef MWLINKRESOLUTION_H_ |
| 3 | +#define MWLINKRESOLUTION_H_ |
| 4 | + |
| 5 | +typedef enum { MWLINKCOLOR_BLUE, MWLINKCOLOR_RED } MWLINKCOLOR; |
| 6 | + |
| 7 | +typedef struct |
| 8 | +{ |
| 9 | + MWLINKCOLOR color; |
| 10 | + const char *url; |
| 11 | + const char *imageUrl; |
| 12 | + const char *imageWidth; |
| 13 | + const char *imageHeight; |
| 14 | + const char *class; |
| 15 | + const char *alt; |
| 16 | + |
| 17 | +#ifndef SWIG |
| 18 | + void (*free)(void *data); |
| 19 | + void *freeData; |
| 20 | +#endif |
| 21 | +} |
| 22 | + MWLINKRESOLUTION; |
| 23 | + |
| 24 | +#ifndef SWIG |
| 25 | +void MWLinkResolutionFree(void *linkResolution); |
| 26 | +#endif |
| 27 | + |
| 28 | +#endif |
Index: trunk/parsers/libmwparser/include/mwlexercontext.h |
— | — | @@ -88,6 +88,9 @@ |
89 | 89 | bool (*isMediaLinkTitle)(struct MWLEXERCONTEXT_struct * context, pANTLR3_STRING text); |
90 | 90 | bool (*setLegalTitleRegexp)(struct MWLEXERCONTEXT_struct *context, const char *perlRegexp); |
91 | 91 | bool (*setMediaLinkTitleRegexp)(struct MWLEXERCONTEXT_struct *context, const char *perlRegexp); |
| 92 | + void (*resolveLinks)(struct MWLEXERCONTEXT_struct *context); |
| 93 | + void (*linkResolver)(MWLINKCOLLECTION *linkCollection, void *data); |
| 94 | + void *linkResolverData; |
92 | 95 | } |
93 | 96 | MWLEXERCONTEXT; |
94 | 97 | |
Index: trunk/parsers/libmwparser/include/mwlistener.h |
— | — | @@ -20,6 +20,7 @@ |
21 | 21 | #ifndef MWLISTENER_H_ |
22 | 22 | #define MWLISTENER_H_ |
23 | 23 | |
| 24 | +struct MWLINKCOLLECTION_struct; |
24 | 25 | |
25 | 26 | /** |
26 | 27 | * This interface should be implemented by the client application. |
— | — | @@ -40,6 +41,10 @@ |
41 | 42 | void * (*newData)(void); |
42 | 43 | void (*freeData)(void *); |
43 | 44 | void (*resetData)(void *); |
| 45 | + |
| 46 | + void (*linkResolver)(struct MWLINKCOLLECTION_struct *linkCollection, void *data); |
| 47 | + void (*setLinkResolverData)(void *listenerData, void **linkResolverData); |
| 48 | + |
44 | 49 | void * (*getResult)(struct MWLISTENER_struct * listener); |
45 | 50 | |
46 | 51 | |
— | — | @@ -95,15 +100,15 @@ |
96 | 101 | void (*endTableBody)(struct MWLISTENER_struct * listener); |
97 | 102 | void (*beginHeading)(struct MWLISTENER_struct * listener, int level, pANTLR3_STRING anchor, pANTLR3_VECTOR attributes); |
98 | 103 | void (*endHeading)(struct MWLISTENER_struct * listener); |
99 | | - void (*beginInternalLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkTitle); |
| 104 | + void (*beginInternalLink)(struct MWLISTENER_struct * listener, pANTLR3_VECTOR attr); |
100 | 105 | void (*endInternalLink)(struct MWLISTENER_struct * listener); |
101 | | - void (*onInternalLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl); |
| 106 | + void (*onInternalLink)(struct MWLISTENER_struct * listener, pANTLR3_VECTOR attr); |
102 | 107 | void (*beginExternalLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl); |
103 | 108 | void (*endExternalLink)(struct MWLISTENER_struct * listener); |
104 | 109 | void (*onExternalLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl); |
105 | | - void (*beginMediaLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 110 | + void (*beginMediaLink)(struct MWLISTENER_struct * listener, pANTLR3_VECTOR attr); |
106 | 111 | void (*endMediaLink)(struct MWLISTENER_struct * listener); |
107 | | - void (*onMediaLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr); |
| 112 | + void (*onMediaLink)(struct MWLISTENER_struct * listener, pANTLR3_VECTOR attr); |
108 | 113 | void (*onTagExtension)(struct MWLISTENER_struct * listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr); |
109 | 114 | void (*beginTableOfContents)(struct MWLISTENER_struct * listener); |
110 | 115 | void (*endTableOfContents)(struct MWLISTENER_struct * listener); |
Index: trunk/parsers/libmwparser/include/mwmedialinkoption.h |
— | — | @@ -0,0 +1,37 @@ |
| 2 | +#ifndef MWMEDIALINKOPTION_H_ |
| 3 | +#define MWMEDIALINKOPTION_H_ |
| 4 | + |
| 5 | +#include <stdbool.h> |
| 6 | + |
| 7 | +typedef enum { |
| 8 | + LOF_NONE, LOF_FRAME, LOF_FRAMELESS, LOF_THUMBNAIL |
| 9 | +} |
| 10 | + MEDIALINKOPTION_FRAME; |
| 11 | + |
| 12 | +typedef enum { |
| 13 | + LOHA_NONE, LOHA_LEFT, LOHA_RIGHT, LOHA_CENTER, |
| 14 | +} |
| 15 | + MEDIALINKOPTION_HALIGN; |
| 16 | + |
| 17 | +typedef enum { |
| 18 | + LOVA_NONE, LOVA_BASELINE, LOVA_SUB, LOVA_SUPER, LOVA_TOP, LOVA_TEXT_TOP, LOVA_MIDDLE, LOVA_BOTTOM, LOVA_TEXT_BOTTOM |
| 19 | +} |
| 20 | + MEDIALINKOPTION_VALIGN; |
| 21 | + |
| 22 | +typedef struct MEDIALINKOPTION_struct |
| 23 | +{ |
| 24 | + MEDIALINKOPTION_FRAME frame; |
| 25 | + MEDIALINKOPTION_HALIGN halign; |
| 26 | + MEDIALINKOPTION_VALIGN valign; |
| 27 | + bool upright; |
| 28 | + bool border; |
| 29 | + pANTLR3_STRING alt; |
| 30 | + pANTLR3_STRING width; |
| 31 | + pANTLR3_STRING height; |
| 32 | +} |
| 33 | + MEDIALINKOPTION; |
| 34 | + |
| 35 | +MEDIALINKOPTION *MWMediaLinkOptionNew(void); |
| 36 | +void MWMediaLinkOptionFree(void *mediaLinkOption); |
| 37 | + |
| 38 | +#endif |
Index: trunk/parsers/libmwparser/include/mwparsercontext.h |
— | — | @@ -88,9 +88,9 @@ |
89 | 89 | void (*beginHtmlCenter)(struct MWPARSERCONTEXT_struct * context, pANTLR3_VECTOR attr); |
90 | 90 | void (*endHtmlCenter)(struct MWPARSERCONTEXT_struct * context); |
91 | 91 | |
92 | | - void (*beginInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkTitle); |
| 92 | + void (*beginInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_VECTOR attr); |
93 | 93 | void (*endInternalLink)(struct MWPARSERCONTEXT_struct * context); |
94 | | - void (*onInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkTitle); |
| 94 | + void (*onInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_VECTOR attr); |
95 | 95 | void (*beginExternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkUrl); |
96 | 96 | void (*endExternalLink)(struct MWPARSERCONTEXT_struct * context); |
97 | 97 | void (*onExternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkUrl); |
— | — | @@ -214,10 +214,15 @@ |
215 | 215 | } |
216 | 216 | MWPARSERCONTEXT; |
217 | 217 | |
| 218 | +struct MWLEXERCONTEXT_struct; |
| 219 | + |
218 | 220 | /** |
219 | | - * Constructor for the parser context super class. |
| 221 | + * Constructor for the parser context class. |
| 222 | + * @param parser pointer to the antlr generated parser. |
| 223 | + * @param listener pointer to listener implementation. |
| 224 | + * @param lexerContext pointer to lexer context. |
220 | 225 | */ |
221 | | -MWPARSERCONTEXT * MWParserContextNew(void* parser, const MWLISTENER *listener); |
| 226 | +MWPARSERCONTEXT * MWParserContextNew(void* parser, const MWLISTENER *listener, struct MWLEXERCONTEXT_struct *lexerContext); |
222 | 227 | |
223 | 228 | /** |
224 | 229 | * Put this macro at the beginning of begin methods that should not be |