Moved text conversion classes to separate bundle

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10755 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2001-08-21 14:52:00 +00:00
parent e4dd491dad
commit 30d3fd1bc0
22 changed files with 409 additions and 844 deletions

View file

@ -38,9 +38,7 @@ include ../config.make
LIBRARY_NAME = libgnustep-gui
# The Objective-C source files to be compiled
libgnustep-gui_C_FILES = \
Parsers/rtfGrammer.tab.c \
Parsers/rtfScanner.c
libgnustep-gui_C_FILES =
# The Objective-C source files to be compiled
libgnustep-gui_OBJC_FILES = Functions.m \
@ -156,9 +154,7 @@ GSFontInfo.m \
GSTable.m \
GSHbox.m \
GSVbox.m \
GSSimpleLayoutManager.m \
Parsers/attributedStringConsumer.m \
Parsers/RTFProducer.m
GSSimpleLayoutManager.m
ifneq ($(FOUNDATION_LIB), fd)
libgnustep-gui_OBJC_FILES += NSPasteboard.m

View file

@ -35,11 +35,8 @@
# otherwise the normal makefile rules will not be performed.
#
./$(GNUSTEP_OBJ_DIR)/Parsers:
$(MKDIRS) ./$(GNUSTEP_OBJ_DIR)/Parsers
# Things to do before compiling
before-all:: ./$(GNUSTEP_OBJ_DIR)/Parsers
# before-all::
# Things to do after compiling
# after-all::
@ -78,9 +75,6 @@ after-distclean::
#
# GNUstep GUI Library specific targets
Parsers/rtfGrammer.tab.c: Parsers/rtfGrammer.y
$(BISON) $(BISON_FLAGS) $<
#
# Make list of class names for DLL exports. I'm not sure how to make this
# work with the correct dependencies, so for now it should be regenerated

View file

@ -56,11 +56,6 @@ ifneq ($(BACKEND_BUNDLE),)
ADDITIONAL_CPPFLAGS += -DBACKEND_BUNDLE=1
endif
BISON_FLAGS = -d -p GSRTF
BISON = BISON_SIMPLE=Parsers/bison.simple bison
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS = -Wall

View file

@ -30,6 +30,8 @@
#include <Foundation/NSString.h>
#include <Foundation/NSRange.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSFileManager.h>
#include <AppKit/NSAttributedString.h>
#include <AppKit/NSParagraphStyle.h>
#include <AppKit/NSTextAttachment.h>
@ -99,6 +101,62 @@ static inline void cache_init ()
}
}
/* Return the class that handles format from the first bundle it finds */
static
Class converter_bundles(NSString *format, BOOL producer)
{
Class converter_class = Nil;
NSEnumerator *benum;
NSString *dpath;
/* Find the bundle paths */
benum = [NSStandardLibraryPaths() objectEnumerator];
while ((dpath = [benum nextObject]))
{
NSEnumerator *direnum;
NSString *path;
dpath = [dpath stringByAppendingPathComponent: @"Bundles"];
dpath = [dpath stringByAppendingPathComponent: @"TextConverters"];
if ([[NSFileManager defaultManager] fileExistsAtPath: dpath])
direnum = [[NSFileManager defaultManager] enumeratorAtPath: dpath];
else
direnum = nil;
while (direnum && (path = [direnum nextObject]))
{
Class bclass;
NSString *full_path;
NSBundle *aBundle;
if ([[path pathExtension] isEqual: @"bundle"] == NO)
continue;
full_path = [dpath stringByAppendingPathComponent: path];
aBundle = [NSBundle bundleWithPath: full_path];
if (aBundle && ((bclass = [aBundle principalClass])))
{
if ([bclass respondsToSelector:
@selector(classForFormat:producer:)])
{
converter_class = (Class)[bclass classForFormat: format
producer: producer];
}
else
{
NSString *converter_name;
if (producer)
converter_name = [format stringByAppendingString: @"Producer"];
else
converter_name = [format stringByAppendingString: @"Consumer"];
converter_class = [aBundle classNamed: converter_name];
}
}
if (converter_class)
break;
}
if (converter_class)
break;
}
return converter_class;
}
/*
Return a suitable converter for the text format supplied as argument.
If producer is YES a class capable of writting that format is returned,
@ -118,10 +176,9 @@ static Class converter_class(NSString *format, BOOL producer)
found = [p_classes objectForKey: format];
if (found == Nil)
{
if ([format isEqual: @"RTF"])
found = NSClassFromString(@"RTFProducer");
else if ([format isEqual: @"RTFD"])
found = NSClassFromString(@"RTFDProducer");
found = converter_bundles(format, producer);
if (found != Nil)
NSDebugLog(@"Found converter %@ for format %@", found, format);
if (found != Nil)
[p_classes setObject: found forKey: format];
}
@ -135,10 +192,9 @@ static Class converter_class(NSString *format, BOOL producer)
found = [c_classes objectForKey: format];
if (found == Nil)
{
if ([format isEqual: @"RTF"])
found = NSClassFromString(@"RTFConsumer");
else if ([format isEqual: @"RTFD"])
found = NSClassFromString(@"RTFDConsumer");
found = converter_bundles(format, producer);
if (found != Nil)
NSDebugLog(@"Found converter %@ for format %@", found, format);
if (found != Nil)
[c_classes setObject: found forKey: format];
}

View file

@ -1,57 +0,0 @@
/*
RTFProducer.h
Writes out a NSAttributedString as RTF
Copyright (C) 2000 Free Software Foundation, Inc.
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: June 2000
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <AppKit/GSTextConverter.h>
@class NSAttributedString;
@class NSMutableDictionary;
@class NSColor;
@class NSFont;
@class NSMutableParagraphStyle;
@interface RTFDProducer: NSObject <GSTextProducer>
{
@public
NSAttributedString *text;
NSMutableDictionary *fontDict;
NSMutableDictionary *colorDict;
NSMutableDictionary *docDict;
NSColor *fgColor;
NSColor *bgColor;
NSFont *currentFont;
/*
NSMutableParagraphStyle *paragraph;
*/
}
@end
@interface RTFProducer: RTFDProducer
// Subclass with no special interface
@end

View file

