r73525 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73524‎ | r73525 | r73526 >
Date:13:03, 22 September 2010
Author:aj
Status:deferred
Tags:
Comment:
added link resolution, refactored media link options, added image link rendering
Modified paths:
  • /trunk/parsers/libmwparser/Makefile.am (modified) (history)
  • /trunk/parsers/libmwparser/Makefile.in (modified) (history)
  • /trunk/parsers/libmwparser/configure (modified) (history)
  • /trunk/parsers/libmwparser/configure.ac (modified) (history)
  • /trunk/parsers/libmwparser/include/mwlexercontext.h (modified) (history)
  • /trunk/parsers/libmwparser/include/mwlinkcollection.h (modified) (history)
  • /trunk/parsers/libmwparser/include/mwlinkresolution.h (added) (history)
  • /trunk/parsers/libmwparser/include/mwlistener.h (modified) (history)
  • /trunk/parsers/libmwparser/include/mwmedialinkoption.h (added) (history)
  • /trunk/parsers/libmwparser/include/mwparsercontext.h (modified) (history)
  • /trunk/parsers/libmwparser/src/mwWikitextLexer.g (modified) (history)
  • /trunk/parsers/libmwparser/src/mwWikitextParser.g (modified) (history)
  • /trunk/parsers/libmwparser/src/mwlexercontext.c (modified) (history)
  • /trunk/parsers/libmwparser/src/mwlinkcollection.c (modified) (history)
  • /trunk/parsers/libmwparser/src/mwlinkresolution.c (added) (history)
  • /trunk/parsers/libmwparser/src/mwlinks.c (modified) (history)
  • /trunk/parsers/libmwparser/src/mwlistener.template (modified) (history)
  • /trunk/parsers/libmwparser/src/mwmedialinkoption.c (added) (history)
  • /trunk/parsers/libmwparser/src/mwparser.c (modified) (history)
  • /trunk/parsers/libmwparser/src/mwparsercontext.c (modified) (history)
  • /trunk/parsers/libmwparser/src/tracingcontext.c (modified) (history)
  • /trunk/parsers/libmwparser/tests/Makefile.in (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/Makefile.am (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/Makefile.in (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/include/mwlinkresolvercallback.h (added) (history)
  • /trunk/parsers/libmwparser/wrapper/include/mwscriptbuf.h (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/src/mwlinkresolvercallback.c (added) (history)
  • /trunk/parsers/libmwparser/wrapper/src/mwparser.i (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/src/mwscriptbuf.c (modified) (history)
  • /trunk/parsers/libmwparser/wrapper/src/mwscriptbufferlistener.c (modified) (history)

Diff [purge]

Index: trunk/parsers/libmwparser/src/mwWikitextLexer.g
@@ -152,6 +152,7 @@
153153 #include <mwlexercontext.h>
154154 #include <mwutils.h>
155155 #include <mwkeyvalue.h>
 156+#include <mwmedialinkoption.h>
156157 }
157158
158159 @lexer::members{
@@ -288,11 +289,19 @@
289290 {
290291 MWLEXERCONTEXT *context = param;
291292 speculationSuccess(context, &context->indentSpeculation);
 293+ bool willFail = context->headingSpeculation.active
 294+ || context->internalLinkSpeculation.active
 295+ || context->mediaLinkSpeculation[0].active
 296+ || context->mediaLinkSpeculation[1].active;
292297 SPECULATION_FAILURE(context,
293298 &context->headingSpeculation,
294299 &context->internalLinkSpeculation,
295300 &context->mediaLinkSpeculation[0],
296301 &context->mediaLinkSpeculation[1]);
 302+
 303+ if (!willFail) {
 304+ context->resolveLinks(context);
 305+ }
297306 }
298307
299308
@@ -302,8 +311,8 @@
303312 fragment
304313 NOWIKI
305314 @init{
306 - ANTLR3_MARKER nowikiStart;
307 - ANTLR3_MARKER nowikiEnd;
 315+ ANTLR3_MARKER nowikiStart = 0;
 316+ ANTLR3_MARKER nowikiEnd = 0;
308317 pANTLR3_VECTOR attrs = NULL;
309318 }:
310319 N O W I K I (SPACE_TAB ATTRIBUTE_LIST_HTML[&attrs]? )? '>'
@@ -333,8 +342,8 @@
334343 fragment
335344 HTML_PRE
336345 @init{
337 - ANTLR3_MARKER preStart;
338 - ANTLR3_MARKER preEnd;
 346+ ANTLR3_MARKER preStart = 0;
 347+ ANTLR3_MARKER preEnd = 0;
339348 pANTLR3_VECTOR attrs = NULL;
340349 }:
341350 {!CX->htmlPreDisabled}?=> P R E (SPACE_TAB ATTRIBUTE_LIST_HTML[&attrs]? )? '>'
@@ -385,8 +394,8 @@
386395
387396 END_HEADING
388397 @init {
389 - ANTLR3_MARKER mark;
390 - ANTLR3_MARKER endHeadingText;
 398+ ANTLR3_MARKER mark = 0;
 399+ ANTLR3_MARKER endHeadingText = 0;
391400 }:
392401 {!CX->wikitextHeadingCloseDisabled}?=> '=' {mark = MARK();endHeadingText = GETCHARINDEX();}
393402 ( ({CX->headingLevel == 1}?=> END_HEADING_EOL[mark])
@@ -416,9 +425,9 @@
417426
418427 INDENTED_LIST_TABLE
419428 @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;
423432 }:
424433 {BOL}?=>
425434 {
@@ -543,14 +552,15 @@
544553 */
545554 INTERNAL_LINK
546555 @init{
547 - ANTLR3_MARKER mark;
 556+ ANTLR3_MARKER mark = 0;
548557 pANTLR3_STRING linkTitle;
549558 pANTLR3_STRING linkAnchor=NULL;
550559 bool isCompleteLink = false;
551560 bool success = true;
552 - bool alreadyInInternalLink;
553 - bool isMediaLink;
 561+ bool alreadyInInternalLink = false;
 562+ bool isMediaLink = false;
554563 pANTLR3_VECTOR attr = NULL;
 564+ MEDIALINKOPTION *mlOption = NULL;
555565 pANTLR3_STRING attrLink = NULL;
556566 }: {!CX->mediaLinkOpenDisabled && !alreadyTried(CX, &CX->internalLinkSpeculation)
557567 /*
@@ -592,7 +602,7 @@
593603 ('#' INTERNAL_LINK_ANCHOR[&linkAnchor])?
594604 (
595605 ']]' {isCompleteLink=true;}
596 - | '|' ({isMediaLink}?=> MEDIA_LINK_ATTRIBUTES[&attr, &attrLink] | )
 606+ | '|' ({isMediaLink}?=> MEDIA_LINK_OPTIONS[&mlOption, &attrLink] | )
597607 | {success = false;}
598608 )
599609 )
@@ -621,8 +631,17 @@
622632 * We'll pack the link title in the attribute vector.
623633 * The parser will unpack it and send it as a separate
624634 * parameter to the client.
 635+ *
 636+ * Argument convention:
 637+ *
 638+ * options, linkTitle, linkAnchor, linkResolution, attributeLinkResolution
625639 */
 640+
 641+ attr->add(attr, mlOption, MWMediaLinkOptionFree);
626642 attr->add(attr, linkTitle, NULL);
 643+ attr->add(attr, linkAnchor, NULL);
 644+ attr->add(attr, NULL, NULL);
 645+ attr->add(attr, NULL, NULL);
627646 token->custom = attr;
628647 if (isCompleteLink) {
629648 token->setType(token, MEDIA_LINK);
@@ -634,7 +653,16 @@
635654 } else if (CX->isLegalTitle(CX, linkTitle)) {
636655 MWLinkCollectionAdd(CX->linkCollection, MWLT_INTERNAL, linkTitle, token);
637656 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;
639667 if (isCompleteLink) {
640668 speculationAbort(CX, &CX->internalLinkSpeculation);
641669 } else {
@@ -674,94 +702,90 @@
675703 ;
676704
677705 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+ )*
686714 ;
687715
688716 fragment
689 -MEDIA_LINK_ATTRIBUTE[pANTLR3_VECTOR *attrs]
 717+MEDIA_LINK_OPTION[MEDIALINKOPTION **mlOption]
690718 @init{
691 - ANTLR3_MARKER start;
 719+ ANTLR3_MARKER start = 0;
692720 }:
693721 {
694 - start = GETCHARINDEX();
 722+ if (*mlOption == NULL) {
 723+ *mlOption = MWMediaLinkOptionNew();
 724+ }
695725 }
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; }))
717744 ;
718745
719746 fragment
720 -MEDIA_LINK_ATTRIBUTE_WITH_VALUE[pANTLR3_VECTOR *attrs, pANTLR3_STRING *link]
 747+MEDIA_LINK_OPTION_WITH_VALUE[MEDIALINKOPTION **mlOption, pANTLR3_STRING *link]
721748 @init{
722 - ANTLR3_MARKER startKey;
723 - ANTLR3_MARKER endKey;
724 - ANTLR3_MARKER startVal;
 749+ ANTLR3_MARKER startVal = 0;
725750 bool hasHeight = false;
726751 bool hasWidth = false;
727752 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;
732757 }:
733758 {
734 - startKey = GETCHARINDEX();
 759+ if (*mlOption == NULL) {
 760+ *mlOption = MWMediaLinkOptionNew();
 761+ }
735762 }
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, ']')}?=> ']')*)
739766 {
740767 pANTLR3_STRING val = SUBSTR1(startVal);
741 - MWKEYVALUE kv = { SUBSTR2(startKey, endKey), val };
742 - addAttribute(CX, attrs, kv);
743768 if (isLink) {
744769 *link = val;
 770+ } else {
 771+ (*mlOption)->alt = val;
745772 }
746773 }
747774 )
748775 | (({startVal1 = GETCHARINDEX(); } (({hasWidth=true; endVal1 = GETCHARINDEX();} DECIMAL_DIGIT)* 'x' {hasHeight=true;})?
749776 {startVal2 = GETCHARINDEX(); } ({ endVal2 = GETCHARINDEX(); } DECIMAL_DIGIT)+ 'px')
750777 {
751 - pANTLR3_STRING width = CX->stringFactory->newStr8(CX->stringFactory, "width");
752778 if (hasHeight) {
753 - pANTLR3_STRING height = CX->stringFactory->newStr8(CX->stringFactory, "height");
754 - MWKEYVALUE h = { height, SUBSTR2(startVal2, endVal2) };
755779 if (hasWidth) {
756 - MWKEYVALUE w = { width, SUBSTR2(startVal1, endVal1) };
757 - addAttribute(CX, attrs, w);
 780+ (*mlOption)->width = SUBSTR2(startVal1, endVal1);
758781 }
759 - addAttribute(CX, attrs, h);
 782+ (*mlOption)->height = SUBSTR2(startVal2, endVal2);
760783 } else {
761 - MWKEYVALUE w = { width, SUBSTR2(startVal2, endVal2) };
762 - addAttribute(CX, attrs, w);
 784+
 785+ (*mlOption)->width = SUBSTR2(startVal2, endVal2);
763786 }
764787 }
765788 )
 789+ )
