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

@ -4,3 +4,4 @@ config.cache
config.make config.make
gnustep-gui.spec gnustep-gui.spec
gnustep-gui-debug.spec gnustep-gui-debug.spec
gui.make

View file

@ -1,3 +1,13 @@
2001-08-21 Adam Fedor <fedor@gnu.org>
* Source/NSAttributedString.m (converter_bundles): New function
to find bundles that do text conversion.
(converter_class): Use it.
* Source/GNUmakefile: Update to remove Parsers files
* TextConverters/RTF/*: New files moved from Source/Parsers.
Builds bundle for RTF text conversion.
2001-08-21 Pierre-Yves <pyrivail@spocky.imada.sdu.dk> 2001-08-21 Pierre-Yves <pyrivail@spocky.imada.sdu.dk>
* Source/NSTableColumn.m * Source/NSTableColumn.m

View file

@ -43,7 +43,7 @@ include ./Version
# #
# The list of subproject directories # The list of subproject directories
# #
SUBPROJECTS = Source Images Model Tools Panels PrinterTypes SUBPROJECTS = Source Images Model Tools Panels PrinterTypes TextConverters
-include GNUmakefile.preamble -include GNUmakefile.preamble

View file

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

View file

@ -35,11 +35,8 @@
# otherwise the normal makefile rules will not be performed. # otherwise the normal makefile rules will not be performed.
# #
./$(GNUSTEP_OBJ_DIR)/Parsers:
$(MKDIRS) ./$(GNUSTEP_OBJ_DIR)/Parsers
# Things to do before compiling # Things to do before compiling
before-all:: ./$(GNUSTEP_OBJ_DIR)/Parsers # before-all::
# Things to do after compiling # Things to do after compiling
# after-all:: # after-all::
@ -78,9 +75,6 @@ after-distclean::
# #
# GNUstep GUI Library specific targets # 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 # 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 # 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 ADDITIONAL_CPPFLAGS += -DBACKEND_BUNDLE=1
endif endif
BISON_FLAGS = -d -p GSRTF
BISON = BISON_SIMPLE=Parsers/bison.simple bison
# Additional flags to pass to the Objective-C compiler # Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS = -Wall ADDITIONAL_OBJCFLAGS = -Wall

View file

@ -30,6 +30,8 @@
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include <Foundation/NSRange.h> #include <Foundation/NSRange.h>
#include <Foundation/NSBundle.h>
#include <Foundation/NSFileManager.h>
#include <AppKit/NSAttributedString.h> #include <AppKit/NSAttributedString.h>
#include <AppKit/NSParagraphStyle.h> #include <AppKit/NSParagraphStyle.h>
#include <AppKit/NSTextAttachment.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. Return a suitable converter for the text format supplied as argument.
If producer is YES a class capable of writting that format is returned, 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]; found = [p_classes objectForKey: format];
if (found == Nil) if (found == Nil)
{ {
if ([format isEqual: @"RTF"]) found = converter_bundles(format, producer);
found = NSClassFromString(@"RTFProducer"); if (found != Nil)
else if ([format isEqual: @"RTFD"]) NSDebugLog(@"Found converter %@ for format %@", found, format);
found = NSClassFromString(@"RTFDProducer");
if (found != Nil) if (found != Nil)
[p_classes setObject: found forKey: format]; [p_classes setObject: found forKey: format];
} }
@ -135,10 +192,9 @@ static Class converter_class(NSString *format, BOOL producer)
found = [c_classes objectForKey: format]; found = [c_classes objectForKey: format];
if (found == Nil) if (found == Nil)
{ {
if ([format isEqual: @"RTF"]) found = converter_bundles(format, producer);
found = NSClassFromString(@"RTFConsumer"); if (found != Nil)
else if ([format isEqual: @"RTFD"]) NSDebugLog(@"Found converter %@ for format %@", found, format);
found = NSClassFromString(@"RTFDConsumer");
if (found != Nil) if (found != Nil)
[c_classes setObject: found forKey: format]; [c_classes setObject: found forKey: format];
} }

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

@ -0,0 +1,36 @@
#
# Makefile for TextConverters bundles
#
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# Author: Adam Fedor <fedor@gnu.org>
#
# 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.
#
# If you are interested in a warranty or support for this source code,
# contact Scott Christley at scottc@net-community.com
#
# 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.
GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
include $(GNUSTEP_MAKEFILES)/common.make
#
# The list of subproject directories
#
SUBPROJECTS = RTF
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -0,0 +1,41 @@
# GNUmakefile
#
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# Author: Adam Fedor <fedor@gnu.org>
#
# This file is part of GNUstep
#
# 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 of the License, 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.
include $(GNUSTEP_MAKEFILES)/common.make
BUNDLE_NAME = RTFConverter
BUNDLE_INSTALL_DIR =$(GNUSTEP_BUNDLES)/TextConverters
RTFConverter_OBJC_FILES = \
RTFConsumer.m RTFProducer.m
RTFConverter_C_FILES = \
rtfGrammer.tab.c rtfScanner.c
RTFConverter_PRINCIPAL_CLASS = RTFConsumer
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/bundle.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,32 @@
# GNUmakefile.postamble
#
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# Author: Philippe C.D. Robert <prh@3dkit.org>
#
# This file is part of GNUstep
#
# 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.
#
# If you are interested in a warranty or support for this source code,
# contact Scott Christley at scottc@net-community.com
#
# 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.
BISON_FLAGS = -d -p GSRTF
BISON = BISON_SIMPLE=bison.simple bison
# This parser doesn't compile with newer bison programs. Needs to be fixed...
#rtfGrammer.tab.c: rtfGrammer.y
# $(BISON) $(BISON_FLAGS) $<

View file

@ -0,0 +1,73 @@
# GNUmakefile.preamble
#
# Copyright (C) 2001 Free Software Foundation, Inc.
#
# Author: Philippe C.D. Robert <prh@3dkit.org>
#
# This file is part of GNUstep
#
# 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.
#
# If you are interested in a warranty or support for this source code,
# contact Scott Christley at scottc@net-community.com
#
# 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.
#
# Makefile.preamble
#
# Project specific makefile variables, and additional
#
# Do not put any Makefile rules in this file, instead they should
# be put into Makefile.postamble.
#
#
# Flags dealing with compiling and linking
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS +=
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS +=
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS +=
#ADDITIONAL_CFLAGS +=
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS +=-I../../Headers
# Additional LDFLAGS to pass to the linker
#ADDITIONAL_LDFLAGS +=
# Additional library directories the linker should search
#ADDITIONAL_LIB_DIRS +=
#ADDITIONAL_TOOL_LIBS +=
#
# Flags dealing with installing and uninstalling
#
# Additional directories to be created during installation
#ADDITIONAL_INSTALL_DIRS +=
#
# Local configuration
#

View file

@ -27,8 +27,9 @@
#include <Foundation/Foundation.h> #include <Foundation/Foundation.h>
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
#include "Parsers/rtfConsumer.h" #include "RTFConsumer.h"
#include "Parsers/rtfConsumerFunctions.h" #include "RTFConsumerFunctions.h"
#include "RTFProducer.h"
/* we have to satisfy the scanner with a stream reading function */ /* we have to satisfy the scanner with a stream reading function */
typedef struct { typedef struct {
@ -225,6 +226,28 @@ readNSString (StringContext *ctxt)
@implementation RTFConsumer @implementation RTFConsumer
/* RTFConsumer is the principal class and thus implements this */
+ (Class) classForFormat: (NSString *)format producer: (BOOL)flag
{
Class cClass = Nil;
if (flag)
{
if ([format isEqual: @"RTFD"])
cClass = [RTFDProducer class];
else if ([format isEqual: @"RTF"])
cClass = [RTFProducer class];
}
else
{
if ([format isEqual: @"RTFD"])
cClass = [RTFDConsumer class];
else if ([format isEqual: @"RTF"])
cClass = [RTFConsumer class];
}
return cClass;
}
+ (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper + (NSAttributedString*) parseFile: (NSFileWrapper *)wrapper
documentAttributes: (NSDictionary **)dict documentAttributes: (NSDictionary **)dict
{ {

View file

@ -28,7 +28,7 @@
#ifndef rtfConsumerFunctions_h_INCLUDE #ifndef rtfConsumerFunctions_h_INCLUDE
#define rtfConsumerFunctions_h_INCLUDE #define rtfConsumerFunctions_h_INCLUDE
#include "Parsers/rtfScanner.h" #include "rtfScanner.h"
/* general statements: /* general statements:
measurement is usually in twips: one twentieth of a point (this is about 0.01764 mm) measurement is usually in twips: one twentieth of a point (this is about 0.01764 mm)

View file

@ -1,5 +1,5 @@
/* A Bison parser, made from Parsers/rtfGrammer.y /* A Bison parser, made from rtfGrammer.y
by GNU Bison version 1.25 by GNU Bison version 1.25
*/ */
@ -86,7 +86,7 @@
#define RTFfamilyDecor 327 #define RTFfamilyDecor 327
#define RTFfamilyTech 328 #define RTFfamilyTech 328
#line 35 "Parsers/rtfGrammer.y" #line 35 "rtfGrammer.y"
/* /*
@ -109,7 +109,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "Parsers/rtfScanner.h" #include "rtfScanner.h"
/* this context is passed to the interface functions */ /* this context is passed to the interface functions */
typedef void * GSRTFctxt; typedef void * GSRTFctxt;
@ -118,10 +118,10 @@ typedef void * GSRTFctxt;
#define YYERROR_VERBOSE #define YYERROR_VERBOSE
#include "rtfConsumerFunctions.h" #include "RTFConsumerFunctions.h"
#line 70 "Parsers/rtfGrammer.y" #line 70 "rtfGrammer.y"
typedef union { typedef union {
int number; int number;
const char *text; const char *text;
@ -961,99 +961,99 @@ yyreduce:
switch (yyn) { switch (yyn) {
case 1: case 1:
#line 159 "Parsers/rtfGrammer.y" #line 159 "rtfGrammer.y"
{ GSRTFstart(ctxt); ; { GSRTFstart(ctxt); ;
break;} break;}
case 2: case 2:
#line 159 "Parsers/rtfGrammer.y" #line 159 "rtfGrammer.y"
{ GSRTFstop(ctxt); ; { GSRTFstop(ctxt); ;
break;} break;}
case 4: case 4:
#line 162 "Parsers/rtfGrammer.y" #line 162 "rtfGrammer.y"
{ yyval.number = 1; ; { yyval.number = 1; ;
break;} break;}
case 5: case 5:
#line 163 "Parsers/rtfGrammer.y" #line 163 "rtfGrammer.y"
{ yyval.number = 2; ; { yyval.number = 2; ;
break;} break;}
case 6: case 6:
#line 164 "Parsers/rtfGrammer.y" #line 164 "rtfGrammer.y"
{ yyval.number = 3; ; { yyval.number = 3; ;
break;} break;}
case 7: case 7:
#line 165 "Parsers/rtfGrammer.y" #line 165 "rtfGrammer.y"
{ yyval.number = 4; ; { yyval.number = 4; ;
break;} break;}
case 12: case 12:
#line 172 "Parsers/rtfGrammer.y" #line 172 "rtfGrammer.y"
{ GSRTFmangleText(ctxt, yyvsp[0].text); free((void *)yyvsp[0].text); ; { GSRTFmangleText(ctxt, yyvsp[0].text); free((void *)yyvsp[0].text); ;
break;} break;}
case 14: case 14:
#line 176 "Parsers/rtfGrammer.y" #line 176 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, NO); ; { GSRTFopenBlock(ctxt, NO); ;
break;} break;}
case 15: case 15:
#line 176 "Parsers/rtfGrammer.y" #line 176 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, NO); ; { GSRTFcloseBlock(ctxt, NO); ;
break;} break;}
case 16: case 16:
#line 177 "Parsers/rtfGrammer.y" #line 177 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 17: case 17:
#line 177 "Parsers/rtfGrammer.y" #line 177 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 18: case 18:
#line 178 "Parsers/rtfGrammer.y" #line 178 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 19: case 19:
#line 178 "Parsers/rtfGrammer.y" #line 178 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 20: case 20:
#line 179 "Parsers/rtfGrammer.y" #line 179 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 21: case 21:
#line 179 "Parsers/rtfGrammer.y" #line 179 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 22: case 22:
#line 180 "Parsers/rtfGrammer.y" #line 180 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 23: case 23:
#line 180 "Parsers/rtfGrammer.y" #line 180 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 24: case 24:
#line 181 "Parsers/rtfGrammer.y" #line 181 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 25: case 25:
#line 181 "Parsers/rtfGrammer.y" #line 181 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 26: case 26:
#line 182 "Parsers/rtfGrammer.y" #line 182 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 27: case 27:
#line 182 "Parsers/rtfGrammer.y" #line 182 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 28: case 28:
#line 183 "Parsers/rtfGrammer.y" #line 183 "rtfGrammer.y"
{ GSRTFopenBlock(ctxt, YES); ; { GSRTFopenBlock(ctxt, YES); ;
break;} break;}
case 29: case 29:
#line 183 "Parsers/rtfGrammer.y" #line 183 "rtfGrammer.y"
{ GSRTFcloseBlock(ctxt, YES); ; { GSRTFcloseBlock(ctxt, YES); ;
break;} break;}
case 31: case 31:
#line 192 "Parsers/rtfGrammer.y" #line 192 "rtfGrammer.y"
{ int font; { int font;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1063,7 +1063,7 @@ case 31:
GSRTFfontNumber(ctxt, font); ; GSRTFfontNumber(ctxt, font); ;
break;} break;}
case 32: case 32:
#line 199 "Parsers/rtfGrammer.y" #line 199 "rtfGrammer.y"
{ int size; { int size;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1073,7 +1073,7 @@ case 32:
GSRTFfontSize(ctxt, size); ; GSRTFfontSize(ctxt, size); ;
break;} break;}
case 33: case 33:
#line 206 "Parsers/rtfGrammer.y" #line 206 "rtfGrammer.y"
{ int width; { int width;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1083,7 +1083,7 @@ case 33:
GSRTFpaperWidth(ctxt, width);; GSRTFpaperWidth(ctxt, width);;
break;} break;}
case 34: case 34:
#line 213 "Parsers/rtfGrammer.y" #line 213 "rtfGrammer.y"
{ int height; { int height;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1093,7 +1093,7 @@ case 34:
GSRTFpaperHeight(ctxt, height);; GSRTFpaperHeight(ctxt, height);;
break;} break;}
case 35: case 35:
#line 220 "Parsers/rtfGrammer.y" #line 220 "rtfGrammer.y"
{ int margin; { int margin;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1103,7 +1103,7 @@ case 35:
GSRTFmarginLeft(ctxt, margin);; GSRTFmarginLeft(ctxt, margin);;
break;} break;}
case 36: case 36:
#line 227 "Parsers/rtfGrammer.y" #line 227 "rtfGrammer.y"
{ int margin; { int margin;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1113,7 +1113,7 @@ case 36:
GSRTFmarginRight(ctxt, margin); ; GSRTFmarginRight(ctxt, margin); ;
break;} break;}
case 37: case 37:
#line 234 "Parsers/rtfGrammer.y" #line 234 "rtfGrammer.y"
{ int margin; { int margin;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1123,7 +1123,7 @@ case 37:
GSRTFmarginTop(ctxt, margin); ; GSRTFmarginTop(ctxt, margin); ;
break;} break;}
case 38: case 38:
#line 241 "Parsers/rtfGrammer.y" #line 241 "rtfGrammer.y"
{ int margin; { int margin;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1133,7 +1133,7 @@ case 38:
GSRTFmarginButtom(ctxt, margin); ; GSRTFmarginButtom(ctxt, margin); ;
break;} break;}
case 39: case 39:
#line 248 "Parsers/rtfGrammer.y" #line 248 "rtfGrammer.y"
{ int indent; { int indent;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1143,7 +1143,7 @@ case 39:
GSRTFfirstLineIndent(ctxt, indent); ; GSRTFfirstLineIndent(ctxt, indent); ;
break;} break;}
case 40: case 40:
#line 255 "Parsers/rtfGrammer.y" #line 255 "rtfGrammer.y"
{ int indent; { int indent;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1153,7 +1153,7 @@ case 40:
GSRTFleftIndent(ctxt, indent);; GSRTFleftIndent(ctxt, indent);;
break;} break;}
case 41: case 41:
#line 262 "Parsers/rtfGrammer.y" #line 262 "rtfGrammer.y"
{ int indent; { int indent;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1163,7 +1163,7 @@ case 41:
GSRTFrightIndent(ctxt, indent);; GSRTFrightIndent(ctxt, indent);;
break;} break;}
case 42: case 42:
#line 269 "Parsers/rtfGrammer.y" #line 269 "rtfGrammer.y"
{ int location; { int location;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1173,23 +1173,23 @@ case 42:
GSRTFtabstop(ctxt, location);; GSRTFtabstop(ctxt, location);;
break;} break;}
case 43: case 43:
#line 276 "Parsers/rtfGrammer.y" #line 276 "rtfGrammer.y"
{ GSRTFalignCenter(ctxt); ; { GSRTFalignCenter(ctxt); ;
break;} break;}
case 44: case 44:
#line 277 "Parsers/rtfGrammer.y" #line 277 "rtfGrammer.y"
{ GSRTFalignJustified(ctxt); ; { GSRTFalignJustified(ctxt); ;
break;} break;}
case 45: case 45:
#line 278 "Parsers/rtfGrammer.y" #line 278 "rtfGrammer.y"
{ GSRTFalignLeft(ctxt); ; { GSRTFalignLeft(ctxt); ;
break;} break;}
case 46: case 46:
#line 279 "Parsers/rtfGrammer.y" #line 279 "rtfGrammer.y"
{ GSRTFalignRight(ctxt); ; { GSRTFalignRight(ctxt); ;
break;} break;}
case 47: case 47:
#line 280 "Parsers/rtfGrammer.y" #line 280 "rtfGrammer.y"
{ int space; { int space;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1199,19 +1199,19 @@ case 47:
GSRTFspaceAbove(ctxt, space); ; GSRTFspaceAbove(ctxt, space); ;
break;} break;}
case 48: case 48:
#line 287 "Parsers/rtfGrammer.y" #line 287 "rtfGrammer.y"
{ GSRTFlineSpace(ctxt, yyvsp[0].cmd.parameter); ; { GSRTFlineSpace(ctxt, yyvsp[0].cmd.parameter); ;
break;} break;}
case 49: case 49:
#line 288 "Parsers/rtfGrammer.y" #line 288 "rtfGrammer.y"
{ GSRTFdefaultParagraph(ctxt); ; { GSRTFdefaultParagraph(ctxt); ;
break;} break;}
case 50: case 50:
#line 289 "Parsers/rtfGrammer.y" #line 289 "rtfGrammer.y"
{ GSRTFstyle(ctxt, yyvsp[0].cmd.parameter); ; { GSRTFstyle(ctxt, yyvsp[0].cmd.parameter); ;
break;} break;}
case 51: case 51:
#line 290 "Parsers/rtfGrammer.y" #line 290 "rtfGrammer.y"
{ int color; { int color;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1221,7 +1221,7 @@ case 51:
GSRTFcolorbg(ctxt, color); ; GSRTFcolorbg(ctxt, color); ;
break;} break;}
case 52: case 52:
#line 297 "Parsers/rtfGrammer.y" #line 297 "rtfGrammer.y"
{ int color; { int color;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1231,7 +1231,7 @@ case 52:
GSRTFcolorfg(ctxt, color); ; GSRTFcolorfg(ctxt, color); ;
break;} break;}
case 53: case 53:
#line 304 "Parsers/rtfGrammer.y" #line 304 "rtfGrammer.y"
{ int script; { int script;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1241,7 +1241,7 @@ case 53:
GSRTFsubscript(ctxt, script); ; GSRTFsubscript(ctxt, script); ;
break;} break;}
case 54: case 54:
#line 311 "Parsers/rtfGrammer.y" #line 311 "rtfGrammer.y"
{ int script; { int script;
if (yyvsp[0].cmd.isEmpty) if (yyvsp[0].cmd.isEmpty)
@ -1251,7 +1251,7 @@ case 54:
GSRTFsuperscript(ctxt, script); ; GSRTFsuperscript(ctxt, script); ;
break;} break;}
case 55: case 55:
#line 318 "Parsers/rtfGrammer.y" #line 318 "rtfGrammer.y"
{ BOOL on; { BOOL on;
if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter) if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter)
@ -1261,7 +1261,7 @@ case 55:
GSRTFbold(ctxt, on); ; GSRTFbold(ctxt, on); ;
break;} break;}
case 56: case 56:
#line 325 "Parsers/rtfGrammer.y" #line 325 "rtfGrammer.y"
{ BOOL on; { BOOL on;
if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter) if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter)
@ -1271,7 +1271,7 @@ case 56:
GSRTFitalic(ctxt, on); ; GSRTFitalic(ctxt, on); ;
break;} break;}
case 57: case 57:
#line 332 "Parsers/rtfGrammer.y" #line 332 "rtfGrammer.y"
{ BOOL on; { BOOL on;
if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter) if (yyvsp[0].cmd.isEmpty || yyvsp[0].cmd.parameter)
@ -1281,74 +1281,74 @@ case 57:
GSRTFunderline(ctxt, on); ; GSRTFunderline(ctxt, on); ;
break;} break;}
case 58: case 58:
#line 339 "Parsers/rtfGrammer.y" #line 339 "rtfGrammer.y"
{ GSRTFunderline(ctxt, NO); ; { GSRTFunderline(ctxt, NO); ;
break;} break;}
case 59: case 59:
#line 340 "Parsers/rtfGrammer.y" #line 340 "rtfGrammer.y"
{ GSRTFdefaultCharacterStyle(ctxt); ; { GSRTFdefaultCharacterStyle(ctxt); ;
break;} break;}
case 60: case 60:
#line 341 "Parsers/rtfGrammer.y" #line 341 "rtfGrammer.y"
{ GSRTFparagraph(ctxt); ; { GSRTFparagraph(ctxt); ;
break;} break;}
case 61: case 61:
#line 342 "Parsers/rtfGrammer.y" #line 342 "rtfGrammer.y"
{ GSRTFparagraph(ctxt); ; { GSRTFparagraph(ctxt); ;
break;} break;}
case 62: case 62:
#line 343 "Parsers/rtfGrammer.y" #line 343 "rtfGrammer.y"
{ GSRTFgenericRTFcommand(ctxt, yyvsp[0].cmd); ; { GSRTFgenericRTFcommand(ctxt, yyvsp[0].cmd); ;
break;} break;}
case 67: case 67:
#line 361 "Parsers/rtfGrammer.y" #line 361 "rtfGrammer.y"
{ GSRTFregisterFont(ctxt, yyvsp[0].text, yyvsp[-2].number, yyvsp[-3].cmd.parameter); { GSRTFregisterFont(ctxt, yyvsp[0].text, yyvsp[-2].number, yyvsp[-3].cmd.parameter);
free((void *)yyvsp[0].text); ; free((void *)yyvsp[0].text); ;
break;} break;}
case 73: case 73:
#line 374 "Parsers/rtfGrammer.y" #line 374 "rtfGrammer.y"
{ yyval.number = RTFfamilyNil - RTFfamilyNil; ; { yyval.number = RTFfamilyNil - RTFfamilyNil; ;
break;} break;}
case 74: case 74:
#line 375 "Parsers/rtfGrammer.y" #line 375 "rtfGrammer.y"
{ yyval.number = RTFfamilyRoman - RTFfamilyNil; ; { yyval.number = RTFfamilyRoman - RTFfamilyNil; ;
break;} break;}
case 75: case 75:
#line 376 "Parsers/rtfGrammer.y" #line 376 "rtfGrammer.y"
{ yyval.number = RTFfamilySwiss - RTFfamilyNil; ; { yyval.number = RTFfamilySwiss - RTFfamilyNil; ;
break;} break;}
case 76: case 76:
#line 377 "Parsers/rtfGrammer.y" #line 377 "rtfGrammer.y"
{ yyval.number = RTFfamilyModern - RTFfamilyNil; ; { yyval.number = RTFfamilyModern - RTFfamilyNil; ;
break;} break;}
case 77: case 77:
#line 378 "Parsers/rtfGrammer.y" #line 378 "rtfGrammer.y"
{ yyval.number = RTFfamilyScript - RTFfamilyNil; ; { yyval.number = RTFfamilyScript - RTFfamilyNil; ;
break;} break;}
case 78: case 78:
#line 379 "Parsers/rtfGrammer.y" #line 379 "rtfGrammer.y"
{ yyval.number = RTFfamilyDecor - RTFfamilyNil; ; { yyval.number = RTFfamilyDecor - RTFfamilyNil; ;
break;} break;}
case 79: case 79:
#line 380 "Parsers/rtfGrammer.y" #line 380 "rtfGrammer.y"
{ yyval.number = RTFfamilyTech - RTFfamilyNil; ; { yyval.number = RTFfamilyTech - RTFfamilyNil; ;
break;} break;}
case 83: case 83:
#line 397 "Parsers/rtfGrammer.y" #line 397 "rtfGrammer.y"
{ {
GSRTFaddColor(ctxt, yyvsp[-3].cmd.parameter, yyvsp[-2].cmd.parameter, yyvsp[-1].cmd.parameter); GSRTFaddColor(ctxt, yyvsp[-3].cmd.parameter, yyvsp[-2].cmd.parameter, yyvsp[-1].cmd.parameter);
free((void *)yyvsp[0].text); free((void *)yyvsp[0].text);
; ;
break;} break;}
case 84: case 84:
#line 402 "Parsers/rtfGrammer.y" #line 402 "rtfGrammer.y"
{ {
GSRTFaddDefaultColor(ctxt); GSRTFaddDefaultColor(ctxt);
free((void *)yyvsp[0].text); free((void *)yyvsp[0].text);
; ;
break;} break;}
case 85: case 85:
#line 411 "Parsers/rtfGrammer.y" #line 411 "rtfGrammer.y"
{ yylsp[0].first_line; ; { yylsp[0].first_line; ;
break;} break;}
} }
@ -1549,7 +1549,7 @@ yyerrhandle:
yystate = yyn; yystate = yyn;
goto yynewstate; goto yynewstate;
} }
#line 414 "Parsers/rtfGrammer.y" #line 414 "rtfGrammer.y"
/* some C code here */ /* some C code here */

