Rewrite parsing RTF link fields.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37947 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2014-06-17 21:06:11 +00:00
parent b48b73ee82
commit c973c719b5
6 changed files with 384 additions and 384 deletions

View file

@ -1,3 +1,11 @@
2014-06-17 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/rtfGrammar.y,
* TextConverters/RTF/RTFConsumerFunctions.h,
* TextConverters/RTF/RTFConsumer.m: Rewrite parsing link fields.
* TextConverters/RTF/rtfGrammar.tab.h,
* TextConverters/RTF/rtfGrammar.tab.m: Regenerated.
2014-06-15 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/rtfScanner.m,

View file

@ -284,8 +284,8 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
- (void) appendString: (NSString*)string;
- (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName;
- (void) appendHelpMarker: (NSString*)markerName;
- (void) appendField: (NSString*)instruction
result: (NSString*)result;
- (void) appendField: (int)start
instruction: (NSString*)instruction;
- (void) reset;
@end
@ -780,17 +780,15 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
}
}
- (void) appendField: (NSString*)instruction
result: (NSString*)fieldResult
- (void) appendField: (int)start
instruction: (NSString*)instruction
{
if (!ignore)
{
int oldPosition = [result length];
int textlen = [fieldResult length];
int oldPosition = start;
int textlen = [result length] - start;
NSRange insertionRange = NSMakeRange(oldPosition, textlen);
[self appendString: fieldResult];
if ([instruction hasPrefix: @"HYPERLINK "])
{
NSDictionary *attributes;
@ -879,6 +877,11 @@ void GSRTFstop (void *ctxt)
NSDebugLLog(@"RTFParser", @"End RTF parsing");
}
int GSRTFgetPosition(void *ctxt)
{
return [((RTFConsumer *)ctxt)->result length];
}
void GSRTFopenBlock (void *ctxt, BOOL ignore)
{
if (!IGNORE)
@ -1385,10 +1388,8 @@ void GSRTFNeXTHelpMarker (void *ctxt, int num, const char *markername)
[(RTFDConsumer *)ctxt appendHelpMarker: markerName];
}
void GSRTFaddField (void *ctxt, const char *inst, const char *result)
void GSRTFaddField (void *ctxt, int start, const char *inst)
{
NSString *fieldResult = [[NSString alloc] initWithCString: result
encoding: ENCODING];
NSString *fieldInstruction;
// Ignore leading blanks
@ -1399,7 +1400,6 @@ void GSRTFaddField (void *ctxt, const char *inst, const char *result)
fieldInstruction = [[NSString alloc] initWithCString: inst
encoding: ENCODING];
[(RTFDConsumer *)ctxt appendField: fieldInstruction result: fieldResult];
[(RTFDConsumer *)ctxt appendField: start instruction: fieldInstruction];
DESTROY(fieldInstruction);
DESTROY(fieldResult);
}

View file

@ -46,6 +46,9 @@ void GSRTFstart(void *ctxt);
/* seal the parsing process, the context or whatever you want */
void GSRTFstop(void *ctxt);
/* */
int GSRTFgetPosition(void *ctxt);
/*
* those pairing functions enclose RTFBlocks. Use it to capture the
* hierarchical attribute changes of blocks. i.e. attributes of a
@ -147,7 +150,7 @@ void GSRTFNeXTHelpLink(void *ctxt, int num, const char *markername,
/* NeXTHelpMarker */
void GSRTFNeXTHelpMarker(void *ctxt, int num, const char *markername);
void GSRTFaddField (void *ctxt, const char *inst, const char *result);
void GSRTFaddField (void *ctxt, int start, const char *inst);
#endif

View file

@ -158,7 +158,7 @@ extern int GSRTFdebug;
typedef union YYSTYPE
{
/* Line 2058 of yacc.c */
#line 82 "rtfGrammar.y"
#line 85 "rtfGrammar.y"
int number;
const char *text;

File diff suppressed because it is too large Load diff

View file

@ -74,6 +74,9 @@ typedef void *GSRTFctxt;
/*int GSRTFlex (YYSTYPE *lvalp, RTFscannerCtxt *lctxt); */
int GSRTFlex(void *lvalp, void *lctxt);
/* */
int fieldStart = 0;
%}
%parse-param {void *ctxt}
@ -196,7 +199,7 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFfamilyTech
%type <number> rtfFontFamily rtfCharset rtfFontStatement
%type <text> rtfFieldinst rtfFieldrslt
%type <text> rtfFieldinst
/* let's go */
@ -235,7 +238,7 @@ rtfBlock: '{' { GSRTFopenBlock(CTXT, NO); } rtfIngredients rtfNeXTstuff '}' { GS
;
rtfField: rtfFieldMod rtfFieldinst rtfFieldrslt { GSRTFaddField(CTXT, $2, $3); free((void *)$2); free((void *)$3); }
rtfField: { fieldStart = GSRTFgetPosition(CTXT);} rtfFieldMod rtfFieldinst rtfFieldrslt { GSRTFaddField(CTXT, fieldStart, $3); free((void *)$3); }
| error
;
@ -259,9 +262,8 @@ rtfFieldalt: /* empty */
| RTFfldalt
;
rtfFieldrslt: '{' rtfIgnore RTFfldrslt RTFtext '}' { $$ = $4;}
| '{' rtfIgnore RTFfldrslt '{' rtfStatementList RTFtext '}' '}' { $$ = $6;}
| '{' error '}' { $$ = NULL;}
rtfFieldrslt: '{' rtfIgnore RTFfldrslt rtfIngredients '}'
| '{' error '}'
;
rtfStatementList: /* empty */