766790 ;
767791
768792 END_INTERNAL_LINK: {!CX->internalLinkCloseDisabled}?=> ']]'
@@ -783,8 +807,8 @@
784808 @init{
785809 bool success = true;
786810 bool complete = true;
787 - ANTLR3_MARKER urlStart;
788 - ANTLR3_MARKER urlEnd;
 811+ ANTLR3_MARKER urlStart = 0;
 812+ ANTLR3_MARKER urlEnd = 0;
789813 }: {!CX->externalLinkOpenDisabled && !alreadyTried(CX, &CX->externalLinkSpeculation)}?=>
790814 {
791815 speculationInitiate(CX, &CX->externalLinkSpeculation);
@@ -798,7 +822,7 @@
799823 pANTLR3_STRING url = SUBSTR2(urlStart, urlEnd);
800824 pANTLR3_COMMON_TOKEN token = NEW_TOK(EXTERNAL_LINK, url);
801825 token->custom = url;
802 - MWLinkCollectionAdd(CX->linkCollection, MWLT_EXTERNAL, url, token);
 826+ //MWLinkCollectionAdd(CX->linkCollection, MWLT_EXTERNAL, url, token);
803827 if (!complete) {
804828 token->setType(token, BEGIN_EXTERNAL_LINK);
805829 onExternalLinkOpen(CX);
@@ -854,7 +878,7 @@
855879 fragment
856880 INTERNAL_LINK_TITLE[pANTLR3_STRING *linkTitle]
857881 @init{
858 - ANTLR3_MARKER start;
 882+ ANTLR3_MARKER start = 0;
859883 }:
860884 {
861885 start = GETCHARINDEX();
@@ -868,7 +892,7 @@
869893 fragment
870894 INTERNAL_LINK_ANCHOR[pANTLR3_STRING *linkAnchor]
871895 @init{
872 - ANTLR3_MARKER start;
 896+ ANTLR3_MARKER start = 0;
873897 }:
874898 {
875899 start = GETCHARINDEX();
@@ -881,7 +905,7 @@
882906
883907 HTML_ENTITY
884908 @init{
885 - ANTLR3_MARKER mark;
 909+ ANTLR3_MARKER mark = 0;
886910 bool success = false;
887911 }:
888912 '&'
@@ -940,8 +964,8 @@
941965
942966 HTML_OPEN_TAG
943967 @init{
944 - ANTLR3_MARKER bodyStart;
945 - ANTLR3_MARKER bodyEnd;
 968+ ANTLR3_MARKER bodyStart = 0;
 969+ ANTLR3_MARKER bodyEnd = 0;
946970 CX->inHtmlPre = false;
947971 CX->inNowiki = false;
948972 pANTLR3_VECTOR attrs = NULL;
@@ -978,17 +1002,17 @@
9791003 fragment
9801004 TAG_EXTENSION
9811005 @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;
9871011 bool success = true;
9881012 bool empty = false;
9891013 pANTLR3_STRING name;
9901014 pANTLR3_VECTOR attr = NULL;
9911015 pANTLR3_STRING body = NULL;
992 - MWPARSER_TAGEXT *tagExt;
 1016+ MWPARSER_TAGEXT *tagExt = NULL;
9931017 }:
9941018 {
9951019 mark = MARK();
@@ -1031,9 +1055,9 @@
10321056 fragment
10331057 TAG_EXTENSION_BODY[pANTLR3_STRING name, ANTLR3_MARKER *bodyEnd]
10341058 @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;
10381062 }:
10391063 (('</' ((LETTER)=> LETTER)+)=> '</' {start = GETCHARINDEX();} ((LETTER)=> {tmpBodyEnd = end = GETCHARINDEX();} LETTER)+ ((SPACE_TAB_CHAR)=> {tmpBodyEnd = GETCHARINDEX();} SPACE_TAB_CHAR)*
10401064 (('>')=> '>' ({name->compareS(name, SUBSTR2(start, end)) == 0}?=> | {*bodyEnd = tmpBodyEnd;} TAG_EXTENSION_BODY[name, bodyEnd])
@@ -1131,7 +1155,7 @@
11321156
11331157 HTML_CLOSE_TAG
11341158 @init{
1135 - ANTLR3_MARKER endHeadingText;
 1159+ ANTLR3_MARKER endHeadingText = 0;
11361160 }:
11371161 {
11381162 endHeadingText = GETCHARINDEX();
@@ -1239,7 +1263,7 @@
12401264 ATTRIBUTE_LIST_TABLE[pANTLR3_VECTOR *attrs]
12411265 @init{
12421266 MWKEYVALUE attr;
1243 - bool success;
 1267+ bool success = false;
12441268 }:
12451269 SKIP_SPACE
12461270 (
@@ -1264,8 +1288,8 @@
12651289 ATTRIBUTE_LIST_TABLE_CELL[pANTLR3_VECTOR *attrs]
12661290 @init{
12671291 MWKEYVALUE attr;
1268 - bool success;
1269 - ANTLR3_MARKER mark;
 1292+ bool success = false;
 1293+ ANTLR3_MARKER mark = 0;
12701294 }:
12711295 {
12721296 mark = MARK();
@@ -1304,7 +1328,7 @@
13051329 ATTRIBUTE_LIST_HTML[pANTLR3_VECTOR *attrs]
13061330 @init{
13071331 MWKEYVALUE attr;
1308 - bool success;
 1332+ bool success = false;
13091333 }:
13101334 (
13111335 (
@@ -1340,7 +1364,7 @@
13411365 fragment
13421366 ATTRIBUTE_NAME[pANTLR3_STRING *name]
13431367 @init{
1344 - ANTLR3_MARKER start;
 1368+ ANTLR3_MARKER start = 0;
13451369 }:
13461370 { start = GETCHARINDEX(); }
13471371 (('xml:')=>'xml:'|('xmlns:')=>'xmlns:')? (LETTER|DECIMAL_DIGIT)+
@@ -1348,7 +1372,10 @@
13491373 ;
13501374
13511375 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+}:
13531380 (
13541381 ('"'
13551382 { start = GETCHARINDEX(); }
@@ -1420,7 +1447,7 @@
14211448 fragment NON_WHITESPACE_OR_BAR_OR_OPEN_BRACKET_CHAR: ~(SPACE_TAB_CHAR | NEWLINE_CHAR | '|' | '[' |'!'|
14221449 '-'|
14231450 '}');
1424 -fragment MEDIA_LINK_ATTRIBUTE_VALUE_CHAR: ~(NON_PRINTABLE_CHAR|'|'|']');
 1451+fragment MEDIA_LINK_OPTION_VALUE_CHAR: ~(NON_PRINTABLE_CHAR|'|'|']');
14251452 fragment SKIP_SPACE: ((SPACE_TAB_CHAR)=> SPACE_TAB_CHAR)*;
14261453 fragment LETTER: UCASE_LETTER | LCASE_LETTER;
14271454 fragment HTML_ENTITY_CHARS: HTML_ENTITY_CHAR+;
Index: trunk/parsers/libmwparser/src/mwlistener.template
@@ -2,6 +2,7 @@
33 #include <mwkeyvalue.h>
44 #include <mwlistener.h>
55 #include <wchar.h>
 6+#include <mwlinkresolution.h>
67
78 /*
89 * A note on memory management: All parameters of type pANTLR3_STRING
@@ -73,15 +74,15 @@
7475 static void PREFIX`EndHtmlBlockquote'(MWLISTENER *listener);
7576 static void PREFIX`BeginHtmlCenter'(MWLISTENER *listener, pANTLR3_VECTOR attributes);
7677 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);
7879 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);
8081 static void PREFIX`BeginExternalLink'(MWLISTENER *listener, pANTLR3_STRING linkUrl);
8182 static void PREFIX`EndExternalLink'(MWLISTENER *listener);
8283 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);
8485 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);
8687 static void PREFIX`OnTagExtension'(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr);
8788 static void PREFIX`BeginHtmlU'(MWLISTENER *listener, pANTLR3_VECTOR attributes);
8889 static void PREFIX`EndHtmlU'(MWLISTENER *listener);
@@ -142,6 +143,19 @@
143144 .newData = PREFIX`New',
144145 .freeData = PREFIX`Free',
145146 .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,
146160 .getResult = PREFIX`GetResult',
147161 .onWord = PREFIX`OnWord',
148162 .onSpecial = PREFIX`OnSpecial',
@@ -506,11 +520,19 @@
507521 * link targetting the page with the given title.
508522 *
509523 * @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
511527 */
512528 static void
513 -PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 529+PREFIX`BeginInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attr)
514530 {
 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);
515537 }
516538
517539 /**
@@ -530,11 +552,19 @@
531553 * TODO: pass link trail and prefix as arguments to this method.
532554 *
533555 * @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
535559 */
536560 static void
537 -PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 561+PREFIX`OnInternalLink'(MWLISTENER *listener, pANTLR3_VECTOR attr)
538562 {
 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);
539569 }
540570
541571 /**
@@ -581,12 +611,21 @@
582612 * Also, note that media links may nest one level.
583613 *
584614 * @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.
587618 */
588619 static void
589 -PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr)
 620+PREFIX`BeginMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr)
590621 {
 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);
591630 }
592631
593632 /**
@@ -606,12 +645,21 @@
607646 * for PREFIX`BeginMediaLink'.
608647 *
609648 * @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.
612652 */
613653 static void
614 -PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr)
 654+PREFIX`OnMediaLink'(MWLISTENER *listener, pANTLR3_VECTOR attr)
615655 {
 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);
616664 }
617665
618666 /**
Index: trunk/parsers/libmwparser/src/mwlinks.c
@@ -1,10 +1,11 @@
22 #include <antlr3.h>
33 #include <mwparsercontext.h>
44 #include <mwlinks.h>
 5+#include <mwlinkresolution.h>
56
6 -static void beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle);
 7+static void beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr);
78 static void endInternalLink(MWPARSERCONTEXT *context);
8 -static void onInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle);
 9+static void onInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr);
910 static void beginExternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkUrl);
1011 static void endExternalLink(MWPARSERCONTEXT *context);
1112 static void onExternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkUrl);
@@ -13,12 +14,22 @@
1415 static void onMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr);
1516
1617 static void
17 -beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle)
 18+beginInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr)
1819 {
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);
2122 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);
2334 }
2435
2536 static void
@@ -31,11 +42,16 @@
3243 }
3344
3445 static void
35 -onInternalLink(MWPARSERCONTEXT *context, pANTLR3_STRING linkTitle)
 46+onInternalLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr)
3647 {
3748 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+ }
3854 MWLISTENER *l = &context->listener;
39 - l->onInternalLink(l, linkTitle);
 55+ l->onInternalLink(l, v);
4056 }
4157
4258 static void
@@ -67,11 +83,9 @@
6884 static void
6985 beginMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr)
7086 {
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);
7488 MWLISTENER *l = &context->listener;
75 - l->beginMediaLink(l, linkUrl, attr);
 89+ l->beginMediaLink(l, attr);
7690 context->tempReopenFormats(context);
7791 }
7892
@@ -88,10 +102,8 @@
89103 onMediaLink(MWPARSERCONTEXT *context, pANTLR3_VECTOR attr)
90104 {
91105 MW_TRIGGER_DELAYED_CALLS(context);
92 - pANTLR3_STRING linkUrl = attr->get(attr, attr->count - 1);
93 - attr->remove(attr, attr->count - 1);
94106 MWLISTENER *l = &context->listener;
95 - l->onMediaLink(l, linkUrl, attr);
 107+ l->onMediaLink(l, attr);
96108 }
97109
98110
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 @@
4040 static void mwFreeStringConversionState(void *state);
4141 static bool setLegalTitleRegexp(MWLEXERCONTEXT *context, const char *perlRegexp);
4242 static bool setMediaLinkTitleRegexp(MWLEXERCONTEXT *context, const char *perlRegexp);
 43+static void resolveLinks(MWLEXERCONTEXT *context);
4344
4445 MWLEXERCONTEXT *MWLexerContextNew(pANTLR3_LEXER lexer)
4546 {
@@ -122,6 +123,9 @@
123124 context->registerTagExtension = registerTagExtension;
124125 context->setLegalTitleRegexp = setLegalTitleRegexp;
125126 context->setMediaLinkTitleRegexp = setMediaLinkTitleRegexp;
 127+ context->resolveLinks = resolveLinks;
 128+ context->linkResolver = NULL;
 129+ context->linkResolverData = NULL;
126130
127131 if (!context->reset(context)) {
128132 context->free(context);
@@ -448,3 +452,12 @@
449453
450454 return true;
451455 }
 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 @@
2222 #include <tracingcontext.h>
2323 #include <mwkeyvalue.h>
2424 #include <wchar.h>
 25+#include <mwlinkresolution.h>
 26+#include <mwmedialinkoption.h>
2527
2628 static const int INDENT_SPACES = 4;
2729
@@ -81,15 +83,15 @@
8284 static void TCEndHtmlBlockquote(MWLISTENER *listener);
8385 static void TCBeginHtmlCenter(MWLISTENER *listener, pANTLR3_VECTOR attributes);
8486 static void TCEndHtmlCenter(MWLISTENER *listener);
85 -static void TCBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle);
 87+static void TCBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr);
8688 static void TCEndInternalLink(MWLISTENER *listener);
87 -static void TCOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle);
 89+static void TCOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr);
8890 static void TCBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl);
8991 static void TCEndExternalLink(MWLISTENER *listener);
9092 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);
9294 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);
9496 static void TCOnTagExtension(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr);
9597 static void TCBeginHtmlU(MWLISTENER *listener, pANTLR3_VECTOR attributes);
9698 static void TCEndHtmlU(MWLISTENER *listener);
@@ -129,6 +131,7 @@
130132 static void TCFree(void *tcontext);
131133
132134 static void TCPrintAttributes(pANTLR3_VECTOR attributes);
 135+static void TCPrintMediaLinkOptions(MEDIALINKOPTION *mlOption);
133136 static void TCPrintIndent(MWLISTENER *listener);
134137 static void TCIncreaseIndent(MWLISTENER *listener);
135138 static void TCDecreaseIndent(MWLISTENER *listener);
@@ -153,6 +156,8 @@
154157 .newData = TCNew,
155158 .freeData = TCFree,
156159 .resetData = NULL,
 160+ .linkResolver = NULL,
 161+ .setLinkResolverData = NULL,
157162 .onWord = TCOnWord,
158163 .onSpecial = TCOnSpecial,
159164 .onSpace = TCOnSpace,
@@ -416,8 +421,14 @@
417422 }
418423
419424 static void
420 -TCBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 425+TCBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
421426 {
 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);
422433 TCPrintIndent(listener);
423434 printf("BEGIN INTERNAL LINK[%s]\n", linkTitle->chars);
424435 TCIncreaseIndent(listener);
@@ -432,8 +443,14 @@
433444 }
434445
435446 static void
436 -TCOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 447+TCOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
437448 {
 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);
438455 TCPrintIndent(listener);
439456 printf("INTERNAL LINK[%s]\n", linkTitle->chars);
440457 }
@@ -462,11 +479,20 @@
463480 }
464481
465482 static void
466 -TCBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr)
 483+TCBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
467484 {
 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);
468494 TCPrintIndent(listener);
469 - printf("BEGIN MEDIA LINK[%s]", linkUrl->chars);
470 - TCPrintAttributes(attr);
 495+ printf("BEGIN MEDIA LINK[%s]", linkTitle->chars);
 496+ TCPrintMediaLinkOptions(mlOption);
471497 printf("\n");
472498 TCIncreaseIndent(listener);
473499 }
@@ -480,10 +506,18 @@
481507 }
482508
483509 static void
484 -TCOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkUrl, pANTLR3_VECTOR attr)
 510+TCOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
485511 {
 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);
486520 TCPrintIndent(listener);
487 - printf("MEDIA LINK[%s]", linkUrl->chars);
 521+ printf("MEDIA LINK[%s]", linkTitle->chars);
488522 TCPrintAttributes(attr);
489523 printf("\n");
490524 }
@@ -685,6 +719,101 @@
686720 }
687721
688722 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
689818 TCBeginTable(MWLISTENER *listener, pANTLR3_VECTOR attributes)
690819 {
691820 TCPrintIndent(listener);
@@ -1193,4 +1322,3 @@
11941323 TC(listener)->indent -= INDENT_SPACES;
11951324 }
11961325
1197 -
Index: trunk/parsers/libmwparser/src/mwWikitextParser.g
@@ -556,22 +556,26 @@
557557
558558 begin_table_of_contents_item:
559559 (h = BEGIN_HEADING { CX->beginTableOfContentsItem(CX, $h->HEADING_LEVEL, $h->getText($h)); })
 560+/*
560561 | (h = HTML_H1_OPEN { CX->beginTableOfContentsItem(CX, 1, $h->getText($h)); })
561562 | (h = HTML_H2_OPEN { CX->beginTableOfContentsItem(CX, 2, $h->getText($h)); })
562563 | (h = HTML_H3_OPEN { CX->beginTableOfContentsItem(CX, 3, $h->getText($h)); })
563564 | (h = HTML_H4_OPEN { CX->beginTableOfContentsItem(CX, 4, $h->getText($h)); })
564565 | (h = HTML_H5_OPEN { CX->beginTableOfContentsItem(CX, 5, $h->getText($h)); })
565566 | (h = HTML_H6_OPEN { CX->beginTableOfContentsItem(CX, 6, $h->getText($h)); })
 567+*/
566568 ;
567569
568570 end_table_of_contents_item:
569571 (END_HEADING { CX->endTableOfContentsItem(CX); })
 572+/*
570573 |(((HTML_H1_CLOSE { CX->endTableOfContentsItem(CX); })
571574 | (HTML_H2_CLOSE { CX->endTableOfContentsItem(CX); })
572575 | (HTML_H3_CLOSE { CX->endTableOfContentsItem(CX); })
573576 | (HTML_H4_CLOSE { CX->endTableOfContentsItem(CX); })
574577 | (HTML_H5_CLOSE { CX->endTableOfContentsItem(CX); })
575578 | (HTML_H6_CLOSE { CX->endTableOfContentsItem(CX); }))|EOF)
 579+*/
576580 ;
577581
578582 link_element: internal_link | external_link | media_link
Index: trunk/parsers/libmwparser/src/mwparser.c
@@ -58,7 +58,7 @@
5959 return NULL;
6060 }
6161
62 - mwparser->parserContext = MWParserContextNew(parser, listener);
 62+ mwparser->parserContext = MWParserContextNew(parser, listener, mwparser->lexerContext);
6363 if (mwparser->parserContext == NULL) {
6464 MWParserFree(mwparser);
6565 return NULL;
Index: trunk/parsers/libmwparser/src/mwparsercontext.c
@@ -26,6 +26,7 @@
2727 #include <mwheadings.h>
2828 #include <mwhtml.h>
2929 #include <mwlinks.h>
 30+#include <mwlexercontext.h>
3031 #include <assert.h>
3132 #include "mwWikitextParser.h"
3233
@@ -130,7 +131,7 @@
131132 }
132133
133134
134 -MWPARSERCONTEXT * MWParserContextNew(void * parser, const MWLISTENER *listener)
 135+MWPARSERCONTEXT * MWParserContextNew(void * parser, const MWLISTENER *listener, MWLEXERCONTEXT *lexerContext)
135136 {
136137 MWPARSERCONTEXT *context = ANTLR3_MALLOC(sizeof(*context));
137138 pmwWikitextParser psr = parser;
@@ -214,6 +215,14 @@
215216 NULL_FAIL(context->listener.data);
216217 }
217218
 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+
218227 context->reset(context);
219228
220229 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+
221 #include <glib.h>
322 #include <antlr3.h>
423 #include <mwlinkcollection.h>
@@ -10,7 +29,7 @@
1130 GList *tokens;
1231 };
1332
14 -typedef struct {
 33+typedef struct LCKEY_struct {
1534 MWLINKTYPE type;
1635 pANTLR3_STRING linkTitle;
1736 } LCKEY;
@@ -52,7 +71,7 @@
5372 return strncmp((char *)k1->linkTitle->chars, (char *)k2->linkTitle->chars, k1->linkTitle->len);
5473 }
5574
56 -typedef struct {
 75+typedef struct LCVAL_struct {
5776 GList *tokenList;
5877 } LCVAL;
5978
@@ -134,7 +153,7 @@
135154 lckeyFree(key);
136155 key = origKey;
137156 }
138 - val->tokenList = g_list_prepend(val->tokenList, val);
 157+ val->tokenList = g_list_prepend(val->tokenList, token);
139158 collection->tokens = g_list_prepend(collection->tokens, val->tokenList);
140159 g_tree_insert(collection->inverseTree, val->tokenList, key);
141160 }
@@ -166,3 +185,70 @@
167186 } while(!last);
168187 }
169188
 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 @@
174174 SWIG_LIB = @SWIG_LIB@
175175 TARGET_LANGUAGE = @TARGET_LANGUAGE@
176176 TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@
 177+TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@
177178 VERSION = @VERSION@
178179 abs_builddir = @abs_builddir@
179180 abs_srcdir = @abs_srcdir@
Index: trunk/parsers/libmwparser/configure.ac
@@ -74,10 +74,11 @@
7575 TARGET_LANGUAGE_LDFLAGS='$(PERLXS_LDFLAGS)'
7676 elif test "x$TARGET_LANGUAGE" == xphp; then
7777 TARGET_LANGUAGE_CFLAGS='-DTARGET_LANGUAGE_PHP $(PHP_CFLAGS)'
78 - TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS)'
 78+ TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS) $(PHP_LIBS)'
7979 fi
8080
8181 AC_SUBST([TARGET_LANGUAGE_CFLAGS])
 82+AC_SUBST([TARGET_LANGUAGE_LDFLAGS])
8283
8384 AM_PROG_LIBTOOL
8485 AC_PROG_LIBTOOL
Index: trunk/parsers/libmwparser/Makefile.am
@@ -13,16 +13,13 @@
1414
1515 ANTLR_LEXER = mwWikitextLexer
1616 ANTLR_PARSER = mwWikitextParser
17 -ANTLR_LEXER_DELEGATES =
1817
1918 ANTLR_GRAMMARS = $(ANTLR_LEXER:=.g) $(ANTLR_PARSER:=.g)
2019
2120 ANTLR_SOURCES = $(ANTLR_LEXER:=.c) $(ANTLR_PARSER:=.c) $(ANTLR_LEXER:=.h) $(ANTLR_PARSER:=.h)
2221
23 -ANTLR_LEXER_DELEGATE_SOURCES =
 22+CLEANFILES = $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc
2423
25 -CLEANFILES = $(ANTLR_LEXER_DELEGATE_SOURCES) $(ANTLR_LEXER_DELEGATES:=.tokens) $(ANTLR_SOURCES) mwlexerpredicates.h mwlexerpredicatedefs.inc
26 -
2724 lib_LTLIBRARIES = libmwparser.la
2825
2926 nodist_libmwparser_la_SOURCES = $(ANTLR_SOURCES) $(ANTLR_LEXER_DELEGATE_SOURCES)
@@ -51,9 +48,11 @@
5249 include/mwkeyvalue.h \
5350 include/mwlexercontext.h \
5451 include/mwlinkcollection.h \
 52+ include/mwlinkresolution.h \
5553 include/mwlinks.h \
5654 include/mwlistener.h \
5755 include/mwparser.h \
 56+ include/mwmedialinkoption.h \
5857 include/mwparsercontext.h \
5958 include/mwtables.h \
6059 include/mwtagext.h \
@@ -66,7 +65,9 @@
6766 src/mwhtml.c \
6867 src/mwlexercontext.c \
6968 src/mwlinks.c \
 69+ src/mwlinkresolution.c \
7070 src/mwlinkcollection.c \
 71+ src/mwmedialinkoption.c \
7172 src/mwparser.c \
7273 src/mwparsercontext.c \
7374 src/mwtagext.c \
@@ -82,12 +83,12 @@
8384 src/mwlexerpredicatedefs.php \
8485 antlr.patch
8586
86 -libmwparser_la_LIBS = $(GLIB_LIBS)
87 -
8887 libmwparser_la_CFLAGS = $(GLIB_CFLAGS) -std=gnu99 -Wall -Wno-unused-variable
8988
9089 libmwparser_la_LDFLAGS = -release $(PACKAGE_VERSION)
9190
 91+libmwparser_la_LIBADD = $(GLIB_LIBS) $(ANTLR3C_LIBS);
 92+
9293 INCLUDES = -I$(top_srcdir)/include
9394
9495 include_HEADERS = config.h
Index: trunk/parsers/libmwparser/wrapper/Makefile.in
@@ -72,10 +72,12 @@
7373 sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
7474 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
7575 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)
8082 libmwp_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
8183 $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libmwp_la_CFLAGS) \
8284 $(CFLAGS) $(libmwp_la_LDFLAGS) $(LDFLAGS) -o $@
@@ -92,7 +94,7 @@
9395 LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
9496 --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
9597 $(LDFLAGS) -o $@
96 -SOURCES = $(libmwp_la_SOURCES)
 98+SOURCES = $(libmwp_la_SOURCES) $(nodist_libmwp_la_SOURCES)
9799 DIST_SOURCES = $(libmwp_la_SOURCES)
98100 HEADERS = $(include_HEADERS)
99101 ETAGS = etags
@@ -172,6 +174,7 @@
173175 SWIG_LIB = @SWIG_LIB@
174176 TARGET_LANGUAGE = @TARGET_LANGUAGE@
175177 TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@
 178+TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@
176179 VERSION = @VERSION@
177180 abs_builddir = @abs_builddir@
178181 abs_srcdir = @abs_srcdir@
@@ -227,13 +230,20 @@
228231 top_srcdir = @top_srcdir@
229232 PHP_CFLAGS = `php-config --includes`
230233 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
232236 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
235243
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 =
238248 INCLUDES = -I$(srcdir)/include -I$(top_srcdir)/include
239249 include_HEADERS = $(top_builddir)/config.h
240250 all: all-am
@@ -310,6 +320,7 @@
311321 distclean-compile:
312322 -rm -f *.tab.c
313323
 324+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwlinkresolvercallback.Plo@am__quote@
314325 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwp_wrap.Plo@am__quote@
315326 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwp_la-mwscriptbufferlistener.Plo@am__quote@
316327
@@ -334,6 +345,13 @@
335346 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
336347 @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
337348
 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+
338356 libmwp_la-mwscriptbufferlistener.lo: src/mwscriptbufferlistener.c
339357 @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
340358 @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwp_la-mwscriptbufferlistener.Tpo $(DEPDIR)/libmwp_la-mwscriptbufferlistener.Plo
@@ -513,7 +531,8 @@
514532 info-am:
515533
516534 install-data-am: install-includeHEADERS
517 -
 535+ @$(NORMAL_INSTALL)
 536+ $(MAKE) $(AM_MAKEFLAGS) install-data-hook
518537 install-dvi: install-dvi-am
519538
520539 install-dvi-am:
@@ -560,18 +579,19 @@
561580
562581 uninstall-am: uninstall-includeHEADERS uninstall-libLTLIBRARIES
563582
564 -.MAKE: install-am install-strip
 583+.MAKE: install-am install-data-am install-strip
565584
566585 .PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
567586 clean-libLTLIBRARIES clean-libtool ctags distclean \
568587 distclean-compile distclean-generic distclean-libtool \
569588 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 \
576596 maintainer-clean-generic mostlyclean mostlyclean-compile \
577597 mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
578598 tags uninstall uninstall-am uninstall-includeHEADERS \
@@ -580,8 +600,11 @@
581601 vpath %.i $(srcdir)/src
582602
583603 mwp_wrap.c: mwparser.i
584 - swig -$(TARGET_LANGUAGE) -Wall -o $@ $<
 604+ swig -$(TARGET_LANGUAGE) $(INCLUDES) -Wall -o $@ $<
585605
 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+
586609 # Tell versions [3.59,3.63) of GNU make to not export all variables.
587610 # Otherwise a system limit (for SysV at least) may be exceeded.
588611 .NOEXPORT:
Index: trunk/parsers/libmwparser/wrapper/include/mwscriptbuf.h
@@ -2,9 +2,21 @@
33 #define _MWSCRIPT_BUF_H
44
55 #include <mwattributes.h>
 6+#include <mwscriptmalloc.h>
67
 8+struct MWSCRIPTBUF_struct;
 9+
 10+static inline void appendBytes(struct MWSCRIPTBUF_struct *buf, const char *bytes, size_t numBytes);
 11+
712 #define BUFSIZE 4096
813
 14+typedef struct MWSCRIPTBUF_INDEX_struct
 15+{
 16+ int row;
 17+ int col;
 18+}
 19+ MWSCRIPTBUF_INDEX;
 20+
921 #ifdef TARGET_LANGUAGE_PERL
1022
1123 #include <EXTERN.h>
@@ -21,7 +33,30 @@
2234 }
2335 MWSCRIPTBUF;
2436
 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+}
2547
 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+
2661 static inline void *
2762 scriptBufResult(MWSCRIPTBUF *buf)
2863 {
@@ -100,6 +135,30 @@
101136 }
102137 MWSCRIPTBUF;
103138
 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+
104163 static inline void *
105164 scriptBufResult(MWSCRIPTBUF *buf)
106165 {
@@ -182,7 +241,7 @@
183242 static inline void
184243 appendAntlr3String(MWSCRIPTBUF *buf, pANTLR3_STRING string)
185244 {
186 - appendBytes(buf, (char *)string->chars, string->size);
 245+ appendBytes(buf, (char *)string->chars, string->size - 1);
187246 }
188247
189248 static inline void
@@ -199,7 +258,7 @@
200259
201260 #define APPEND_ATTR_VECTOR(element, attr) (appendAttrVector(BUF, element, attr))
202261
203 -#define APPEND_CONST_STRING(string) (appendBytes(BUF, string, sizeof(string)))
 262+#define APPEND_CONST_STRING(string) (appendBytes(BUF, string, sizeof(string) - 1))
204263
205264 #define APPEND_STRING(string) (appendBytes(BUF, string, strlen(string)))
206265
@@ -213,6 +272,8 @@
214273 } \
215274 } while (0)
216275
 276+struct MWLINKCOLLECTION_struct;
217277
 278+void MWScriptCallbackResolveLinks(struct MWLINKCOLLECTION_struct *linkCollection, void *data);
218279
219280 #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 @@
22
3 -#include <mwscriptbuf.h>
43
 4+
Index: trunk/parsers/libmwparser/wrapper/src/mwparser.i
@@ -4,16 +4,38 @@
55 #include <antlr3.h>
66 #include <mwparser.h>
77 #include <mwlistener.h>
 8+#include <mwlinkresolution.h>
 9+#include <mwlinkcollection.h>
810 extern MWLISTENER mwScriptBufferListener;
911 static MWPARSER_OPTIONS *null_options = NULL;
1012 %}
1113
 14+%include <mwlinkresolution.h>
 15+
1216 #ifdef SWIGPERL
1317 %typemap(in) SV *string {
1418 SvREFCNT_inc($input);
1519 $1 = $input;
1620 }
1721
 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+
1840 %{
1941 static SV *MWParseArticle(MWPARSER *parser)
2042 {
@@ -21,20 +43,59 @@
2244 return MWParserGetResult(parser);
2345 }
2446
25 - static void freeString(void *string) {
26 - SV *sv = string;
 47+ static void freeScriptVar(void *v)
 48+ {
 49+ SV *sv = v;
2750 SvREFCNT_dec(sv);
2851 }
2952
3053 static MWPARSER_INPUT_STREAM * new_MWParserInput(SV *string)
3154 {
32 - return MWParserOpenStringWithCleanup("input", SvPVX(string), SvCUR(string), MWPARSER_UTF8, string, freeString);
 55+ return MWParserOpenStringWithCleanup("input", SvPVX(string), SvCUR(string), MWPARSER_UTF8, string, freeScriptVar);
3356 }
 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+ }
3483 %}
3584
3685 %typemap(out) SV * sv {
3786 $result = $1;
3887 }
 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+
39100 #elif defined (SWIGPHP)
40101 %{
41102 static zval *MWParseArticle(MWPARSER *parser)
@@ -42,15 +103,44 @@
43104 MWParserParseArticle(parser, NULL);
44105 return MWParserGetResult(parser);
45106 }
46 - static void freeString(void *string) {
47 - zval *z = string;
 107+
 108+ static void freeScriptVar(void *v)
 109+ {
 110+ zval *z = v;
48111 Z_DELREF_P(z);
49112 }
50113
51114 static MWPARSER_INPUT_STREAM * new_MWParserInput(zval *string)
52115 {
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);
54117 }
 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+
55145 %}
56146
57147 %typemap(out) zval * {
@@ -64,8 +154,26 @@
65155 Z_ADDREF_P(*$input);
66156 $1 = *$input;
67157 }
 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+
68173 #endif
69174
 175+extern MWLCKEY * getMWLCKey(void);
 176+
 177+
70178 %{
71179 static MWPARSER *new_MWParser(MWPARSER_INPUT_STREAM *inputStream)
72180 {
@@ -97,6 +205,11 @@
98206
99207 extern bool MWParserSetMediaLinkTitleRegexp(MWPARSER *parser, const char *perlRegexp);
100208
 209+extern void MWLinkCollectionResolve(MWLINKCOLLECTION *linkCollection,
 210+ MWLCKEY *key,
 211+ MWLINKRESOLUTION *resolution);
 212+
 213+
101214 typedef struct MWPARSER_TAGEXT_struct {
102215 char * name;
103216 bool isBlock;
@@ -107,9 +220,15 @@
108221
109222 #ifdef SWIGPERL
110223 static SV *MWParseArticle(MWPARSER *parser);
 224+static SV *MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection);
111225 static MWPARSER_INPUT_STREAM * new_MWParserInput(SV *string);
112226 #elif defined(SWIGPHP)
113227 static zval *MWParseArticle(MWPARSER *parser);
114228 static MWPARSER_INPUT_STREAM * new_MWParserInput(zval *string);
 229+static zval* MWLinkCollectionGet(MWLINKCOLLECTION *linkCollection);
115230 #endif
116231
 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 @@
55 #include <assert.h>
66 #include <stdbool.h>
77 #include <mwscriptbuf.h>
 8+#include <mwlinkresolution.h>
 9+#include <mwlinkcollection.h>
 10+#include <mwlinkresolvercallback.h>
 11+#include <mwmedialinkoption.h>
812
9 -
1013 /*
1114 * A note on memory management: All parameters of type pANTLR3_STRING
1215 * or pANTLR3_VECTOR have been allocated by the antlr runtime via
@@ -76,15 +79,15 @@
7780 static void SBEndHtmlBlockquote(MWLISTENER *listener);
7881 static void SBBeginHtmlCenter(MWLISTENER *listener, pANTLR3_VECTOR attr);
7982 static void SBEndHtmlCenter(MWLISTENER *listener);
80 -static void SBBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle);
 83+static void SBBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr);
8184 static void SBEndInternalLink(MWLISTENER *listener);
82 -static void SBOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle);
 85+static void SBOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr);
8386 static void SBBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl);
8487 static void SBEndExternalLink(MWLISTENER *listener);
8588 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);
8790 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);
8992 static void SBOnTagExtension(MWLISTENER *listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr);
9093 static void SBBeginHtmlU(MWLISTENER *listener, pANTLR3_VECTOR attr);
9194 static void SBEndHtmlU(MWLISTENER *listener);
@@ -123,6 +126,8 @@
124127 static void SBReset(void *data);
125128 static void SBFree(void *data);
126129 static void * SBGetResult(MWLISTENER *listener);
 130+static void SBLinkResolver(MWLINKCOLLECTION *linkCollection, void *data);
 131+static void SBSetLinkResolverData(void *listenerData, void **linkResolverData);
127132
128133 /**
129134 * Data storage for the listener.
@@ -132,6 +137,16 @@
133138 MWSCRIPTBUF buf;
134139 pANTLR3_STRING_FACTORY stringFactory;
135140 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;
136151 }
137152 SCRIPT_BUF;
138153
@@ -150,6 +165,8 @@
151166 .newData = SBNew,
152167 .freeData = SBFree,
153168 .resetData = SBReset,
 169+ .linkResolver = SBLinkResolver,
 170+ .setLinkResolverData = SBSetLinkResolverData,
154171 .getResult = SBGetResult,
155172 .onWord = SBOnWord,
156173 .onSpecial = SBOnSpecial,
@@ -281,6 +298,13 @@
282299 return NULL;
283300 }
284301
 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+
285309 return data;
286310 }
287311
@@ -321,6 +345,17 @@
322346 return scriptBufResult(BUF);
323347 }
324348
 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+
325360 /**
326361 * Method that will be called to indicate that a "word" should be
327362 * rendered.
@@ -423,16 +458,26 @@
424459 static void
425460 SBOnBr(MWLISTENER *listener, pANTLR3_VECTOR attr)
426461 {
427 - APPEND_CONST_STRING("<br/>");
 462+ if (DATA->renderMarkup) {
 463+ APPEND_CONST_STRING("<br/>");
 464+ }
428465 }
429466
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 ">"); \
437482 } \
438483 } while (0)
439484
@@ -456,7 +501,7 @@
457502 static void
458503 SBEndParagraph(MWLISTENER *listener)
459504 {
460 - APPEND_CONST_STRING("</p>");
 505+ HTML_END("p");
461506 }
462507
463508 /**
@@ -499,7 +544,7 @@
500545 static void
501546 SBEndItalic(MWLISTENER *listener)
502547 {
503 - APPEND_CONST_STRING("</i>");
 548+ HTML_END("i");
504549 }
505550
506551 /**
@@ -522,7 +567,7 @@
523568 static void
524569 SBEndBold(MWLISTENER *listener)
525570 {
526 - APPEND_CONST_STRING("</b>");
 571+ HTML_END("b");
527572 }
528573
529574 /**
@@ -533,7 +578,9 @@
534579 static void
535580 SBBeginPre(MWLISTENER *listener)
536581 {
537 - APPEND_CONST_STRING("<pre>");
 582+ if (DATA->renderMarkup) {
 583+ APPEND_CONST_STRING("<pre>");
 584+ }
538585 }
539586
540587 /**
@@ -544,7 +591,7 @@
545592 static void
546593 SBEndPre(MWLISTENER *listener)
547594 {
548 - APPEND_CONST_STRING("</pre>");
 595+ HTML_END("pre");
549596 }
550597
551598 /**
@@ -593,41 +640,80 @@
594641 {
595642 switch (DATA->headingLevel) {
596643 case 1:
597 - APPEND_CONST_STRING("</h1>");
 644+ HTML_END("h1");
598645 break;
599646 case 2:
600 - APPEND_CONST_STRING("</h2>");
 647+ HTML_END("h2");
601648 break;
602649 case 3:
603 - APPEND_CONST_STRING("</h3>");
 650+ HTML_END("h3");
604651 break;
605652 case 4:
606 - APPEND_CONST_STRING("</h4>");
 653+ HTML_END("h4");
607654 break;
608655 case 5:
609 - APPEND_CONST_STRING("</h5>");
 656+ HTML_END("h5");
610657 break;
611658 case 6:
612 - APPEND_CONST_STRING("</h6>");
 659+ HTML_END("h6");
613660 break;
614661 default:
615662 assert(false);
616663 }
617664 }
618665
 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+
619698 /**
620699 * Initiate formatting of the link text corresponding to an internal
621700 * link targetting the page with the given title.
622701 *
623702 * @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
625706 */
626707 static void
627 -SBBeginInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 708+SBBeginInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
628709 {
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);
632718 }
633719
634720 /**
@@ -638,9 +724,10 @@
639725 static void
640726 SBEndInternalLink(MWLISTENER *listener)
641727 {
642 - APPEND_CONST_STRING("<!-- END INTERNAL LINK -->");
 728+ HTML_END("a");
643729 }
644730
 731+
645732 /**
646733 * A complete internal link has been encountered. The link title
647734 * should be used as the text contents of the link.
@@ -648,14 +735,24 @@
649736 * TODO: pass link trail and prefix as arguments to this method.
650737 *
651738 * @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
653742 */
654743 static void
655 -SBOnInternalLink(MWLISTENER *listener, pANTLR3_STRING linkTitle)
 744+SBOnInternalLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
656745 {
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);
660757 }
661758
662759 /**
@@ -668,10 +765,12 @@
669766 static void
670767 SBBeginExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl)
671768 {
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+ }
676775 }
677776
678777 /**
@@ -682,7 +781,7 @@
683782 static void
684783 SBEndExternalLink(MWLISTENER *listener)
685784 {
686 - APPEND_CONST_STRING("</a>");
 785+ HTML_END("a");
687786 }
688787
689788 /**
@@ -695,12 +794,135 @@
696795 static void
697796 SBOnExternalLink(MWLISTENER *listener, pANTLR3_STRING linkUrl)
698797 {
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);
702902 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+ }
705927 APPEND_CONST_STRING("</a>");
706928 }
707929
@@ -714,12 +936,22 @@
715937 * Also, note that media links may nest one level.
716938 *
717939 * @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.
720943 */
721944 static void
722 -SBBeginMediaLink(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr)
 945+SBBeginMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
723946 {
 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+ }
724956 }
725957
726958 /**
@@ -730,6 +962,14 @@
731963 static void
732964 SBEndMediaLink(MWLISTENER *listener)
733965 {
 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+ }
734974 }
735975
736976 /**
@@ -739,12 +979,23 @@
740980 * for SBBeginMediaLink.
741981 *
742982 * @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.
745986 */
746987 static void
747 -SBOnMediaLink(MWLISTENER *listener, pANTLR3_STRING linkTitle, pANTLR3_VECTOR attr)
 988+SBOnMediaLink(MWLISTENER *listener, pANTLR3_VECTOR attr)
748989 {
 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+ }
7491000 }
7501001
7511002 /**
@@ -761,12 +1012,13 @@
7621013 static void
7631014 SBOnTagExtension(MWLISTENER *listener, const char *name, pANTLR3_STRING body, pANTLR3_VECTOR attr)
7641015 {
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+ }
7711023 }
7721024
7731025 /**
@@ -798,7 +1050,7 @@
7991051 static void
8001052 SBEndBulletList(MWLISTENER *listener)
8011053 {
802 - APPEND_CONST_STRING("</ul>");
 1054+ HTML_END("ul");
8031055 }
8041056
8051057 /**
@@ -821,7 +1073,7 @@
8221074 static void
8231075 SBEndBulletListItem(MWLISTENER *listener)
8241076 {
825 - APPEND_CONST_STRING("</li>");
 1077+ HTML_END("li");
8261078 }
8271079
8281080 /**
@@ -846,7 +1098,7 @@
8471099 static void
8481100 SBEndEnumerationList(MWLISTENER *listener)
8491101 {
850 - APPEND_CONST_STRING("</ol>");
 1102+ HTML_END("ol");
8511103 }
8521104
8531105 /**
@@ -869,7 +1121,7 @@
8701122 static void
8711123 SBEndEnumerationItem(MWLISTENER *listener)
8721124 {
873 - APPEND_CONST_STRING("</li>");
 1125+ HTML_END("li");
8741126 }
8751127
8761128 /**
@@ -894,7 +1146,7 @@
8951147 static void
8961148 SBEndDefinitionList(MWLISTENER *listener)
8971149 {
898 - APPEND_CONST_STRING("</dl>");
 1150+ HTML_END("dl");
8991151 }
9001152
9011153 /**
@@ -917,7 +1169,7 @@
9181170 static void
9191171 SBEndDefinedTermItem(MWLISTENER *listener)
9201172 {
921 - APPEND_CONST_STRING("</dt>");
 1173+ HTML_END("dt");
9221174 }
9231175
9241176 /**
@@ -940,7 +1192,7 @@
9411193 static void
9421194 SBEndDefinitionItem(MWLISTENER *listener)
9431195 {
944 - APPEND_CONST_STRING("</dd>");
 1196+ HTML_END("dd");
9451197 }
9461198
9471199 /**
@@ -1014,7 +1266,7 @@
10151267 static void
10161268 SBEndTable(MWLISTENER *listener)
10171269 {
1018 - APPEND_CONST_STRING("</table>");
 1270+ HTML_END("table");
10191271 }
10201272
10211273 /**
@@ -1037,7 +1289,7 @@
10381290 static void
10391291 SBEndTableRow(MWLISTENER *listener)
10401292 {
1041 - APPEND_CONST_STRING("</tr>");
 1293+ HTML_END("tr");
10421294 }
10431295
10441296 /**
@@ -1060,7 +1312,7 @@
10611313 static void
10621314 SBEndTableCell(MWLISTENER *listener)
10631315 {
1064 - APPEND_CONST_STRING("</td>");
 1316+ HTML_END("td");
10651317 }
10661318
10671319 /**
@@ -1083,7 +1335,7 @@
10841336 static void
10851337 SBEndTableHeading(MWLISTENER *listener)
10861338 {
1087 - APPEND_CONST_STRING("</th>");
 1339+ HTML_END("th");
10881340 }
10891341
10901342 /**
@@ -1106,7 +1358,7 @@
11071359 static void
11081360 SBEndTableCaption(MWLISTENER *listener)
11091361 {
1110 - APPEND_CONST_STRING("</caption>");
 1362+ HTML_END("caption");
11111363 }
11121364
11131365
@@ -1130,7 +1382,7 @@
11311383 static void
11321384 SBEndTableBody(MWLISTENER *listener)
11331385 {
1134 - APPEND_CONST_STRING("</tbody>");
 1386+ HTML_END("tbody");
11351387 }
11361388
11371389 /**
@@ -1192,7 +1444,7 @@
11931445 static void
11941446 SBEndHtmlDiv(MWLISTENER *listener)
11951447 {
1196 - APPEND_CONST_STRING("</div>");
 1448+ HTML_END("div");
11971449 }
11981450
11991451 /**
@@ -1215,7 +1467,7 @@
12161468 static void
12171469 SBEndHtmlBlockquote(MWLISTENER *listener)
12181470 {
1219 - APPEND_CONST_STRING("</blockquote>");
 1471+ HTML_END("blockquote");
12201472 }
12211473
12221474 /**
@@ -1238,7 +1490,7 @@
12391491 static void
12401492 SBEndHtmlCenter(MWLISTENER *listener)
12411493 {
1242 - APPEND_CONST_STRING("</center>");
 1494+ HTML_END("center");
12431495 }
12441496
12451497 /**
@@ -1261,7 +1513,7 @@
12621514 static void
12631515 SBEndHtmlU(MWLISTENER *listener)
12641516 {
1265 - APPEND_CONST_STRING("</u>");
 1517+ HTML_END("u");
12661518 }
12671519
12681520 /**
@@ -1284,7 +1536,7 @@
12851537 static void
12861538 SBEndHtmlDel(MWLISTENER *listener)
12871539 {
1288 - APPEND_CONST_STRING("</del>");
 1540+ HTML_END("del");
12891541 }
12901542
12911543 /**
@@ -1307,7 +1559,7 @@
13081560 static void
13091561 SBEndHtmlIns(MWLISTENER *listener)
13101562 {
1311 - APPEND_CONST_STRING("</ins>");
 1563+ HTML_END("ins");
13121564 }
13131565
13141566 /**
@@ -1330,7 +1582,7 @@
13311583 static void
13321584 SBEndHtmlFont(MWLISTENER *listener)
13331585 {
1334 - APPEND_CONST_STRING("</font>");
 1586+ HTML_END("font");
13351587 }
13361588
13371589 /**
@@ -1353,7 +1605,7 @@
13541606 static void
13551607 SBEndHtmlBig(MWLISTENER *listener)
13561608 {
1357 - APPEND_CONST_STRING("</big>");
 1609+ HTML_END("big");
13581610 }
13591611
13601612 /**
@@ -1376,7 +1628,7 @@
13771629 static void
13781630 SBEndHtmlSmall(MWLISTENER *listener)
13791631 {
1380 - APPEND_CONST_STRING("</small>");
 1632+ HTML_END("small");
13811633 }
13821634
13831635 /**
@@ -1399,7 +1651,7 @@
14001652 static void
14011653 SBEndHtmlSub(MWLISTENER *listener)
14021654 {
1403 - APPEND_CONST_STRING("</sub>");
 1655+ HTML_END("sub");
14041656 }
14051657
14061658 /**
@@ -1422,7 +1674,7 @@
14231675 static void
14241676 SBEndHtmlSup(MWLISTENER *listener)
14251677 {
1426 - APPEND_CONST_STRING("</sup>");
 1678+ HTML_END("sup");
14271679 }
14281680
14291681 /**
@@ -1445,7 +1697,7 @@
14461698 static void
14471699 SBEndHtmlCite(MWLISTENER *listener)
14481700 {
1449 - APPEND_CONST_STRING("</cite>");
 1701+ HTML_END("cite");
14501702 }
14511703
14521704 /**
@@ -1468,7 +1720,7 @@
14691721 static void
14701722 SBEndHtmlCode(MWLISTENER *listener)
14711723 {
1472 - APPEND_CONST_STRING("</code>");
 1724+ HTML_END("code");
14731725 }
14741726
14751727 /**
@@ -1491,7 +1743,7 @@
14921744 static void
14931745 SBEndHtmlStrike(MWLISTENER *listener)
14941746 {
1495 - APPEND_CONST_STRING("</strike>");
 1747+ HTML_END("strike");
14961748 }
14971749
14981750 /**
@@ -1514,7 +1766,7 @@
15151767 static void
15161768 SBEndHtmlStrong(MWLISTENER *listener)
15171769 {
1518 - APPEND_CONST_STRING("</strong>");
 1770+ HTML_END("strong");
15191771 }
15201772
15211773 /**
@@ -1537,7 +1789,7 @@
15381790 static void
15391791 SBEndHtmlSpan(MWLISTENER *listener)
15401792 {
1541 - APPEND_CONST_STRING("</span>");
 1793+ HTML_END("span");
15421794 }
15431795
15441796 /**
@@ -1560,7 +1812,7 @@
15611813 static void
15621814 SBEndHtmlTt(MWLISTENER *listener)
15631815 {
1564 - APPEND_CONST_STRING("</tt>");
 1816+ HTML_END("tt");
15651817 }
15661818
15671819 /**
@@ -1583,7 +1835,7 @@
15841836 static void
15851837 SBEndHtmlVar(MWLISTENER *listener)
15861838 {
1587 - APPEND_CONST_STRING("</var>");
 1839+ HTML_END("var");
15881840 }
15891841
15901842 /**
@@ -1606,7 +1858,7 @@
16071859 static void
16081860 SBEndHtmlAbbr(MWLISTENER *listener)
16091861 {
1610 - APPEND_CONST_STRING("</abbr>");
 1862+ HTML_END("abbr");
16111863 }
16121864
16131865
@@ -1623,5 +1875,5 @@
16241876 {
16251877 HTML_TAG("pre");
16261878 SBOnSpecial(listener, body);
1627 - APPEND_CONST_STRING("</pre>");
 1879+ HTML_END("pre");
16281880 }
Index: trunk/parsers/libmwparser/wrapper/Makefile.am
@@ -2,23 +2,35 @@
33
44 PHP_CFLAGS=`php-config --includes`
55 PHP_LDFLAGS=`php-config --ldflags`
 6+PHP_LIBS=`php-config --libs`
67
7 -CLEANFILES=mwp_wrap.c mwp.pm
 8+CLEANFILES=mwp_wrap.c mwp.pm mwp.php php_mwp.h
89
910 lib_LTLIBRARIES = libmwp.la
1011
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
1318
14 -libmwp_la_CFLAGS = $(TARGET_LANGUAGE_CFLAGS) $(GLIB_CFLAGS) -Wall
1519
16 -libmwp_la_LDFLAGS = $(TARGET_LANGUAGE_LDFLAGS) $(GLIB_LDFLAGS)
 20+nodist_libmwp_la_SOURCES = mwp_wrap.c
1721
 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+
1828 INCLUDES = -I$(srcdir)/include -I$(top_srcdir)/include
1929
 30+
2031 include_HEADERS = $(top_builddir)/config.h
2132
2233 mwp_wrap.c: mwparser.i
23 - swig -$(TARGET_LANGUAGE) -Wall -o $@ $<
 34+ swig -$(TARGET_LANGUAGE) $(INCLUDES) -Wall -o $@ $<
2435
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 @@
791791 build_cpu
792792 build
793793 LIBTOOL
 794+TARGET_LANGUAGE_LDFLAGS
794795 TARGET_LANGUAGE_CFLAGS
795796 TARGET_LANGUAGE
796797 GLIB_LIBS
@@ -5404,11 +5405,12 @@
54055406 TARGET_LANGUAGE_LDFLAGS='$(PERLXS_LDFLAGS)'
54065407 elif test "x$TARGET_LANGUAGE" == xphp; then
54075408 TARGET_LANGUAGE_CFLAGS='-DTARGET_LANGUAGE_PHP $(PHP_CFLAGS)'
5408 - TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS)'
 5409+ TARGET_LANGUAGE_LDFLAGS='$(PHP_LDFLAGS) $(PHP_LIBS)'
54095410 fi
54105411
54115412
54125413
 5414+
54135415 case `pwd` in
54145416 *\ * | *\ *)
54155417 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5
@@ -5959,13 +5961,13 @@
59605962 else
59615963 lt_cv_nm_interface="BSD nm"
59625964 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)
59645966 (eval "$ac_compile" 2>conftest.err)
59655967 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)
59675969 (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
59685970 cat conftest.err >&5
5969 - (eval echo "\"\$as_me:5968: output\"" >&5)
 5971+ (eval echo "\"\$as_me:5970: output\"" >&5)
59705972 cat conftest.out >&5
59715973 if $GREP 'External.*some_variable' conftest.out > /dev/null; then
59725974 lt_cv_nm_interface="MS dumpbin"
@@ -7170,7 +7172,7 @@
71717173 ;;
71727174 *-*-irix6*)
71737175 # Find out which ABI we are using.
7174 - echo '#line 7173 "configure"' > conftest.$ac_ext
 7176+ echo '#line 7175 "configure"' > conftest.$ac_ext
71757177 if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
71767178 (eval $ac_compile) 2>&5
71777179 ac_status=$?
@@ -8432,11 +8434,11 @@
84338435 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
84348436 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
84358437 -e 's:$: $lt_compiler_flag:'`
8436 - (eval echo "\"\$as_me:8435: $lt_compile\"" >&5)
 8438+ (eval echo "\"\$as_me:8437: $lt_compile\"" >&5)
84378439 (eval "$lt_compile" 2>conftest.err)
84388440 ac_status=$?
84398441 cat conftest.err >&5
8440 - echo "$as_me:8439: \$? = $ac_status" >&5
 8442+ echo "$as_me:8441: \$? = $ac_status" >&5
84418443 if (exit $ac_status) && test -s "$ac_outfile"; then
84428444 # The compiler can only warn and ignore the option if not recognized
84438445 # So say no if there are warnings other than the usual output.
@@ -8771,11 +8773,11 @@
87728774 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
87738775 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
87748776 -e 's:$: $lt_compiler_flag:'`
8775 - (eval echo "\"\$as_me:8774: $lt_compile\"" >&5)
 8777+ (eval echo "\"\$as_me:8776: $lt_compile\"" >&5)
87768778 (eval "$lt_compile" 2>conftest.err)
87778779 ac_status=$?
87788780 cat conftest.err >&5
8779 - echo "$as_me:8778: \$? = $ac_status" >&5
 8781+ echo "$as_me:8780: \$? = $ac_status" >&5
87808782 if (exit $ac_status) && test -s "$ac_outfile"; then
87818783 # The compiler can only warn and ignore the option if not recognized
87828784 # So say no if there are warnings other than the usual output.
@@ -8876,11 +8878,11 @@
88778879 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
88788880 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
88798881 -e 's:$: $lt_compiler_flag:'`
8880 - (eval echo "\"\$as_me:8879: $lt_compile\"" >&5)
 8882+ (eval echo "\"\$as_me:8881: $lt_compile\"" >&5)
88818883 (eval "$lt_compile" 2>out/conftest.err)
88828884 ac_status=$?
88838885 cat out/conftest.err >&5
8884 - echo "$as_me:8883: \$? = $ac_status" >&5
 8886+ echo "$as_me:8885: \$? = $ac_status" >&5
88858887 if (exit $ac_status) && test -s out/conftest2.$ac_objext
88868888 then
88878889 # The compiler can only warn and ignore the option if not recognized
@@ -8931,11 +8933,11 @@
89328934 -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
89338935 -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
89348936 -e 's:$: $lt_compiler_flag:'`
8935 - (eval echo "\"\$as_me:8934: $lt_compile\"" >&5)
 8937+ (eval echo "\"\$as_me:8936: $lt_compile\"" >&5)
89368938 (eval "$lt_compile" 2>out/conftest.err)
89378939 ac_status=$?
89388940 cat out/conftest.err >&5
8939 - echo "$as_me:8938: \$? = $ac_status" >&5
 8941+ echo "$as_me:8940: \$? = $ac_status" >&5
89408942 if (exit $ac_status) && test -s out/conftest2.$ac_objext
89418943 then
89428944 # The compiler can only warn and ignore the option if not recognized
@@ -11315,7 +11317,7 @@
1131611318 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1131711319 lt_status=$lt_dlunknown
1131811320 cat > conftest.$ac_ext <<_LT_EOF
11319 -#line 11318 "configure"
 11321+#line 11320 "configure"
1132011322 #include "confdefs.h"
1132111323
1132211324 #if HAVE_DLFCN_H
@@ -11411,7 +11413,7 @@
1141211414 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1141311415 lt_status=$lt_dlunknown
1141411416 cat > conftest.$ac_ext <<_LT_EOF
11415 -#line 11414 "configure"
 11417+#line 11416 "configure"
1141611418 #include "confdefs.h"
1141711419
1141811420 #if HAVE_DLFCN_H
Index: trunk/parsers/libmwparser/Makefile.in
@@ -77,12 +77,15 @@
7878 sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
7979 am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(includedir)"
8080 LTLIBRARIES = $(lib_LTLIBRARIES)
81 -libmwparser_la_LIBADD =
 81+am__DEPENDENCIES_1 =
 82+libmwparser_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(ANTLR3C_LIBS);
8283 am_libmwparser_la_OBJECTS = libmwparser_la-mwattributes.lo \
8384 libmwparser_la-mwbasicevents.lo libmwparser_la-mwformats.lo \
8485 libmwparser_la-mwheadings.lo libmwparser_la-mwhtml.lo \
8586 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 \
8790 libmwparser_la-mwparsercontext.lo libmwparser_la-mwtagext.lo \
8891 libmwparser_la-mwtables.lo libmwparser_la-tracingcontext.lo
8992 am__objects_1 = libmwparser_la-mwWikitextLexer.lo
@@ -90,7 +93,7 @@
9194 am__objects_3 =
9295 am__objects_4 = $(am__objects_1) $(am__objects_2) $(am__objects_3) \
9396 $(am__objects_3)
94 -nodist_libmwparser_la_OBJECTS = $(am__objects_4) $(am__objects_3)
 97+nodist_libmwparser_la_OBJECTS = $(am__objects_4)
9598 libmwparser_la_OBJECTS = $(am_libmwparser_la_OBJECTS) \
9699 $(nodist_libmwparser_la_OBJECTS)
97100 libmwparser_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
@@ -237,6 +240,7 @@
238241 SWIG_LIB = @SWIG_LIB@
239242 TARGET_LANGUAGE = @TARGET_LANGUAGE@
240243 TARGET_LANGUAGE_CFLAGS = @TARGET_LANGUAGE_CFLAGS@
 244+TARGET_LANGUAGE_LDFLAGS = @TARGET_LANGUAGE_LDFLAGS@
241245 VERSION = @VERSION@
242246 abs_builddir = @abs_builddir@
243247 abs_srcdir = @abs_srcdir@
@@ -297,11 +301,9 @@
298302 SUBDIRS = tests wrapper
299303 ANTLR_LEXER = mwWikitextLexer
300304 ANTLR_PARSER = mwWikitextParser
301 -ANTLR_LEXER_DELEGATES =
302305 ANTLR_GRAMMARS = $(ANTLR_LEXER:=.g) $(ANTLR_PARSER:=.g)
303306 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
306308 lib_LTLIBRARIES = libmwparser.la
307309 nodist_libmwparser_la_SOURCES = $(ANTLR_SOURCES) $(ANTLR_LEXER_DELEGATE_SOURCES)
308310 libmwparser_la_SOURCES = \
@@ -314,9 +316,11 @@
315317 include/mwkeyvalue.h \
316318 include/mwlexercontext.h \
317319 include/mwlinkcollection.h \
 320+ include/mwlinkresolution.h \
318321 include/mwlinks.h \
319322 include/mwlistener.h \
320323 include/mwparser.h \
 324+ include/mwmedialinkoption.h \
321325 include/mwparsercontext.h \
322326 include/mwtables.h \
323327 include/mwtagext.h \
@@ -329,7 +333,9 @@
330334 src/mwhtml.c \
331335 src/mwlexercontext.c \
332336 src/mwlinks.c \
 337+ src/mwlinkresolution.c \
333338 src/mwlinkcollection.c \
 339+ src/mwmedialinkoption.c \
334340 src/mwparser.c \
335341 src/mwparsercontext.c \
336342 src/mwtagext.c \
@@ -342,9 +348,9 @@
343349 src/mwlexerpredicatedefs.php \
344350 antlr.patch
345351
346 -libmwparser_la_LIBS = $(GLIB_LIBS)
347352 libmwparser_la_CFLAGS = $(GLIB_CFLAGS) -std=gnu99 -Wall -Wno-unused-variable
348353 libmwparser_la_LDFLAGS = -release $(PACKAGE_VERSION)
 354+libmwparser_la_LIBADD = $(GLIB_LIBS) $(ANTLR3C_LIBS);
349355 INCLUDES = -I$(top_srcdir)/include
350356 include_HEADERS = config.h
351357 ANTLR_PRODUCTS =
@@ -455,7 +461,9 @@
456462 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwhtml.Plo@am__quote@
457463 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwlexercontext.Plo@am__quote@
458464 @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@
459466 @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@
460468 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwparser.Plo@am__quote@
461469 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwparsercontext.Plo@am__quote@
462470 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libmwparser_la-mwtables.Plo@am__quote@
@@ -532,6 +540,13 @@
533541 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
534542 @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
535543
 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+
536551 libmwparser_la-mwlinkcollection.lo: src/mwlinkcollection.c
537552 @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
538553 @am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libmwparser_la-mwlinkcollection.Tpo $(DEPDIR)/libmwparser_la-mwlinkcollection.Plo
@@ -539,6 +554,13 @@
540555 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
541556 @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
542557
 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+
543565 libmwparser_la-mwparser.lo: src/mwparser.c
544566 @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
545567 @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 @@
22 #ifndef MWLINKCOLLECTION_H_
33 #define MWLINKCOLLECTION_H_
44
 5+#include <mwlinkresolution.h>
 6+
57 typedef struct MWLINKCOLLECTION_struct MWLINKCOLLECTION;
68
79 typedef void * MWLINKCOLLECTION_MARK;
810
 11+typedef struct LCKEY_struct MWLCKEY;
 12+
913 typedef enum MWLINKTYPE { MWLT_INTERNAL, MWLT_EXTERNAL, MWLT_MEDIA, MWLT_LINKATTR } MWLINKTYPE;
1014
1115 MWLINKCOLLECTION *MWLinkCollectionNew(void);
@@ -13,8 +17,23 @@
1418 MWLINKTYPE type,
1519 pANTLR3_STRING link,
1620 pANTLR3_COMMON_TOKEN token);
 21+int MWLinkCollectionNumLinks(MWLINKCOLLECTION *collection);
1722
1823 MWLINKCOLLECTION_MARK MWLinkCollectionMark(MWLINKCOLLECTION *collection);
1924 void MWLinkCollectionRewind(MWLINKCOLLECTION *collection, MWLINKCOLLECTION_MARK mark);
2025
 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+
2140 #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 @@
8989 bool (*isMediaLinkTitle)(struct MWLEXERCONTEXT_struct * context, pANTLR3_STRING text);
9090 bool (*setLegalTitleRegexp)(struct MWLEXERCONTEXT_struct *context, const char *perlRegexp);
9191 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;
9295 }
9396 MWLEXERCONTEXT;
9497
Index: trunk/parsers/libmwparser/include/mwlistener.h
@@ -20,6 +20,7 @@
2121 #ifndef MWLISTENER_H_
2222 #define MWLISTENER_H_
2323
 24+struct MWLINKCOLLECTION_struct;
2425
2526 /**
2627 * This interface should be implemented by the client application.
@@ -40,6 +41,10 @@
4142 void * (*newData)(void);
4243 void (*freeData)(void *);
4344 void (*resetData)(void *);
 45+
 46+ void (*linkResolver)(struct MWLINKCOLLECTION_struct *linkCollection, void *data);
 47+ void (*setLinkResolverData)(void *listenerData, void **linkResolverData);
 48+
4449 void * (*getResult)(struct MWLISTENER_struct * listener);
4550
4651
@@ -95,15 +100,15 @@
96101 void (*endTableBody)(struct MWLISTENER_struct * listener);
97102 void (*beginHeading)(struct MWLISTENER_struct * listener, int level, pANTLR3_STRING anchor, pANTLR3_VECTOR attributes);
98103 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);
100105 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);
102107 void (*beginExternalLink)(struct MWLISTENER_struct * listener, pANTLR3_STRING linkUrl);
103108 void (*endExternalLink)(struct MWLISTENER_struct * listener);
104109 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);
106111 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);
108113 void (*onTagExtension)(struct MWLISTENER_struct * listener, const char * name, pANTLR3_STRING body, pANTLR3_VECTOR attr);
109114 void (*beginTableOfContents)(struct MWLISTENER_struct * listener);
110115 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 @@
8989 void (*beginHtmlCenter)(struct MWPARSERCONTEXT_struct * context, pANTLR3_VECTOR attr);
9090 void (*endHtmlCenter)(struct MWPARSERCONTEXT_struct * context);
9191
92 - void (*beginInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkTitle);
 92+ void (*beginInternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_VECTOR attr);
9393 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);
9595 void (*beginExternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkUrl);
9696 void (*endExternalLink)(struct MWPARSERCONTEXT_struct * context);
9797 void (*onExternalLink)(struct MWPARSERCONTEXT_struct * context, pANTLR3_STRING linkUrl);
@@ -214,10 +214,15 @@
215215 }
216216 MWPARSERCONTEXT;
217217
 218+struct MWLEXERCONTEXT_struct;
 219+
218220 /**
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.
220225 */
221 -MWPARSERCONTEXT * MWParserContextNew(void* parser, const MWLISTENER *listener);
 226+MWPARSERCONTEXT * MWParserContextNew(void* parser, const MWLISTENER *listener, struct MWLEXERCONTEXT_struct *lexerContext);
222227
223228 /**
224229 * Put this macro at the beginning of begin methods that should not be

Status & tagging log