@ -1,704 +0,0 @@
/*
RTFProducer.m
Writes out a NSAttributedString as RTF
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Daniel Bðhringer
Date: November 1999
Modifications: Fred Kiefer <FredKiefer@gmx.de>
Date: June 2000
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include "RTFProducer.h"
// FIXME: Should be defined in a central place
#define PAPERSIZE @"PaperSize"
#define LEFTMARGIN @"LeftMargin"
#define RIGHTMARGIN @"RightMargin"
#define TOPMARGIN @"TopMargin"
#define BUTTOMMARGIN @"ButtomMargin"
#define points2twips(a) ((a)*20.0)
@interface RTFDProducer (Private)
- (NSString*) headerString;
- (NSString*) trailerString;
- (NSString*) bodyString;
- (NSString*) RTFDStringFromAttributedString: (NSAttributedString*)aText
documentAttributes: (NSDictionary*)dict;
@end
@implementation RTFDProducer
+ (NSFileWrapper*) produceFileFrom: (NSAttributedString*) aText
documentAttributes: (NSDictionary*)dict
{
RTFDProducer *new = [self new];
NSData *data;
NSFileWrapper *wrapper;
data = [[new RTFDStringFromAttributedString: aText
documentAttributes: dict]
dataUsingEncoding: NSISOLatin1StringEncoding];
if ([aText containsAttachments])
{
NSMutableDictionary *fileDict = [NSMutableDictionary dictionary];
NSFileWrapper *txt = [[NSFileWrapper alloc]
initRegularFileWithContents: data];
[fileDict setObject: txt forKey: @"TXT.rtf"];
RELEASE(txt);
// FIXME: We have to add the attachments to the directory file wrapper
wrapper = [[NSFileWrapper alloc] initDirectoryWithFileWrappers: fileDict];
}
else
wrapper = [[NSFileWrapper alloc] initRegularFileWithContents: data];
RELEASE(new);
return AUTORELEASE(wrapper);
}
+ (NSData*) produceDataFrom: (NSAttributedString*) aText
documentAttributes: (NSDictionary*)dict
{
return [[self produceFileFrom: aText
documentAttributes: dict] serializedRepresentation];
}
- (id)init
{
/*
* maintain a dictionary for the used colours
* (for rtf-header generation)
*/
colorDict = [NSMutableDictionary new];
/*
* maintain a dictionary for the used fonts
* (for rtf-header generation)
*/
fontDict = [NSMutableDictionary new];
currentFont = nil;
ASSIGN(fgColor, [NSColor textColor]);
ASSIGN(bgColor, [NSColor textBackgroundColor]);
return self;
}
- (void) dealloc
{
RELEASE(text);
RELEASE(fontDict);
RELEASE(colorDict);
RELEASE(docDict);
RELEASE(currentFont);
RELEASE(fgColor);
RELEASE(bgColor);
}
@end
@implementation RTFProducer
+ (NSData*) produceDataFrom: (NSAttributedString*) aText
documentAttributes: (NSDictionary*)dict
{
RTFProducer *new = [self new];
NSData *data;
data = [[new RTFDStringFromAttributedString: aText
documentAttributes: dict]
dataUsingEncoding: NSISOLatin1StringEncoding];
RELEASE(new);
return data;
}
+ (NSFileWrapper*) produceFileFrom: (NSAttributedString*) aText
documentAttributes: (NSDictionary*)dict
{
return [[NSFileWrapper alloc] initRegularFileWithContents:
[self produceDataFrom: aText
documentAttributes: dict]];
}
@end
@implementation RTFDProducer (Private)
- (NSString*) fontTable
{
// write Font Table
if ([fontDict count])
{
NSMutableString *fontlistString = [NSMutableString string];
NSEnumerator *fontEnum;
NSString *currFont;
NSArray *keyArray;
keyArray = [fontDict allKeys];
keyArray = [keyArray sortedArrayUsingSelector: @selector(compare:)];
fontEnum = [keyArray objectEnumerator];
while ((currFont = [fontEnum nextObject]) != nil)
{
NSString *fontFamily;
NSString *detail;
// If we ever have more fonts to map to families, we should use a dictionary
if ([currFont isEqualToString: @"Symbol"])
fontFamily = @"tech";
else if ([currFont isEqualToString: @"Helvetica"])
fontFamily = @"swiss";
else if ([currFont isEqualToString: @"Courier"])
fontFamily = @"modern";
else if ([currFont isEqualToString: @"Times"])
fontFamily = @"roman";
else
fontFamily = @"nil";
detail = [NSString stringWithFormat: @"%@\\f%@ %@;",
[fontDict objectForKey: currFont], fontFamily, currFont];
[fontlistString appendString: detail];
}
return [NSString stringWithFormat: @"{\\fonttbl%@}\n", fontlistString];
}
else
return @"";
}
- (NSString*) colorTable
{
// write Colour table
if ([colorDict count])
{
NSMutableString *result;
unsigned int count = [colorDict count];
NSMutableArray *list = [NSMutableArray arrayWithCapacity: count];
NSEnumerator *keyEnum = [colorDict keyEnumerator];
id next;
int i;
while ((next = [keyEnum nextObject]) != nil)
{
NSNumber *cn = [colorDict objectForKey: next];
[list insertObject: next atIndex: [cn intValue]-1];
}
result = (NSMutableString*)[NSMutableString stringWithString: @"{\\colortbl;"];
for (i = 0; i < count; i++)
{
NSColor *color = [[list objectAtIndex: i]
colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
[result appendString: [NSString stringWithFormat:
@"\\red%d\\green%d\\blue%d;",
(int)([color redComponent]*255),
(int)([color greenComponent]*255),
(int)([color blueComponent]*255)]];
}
[result appendString: @"}\n"];
return result;
}
else
return @"";
}
- (NSString*) documentAttributes
{
if (docDict != nil)
{
NSMutableString *result;
NSString *detail;
NSValue *val;
NSNumber *num;
result = (NSMutableString*)[NSMutableString string];
val = [docDict objectForKey: PAPERSIZE];
if (val != nil)
{
NSSize size = [val sizeValue];
detail = [NSString stringWithFormat: @"\\paperw%d \\paperh%d",
(int)points2twips(size.width),
(int)points2twips(size.height)];
[result appendString: detail];
}
num = [docDict objectForKey: LEFTMARGIN];
if (num != nil)
{
float f = [num floatValue];
detail = [NSString stringWithFormat: @"\\margl%d",
(int)points2twips(f)];
[result appendString: detail];
}
num = [docDict objectForKey: RIGHTMARGIN];
if (num != nil)
{
float f = [num floatValue];
detail = [NSString stringWithFormat: @"\\margr%d",
(int)points2twips(f)];
[result appendString: detail];
}
num = [docDict objectForKey: TOPMARGIN];
if (num != nil)
{
float f = [num floatValue];
detail = [NSString stringWithFormat: @"\\margt%d",
(int)points2twips(f)];
[result appendString: detail];
}
num = [docDict objectForKey: BUTTOMMARGIN];
if (num != nil)
{
float f = [num floatValue];
detail = [NSString stringWithFormat: @"\\margb%d",
(int)points2twips(f)];
[result appendString: detail];
}
return result;
}
else
return @"";
}
- (NSString*) headerString
{
NSMutableString *result;
result = (NSMutableString*)[NSMutableString stringWithString: @"{\\rtf1\\ansi"];
[result appendString: [self fontTable]];
[result appendString: [self colorTable]];
[result appendString: [self documentAttributes]];
return result;
}
- (NSString*) trailerString
{
return @"}";
}
- (NSString*) fontToken: (NSString*) fontName
{
NSString *fCount = [fontDict objectForKey: fontName];
if (fCount == nil)
{
unsigned count = [fontDict count];
fCount = [NSString stringWithFormat: @"\\f%d", count];
[fontDict setObject: fCount forKey: fontName];
}
return fCount;
}
- (int) numberForColor: (NSColor*)color
{
unsigned int cn;
NSNumber *num = [colorDict objectForKey: color];
if (num == nil)
{
cn = [colorDict count] + 1;
[colorDict setObject: [NSNumber numberWithInt: cn]
forKey: color];
}
else
cn = [num intValue];
return cn;
}
- (NSString*) paragraphStyle: (NSParagraphStyle*) paraStyle
{
NSMutableString *headerString = (NSMutableString *)[NSMutableString
stringWithString:
@"\\pard\\plain"];
int twips;
if (paraStyle == nil)
return headerString;
switch ([paraStyle alignment])
{
case NSRightTextAlignment:
[headerString appendString: @"\\qr"];
break;
case NSCenterTextAlignment:
[headerString appendString: @"\\qc"];
break;
case NSLeftTextAlignment:
[headerString appendString: @"\\ql"];
break;
case NSJustifiedTextAlignment:
[headerString appendString: @"\\qj"];
break;
default: break;
}
// write first line indent and left indent
twips = (int)points2twips([paraStyle firstLineHeadIndent]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\fi%d",
twips]];
}
twips = (int)points2twips([paraStyle headIndent]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\li%d",
twips]];
}
twips = (int)points2twips([paraStyle tailIndent]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\ri%d",
twips]];
}
twips = (int)points2twips([paraStyle paragraphSpacing]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\sa%d",
twips]];
}
twips = (int)points2twips([paraStyle minimumLineHeight]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\sl%d",
twips]];
}
twips = (int)points2twips([paraStyle maximumLineHeight]);
if (twips != 0.0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\sl-%d",
twips]];
}
// FIXME: Tab definitions are still missing
return headerString;
}
- (NSString*) runStringForString: (NSString*) substring
attributes: (NSDictionary*) attributes
paragraphStart: (BOOL) first
{
NSMutableString *result = [NSMutableString stringWithCapacity:
[substring length]*2];
NSMutableString *headerString = [NSMutableString stringWithCapacity: 20];
NSMutableString *trailerString = [NSMutableString stringWithCapacity: 20];
NSEnumerator *attribEnum;
id currAttrib;
if (first)
{
NSParagraphStyle *paraStyle = [attributes objectForKey:
NSParagraphStyleAttributeName];
[headerString appendString: [self paragraphStyle: paraStyle]];
DESTROY(currentFont);
}
/*
* analyze attributes of current run
*
* FIXME: All the character attributes should be output relative to the font
* attributes of the paragraph. So if the paragraph has underline on it should
* still be possible to switch it off for some characters, which currently is
* not possible.
*/
attribEnum = [attributes keyEnumerator];
while ((currAttrib = [attribEnum nextObject]) != nil)
{
if ([currAttrib isEqualToString: NSFontAttributeName])
{
/*
* handle fonts
*/
NSFont *font;
NSString *fontName;
NSFontTraitMask traits;
NSFontTraitMask oldTraits;
font = [attributes objectForKey: NSFontAttributeName];
fontName = [font familyName];
traits = [[NSFontManager sharedFontManager] traitsOfFont: font];
if (currentFont == nil)
oldTraits = 0;
else
oldTraits = [[NSFontManager sharedFontManager] traitsOfFont: currentFont];
/*
* font name
*/
if (currentFont == nil ||
![fontName isEqualToString: [currentFont familyName]])
{
[headerString appendString: [self fontToken: fontName]];
}
/*
* font size
*/
if (currentFont == nil ||
[font pointSize] != [currentFont pointSize])
{
int points = (int)[font pointSize]*2;
NSString *pString;
pString = [NSString stringWithFormat: @"\\fs%d", points];
[headerString appendString: pString];
}
/*
* font attributes
*/
if ((traits & NSItalicFontMask) != (oldTraits & NSItalicFontMask))
{
if (traits & NSItalicFontMask)
{
[headerString appendString: @"\\i"];
[trailerString appendString: @"\\i0"];
}
else
{
[headerString appendString: @"\\i0"];
[trailerString appendString: @"\\i"];
}
}
if ((traits & NSBoldFontMask) != (oldTraits & NSBoldFontMask))
{
if (traits & NSBoldFontMask)
{
[headerString appendString: @"\\b"];
[trailerString appendString: @"\\b0"];
}
else
{
[headerString appendString: @"\\b0"];
[trailerString appendString: @"\\b"];
}
}
if (first)
ASSIGN(currentFont, font);
}
else if ([currAttrib isEqualToString: NSForegroundColorAttributeName])
{
NSColor *color = [attributes objectForKey: NSForegroundColorAttributeName];
if (![color isEqual: fgColor])
{
[headerString appendString: [NSString stringWithFormat:
@"\\cf%d",
[self numberForColor: color]]];
[trailerString appendString: @"\\cf0"];
}
}
else if ([currAttrib isEqualToString: NSBackgroundColorAttributeName])
{
NSColor *color = [attributes objectForKey: NSBackgroundColorAttributeName];
if (![color isEqual: bgColor])
{
[headerString appendString: [NSString stringWithFormat:
@"\\cb%d",
[self numberForColor: color]]];
[trailerString appendString: @"\\cb0"];
}
}
else if ([currAttrib isEqualToString: NSUnderlineStyleAttributeName])
{
[headerString appendString: @"\\ul"];
[trailerString appendString: @"\\ulnone"];
}
else if ([currAttrib isEqualToString: NSSuperscriptAttributeName])
{
NSNumber *value = [attributes objectForKey: NSSuperscriptAttributeName];
int svalue = [value intValue] * 6;
if (svalue > 0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\up%d", svalue]];
[trailerString appendString: @"\\up0"];
}
else if (svalue < 0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\dn-%d", svalue]];
[trailerString appendString: @"\\dn0"];
}
}
else if ([currAttrib isEqualToString: NSBaselineOffsetAttributeName])
{
NSNumber *value = [attributes objectForKey: NSBaselineOffsetAttributeName];
int svalue = (int)[value floatValue] * 2;
if (svalue > 0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\up%d", svalue]];
[trailerString appendString: @"\\up0"];
}
else if (svalue < 0)
{
[headerString appendString: [NSString stringWithFormat:
@"\\dn-%d", svalue]];
[trailerString appendString: @"\\dn0"];
}
}
else if ([currAttrib isEqualToString: NSAttachmentAttributeName])
{
}
else if ([currAttrib isEqualToString: NSLigatureAttributeName])
{
}
else if ([currAttrib isEqualToString: NSKernAttributeName])
{
}
}
// FIXME: There should be a more efficient way to replace these
substring = [substring stringByReplacingString: @"\\"
withString: @"\\\\"];
substring = [substring stringByReplacingString: @"\n"
withString: @"\\par\n"];
substring = [substring stringByReplacingString: @"\t"
withString: @"\\tab "];
substring = [substring stringByReplacingString: @"{"
withString: @"\\{"];
substring = [substring stringByReplacingString: @"}"
withString: @"\\}"];
// FIXME: All characters not in the standard encoding must be
// replaced by \'xx
if (!first)
{
NSString *braces;
if ([headerString length])
braces = [NSString stringWithFormat: @"{%@ %@}",
headerString, substring];
else
braces = substring;
[result appendString: braces];
}
else
{
NSString *nobraces;
if ([headerString length])
nobraces = [NSString stringWithFormat: @"%@ %@",
headerString, substring];
else
nobraces = substring;
/* This has no result, as the character style is reset for each paragraph
if ([trailerString length])
nobraces = [NSString stringWithFormat: @"%@%@ ",
nobraces, trailerString];
*/
[result appendString: nobraces];
}
return result;
}
- (NSString*) bodyString
{
NSString *string = [text string];
NSMutableString *result = [NSMutableString string];
unsigned loc = 0;
unsigned length = [string length];
while (loc < length)
{
// Range of the current run
NSRange currRange = NSMakeRange(loc, 0);
// Range of the current paragraph
NSRange completeRange = [string lineRangeForRange: currRange];
BOOL first = YES;
while (NSMaxRange(currRange) < NSMaxRange(completeRange)) // save all "runs"
{
NSDictionary *attributes;
NSString *substring;
NSString *runString;
attributes = [text attributesAtIndex: NSMaxRange(currRange)
longestEffectiveRange: &currRange
inRange: completeRange];
substring = [string substringWithRange: currRange];
runString = [self runStringForString: substring
attributes: attributes
paragraphStart: first];
[result appendString: runString];
first = NO;
}
loc = NSMaxRange(completeRange);
}
return result;
}
- (NSString*) RTFDStringFromAttributedString: (NSAttributedString*)aText
documentAttributes: (NSDictionary*)dict
{
NSMutableString *output = [NSMutableString string];
NSString *headerString;
NSString *trailerString;
NSString *bodyString;
ASSIGN(text, aText);
ASSIGN(docDict, dict);
/*
* do not change order! (esp. body has to be generated first; builds context)
*/
bodyString = [self bodyString];
trailerString = [self trailerString];
headerString = [self headerString];
[output appendString: headerString];
[output appendString: bodyString];
[output appendString: trailerString];
return (NSString*)output;
}
@end

