$NetBSD: patch-ae,v 1.3 2005/03/27 18:22:35 ben Exp $ --- lib/reader.c.orig 1994-04-05 12:14:55.000000000 -0700 +++ lib/reader.c @@ -587,38 +587,45 @@ RTFFont *fp; if (autoCharSetFlags == 0) return; - if ((autoCharSetFlags & rtfReadCharSet) - && RTFCheckCM (rtfControl, rtfCharSet)) + if (autoCharSetFlags & rtfReadCharSet) { - ReadCharSetMaps (); - } - else if ((autoCharSetFlags & rtfSwitchCharSet) - && RTFCheckCMM (rtfControl, rtfCharAttr, rtfFontNum)) - { - 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 +1213,7 @@ RTFFont *fp; char buf[rtfBufSiz], *bp; int old = -1; char *fn = "ReadFontTbl"; +int i; for (;;) { @@ -1311,11 +1331,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 */ } @@ -2260,6 +2299,7 @@ static RTFKey rtfKey[] = rtfCharSet, rtfMacCharSet, "mac", 0, rtfCharSet, rtfAnsiCharSet, "ansi", 0, + rtfCharSet, rtfAnsiCpCharSet, "ansicpg", 0, rtfCharSet, rtfPcCharSet, "pc", 0, rtfCharSet, rtfPcaCharSet, "pca", 0,