pkgsrc/textproc/rtf-tools/patches/patch-ae
2006-01-08 20:52:57 +00:00

166 lines
4.4 KiB
Text

$NetBSD: patch-ae,v 1.5 2006/01/08 20:52:57 joerg Exp $
--- lib/reader.c.orig 1994-04-05 19:14:55.000000000 +0000
+++ lib/reader.c
@@ -137,7 +137,7 @@ static RTFColor *colorList = (RTFColor *
static RTFStyle *styleList = (RTFStyle *) NULL;
-static FILE *rtffp = stdin;
+static FILE *rtffp;
static char *inputName = (char *) NULL;
static char *outputName = (char *) NULL;
@@ -207,6 +207,9 @@ RTFFont *fp;
RTFStyle *sp;
RTFStyleElt *eltList, *ep;
+ if (rtffp == NULL)
+ rtffp = stdin;
+
if (rtfTextBuf == (char *) NULL) /* initialize the text buffers */
{
rtfTextBuf = RTFAlloc (rtfBufSiz);
@@ -587,38 +590,45 @@ RTFFont *fp;
if (autoCharSetFlags == 0)
return;
- if ((autoCharSetFlags & rtfReadCharSet)
- && RTFCheckCM (rtfControl, rtfCharSet))
- {
- ReadCharSetMaps ();
- }
- else if ((autoCharSetFlags & rtfSwitchCharSet)
- && RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
+ if (autoCharSetFlags & rtfReadCharSet)
{
- if ((fp = RTFGetFont (rtfParam)) != (RTFFont *) NULL)
+ if (RTFCheckCM (rtfControl, rtfCharSet))
{
- if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
- curCharSet = rtfCSSymbol;
- else
- curCharSet = rtfCSGeneral;
- RTFSetCharSet (curCharSet);
+ ReadCharSetMaps ();
}
- }
- else if ((autoCharSetFlags & rtfSwitchCharSet) && rtfClass == rtfGroup)
- {
- switch (rtfMajor)
+ else if (RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum))
{
- case rtfBeginGroup:
- if (csTop >= maxCSStack)
- RTFPanic ("_RTFGetToken: stack overflow");
- csStack[csTop++] = curCharSet;
- break;
- case rtfEndGroup:
- if (csTop <= 0)
- RTFPanic ("_RTFGetToken: stack underflow");
- curCharSet = csStack[--csTop];
+ if ((fp = RTFGetFont (rtfParam)) != (RTFFont *) NULL)
+ {
+ if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
+ curCharSet = rtfCSSymbol;
+ else
+ curCharSet = rtfCSGeneral;
+ RTFSetCharSet (curCharSet);
+ }
+ }
+ /* so \plain will revert to normal character set -Ben */
+ else if (RTFCheckCMM (rtfControl, rtfCharAttr, rtfPlain))
+ {
+ curCharSet = rtfCSGeneral;
RTFSetCharSet (curCharSet);
- break;
+ }
+ else if (rtfClass == rtfGroup)
+ {
+ switch (rtfMajor)
+ {
+ case rtfBeginGroup:
+ if (csTop >= maxCSStack)
+ RTFPanic ("_RTFGetToken: stack overflow");
+ csStack[csTop++] = curCharSet;
+ break;
+ case rtfEndGroup:
+ if (csTop <= 0)
+ RTFPanic ("_RTFGetToken: stack underflow");
+ curCharSet = csStack[--csTop];
+ RTFSetCharSet (curCharSet);
+ break;
+ }
}
}
}
@@ -1194,6 +1204,7 @@ RTFFont *fp;
char buf[rtfBufSiz], *bp;
int old = -1;
char *fn = "ReadFontTbl";
+int i;
for (;;)
{
@@ -1311,11 +1322,30 @@ char *fn = "ReadFontTbl";
RTFPanic ("%s: missing \"}\"", fn);
}
}
- if (fp->rtfFNum == -1)
- RTFPanic ("%s: missing font number", fn);
+
/*
* Could check other pieces of structure here, too, I suppose.
*/
+
+/*
+ * I think that would be a good idea because I ran across a program that
+ * generates incorrect RTF that specifies a font family but not a font
+ * name. This was ignored and caused rtf2xxx to coredump when it tried
+ * to strncmp() the NULL name.
+ *
+ * Better to leave no doubt about who's at fault. -Ben
+ */
+ i = 0;
+ fp = fontList;
+ while (fp != (RTFFont *)NULL) {
+ if (fp->rtfFNum == -1)
+ RTFPanic ("%s: missing font number, entry %d in font table", fn, i);
+ if (fp->rtfFName == (char *) NULL)
+ RTFPanic ("%s: missing font name, font number %d", fn, fp->rtfFNum);
+ fp = fp->rtfNextFont;
+ i++;
+ }
+
RTFRouteToken (); /* feed "}" back to router */
}
@@ -1375,6 +1405,7 @@ ReadStyleSheet ()
RTFStyle *sp;
RTFStyleElt *sep, *sepLast;
char buf[rtfBufSiz], *bp;
+char *bs;
char *fn = "ReadStyleSheet";
for (;;)
@@ -1507,8 +1538,10 @@ char *fn = "ReadStyleSheet";
RTFPanic ("%s: missing style name", fn);
if (sp->rtfSNum < 0)
{
- if (strncmp (buf, "Normal", 6) != 0
- && strncmp (buf, "Standard", 8) != 0)
+ /* skip leading spaces */
+ for (bs = buf; *bs == ' '; bs++);
+ if (strncmp (bs, "Normal", 6) != 0
+ && strncmp (bs, "Standard", 8) != 0)
RTFPanic ("%s: missing style number", fn);
sp->rtfSNum = rtfNormalStyleNum;
}
@@ -2260,6 +2293,7 @@ static RTFKey rtfKey[] =
rtfCharSet, rtfMacCharSet, "mac", 0,
rtfCharSet, rtfAnsiCharSet, "ansi", 0,
+ rtfCharSet, rtfAnsiCpCharSet, "ansicpg", 0,
rtfCharSet, rtfPcCharSet, "pc", 0,
rtfCharSet, rtfPcaCharSet, "pca", 0,