View file

@ -1,890 +0,0 @@
/* attributedStringConsumer.m
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: June 2000
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include "Parsers/rtfConsumer.h"
#include "Parsers/rtfConsumerFunctions.h"
/* we have to satisfy the scanner with a stream reading function */
typedef struct {
NSString *string;
int position;
int length;
} StringContext;
static void
initStringContext (StringContext *ctxt, NSString *string)
{
ctxt->string = string;
ctxt->position = 0;
ctxt->length = [string length];
}
static int
readNSString (StringContext *ctxt)
{
return (ctxt->position < ctxt->length )
? [ctxt->string characterAtIndex:ctxt->position++]: EOF;
}
// Hold the attributs of the current run
@interface RTFAttribute: NSObject <NSCopying>
{
@public
BOOL changed;
BOOL tabChanged;
NSMutableParagraphStyle *paragraph;
NSColor *fgColour;
NSColor *bgColour;
NSString *fontName;
float fontSize;
BOOL bold;
BOOL italic;
BOOL underline;
int script;
}
- (NSFont*) currentFont;
- (NSNumber*) script;
- (NSNumber*) underline;
- (void) resetParagraphStyle;
- (void) resetFont;
- (void) addTab: (float)location type: (NSTextTabType)type;
@end
@implementation RTFAttribute
- (id) init
{
[self resetFont];
[self resetParagraphStyle];
return self;
}
- (void) dealloc
{
RELEASE(paragraph);
RELEASE(fontName);
RELEASE(fgColour);
RELEASE(bgColour);
[super dealloc];
}
- (id) copyWithZone: (NSZone*)zone
{
RTFAttribute *new = (RTFAttribute *)NSCopyObject (self, 0, zone);
new->paragraph = [paragraph copyWithZone: zone];
RETAIN(new->fontName);
RETAIN(new->fgColour);
RETAIN(new->bgColour);
return new;
}
- (NSFont*) currentFont
{
NSFont *font;
NSFontTraitMask traits = 0;
int weight;
if (bold)
{
weight = 9;
traits |= NSBoldFontMask;
}
else
{
weight = 5;
traits |= NSUnboldFontMask;
}
if (italic)
{
traits |= NSItalicFontMask;
}
else
{
traits |= NSUnitalicFontMask;
}
font = [[NSFontManager sharedFontManager] fontWithFamily: fontName
traits: traits
weight: weight
size: fontSize];
if (font == nil)
{
NSDebugMLLog(@"RTFParser",
@"Could not find font %@ size %f traits %d weight %d",
fontName, fontSize, traits, weight);
font = [NSFont userFontOfSize: fontSize];
}
return font;
}
- (NSNumber*) script
{
return [NSNumber numberWithInt: script];
}
- (NSNumber*) underline
{
if (underline)
return [NSNumber numberWithInt: NSSingleUnderlineStyle];
else
return nil;
}
- (void) resetParagraphStyle
{
ASSIGN(paragraph, [NSMutableParagraphStyle defaultParagraphStyle]);
tabChanged = NO;
changed = YES;
}
- (void) resetFont
{
NSFont *font = [NSFont userFontOfSize:12];
ASSIGN(fontName, [font familyName]);
fontSize = 12.0;
italic = NO;
bold = NO;
underline = NO;
script = 0;
DESTROY(fgColour);
DESTROY(bgColour);
changed = YES;
}
- (void) addTab: (float) location type: (NSTextTabType) type
{
NSTextTab *tab = [[NSTextTab alloc] initWithType: NSLeftTabStopType
location: location];
if (!tabChanged)
{
// remove all tab stops
[paragraph setTabStops: [NSArray arrayWithObject: tab]];
tabChanged = YES;
}
else
{
[paragraph addTabStop: tab];
}
changed = YES;
RELEASE(tab);
}
@end
@interface RTFConsumer (Private)
- (NSAttributedString*) parseRTF: (NSData *)rtfData
documentAttributes: (NSDictionary **)dict;
- (NSDictionary*) documentAttributes;
- (NSAttributedString*) result;
- (RTFAttribute*) attr;
- (void) push;
- (void) pop;
@end
@implementation RTFConsumer
+ (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper
documentAttributes: (NSDictionary **)dict
{
RTFConsumer *consumer = [RTFConsumer new];
NSAttributedString *text = nil;
if ([wrapper isRegularFile])
{
text = [consumer parseRTF: [wrapper regularFileContents]
documentAttributes: dict];
}
else if ([wrapper isDirectory])
{
NSDictionary *files = [wrapper fileWrappers];
NSFileWrapper *contents;
//FIXME: We should store the files in the consumer
// We try to read the main file in the directory
if ((contents = [files objectForKey: @"TXT.rtf"]) != nil)
{
text = [consumer parseRTF: [contents regularFileContents]
documentAttributes: dict];
}
}
RELEASE(consumer);
return text;
}
+ (NSAttributedString*) parseData: (NSData *)rtfData
documentAttributes: (NSDictionary **)dict
{
RTFConsumer *consumer = [RTFConsumer new];
NSAttributedString *text;
text = [consumer parseRTF: rtfData
documentAttributes: dict];
RELEASE(consumer);
return text;
}
- (id) init
{
ignore = 0;
result = nil;
documentAttributes = nil;
fonts = nil;
attrs = nil;
colours = nil;
return self;
}
- (void) dealloc
{
RELEASE(fonts);
RELEASE(attrs);
RELEASE(colours);
RELEASE(result);
RELEASE(documentAttributes);
[super dealloc];
}
@end
@implementation RTFDConsumer
+ (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper
documentAttributes: (NSDictionary **)dict
{
return [super parseFile: wrapper
documentAttributes: dict];
}
+ (NSAttributedString*) parseData: (NSData *)rtfData
documentAttributes: (NSDictionary **)dict
{
NSAttributedString *str;
NSFileWrapper *wrapper = [[NSFileWrapper alloc]
initWithSerializedRepresentation: rtfData];
str = [self parseFile: wrapper documentAttributes: dict];
RELEASE (wrapper);
return str;
}
@end
@implementation RTFConsumer (Private)
- (NSDictionary*) documentAttributes
{
RETAIN(documentAttributes);
return AUTORELEASE(documentAttributes);
}
- (void) reset
{
RTFAttribute *attr = [RTFAttribute new];
ignore = 0;
DESTROY(result);
result = [[NSMutableAttributedString alloc] init];
ASSIGN(documentAttributes, [NSMutableDictionary dictionary]);
ASSIGN(fonts, [NSMutableDictionary dictionary]);
ASSIGN(attrs, [NSMutableArray array]);
ASSIGN(colours, [NSMutableArray array]);
[attrs addObject: attr];
RELEASE(attr);
}
- (RTFAttribute*) attr
{
return [attrs lastObject];
}
- (void) push
{
RTFAttribute *attr = [[attrs lastObject] copy];
[attrs addObject: attr];
RELEASE(attr);
}
- (void) pop
{
[attrs removeLastObject];
((RTFAttribute*)[attrs lastObject])->changed = YES;
}
- (NSAttributedString*) result
{
RETAIN(result);
return AUTORELEASE(result);
}
- (NSAttributedString*) parseRTF: (NSData *)rtfData
documentAttributes: (NSDictionary **)dict
{
CREATE_AUTORELEASE_POOL(pool);
RTFscannerCtxt scanner;
StringContext stringCtxt;
// We should read in the first few characters to find out which
// encoding we have
NSString *rtfString = [[NSString alloc]
initWithData: rtfData
encoding: NSASCIIStringEncoding];
// Reset this RFTConsumer, as it might already have been used!
[self reset];
initStringContext(&stringCtxt, rtfString);
lexInitContext(&scanner, &stringCtxt, (int (*)(void*))readNSString);
NS_DURING
GSRTFparse((void *)self, &scanner);
NS_HANDLER
NSLog(@"Problem during RTF Parsing: %@",
[localException reason]);
//[localException raise];
NS_ENDHANDLER
RELEASE(rtfString);
RELEASE(pool);
// document attributes
if (dict)
{
*dict = [self documentAttributes];
}
return [self result];
}
@end
#undef IGNORE
#define FONTS ((RTFConsumer *)ctxt)->fonts
#define COLOURS ((RTFConsumer *)ctxt)->colours
#define RESULT ((RTFConsumer *)ctxt)->result
#define IGNORE ((RTFConsumer *)ctxt)->ignore
#define TEXTPOSITION [RESULT length]
#define DOCUMENTATTRIBUTES ((RTFConsumer*)ctxt)->documentAttributes
#define CTXT [((RTFConsumer *)ctxt) attr]
#define CHANGED CTXT->changed
#define PARAGRAPH CTXT->paragraph
#define FONTNAME CTXT->fontName
#define SCRIPT CTXT->script
#define ITALIC CTXT->italic
#define BOLD CTXT->bold
#define UNDERLINE CTXT->underline
#define FGCOLOUR CTXT->fgColour
#define BGCOLOUR CTXT->bgColour
#define PAPERSIZE @"PaperSize"
#define LEFTMARGIN @"LeftMargin"
#define RIGHTMARGIN @"RightMargin"
#define TOPMARGIN @"TopMargin"
#define BUTTOMMARGIN @"ButtomMargin"
/*
we must implement from the rtfConsumerFunctions.h file (Supporting files)
this includes the yacc error handling and output
*/
/* handle errors (this is the yacc error mech) */
void GSRTFerror (const char *msg)
{
[NSException raise:NSInvalidArgumentException
format:@"Syntax error in RTF: %s", msg];
}
void GSRTFgenericRTFcommand (void *ctxt, RTFcmd cmd)
{
NSDebugLLog(@"RTFParser", @"encountered rtf cmd:%s", cmd.name);
if (!cmd.isEmpty)
NSDebugLLog(@"RTFParser", @" argument is %d\n", cmd.parameter);
}
//Start: we're doing some initialization
void GSRTFstart (void *ctxt)
{
NSDebugLLog(@"RTFParser", @"Start RTF parsing");
[RESULT beginEditing];
}
// Finished to parse one piece of RTF.
void GSRTFstop (void *ctxt)
{
//<!> close all open bolds et al.
[RESULT endEditing];
NSDebugLLog(@"RTFParser", @"End RTF parsing");
}
void GSRTFopenBlock (void *ctxt, BOOL ignore)
{
if (!IGNORE)
{
[(RTFConsumer *)ctxt push];
}
// Switch off any output for ignored block statements
if (ignore)
{
IGNORE++;
}
}
void GSRTFcloseBlock (void *ctxt, BOOL ignore)
{
if (ignore)
{
IGNORE--;
}
if (!IGNORE)
{
[(RTFConsumer *)ctxt pop];
}
}
void GSRTFmangleText (void *ctxt, const char *text)
{
int oldPosition = TEXTPOSITION;
int textlen = strlen(text);
NSRange insertionRange = NSMakeRange(oldPosition,0);
NSMutableDictionary *attributes;
if (!IGNORE && textlen)
{
[RESULT replaceCharactersInRange: insertionRange
withString: [NSString stringWithCString:text]];
if (CHANGED)
{
attributes = [NSMutableDictionary
dictionaryWithObjectsAndKeys:
[CTXT currentFont], NSFontAttributeName,
PARAGRAPH, NSParagraphStyleAttributeName,
nil];
if (UNDERLINE)
{
[attributes setObject: [CTXT underline]
forKey: NSUnderlineStyleAttributeName];
}
if (SCRIPT)
{
[attributes setObject: [CTXT script]
forKey: NSSuperscriptAttributeName];
}
if (FGCOLOUR != nil)
{
[attributes setObject: FGCOLOUR
forKey: NSForegroundColorAttributeName];
}
if (BGCOLOUR != nil)
{
[attributes setObject: BGCOLOUR
forKey: NSBackgroundColorAttributeName];
}
[RESULT setAttributes: attributes
range: NSMakeRange(oldPosition, textlen)];
CHANGED = NO;
}
}
}
void GSRTFregisterFont (void *ctxt, const char *fontName,
RTFfontFamily family, int fontNumber)
{
NSString *fontNameString;
NSNumber *fontId = [NSNumber numberWithInt: fontNumber];
if (!fontName || !*fontName)
{
[NSException raise: NSInvalidArgumentException
format: @"Error in RTF (font omitted?), position:%d",
TEXTPOSITION];
}
// exclude trailing ';' from fontName
fontNameString = [NSString stringWithCString: fontName
length: strlen(fontName)-1];
[FONTS setObject: fontNameString forKey: fontId];
}
void GSRTFfontNumber (void *ctxt, int fontNumber)
{
NSNumber *fontId = [NSNumber numberWithInt: fontNumber];
NSString *fontName = [FONTS objectForKey: fontId];
if (fontName == nil)
{
/* we're about to set an unknown font */
[NSException raise: NSInvalidArgumentException
format: @"Error in RTF (referring to undefined font \\f%d), position:%d",
fontNumber,
TEXTPOSITION];
}
else
{
if (![fontName isEqual: FONTNAME])
{
ASSIGN(FONTNAME, fontName);
CHANGED = YES;
}
}
}
// <N> fontSize is in halfpoints according to spec
void GSRTFfontSize (void *ctxt, int fontSize)
{
float size = halfpoints2points(fontSize);
if (size != CTXT->fontSize)
{
CTXT->fontSize = size;
CHANGED = YES;
}
}
void GSRTFpaperWidth (void *ctxt, int width)
{
float fwidth = twips2points(width);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
NSValue *val = [dict objectForKey: PAPERSIZE];
NSSize size;
if (val == nil)
{
size = NSMakeSize(fwidth, 792);
}
else
{
size = [val sizeValue];
size.width = fwidth;
}
[dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE];
}
void GSRTFpaperHeight (void *ctxt, int height)
{
float fheight = twips2points(height);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
NSValue *val = [dict objectForKey: PAPERSIZE];
NSSize size;
if (val == nil)
{
size = NSMakeSize(612, fheight);
}
else
{
size = [val sizeValue];
size.height = fheight;
}
[dict setObject: [NSValue valueWithSize: size] forKey: PAPERSIZE];
}
void GSRTFmarginLeft (void *ctxt, int margin)
{
float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: LEFTMARGIN];
}
void GSRTFmarginRight (void *ctxt, int margin)
{
float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: RIGHTMARGIN];
}
void GSRTFmarginTop (void *ctxt, int margin)
{
float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: TOPMARGIN];
}
void GSRTFmarginButtom (void *ctxt, int margin)
{
float fmargin = twips2points(margin);
NSMutableDictionary *dict = DOCUMENTATTRIBUTES;
[dict setObject: [NSNumber numberWithFloat: fmargin] forKey: BUTTOMMARGIN];
}
void GSRTFfirstLineIndent (void *ctxt, int indent)
{
NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent);
// FIXME: This should changed the left indent of the paragraph, if < 0
// for attributed strings only positiv indent is allowed
if ((findent >= 0.0) && ([para firstLineHeadIndent] != findent))
{
[para setFirstLineHeadIndent: findent];
CHANGED = YES;
}
}
void GSRTFleftIndent (void *ctxt, int indent)
{
NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent);
// for attributed strings only positiv indent is allowed
if ((findent >= 0.0) && ([para headIndent] != findent))
{
[para setHeadIndent: findent];
CHANGED = YES;
}
}
void GSRTFrightIndent (void *ctxt, int indent)
{
NSMutableParagraphStyle *para = PARAGRAPH;
float findent = twips2points(indent);
// for attributed strings only positiv indent is allowed
if ((findent >= 0.0) && ([para tailIndent] != findent))
{
[para setTailIndent: findent];
CHANGED = YES;
}
}
void GSRTFtabstop (void *ctxt, int location)
{
float flocation = twips2points(location);
if (flocation >= 0.0)
{
[CTXT addTab: flocation type: NSLeftTabStopType];
}
}
void GSRTFalignCenter (void *ctxt)
{
NSMutableParagraphStyle *para = PARAGRAPH;
if ([para alignment] != NSCenterTextAlignment)
{
[para setAlignment: NSCenterTextAlignment];
CHANGED = YES;
}
}
void GSRTFalignJustified (void *ctxt)
{
NSMutableParagraphStyle *para = PARAGRAPH;
if ([para alignment] != NSJustifiedTextAlignment)
{
[para setAlignment: NSJustifiedTextAlignment];
CHANGED = YES;
}
}
void GSRTFalignLeft (void *ctxt)
{
NSMutableParagraphStyle *para = PARAGRAPH;
if ([para alignment] != NSLeftTextAlignment)
{
[para setAlignment: NSLeftTextAlignment];
CHANGED = YES;
}
}
void GSRTFalignRight (void *ctxt)
{
NSMutableParagraphStyle *para = PARAGRAPH;
if ([para alignment] != NSRightTextAlignment)
{
[para setAlignment: NSRightTextAlignment];
CHANGED = YES;
}
}
void GSRTFspaceAbove (void *ctxt, int space)
{
NSMutableParagraphStyle *para = PARAGRAPH;
float fspace = twips2points(space);
if (fspace >= 0.0)
{
[para setParagraphSpacing: fspace];
}
}
void GSRTFlineSpace (void *ctxt, int space)
{
NSMutableParagraphStyle *para = PARAGRAPH;
float fspace = twips2points(space);
if (space == 1000)
{
[para setMinimumLineHeight: 0.0];
[para setMaximumLineHeight: 0.0];
}
else if (fspace < 0.0)
{
[para setMaximumLineHeight: -fspace];
}
else
{
[para setMinimumLineHeight: fspace];
}
}
void GSRTFdefaultParagraph (void *ctxt)
{
[CTXT resetParagraphStyle];
}
void GSRTFstyle (void *ctxt, int style)
{
}
void GSRTFdefaultCharacterStyle (void *ctxt)
{
[CTXT resetFont];
}
void GSRTFaddColor (void *ctxt, int red, int green, int blue)
{
NSColor *colour = [NSColor colorWithCalibratedRed: red/255.0
green: green/255.0
blue: blue/255.0
alpha: 1.0];
[COLOURS addObject: colour];
}
void GSRTFaddDefaultColor (void *ctxt)
{
[COLOURS addObject: [NSColor textColor]];
}
void GSRTFcolorbg (void *ctxt, int color)
{
if ([COLOURS count] <= color)
{
ASSIGN (BGCOLOUR, [NSColor whiteColor]);
}
else
{
ASSIGN (BGCOLOUR, [COLOURS objectAtIndex: color]);
}
}
void GSRTFcolorfg (void *ctxt, int color)
{
if ([COLOURS count] <= color)
{
ASSIGN (FGCOLOUR, [NSColor blackColor]);
}
else
{
ASSIGN (FGCOLOUR, [COLOURS objectAtIndex: color]);
}
}
void GSRTFsubscript (void *ctxt, int script)
{
script = (int) (-halfpoints2points(script) / 3.0);
if (script != SCRIPT)
{
SCRIPT = script;
CHANGED = YES;
}
}
void GSRTFsuperscript (void *ctxt, int script)
{
script = (int) (halfpoints2points(script) / 3.0);
if (script != SCRIPT)
{
SCRIPT = script;
CHANGED = YES;
}
}
void GSRTFitalic (void *ctxt, BOOL state)
{
if (state != ITALIC)
{
ITALIC = state;
CHANGED = YES;
}
}
void GSRTFbold (void *ctxt, BOOL state)
{
if (state != BOLD)
{
BOLD = state;
CHANGED = YES;
}
}
void GSRTFunderline (void *ctxt, BOOL state)
{
if (state != UNDERLINE)
{
UNDERLINE = state;
CHANGED = YES;
}
}
void GSRTFparagraph (void *ctxt)
{
GSRTFmangleText(ctxt, "\n");
CTXT->tabChanged = NO;
}