View file

@ -54,16 +54,17 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "Parsers/rtfScanner.h" #include "rtfScanner.h"
/* this context is passed to the interface functions */ /* this context is passed to the interface functions */
typedef void * GSRTFctxt; typedef void * GSRTFctxt;
#define YYPARSE_PARAM ctxt, lctxt #define YYPARSE_PARAM ctxt, lctxt
#define YYLEX_PARAM lctxt #define YYLEX_PARAM lctxt
#define CTXT ctxt
#define YYERROR_VERBOSE #define YYERROR_VERBOSE
#include "rtfConsumerFunctions.h" #include "RTFConsumerFunctions.h"
%} %}
@ -156,7 +157,7 @@ typedef void * GSRTFctxt;
%% %%
rtfFile: '{' { GSRTFstart(ctxt); } RTFstart rtfCharset rtfIngredients { GSRTFstop(ctxt); } '}' rtfFile: '{' { GSRTFstart(CTXT); } RTFstart rtfCharset rtfIngredients { GSRTFstop(CTXT); } '}'
; ;
rtfCharset: RTFansi { $$ = 1; } rtfCharset: RTFansi { $$ = 1; }
@ -169,18 +170,18 @@ rtfIngredients: /* empty */
| rtfIngredients rtfFontList | rtfIngredients rtfFontList
| rtfIngredients rtfColorDef | rtfIngredients rtfColorDef
| rtfIngredients rtfStatement | rtfIngredients rtfStatement
| rtfIngredients RTFtext { GSRTFmangleText(ctxt, $2); free((void *)$2); } | rtfIngredients RTFtext { GSRTFmangleText(CTXT, $2); free((void *)$2); }
| rtfIngredients rtfBlock | rtfIngredients rtfBlock
; ;
rtfBlock: '{' { GSRTFopenBlock(ctxt, NO); } rtfIngredients '}' { GSRTFcloseBlock(ctxt, NO); } rtfBlock: '{' { GSRTFopenBlock(CTXT, NO); } rtfIngredients '}' { GSRTFcloseBlock(CTXT, NO); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFignore rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFignore rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFinfo rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFinfo rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFstylesheet rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFstylesheet rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFfootnote rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFfootnote rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFheader rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFheader rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFfooter rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' { GSRTFopenBlock(ctxt, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(ctxt, YES); } | '{' { GSRTFopenBlock(CTXT, YES); } RTFpict rtfIngredients '}' { GSRTFcloseBlock(CTXT, YES); }
| '{' '}' /* empty */ | '{' '}' /* empty */
; ;
@ -195,152 +196,152 @@ rtfStatement: RTFfont { int font;
font = 0; font = 0;
else else
font = $1.parameter; font = $1.parameter;
GSRTFfontNumber(ctxt, font); } GSRTFfontNumber(CTXT, font); }
| RTFfontSize { int size; | RTFfontSize { int size;
if ($1.isEmpty) if ($1.isEmpty)
size = 24; size = 24;
else else
size = $1.parameter; size = $1.parameter;
GSRTFfontSize(ctxt, size); } GSRTFfontSize(CTXT, size); }
| RTFpaperWidth { int width; | RTFpaperWidth { int width;
if ($1.isEmpty) if ($1.isEmpty)
width = 12240; width = 12240;
else else
width = $1.parameter; width = $1.parameter;
GSRTFpaperWidth(ctxt, width);} GSRTFpaperWidth(CTXT, width);}
| RTFpaperHeight { int height; | RTFpaperHeight { int height;
if ($1.isEmpty) if ($1.isEmpty)
height = 15840; height = 15840;
else else
height = $1.parameter; height = $1.parameter;
GSRTFpaperHeight(ctxt, height);} GSRTFpaperHeight(CTXT, height);}
| RTFmarginLeft { int margin; | RTFmarginLeft { int margin;
if ($1.isEmpty) if ($1.isEmpty)
margin = 1800; margin = 1800;
else else
margin = $1.parameter; margin = $1.parameter;
GSRTFmarginLeft(ctxt, margin);} GSRTFmarginLeft(CTXT, margin);}
| RTFmarginRight { int margin; | RTFmarginRight { int margin;
if ($1.isEmpty) if ($1.isEmpty)
margin = 1800; margin = 1800;
else else
margin = $1.parameter; margin = $1.parameter;
GSRTFmarginRight(ctxt, margin); } GSRTFmarginRight(CTXT, margin); }
| RTFmarginTop { int margin; | RTFmarginTop { int margin;
if ($1.isEmpty) if ($1.isEmpty)
margin = 1440; margin = 1440;
else else
margin = $1.parameter; margin = $1.parameter;
GSRTFmarginTop(ctxt, margin); } GSRTFmarginTop(CTXT, margin); }
| RTFmarginButtom { int margin; | RTFmarginButtom { int margin;
if ($1.isEmpty) if ($1.isEmpty)
margin = 1440; margin = 1440;
else else
margin = $1.parameter; margin = $1.parameter;
GSRTFmarginButtom(ctxt, margin); } GSRTFmarginButtom(CTXT, margin); }
| RTFfirstLineIndent { int indent; | RTFfirstLineIndent { int indent;
if ($1.isEmpty) if ($1.isEmpty)
indent = 0; indent = 0;
else else
indent = $1.parameter; indent = $1.parameter;
GSRTFfirstLineIndent(ctxt, indent); } GSRTFfirstLineIndent(CTXT, indent); }
| RTFleftIndent { int indent; | RTFleftIndent { int indent;
if ($1.isEmpty) if ($1.isEmpty)
indent = 0; indent = 0;
else else
indent = $1.parameter; indent = $1.parameter;
GSRTFleftIndent(ctxt, indent);} GSRTFleftIndent(CTXT, indent);}
| RTFrightIndent { int indent; | RTFrightIndent { int indent;
if ($1.isEmpty) if ($1.isEmpty)
indent = 0; indent = 0;
else else
indent = $1.parameter; indent = $1.parameter;
GSRTFrightIndent(ctxt, indent);} GSRTFrightIndent(CTXT, indent);}
| RTFtabstop { int location; | RTFtabstop { int location;
if ($1.isEmpty) if ($1.isEmpty)
location = 0; location = 0;
else else
location = $1.parameter; location = $1.parameter;
GSRTFtabstop(ctxt, location);} GSRTFtabstop(CTXT, location);}
| RTFalignCenter { GSRTFalignCenter(ctxt); } | RTFalignCenter { GSRTFalignCenter(CTXT); }
| RTFalignJustified { GSRTFalignJustified(ctxt); } | RTFalignJustified { GSRTFalignJustified(CTXT); }
| RTFalignLeft { GSRTFalignLeft(ctxt); } | RTFalignLeft { GSRTFalignLeft(CTXT); }
| RTFalignRight { GSRTFalignRight(ctxt); } | RTFalignRight { GSRTFalignRight(CTXT); }
| RTFspaceAbove { int space; | RTFspaceAbove { int space;
if ($1.isEmpty) if ($1.isEmpty)
space = 0; space = 0;
else else
space = $1.parameter; space = $1.parameter;
GSRTFspaceAbove(ctxt, space); } GSRTFspaceAbove(CTXT, space); }
| RTFlineSpace { GSRTFlineSpace(ctxt, $1.parameter); } | RTFlineSpace { GSRTFlineSpace(CTXT, $1.parameter); }
| RTFdefaultParagraph { GSRTFdefaultParagraph(ctxt); } | RTFdefaultParagraph { GSRTFdefaultParagraph(CTXT); }
| RTFstyle { GSRTFstyle(ctxt, $1.parameter); } | RTFstyle { GSRTFstyle(CTXT, $1.parameter); }
| RTFcolorbg { int color; | RTFcolorbg { int color;
if ($1.isEmpty) if ($1.isEmpty)
color = 0; color = 0;
else else
color = $1.parameter; color = $1.parameter;
GSRTFcolorbg(ctxt, color); } GSRTFcolorbg(CTXT, color); }
| RTFcolorfg { int color; | RTFcolorfg { int color;
if ($1.isEmpty) if ($1.isEmpty)
color = 0; color = 0;
else else
color = $1.parameter; color = $1.parameter;
GSRTFcolorfg(ctxt, color); } GSRTFcolorfg(CTXT, color); }
| RTFsubscript { int script; | RTFsubscript { int script;
if ($1.isEmpty) if ($1.isEmpty)
script = 6; script = 6;
else else
script = $1.parameter; script = $1.parameter;
GSRTFsubscript(ctxt, script); } GSRTFsubscript(CTXT, script); }
| RTFsuperscript { int script; | RTFsuperscript { int script;
if ($1.isEmpty) if ($1.isEmpty)
script = 6; script = 6;
else else
script = $1.parameter; script = $1.parameter;
GSRTFsuperscript(ctxt, script); } GSRTFsuperscript(CTXT, script); }
| RTFbold { BOOL on; | RTFbold { BOOL on;
if ($1.isEmpty || $1.parameter) if ($1.isEmpty || $1.parameter)
on = YES; on = YES;
else else
on = NO; on = NO;
GSRTFbold(ctxt, on); } GSRTFbold(CTXT, on); }
| RTFitalic { BOOL on; | RTFitalic { BOOL on;
if ($1.isEmpty || $1.parameter) if ($1.isEmpty || $1.parameter)
on = YES; on = YES;
else else
on = NO; on = NO;
GSRTFitalic(ctxt, on); } GSRTFitalic(CTXT, on); }
| RTFunderline { BOOL on; | RTFunderline { BOOL on;
if ($1.isEmpty || $1.parameter) if ($1.isEmpty || $1.parameter)
on = YES; on = YES;
else else
on = NO; on = NO;
GSRTFunderline(ctxt, on); } GSRTFunderline(CTXT, on); }
| RTFunderlineStop { GSRTFunderline(ctxt, NO); } | RTFunderlineStop { GSRTFunderline(CTXT, NO); }
| RTFplain { GSRTFdefaultCharacterStyle(ctxt); } | RTFplain { GSRTFdefaultCharacterStyle(CTXT); }
| RTFparagraph { GSRTFparagraph(ctxt); } | RTFparagraph { GSRTFparagraph(CTXT); }
| RTFrow { GSRTFparagraph(ctxt); } | RTFrow { GSRTFparagraph(CTXT); }
| RTFOtherStatement { GSRTFgenericRTFcommand(ctxt, $1); } | RTFOtherStatement { GSRTFgenericRTFcommand(CTXT, $1); }
; ;
/* /*
@ -358,7 +359,7 @@ rtfFonts:
/* the first RTFfont tags the font with a number */ /* the first RTFfont tags the font with a number */
/* RTFtext introduces the fontName */ /* RTFtext introduces the fontName */
rtfFontStatement: RTFfont rtfFontFamily rtfFontAttrs RTFtext { GSRTFregisterFont(ctxt, $4, $2, $1.parameter); rtfFontStatement: RTFfont rtfFontFamily rtfFontAttrs RTFtext { GSRTFregisterFont(CTXT, $4, $2, $1.parameter);
free((void *)$4); } free((void *)$4); }
; ;
@ -395,12 +396,12 @@ rtfColors: /* empty */
/* We get the ';' as RTFText */ /* We get the ';' as RTFText */
rtfColorStatement: RTFred RTFgreen RTFblue RTFtext rtfColorStatement: RTFred RTFgreen RTFblue RTFtext
{ {
GSRTFaddColor(ctxt, $1.parameter, $2.parameter, $3.parameter); GSRTFaddColor(CTXT, $1.parameter, $2.parameter, $3.parameter);
free((void *)$4); free((void *)$4);
} }
| RTFtext | RTFtext
{ {
GSRTFaddDefaultColor(ctxt); GSRTFaddDefaultColor(CTXT);
free((void *)$1); free((void *)$1);
} }
; ;

View file

@ -26,8 +26,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
#include "Parsers/rtfScanner.h" #include "rtfScanner.h"
#include "Parsers/rtfGrammer.tab.h" #include "rtfGrammer.tab.h"
// <§> scanner types and helpers // <§> scanner types and helpers