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:
fredkiefer 2014-06-17 21:06:11 +00:00
parent 101259e3e4
commit e4b9c44b1a
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> 2014-06-15 Fred Kiefer <FredKiefer@gmx.de>
* TextConverters/RTF/rtfScanner.m, * TextConverters/RTF/rtfScanner.m,

View file

@ -284,8 +284,8 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
- (void) appendString: (NSString*)string; - (void) appendString: (NSString*)string;
- (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName; - (void) appendHelpLink: (NSString*)fileName marker: (NSString *)markerName;
- (void) appendHelpMarker: (NSString*)markerName; - (void) appendHelpMarker: (NSString*)markerName;
- (void) appendField: (NSString*)instruction - (void) appendField: (int)start
result: (NSString*)result; instruction: (NSString*)instruction;
- (void) reset; - (void) reset;
@end @end
@ -780,17 +780,15 @@ static BOOL classInheritsFromNSMutableAttributedString (Class c)
} }
} }
- (void) appendField: (NSString*)instruction - (void) appendField: (int)start
result: (NSString*)fieldResult instruction: (NSString*)instruction
{ {
if (!ignore) if (!ignore)
{ {
int oldPosition = [result length]; int oldPosition = start;
int textlen = [fieldResult length]; int textlen = [result length] - start;
NSRange insertionRange = NSMakeRange(oldPosition, textlen); NSRange insertionRange = NSMakeRange(oldPosition, textlen);
[self appendString: fieldResult];
if ([instruction hasPrefix: @"HYPERLINK "]) if ([instruction hasPrefix: @"HYPERLINK "])
{ {
NSDictionary *attributes; NSDictionary *attributes;
@ -879,6 +877,11 @@ void GSRTFstop (void *ctxt)
NSDebugLLog(@"RTFParser", @"End RTF parsing"); NSDebugLLog(@"RTFParser", @"End RTF parsing");
} }
int GSRTFgetPosition(void *ctxt)
{
return [((RTFConsumer *)ctxt)->result length];
}
void GSRTFopenBlock (void *ctxt, BOOL ignore) void GSRTFopenBlock (void *ctxt, BOOL ignore)
{ {
if (!IGNORE) if (!IGNORE)
@ -1385,10 +1388,8 @@ void GSRTFNeXTHelpMarker (void *ctxt, int num, const char *markername)
[(RTFDConsumer *)ctxt appendHelpMarker: 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; NSString *fieldInstruction;
// Ignore leading blanks // Ignore leading blanks
@ -1399,7 +1400,6 @@ void GSRTFaddField (void *ctxt, const char *inst, const char *result)
fieldInstruction = [[NSString alloc] initWithCString: inst fieldInstruction = [[NSString alloc] initWithCString: inst
encoding: ENCODING]; encoding: ENCODING];
[(RTFDConsumer *)ctxt appendField: fieldInstruction result: fieldResult]; [(RTFDConsumer *)ctxt appendField: start instruction: fieldInstruction];
DESTROY(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 */ /* seal the parsing process, the context or whatever you want */
void GSRTFstop(void *ctxt); void GSRTFstop(void *ctxt);
/* */
int GSRTFgetPosition(void *ctxt);
/* /*
* those pairing functions enclose RTFBlocks. Use it to capture the * those pairing functions enclose RTFBlocks. Use it to capture the
* hierarchical attribute changes of blocks. i.e. attributes of a * hierarchical attribute changes of blocks. i.e. attributes of a
@ -147,7 +150,7 @@ void GSRTFNeXTHelpLink(void *ctxt, int num, const char *markername,
/* NeXTHelpMarker */ /* NeXTHelpMarker */
void GSRTFNeXTHelpMarker(void *ctxt, int num, const char *markername); 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 #endif

View file

@ -158,7 +158,7 @@ extern int GSRTFdebug;
typedef union YYSTYPE typedef union YYSTYPE
{ {
/* Line 2058 of yacc.c */ /* Line 2058 of yacc.c */
#line 82 "rtfGrammar.y" #line 85 "rtfGrammar.y"
int number; int number;
const char *text; 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 (YYSTYPE *lvalp, RTFscannerCtxt *lctxt); */
int GSRTFlex(void *lvalp, void *lctxt); int GSRTFlex(void *lvalp, void *lctxt);
/* */
int fieldStart = 0;
%} %}
%parse-param {void *ctxt} %parse-param {void *ctxt}
@ -196,7 +199,7 @@ int GSRTFlex(void *lvalp, void *lctxt);
%token RTFfamilyTech %token RTFfamilyTech
%type <number> rtfFontFamily rtfCharset rtfFontStatement %type <number> rtfFontFamily rtfCharset rtfFontStatement
%type <text> rtfFieldinst rtfFieldrslt %type <text> rtfFieldinst
/* let's go */ /* 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 | error
; ;
@ -259,9 +262,8 @@ rtfFieldalt: /* empty */
| RTFfldalt | RTFfldalt
; ;
rtfFieldrslt: '{' rtfIgnore RTFfldrslt RTFtext '}' { $$ = $4;} rtfFieldrslt: '{' rtfIgnore RTFfldrslt rtfIngredients '}'
| '{' rtfIgnore RTFfldrslt '{' rtfStatementList RTFtext '}' '}' { $$ = $6;} | '{' error '}'
| '{' error '}' { $$ = NULL;}
; ;
rtfStatementList: /* empty */ rtfStatementList: /* empty */