View file

@ -1,693 +0,0 @@
/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
#line 3 "/usr/local/share/bison.simple"
/* Skeleton output parser for bison,
Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
#ifndef alloca
#ifdef __GNUC__
#define alloca __builtin_alloca
#else /* not GNU C. */
#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi)
#include <alloca.h>
#else /* not sparc */
#if defined (MSDOS) && !defined (__TURBOC__)
#include <malloc.h>
#else /* not MSDOS, or __TURBOC__ */
#if defined(_AIX)
#include <malloc.h>
#pragma alloca
#else /* not MSDOS, __TURBOC__, or _AIX */
#ifdef __hpux
#ifdef __cplusplus
extern "C" {
void *alloca (unsigned int);
};
#else /* not __cplusplus */
void *alloca ();
#endif /* not __cplusplus */
#endif /* __hpux */
#endif /* not _AIX */
#endif /* not MSDOS, or __TURBOC__ */
#endif /* not sparc. */
#endif /* not GNU C. */
#endif /* alloca not defined. */
/* This is the parser code that is written into each bison parser
when the %semantic_parser declaration is not specified in the grammar.
It was written by Richard Stallman by simplifying the hairy parser
used when %semantic_parser is specified. */
/* Note: there must be only one dollar sign in this file.
It is replaced by the list of actions, each action
as one case of the switch. */
#define yyerrok (yyerrstatus = 0)
#define yyclearin (yychar = YYEMPTY)
#define YYEMPTY -2
#define YYEOF 0
#define YYACCEPT return(0)
#define YYABORT return(1)
#define YYERROR goto yyerrlab1
/* Like YYERROR except do call yyerror.
This remains here temporarily to ease the
transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go. */
#define YYFAIL goto yyerrlab
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP() \
do \
if (yychar == YYEMPTY && yylen == 1) \
{ yychar = (token), yylval = (value); \
yychar1 = YYTRANSLATE (yychar); \
YYPOPSTACK; \
goto yybackup; \
} \
else \
{ yyerror ("syntax error: cannot back up"); YYERROR; } \
while (0)
#define YYTERROR 1
#define YYERRCODE 256
#ifndef YYPURE
#define YYLEX yylex()
#endif
#ifdef YYPURE
#ifdef YYLSP_NEEDED
#ifdef YYLEX_PARAM
#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
#else
#define YYLEX yylex(&yylval, &yylloc)
#endif
#else /* not YYLSP_NEEDED */
#ifdef YYLEX_PARAM
#define YYLEX yylex(&yylval, YYLEX_PARAM)
#else
#define YYLEX yylex(&yylval)
#endif
#endif /* not YYLSP_NEEDED */
#endif
/* If nonreentrant, generate the variables here */
#ifndef YYPURE
int yychar; /* the lookahead symbol */
YYSTYPE yylval; /* the semantic value of the */
/* lookahead symbol */
#ifdef YYLSP_NEEDED
YYLTYPE yylloc; /* location data for the lookahead */
/* symbol */
#endif
int yynerrs; /* number of parse errors so far */
#endif /* not YYPURE */
#if YYDEBUG != 0
int yydebug; /* nonzero means print parse trace */
/* Since this is uninitialized, it does not stop multiple parsers
from coexisting. */
#endif
/* YYINITDEPTH indicates the initial size of the parser's stacks */
#ifndef YYINITDEPTH
#define YYINITDEPTH 200
#endif
/* YYMAXDEPTH is the maximum size the stacks can grow to
(effective only if the built-in stack extension method is used). */
#if YYMAXDEPTH == 0
#undef YYMAXDEPTH
#endif
#ifndef YYMAXDEPTH
#define YYMAXDEPTH 10000
#endif
/* Prevent warning if -Wstrict-prototypes. */
#ifdef __GNUC__
/*int yyparse ();*/
#endif
#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
#else /* not GNU C or C++ */
#ifndef __cplusplus
/* This is the most reliable way to avoid incompatibilities
in available built-in functions on various systems. */
static void
__yy_memcpy (to, from, count)
char *to;
char *from;
int count;
{
register char *f = from;
register char *t = to;
register int i = count;
while (i-- > 0)
*t++ = *f++;
}
#else /* __cplusplus */
/* This is the most reliable way to avoid incompatibilities
in available built-in functions on various systems. */
static void
__yy_memcpy (char *to, char *from, int count)
{
register char *f = from;
register char *t = to;
register int i = count;
while (i-- > 0)
*t++ = *f++;
}
#endif
#endif
#line 196 "/usr/local/share/bison.simple"
/* The user can define YYPARSE_PARAM as the name of an argument to be passed
into yyparse. The argument should have type void *.
It should actually point to an object.
Grammar actions can access the variable by casting it
to the proper pointer type. */
typedef void *VOIDP;
#ifdef YYPARSE_PARAM
#ifdef __cplusplus
#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
#define YYPARSE_PARAM_DECL
#else /* not __cplusplus */
#define YYPARSE_PARAM_ARG YYPARSE_PARAM
#define YYPARSE_PARAM_DECL VOIDP YYPARSE_PARAM;
#endif /* not __cplusplus */
#else /* not YYPARSE_PARAM */
#define YYPARSE_PARAM_ARG
#define YYPARSE_PARAM_DECL
#endif /* not YYPARSE_PARAM */
int
yyparse(YYPARSE_PARAM_ARG)
YYPARSE_PARAM_DECL
{
register int yystate;
register int yyn;
register short *yyssp;
register YYSTYPE *yyvsp;
int yyerrstatus; /* number of tokens to shift before error messages enabled */
int yychar1 = 0; /* lookahead token as an internal (translated) token number */
short yyssa[YYINITDEPTH]; /* the state stack */
YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
short *yyss = yyssa; /* refer to the stacks thru separate pointers */
YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
#ifdef YYLSP_NEEDED
YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
YYLTYPE *yyls = yylsa;
YYLTYPE *yylsp;
#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
#else
#define YYPOPSTACK (yyvsp--, yyssp--)
#endif
int yystacksize = YYINITDEPTH;
#ifdef YYPURE
int yychar;
YYSTYPE yylval;
int yynerrs;
#ifdef YYLSP_NEEDED
YYLTYPE yylloc;
#endif
#endif
YYSTYPE yyval; /* the variable used to return */
/* semantic values from the action */
/* routines */
int yylen;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Starting parse\n");
#endif
yystate = 0;
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
so that they stay on the same level as the state stack.
The wasted elements are never initialized. */
yyssp = yyss - 1;
yyvsp = yyvs;
#ifdef YYLSP_NEEDED
yylsp = yyls;
#endif
/* Push a new state, which is found in yystate . */
/* In all cases, when you get here, the value and location stacks
have just been pushed. so pushing a state here evens the stacks. */
yynewstate:
*++yyssp = yystate;
if (yyssp >= yyss + yystacksize - 1)
{
/* Give user a chance to reallocate the stack */
/* Use copies of these so that the &'s don't force the real ones into memory. */
YYSTYPE *yyvs1 = yyvs;
short *yyss1 = yyss;
#ifdef YYLSP_NEEDED
YYLTYPE *yyls1 = yyls;
#endif
/* Get the current used size of the three stacks, in elements. */
int size = yyssp - yyss + 1;
#ifdef yyoverflow
/* Each stack pointer address is followed by the size of
the data in use in that stack, in bytes. */
#ifdef YYLSP_NEEDED
/* This used to be a conditional around just the two extra args,
but that might be undefined if yyoverflow is a macro. */
yyoverflow("parser stack overflow",
&yyss1, size * sizeof (*yyssp),
&yyvs1, size * sizeof (*yyvsp),
&yyls1, size * sizeof (*yylsp),
&yystacksize);
#else
yyoverflow("parser stack overflow",
&yyss1, size * sizeof (*yyssp),
&yyvs1, size * sizeof (*yyvsp),
&yystacksize);
#endif
yyss = yyss1; yyvs = yyvs1;
#ifdef YYLSP_NEEDED
yyls = yyls1;
#endif
#else /* no yyoverflow */
/* Extend the stack our own way. */
if (yystacksize >= YYMAXDEPTH)
{
yyerror("parser stack overflow");
return 2;
}
yystacksize *= 2;
if (yystacksize > YYMAXDEPTH)
yystacksize = YYMAXDEPTH;
yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
__yy_memcpy ((char *)yyss, (char *)yyss1, size * sizeof (*yyssp));
yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
__yy_memcpy ((char *)yyvs, (char *)yyvs1, size * sizeof (*yyvsp));
#ifdef YYLSP_NEEDED
yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
__yy_memcpy ((char *)yyls, (char *)yyls1, size * sizeof (*yylsp));
#endif
#endif /* no yyoverflow */
yyssp = yyss + size - 1;
yyvsp = yyvs + size - 1;
#ifdef YYLSP_NEEDED
yylsp = yyls + size - 1;
#endif
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Stack size increased to %d\n", yystacksize);
#endif
if (yyssp >= yyss + yystacksize - 1)
YYABORT;
}
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Entering state %d\n", yystate);
#endif
goto yybackup;
yybackup:
/* Do appropriate processing given the current state. */
/* Read a lookahead token if we need one and don't already have one. */
/* yyresume: */
/* First try to decide what to do without reference to lookahead token. */
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yydefault;
/* Not known => get a lookahead token if don't already have one. */
/* yychar is either YYEMPTY or YYEOF
or a valid token in external form. */
if (yychar == YYEMPTY)
{
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Reading a token: ");
#endif
yychar = YYLEX;
}
/* Convert token to internal form (in yychar1) for indexing tables with */
if (yychar <= 0) /* This means end of input. */
{
yychar1 = 0;
yychar = YYEOF; /* Don't call YYLEX any more */
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Now at end of input.\n");
#endif
}
else
{
yychar1 = YYTRANSLATE(yychar);
#if YYDEBUG != 0
if (yydebug)
{
fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
/* Give the individual parser a way to print the precise meaning
of a token, for further debugging info. */
#ifdef YYPRINT
YYPRINT (stderr, yychar, yylval);
#endif
fprintf (stderr, ")\n");
}
#endif
}
yyn += yychar1;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
goto yydefault;
yyn = yytable[yyn];
/* yyn is what to do for this token type in this state.
Negative => reduce, -yyn is rule number.
Positive => shift, yyn is new state.
New state is final state => don't bother to shift,
just return success.
0, or most negative number => error. */
if (yyn < 0)
{
if (yyn == YYFLAG)
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrlab;
if (yyn == YYFINAL)
YYACCEPT;
/* Shift the lookahead token. */
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
#endif
/* Discard the token being shifted unless it is eof. */
if (yychar != YYEOF)
yychar = YYEMPTY;
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yylsp = yylloc;
#endif
/* count tokens shifted since error; after three, turn off error status. */
if (yyerrstatus) yyerrstatus--;
yystate = yyn;
goto yynewstate;
/* Do the default action for the current state. */
yydefault:
yyn = yydefact[yystate];
if (yyn == 0)
goto yyerrlab;
/* Do a reduction. yyn is the number of a rule to reduce with. */
yyreduce:
yylen = yyr2[yyn];
if (yylen > 0)
yyval = yyvsp[1-yylen]; /* implement default value of the action */
#if YYDEBUG != 0
if (yydebug)
{
int i;
fprintf (stderr, "Reducing via rule %d (line %d), ",
yyn, yyrline[yyn]);
/* Print the symbols being reduced, and their result. */
for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
fprintf (stderr, "%s ", yytname[yyrhs[i]]);
fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
}
#endif
$ /* the action file gets copied in in place of this dollarsign */
#line 498 "/usr/local/share/bison.simple"
yyvsp -= yylen;
yyssp -= yylen;
#ifdef YYLSP_NEEDED
yylsp -= yylen;
#endif
#if YYDEBUG != 0
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, "state stack now");
while (ssp1 != yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
*++yyvsp = yyval;
#ifdef YYLSP_NEEDED
yylsp++;
if (yylen == 0)
{
yylsp->first_line = yylloc.first_line;
yylsp->first_column = yylloc.first_column;
yylsp->last_line = (yylsp-1)->last_line;
yylsp->last_column = (yylsp-1)->last_column;
yylsp->text = 0;
}
else
{
yylsp->last_line = (yylsp+yylen-1)->last_line;
yylsp->last_column = (yylsp+yylen-1)->last_column;
}
#endif
/* Now "shift" the result of the reduction.
Determine what state that goes to,
based on the state we popped back to
and the rule number reduced by. */
yyn = yyr1[yyn];
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
yystate = yytable[yystate];
else
yystate = yydefgoto[yyn - YYNTBASE];
goto yynewstate;
yyerrlab: /* here on detecting error */
if (! yyerrstatus)
/* If not already recovering from an error, report this error. */
{
++yynerrs;
#ifdef YYERROR_VERBOSE
yyn = yypact[yystate];
if (yyn > YYFLAG && yyn < YYLAST)
{
int size = 0;
char *msg;
int x, count;
count = 0;
/* Start X at -yyn if nec to avoid negative indexes in yycheck. */
for (x = (yyn < 0 ? -yyn : 0);
x < (sizeof(yytname) / sizeof(char *)); x++)
if (yycheck[x + yyn] == x)
size += strlen(yytname[x]) + 15, count++;
msg = (char *) malloc(size + 15);
if (msg != 0)
{
strcpy(msg, "parse error");
if (count < 5)
{
count = 0;
for (x = (yyn < 0 ? -yyn : 0);
x < (sizeof(yytname) / sizeof(char *)); x++)
if (yycheck[x + yyn] == x)
{
strcat(msg, count == 0 ? ", expecting `" : " or `");
strcat(msg, yytname[x]);
strcat(msg, "'");
count++;
}
}
yyerror(msg);
free(msg);
}
else
yyerror ("parse error; also virtual memory exceeded");
}
else
#endif /* YYERROR_VERBOSE */
yyerror("parse error");
}
goto yyerrlab1;
yyerrlab1: /* here on error raised explicitly by an action */
if (yyerrstatus == 3)
{
/* if just tried and failed to reuse lookahead token after an error, discard it. */
/* return failure if at end of input */
if (yychar == YYEOF)
YYABORT;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
#endif
yychar = YYEMPTY;
}
/* Else will try to reuse lookahead token
after shifting the error token. */
yyerrstatus = 3; /* Each real token shifted decrements this */
goto yyerrhandle;
yyerrdefault: /* current state does not do anything special for the error token. */
#if 0
/* This is wrong; only states that explicitly want error tokens
should shift them. */
yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
if (yyn) goto yydefault;
#endif
yyerrpop: /* pop the current state because it cannot handle the error token */
if (yyssp == yyss) YYABORT;
yyvsp--;
yystate = *--yyssp;
#ifdef YYLSP_NEEDED
yylsp--;
#endif
#if YYDEBUG != 0
if (yydebug)
{
short *ssp1 = yyss - 1;
fprintf (stderr, "Error: state stack now");
while (ssp1 != yyssp)
fprintf (stderr, " %d", *++ssp1);
fprintf (stderr, "\n");
}
#endif
yyerrhandle:
yyn = yypact[yystate];
if (yyn == YYFLAG)
goto yyerrdefault;
yyn += YYTERROR;
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
goto yyerrdefault;
yyn = yytable[yyn];
if (yyn < 0)
{
if (yyn == YYFLAG)
goto yyerrpop;
yyn = -yyn;
goto yyreduce;
}
else if (yyn == 0)
goto yyerrpop;
if (yyn == YYFINAL)
YYACCEPT;
#if YYDEBUG != 0
if (yydebug)
fprintf(stderr, "Shifting error token, ");
#endif
*++yyvsp = yylval;
#ifdef YYLSP_NEEDED
*++yylsp = yylloc;
#endif
yystate = yyn;
goto yynewstate;
}

View file

@ -1,51 +0,0 @@
/* rtfConsumer.h created by pingu on Fri 12-Nov-1999
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _rtfConsumer_h_INCLUDE
#define _rtfConsumer_h_INCLUDE
#include <AppKit/GSTextConverter.h>
@class NSMutableDictionary;
@class NSMutableArray;
@class NSMutableAttributedString;
@interface RTFConsumer: NSObject <GSTextConsumer>
{
@public
NSMutableDictionary *documentAttributes;
NSMutableDictionary *fonts;
NSMutableArray *colours;
NSMutableArray *attrs;
NSMutableAttributedString *result;
int ignore;
}
@end
@interface RTFDConsumer: RTFConsumer
@end
#endif

View file

@ -1,135 +0,0 @@
/* rtfConsumerFunctions.h created by pingu on Wed 17-Nov-1999
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* here we define the interface functions to grammer consumers */
#ifndef rtfConsumerFunctions_h_INCLUDE
#define rtfConsumerFunctions_h_INCLUDE
#include "Parsers/rtfScanner.h"
/* general statements:
measurement is usually in twips: one twentieth of a point (this is about 0.01764 mm)
a tabstop of 540 twips (as it occurs on NeXT) is therefore about 0.95 cm
*/
#define halfpoints2points(a) ((a)/2.0)
#define twips2points(a) ((a)/20.0)
#define twips2mm(a) ((a)*0.01764)
/* prepare the ctxt, or whatever you want */
void GSRTFstart(void *ctxt);
/* seal the parsing process, the context or whatever you want */
void GSRTFstop(void *ctxt);
/* those pairing functions enclose RTFBlocks. Use it to capture the hierarchical attribute changes of blocks.
i.e. attributes of a block are forgotten once a block is closed
*/
void GSRTFopenBlock(void *ctxt, BOOL ignore);
void GSRTFcloseBlock(void *ctxt, BOOL ignore);
/* handle errors */
void GSRTFerror(const char *msg);
/* handle rtf commands not expicated in the grammer */
void GSRTFgenericRTFcommand(void *ctxt, RTFcmd cmd);
/* go, handle text */
void GSRTFmangleText(void *ctxt, const char *text);
/*
font functions
*/
/* get noticed that a particular font is introduced */
void GSRTFregisterFont(void *ctxt, const char *fontName,
RTFfontFamily family, int fontNumber);
/* change font number */
void GSRTFfontNumber(void *ctxt, int fontNumber);
/* change font size in half points*/
void GSRTFfontSize(void *ctxt, int fontSize);
/* set paper width in twips */
void GSRTFpaperWidth(void *ctxt, int width);
/* set paper height in twips */
void GSRTFpaperHeight(void *ctxt, int height);
/* set left margin in twips */
void GSRTFmarginLeft(void *ctxt, int margin);
/* set right margin in twips */
void GSRTFmarginRight(void *ctxt, int margin);
/* set top margin in twips */
void GSRTFmarginTop(void *ctxt, int margin);
/* set buttom margin in twips */
void GSRTFmarginButtom(void *ctxt, int margin);
/* set first line indent */
void GSRTFfirstLineIndent(void *ctxt, int indent);
/* set left indent */
void GSRTFleftIndent(void *ctxt, int indent);
/* set right indent */
void GSRTFrightIndent(void *ctxt, int indent);
/* set tabstop */
void GSRTFtabstop(void *ctxt, int location);
/* set center alignment */
void GSRTFalignCenter(void *ctxt);
/* set justified alignment */
void GSRTFalignJustified(void *ctxt);
/* set left alignment */
void GSRTFalignLeft(void *ctxt);
/* set right alignment */
void GSRTFalignRight(void *ctxt);
/* set space above */
void GSRTFspaceAbove(void *ctxt, int location);
/* set line space */
void GSRTFlineSpace(void *ctxt, int location);
/* set default paragraph style */
void GSRTFdefaultParagraph(void *ctxt);
/* set paragraph style */
void GSRTFstyle(void *ctxt, int style);
/* Add a colour to the colour table*/
void GSRTFaddColor(void *ctxt, int red, int green, int blue);
/* Add the default colour to the colour table*/
void GSRTFaddDefaultColor(void *ctxt);
/* set background colour */
void GSRTFcolorbg(void *ctxt, int color);
/* set foreground colour */
void GSRTFcolorfg(void *ctxt, int color);
/* set default character style */
void GSRTFdefaultCharacterStyle(void *ctxt);
/* set subscript in half points */
void GSRTFsubscript(void *ctxt, int script);
/* set superscript in half points */
void GSRTFsuperscript(void *ctxt, int script);
/* Switch bold mode on or off */
void GSRTFbold(void *ctxt, BOOL on);
/* Switch italic mode on or off */
void GSRTFitalic(void *ctxt, BOOL on);
/* Switch underline mode on or off */
void GSRTFunderline(void *ctxt, BOOL on);
/* new paragraph */
void GSRTFparagraph(void *ctxt);
#endif

File diff suppressed because it is too large Load diff

View file

@ -1,94 +0,0 @@
typedef union {
int number;
const char *text;
RTFcmd cmd;
} YYSTYPE;
#ifndef YYLTYPE
typedef
struct yyltype
{
int timestamp;
int first_line;
int first_column;
int last_line;
int last_column;
char *text;
}
yyltype;
#define YYLTYPE yyltype
#endif
#define RTFtext 258
#define RTFstart 259
#define RTFansi 260
#define RTFmac 261
#define RTFpc 262
#define RTFpca 263
#define RTFignore 264
#define RTFinfo 265
#define RTFstylesheet 266
#define RTFfootnote 267
#define RTFheader 268
#define RTFfooter 269
#define RTFpict 270
#define RTFplain 271
#define RTFparagraph 272
#define RTFdefaultParagraph 273
#define RTFrow 274
#define RTFcell 275
#define RTFtabulator 276
#define RTFemdash 277
#define RTFendash 278
#define RTFemspace 279
#define RTFenspace 280
#define RTFbullet 281
#define RTFlquote 282
#define RTFrquote 283
#define RTFldblquote 284
#define RTFrdblquote 285
#define RTFred 286
#define RTFgreen 287
#define RTFblue 288
#define RTFcolorbg 289
#define RTFcolorfg 290
#define RTFcolortable 291
#define RTFfont 292
#define RTFfontSize 293
#define RTFpaperWidth 294
#define RTFpaperHeight 295
#define RTFmarginLeft 296
#define RTFmarginRight 297
#define RTFmarginTop 298
#define RTFmarginButtom 299
#define RTFfirstLineIndent 300
#define RTFleftIndent 301
#define RTFrightIndent 302
#define RTFalignCenter 303
#define RTFalignJustified 304
#define RTFalignLeft 305
#define RTFalignRight 306
#define RTFlineSpace 307
#define RTFspaceAbove 308
#define RTFstyle 309
#define RTFbold 310
#define RTFitalic 311
#define RTFunderline 312
#define RTFunderlineStop 313
#define RTFsubscript 314
#define RTFsuperscript 315
#define RTFtabstop 316
#define RTFfcharset 317
#define RTFfprq 318
#define RTFcpg 319
#define RTFOtherStatement 320
#define RTFfontListStart 321
#define RTFfamilyNil 322
#define RTFfamilyRoman 323
#define RTFfamilySwiss 324
#define RTFfamilyModern 325
#define RTFfamilyScript 326
#define RTFfamilyDecor 327
#define RTFfamilyTech 328

View file

@ -1,417 +0,0 @@
/* rtfGrammer.y
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
if processed using -p GSRTFP (as recommended) it will introduce the following global symbols:
'GSRTFPparse', `GSRTFPlex', `GSRTFPerror', `GSRTFPnerrs', `GSRTFPlval',
`GSRTFPchar', `GSRTFPdebug
*/
/* we request for a reentrant parser */
%pure_parser
%{
/*
The overall plan is to make this grammer universal in usage.
Intrested buddies can implement plain C functions to consume what
the grammer is producing. this way the rtf-grammer-tree can be
converted to what is needed: GNUstep attributed strings, tex files,
...
The plan is laid out by defining a set of C functions which cover
all what is needed to mangle rtf information (it is NeXT centric
however and may even lack some features). Be aware that some
functions are called at specific times when some information may or
may not be available. The first argument of all functions is a
context, which is asked to be maintained by the consumer at
whichever purpose seems appropriate. This context must be passed to
the parser by issuing 'value = GSRTFparse(ctxt, lctxt);' in the
first place.
*/
#include <stdlib.h>
#include <string.h>
#include "Parsers/rtfScanner.h"
/* this context is passed to the interface functions */
typedef void * GSRTFctxt;
#define YYPARSE_PARAM ctxt, lctxt
#define YYLEX_PARAM lctxt
#define YYERROR_VERBOSE
#include "rtfConsumerFunctions.h"
%}
%union {
int number;
const char *text;
RTFcmd cmd;
}
/* <!><p> RTFtext values have to be freed */
%token <text> RTFtext
%token RTFstart
%token RTFansi
%token RTFmac
%token RTFpc
%token RTFpca
%token RTFignore
%token RTFinfo
%token RTFstylesheet
%token RTFfootnote
%token RTFheader
%token RTFfooter
%token RTFpict
%token RTFplain
%token RTFparagraph
%token RTFdefaultParagraph
%token RTFrow
%token RTFcell
%token RTFtabulator
%token RTFemdash
%token RTFendash
%token RTFemspace
%token RTFenspace
%token RTFbullet
%token RTFlquote
%token RTFrquote
%token RTFldblquote
%token RTFrdblquote
%token <cmd> RTFred
%token <cmd> RTFgreen
%token <cmd> RTFblue
%token <cmd> RTFcolorbg
%token <cmd> RTFcolorfg
%token <cmd> RTFcolortable
%token <cmd> RTFfont
%token <cmd> RTFfontSize
%token <cmd> RTFpaperWidth
%token <cmd> RTFpaperHeight
%token <cmd> RTFmarginLeft
%token <cmd> RTFmarginRight
%token <cmd> RTFmarginTop
%token <cmd> RTFmarginButtom
%token <cmd> RTFfirstLineIndent
%token <cmd> RTFleftIndent
%token <cmd> RTFrightIndent
%token <cmd> RTFalignCenter
%token <cmd> RTFalignJustified
%token <cmd> RTFalignLeft
%token <cmd> RTFalignRight
%token <cmd> RTFlineSpace
%token <cmd> RTFspaceAbove
%token <cmd> RTFstyle
%token <cmd> RTFbold
%token <cmd> RTFitalic
%token <cmd> RTFunderline
%token <cmd> RTFunderlineStop
%token <cmd> RTFsubscript
%token <cmd> RTFsuperscript
%token <cmd> RTFtabstop
%token <cmd> RTFfcharset
%token <cmd> RTFfprq
%token <cmd> RTFcpg
%token <cmd> RTFOtherStatement
%token RTFfontListStart
// <!> we assume token numbers to be sequential
// \fnil | \froman | \fswiss | \fmodern | \fscript | \fdecor | \ftech
// look at rtfScanner.h for enum definition
%token RTFfamilyNil
%token RTFfamilyRoman
%token RTFfamilySwiss
%token RTFfamilyModern
%token RTFfamilyScript
%token RTFfamilyDecor
%token RTFfamilyTech
%type <number> rtfFontFamily rtfCharset rtfFontStatement
/* let's go */
%%
rtfFile: '{' { GSRTFstart(ctxt); } RTFstart rtfCharset rtfIngredients { GSRTFstop(ctxt); } '}'
;
rtfCharset: RTFansi { $$ = 1; }
| RTFmac { $$ = 2; }
| RTFpc { $$ = 3; }
| RTFpca { $$ = 4; }
;
rtfIngredients: /* empty */
| rtfIngredients rtfFontList
| rtfIngredients rtfColorDef
| rtfIngredients rtfStatement
| rtfIngredients RTFtext { GSRTFmangleText(ctxt, $2); free((void *)$2); }
| rtfIngredients rtfBlock
;
rtfBlock: '{' { GSRTFopenBlock(ctxt, NO); } rtfIngredients '}' { GSRTFcloseBlock(ctxt, NO); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFignore rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFinfo rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFstylesheet rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFfootnote rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFheader rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); }
| '{' '}' /* empty */
;
/*
RTF statements start with a '\', have a alpha name and a number argument
*/
rtfStatement: RTFfont { int font;
if ($1.isEmpty)
font = 0;
else
font = $1.parameter;
GSRTFfontNumber(ctxt, font); }
| RTFfontSize { int size;
if ($1.isEmpty)
size = 24;
else
size = $1.parameter;
GSRTFfontSize(ctxt, size); }
| RTFpaperWidth { int width;
if ($1.isEmpty)
width = 12240;
else
width = $1.parameter;
GSRTFpaperWidth(ctxt, width);}
| RTFpaperHeight { int height;
if ($1.isEmpty)
height = 15840;
else
height = $1.parameter;
GSRTFpaperHeight(ctxt, height);}
| RTFmarginLeft { int margin;
if ($1.isEmpty)
margin = 1800;
else
margin = $1.parameter;
GSRTFmarginLeft(ctxt, margin);}
| RTFmarginRight { int margin;
if ($1.isEmpty)
margin = 1800;
else
margin = $1.parameter;
GSRTFmarginRight(ctxt, margin); }
| RTFmarginTop { int margin;
if ($1.isEmpty)
margin = 1440;
else
margin = $1.parameter;
GSRTFmarginTop(ctxt, margin); }
| RTFmarginButtom { int margin;
if ($1.isEmpty)
margin = 1440;
else
margin = $1.parameter;
GSRTFmarginButtom(ctxt, margin); }
| RTFfirstLineIndent { int indent;
if ($1.isEmpty)
indent = 0;
else
indent = $1.parameter;
GSRTFfirstLineIndent(ctxt, indent); }
| RTFleftIndent { int indent;
if ($1.isEmpty)
indent = 0;
else
indent = $1.parameter;
GSRTFleftIndent(ctxt, indent);}
| RTFrightIndent { int indent;
if ($1.isEmpty)
indent = 0;
else
indent = $1.parameter;
GSRTFrightIndent(ctxt, indent);}
| RTFtabstop { int location;
if ($1.isEmpty)
location = 0;
else
location = $1.parameter;
GSRTFtabstop(ctxt, location);}
| RTFalignCenter { GSRTFalignCenter(ctxt); }
| RTFalignJustified { GSRTFalignJustified(ctxt); }
| RTFalignLeft { GSRTFalignLeft(ctxt); }
| RTFalignRight { GSRTFalignRight(ctxt); }
| RTFspaceAbove { int space;
if ($1.isEmpty)
space = 0;
else
space = $1.parameter;
GSRTFspaceAbove(ctxt, space); }
| RTFlineSpace { GSRTFlineSpace(ctxt, $1.parameter); }
| RTFdefaultParagraph { GSRTFdefaultParagraph(ctxt); }
| RTFstyle { GSRTFstyle(ctxt, $1.parameter); }
| RTFcolorbg { int color;
if ($1.isEmpty)
color = 0;
else
color = $1.parameter;
GSRTFcolorbg(ctxt, color); }
| RTFcolorfg { int color;
if ($1.isEmpty)
color = 0;
else
color = $1.parameter;
GSRTFcolorfg(ctxt, color); }
| RTFsubscript { int script;
if ($1.isEmpty)
script = 6;
else
script = $1.parameter;
GSRTFsubscript(ctxt, script); }
| RTFsuperscript { int script;
if ($1.isEmpty)
script = 6;
else
script = $1.parameter;
GSRTFsuperscript(ctxt, script); }
| RTFbold { BOOL on;
if ($1.isEmpty || $1.parameter)
on = YES;
else
on = NO;
GSRTFbold(ctxt, on); }
| RTFitalic { BOOL on;
if ($1.isEmpty || $1.parameter)
on = YES;
else
on = NO;
GSRTFitalic(ctxt, on); }
| RTFunderline { BOOL on;
if ($1.isEmpty || $1.parameter)
on = YES;
else
on = NO;
GSRTFunderline(ctxt, on); }
| RTFunderlineStop { GSRTFunderline(ctxt, NO); }
| RTFplain { GSRTFdefaultCharacterStyle(ctxt); }
| RTFparagraph { GSRTFparagraph(ctxt); }
| RTFrow { GSRTFparagraph(ctxt); }
| RTFOtherStatement { GSRTFgenericRTFcommand(ctxt, $1); }
;
/*
Font description
*/
rtfFontList: '{' RTFfontListStart rtfFonts '}'
;
rtfFonts:
| rtfFonts rtfFontStatement
| rtfFonts '{' rtfFontStatement '}'
;
/* the first RTFfont tags the font with a number */
/* RTFtext introduces the fontName */
rtfFontStatement: RTFfont rtfFontFamily rtfFontAttrs RTFtext { GSRTFregisterFont(ctxt, $4, $2, $1.parameter);
free((void *)$4); }
;
rtfFontAttrs: /* empty */
| rtfFontAttrs RTFfcharset
| rtfFontAttrs RTFfprq
| rtfFontAttrs RTFcpg
| rtfFontAttrs rtfBlock
;
rtfFontFamily:
RTFfamilyNil { $$ = RTFfamilyNil - RTFfamilyNil; }
| RTFfamilyRoman { $$ = RTFfamilyRoman - RTFfamilyNil; }
| RTFfamilySwiss { $$ = RTFfamilySwiss - RTFfamilyNil; }
| RTFfamilyModern { $$ = RTFfamilyModern - RTFfamilyNil; }
| RTFfamilyScript { $$ = RTFfamilyScript - RTFfamilyNil; }
| RTFfamilyDecor { $$ = RTFfamilyDecor - RTFfamilyNil; }
| RTFfamilyTech { $$ = RTFfamilyTech - RTFfamilyNil; }
;
/*
Colour definition
*/
rtfColorDef: '{' RTFcolortable rtfColors '}'
;
rtfColors: /* empty */
| rtfColors rtfColorStatement
;
/* We get the ';' as RTFText */
rtfColorStatement: RTFred RTFgreen RTFblue RTFtext
{
GSRTFaddColor(ctxt, $1.parameter, $2.parameter, $3.parameter);
free((void *)$4);
}
| RTFtext
{
GSRTFaddDefaultColor(ctxt);
free((void *)$1);
}
;
/*
some cludgy trailer
*/
dummyNonTerminal: '\\' { @1.first_line; } /* we introduce a @n to fix the lex attributes */
;
%%
/* some C code here */

View file

@ -1,445 +0,0 @@
/* rtcScanner
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "Parsers/rtfScanner.h"
#include "Parsers/rtfGrammer.tab.h"
// <§> scanner types and helpers
#define CArraySize(a) (sizeof(a)/sizeof((a)[0])-1)
typedef struct {
char *bf;
int length, position, chunkSize;
} DynamicString;
typedef struct {
const char *string;
int token;
} LexKeyword;
GSLexError initDynamicString(DynamicString *string)
{
string->length = 0, string->position = 0, string->chunkSize = 128;
string->bf = calloc(1, string->length = string->chunkSize);
if (!string->bf)
return LEXoutOfMemory;
return NoError;
}
GSLexError appendChar(DynamicString *string, int c)
{
if (string->position == string->length)
{
if (!(string->bf = realloc(string->bf,
string->length += string->chunkSize)))
return LEXoutOfMemory;
else
string->chunkSize <<= 1;
}
string->bf[string->position++] = c;
return NoError;
}
void lexInitContext(RTFscannerCtxt *lctxt, void *customContext,
int (*getcharFunction)(void *))
{
lctxt->streamLineNumber = 1;
lctxt->streamPosition = lctxt->pushbackCount = 0;
lctxt->lgetchar = getcharFunction;
lctxt->customContext = customContext;
}
int lexGetchar(RTFscannerCtxt *lctxt)
{
int c;
if (lctxt->pushbackCount)
{
lctxt->pushbackCount--;
c = lctxt->pushbackBuffer[lctxt->pushbackCount];
}
else
{
lctxt->streamPosition++;
c = lctxt->lgetchar(lctxt->customContext);
}
if (c == '\n')
lctxt->streamLineNumber++;
return c;
}
void lexUngetchar(RTFscannerCtxt *lctxt, int c)
{
if (c == '\n')
lctxt->streamLineNumber--;
lctxt->pushbackBuffer[lctxt->pushbackCount++] = c; //<!> no checking here
}
int lexStreamPosition(RTFscannerCtxt *lctxt)
{
return lctxt->streamPosition - lctxt->pushbackCount;
}
char *my_strdup(const char *str)
{
char *copy = str? malloc(strlen(str) + 1): 0;
return !copy? 0: strcpy(copy, str);
}
int findStringFromKeywordArray(const char *string, const LexKeyword *array,
int arrayCount)
{
int min, max, mid, cmp;
const LexKeyword *currentKeyword;
for (min=0, max=arrayCount; min<=max; )
{
mid = (min+max)>>1;
currentKeyword = array + mid;
if (!(cmp = strcmp(string, currentKeyword->string)))
{
return currentKeyword->token;
}
else if (cmp>0)
min=mid+1;
else
max=mid-1;
}
return 0; // couldn't find
}
// end <§> scanner types and helpers
// <§> core scanner functions
#define token(a) (a)
// <!> must be sorted
LexKeyword RTFcommands[]={
"ansi", token(RTFansi),
"b", token(RTFbold),
"blue", token(RTFblue),
"bullet", token(RTFbullet),
"cb", token(RTFcolorbg),
"cell", token(RTFcell),
"cf", token(RTFcolorfg),
"colortbl", token(RTFcolortable),
"cpg", token(RTFcpg),
"dn", token(RTFsubscript),
"emdash", token(RTFemdash),
"emspace", token(RTFemspace),
"endash", token(RTFendash),
"enspace", token(RTFenspace),
"f", token(RTFfont),
"fcharset", token(RTFfcharset),
"fdecor", token(RTFfamilyDecor),
"fi", token(RTFfirstLineIndent),
"fmodern", token(RTFfamilyModern),
"fnil", token(RTFfamilyNil),
"fonttbl", token(RTFfontListStart),
/* All footers are mapped on one entry */
"footer", token(RTFfooter),
"footerf", token(RTFfooter),
"footerl", token(RTFfooter),
"footerr", token(RTFfooter),
"footnote", token(RTFfootnote),
"fprq", token(RTFfprq),
"froman", token(RTFfamilyRoman),
"fs", token(RTFfontSize),
"fscript", token(RTFfamilyScript),
"fswiss", token(RTFfamilySwiss),
"ftech", token(RTFfamilyTech),
"green", token(RTFgreen),
/* All headers are mapped on one entry */
"header", token(RTFheader),
"headerf", token(RTFheader),
"headerl", token(RTFheader),
"headerr", token(RTFheader),
"i", token(RTFitalic),
"info", token(RTFinfo),
"ldblquote", token(RTFldblquote),
"li", token(RTFleftIndent),
"lquote", token(RTFlquote),
"mac", token(RTFmac),
"margb", token(RTFmarginButtom),
"margl", token(RTFmarginLeft),
"margr", token(RTFmarginRight),
"margt", token(RTFmarginTop),
"paperh", token(RTFpaperHeight),
"paperw", token(RTFpaperWidth),
"par", token(RTFparagraph),
"pard", token(RTFdefaultParagraph),
"pc", token(RTFpc),
"pca", token(RTFpca),
"pict", token(RTFpict),
"plain", token(RTFplain),
"qc", token(RTFalignCenter),
"qj", token(RTFalignJustified),
"ql", token(RTFalignLeft),
"qr", token(RTFalignRight),
"rdblquote", token(RTFrdblquote),
"red", token(RTFred),
"ri", token(RTFrightIndent),
"row", token(RTFrow),
"rquote", token(RTFrquote),
"rtf", token(RTFstart),
"s", token(RTFstyle),
"sa", token(RTFspaceAbove),
"sl", token(RTFlineSpace),
"stylesheet", token(RTFstylesheet),
"tab", token(RTFtabulator),
"tx", token(RTFtabstop),
/* All underline are mapped on one entry */
"ul", token(RTFunderline),
"uld", token(RTFunderline),
"uldb", token(RTFunderline),
"ulnone", token(RTFunderlineStop),
"ulw", token(RTFunderline),
"up", token(RTFsuperscript)
};
BOOL probeCommand(RTFscannerCtxt *lctxt)
{
int c = lexGetchar(lctxt);
lexUngetchar(lctxt, c);
if (isalpha(c))
return YES;
return NO;
}
// <N> According to spec a cmdLength of 32 is respected
#define RTFMaxCmdLength 32
#define RTFMaxArgumentLength 64
GSLexError readCommand(RTFscannerCtxt *lctxt, YYSTYPE *lvalp, int *token) // the '\\' is already read
{
char cmdNameBf[RTFMaxCmdLength+1], *cmdName = cmdNameBf;
char argumentBf[RTFMaxArgumentLength+1], *argument = argumentBf;
int c, foundToken;
lvalp->cmd.name = 0; // initialize
while (isalpha( c = lexGetchar(lctxt) ))
{
*cmdName++ = c;
if (cmdName >= cmdNameBf + RTFMaxCmdLength)
return LEXsyntaxError;
}
*cmdName = 0;
if (!(foundToken = findStringFromKeywordArray(cmdNameBf, RTFcommands,
CArraySize(RTFcommands))))
{
if (!(lvalp->cmd.name = my_strdup(cmdNameBf)))
return LEXoutOfMemory;
*token = RTFOtherStatement;
}
else
{
*token = foundToken;
}
if (c == ' ') // this is an empty argument
{
lvalp->cmd.isEmpty = YES;
}
else if (isdigit(c) || c == '-') // we've found a numerical argument
{
do
{
*argument++ = c;
if (argument >= argumentBf + RTFMaxArgumentLength)
return LEXsyntaxError;
} while (isdigit(c = lexGetchar(lctxt)));
*argument = 0;
if (c != ' ')
lexUngetchar(lctxt, c); // <N> ungetc non-digit
// the consumption of the space seems necessary on NeXT but
// is not according to spec
lvalp->cmd.isEmpty = NO;
lvalp->cmd.parameter = atoi(argumentBf);
}
else
{
lvalp->cmd.isEmpty = YES;
lexUngetchar(lctxt, c); // ungetc non-whitespace delimiter
}
return NoError;
}
GSLexError readText(RTFscannerCtxt *lctxt, YYSTYPE *lvalp)
{
int c;
DynamicString text;
GSLexError error;
if ((error = initDynamicString(&text)))
return error;
for (;;)
{
c = lexGetchar(lctxt);
if (c == EOF || c == '{' || c == '}' || c == '\\')
{
lexUngetchar(lctxt, c);
break;
}
else
{
if (c != '\n' && c != '\r') // <N> newline and cr are ignored if not quoted
appendChar(&text, c);
}
}
appendChar(&text, 0);
lvalp->text = text.bf; // release is up to the consumer
return NoError;
}
// read in a character as two hex digit
static int gethex(RTFscannerCtxt *lctxt)
{
int c = 0;
int i;
for (i = 0; i < 2; i++)
{
int c1 = lexGetchar(lctxt);
if (!isxdigit(c1))
{
lexUngetchar(lctxt, c1);
break;
}
else
{
c = c * 16;
if (isdigit(c1))
c += c1 - '0';
else if (isupper(c1))
c += c1 - 'A' + 10;
else
c += c1 - 'a' + 10;
}
}
return c;
}
int GSRTFlex(YYSTYPE *lvalp, YYLTYPE *llocp, RTFscannerCtxt *lctxt) /* provide value and position in the params */
{
int c;
int token = 0;
char *cv;
do
c = lexGetchar(lctxt);
while ( c == '\n' || c == '\r' ); // <A> the listed characters are to be ignored
switch (c)
{
case EOF: token = 0;
break;
case '{': token = '{';
break;
case '}': token = '}';
break;
case '\\':
if (probeCommand(lctxt) == YES)
{
readCommand(lctxt, lvalp, &token);
switch (token)
{
case RTFtabulator: c = '\t';
break;
case RTFcell: c = '\t';
break;
case RTFemdash: c = '-';
break;
case RTFendash: c = '-';
break;
case RTFbullet: c = '*';
break;
case RTFlquote: c = '`';
break;
case RTFrquote: c = '\'';
break;
case RTFldblquote: c = '"';
break;
case RTFrdblquote: c = '"';
break;
default:
return token;
}
}
else
{
c = lexGetchar(lctxt);
switch (c)
{
case EOF: token = 0;
return token;
case '\'':
// Convert the next two hex digits into a char
c = gethex(lctxt);
break;
case '*': return RTFignore;
case '|':
case '-':
case ':':
// Ignore these characters
c = lexGetchar(lctxt);
break;
case '_': c = '-';
break;
case '~': c = ' ';
break;
case '\n':
case '\r':
return RTFparagraph;
case '{':
case '}':
case '\\':
// release is up to the consumer
cv = calloc(1, 2);
cv[0] = c;
cv[1] = '\0';
lvalp->text = cv;
token = RTFtext;
return token;
default:
// fall through
}
}
// else fall through to default: read text <A>
// no break <A>
default:
lexUngetchar(lctxt, c);
readText(lctxt, lvalp);
token = RTFtext;
break;
}
//*llocp = lctxt->position();
return token;
}

View file

@ -1,68 +0,0 @@
/* rtcScanner.h
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Stefan Bðhringer (stefan.boehringer@uni-bochum.de)
Date: Dec 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef rtfScanner_h_INCLUDE
#define rtfScanner_h_INCLUDE
#include <objc/objc.h>
#if !defined(YES)
typedef char BOOL;
enum { NO, YES };
#endif
typedef enum { NoError, LEXoutOfMemory, LEXsyntaxError } GSLexError;
typedef struct _RTFscannerCtxt {
int (*lgetchar)(void *);
char pushbackBuffer[4]; // gaurantee 4 chars of pushback
int pushbackCount;
int streamPosition;
int streamLineNumber;
void *customContext;
} RTFscannerCtxt;
typedef struct {
BOOL isEmpty;
int parameter;
int token;
const char *name;
} RTFcmd;
typedef enum {
GSRTFfamilyNil, GSRTFfamilyRoman, GSRTFfamilySwiss,
GSRTFfamilyModern, GSRTFfamilyScript, GSRTFfamilyDecor,
GSRTFfamilyTech
} RTFfontFamily;
void lexInitContext(RTFscannerCtxt *lctxt, void *customContext, int (*getcharFunction)());
/* external symbols from the grammer */
/*int GSRTFparse(void *ctxt, RTFscannerCtxt *lctxt);*/
int GSRTFparse(void *ctxt, void *lctxt);
#endif