1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
$NetBSD: patch-ae,v 1.4 2005/03/28 14:48:23 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 +1201,7 @@ RTFFont *fp;
char buf[rtfBufSiz], *bp;
int old = -1;
char *fn = "ReadFontTbl";
+int i;
for (;;)
{
@@ -1311,11 +1319,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 +1402,7 @@ ReadStyleSheet ()
RTFStyle *sp;
RTFStyleElt *sep, *sepLast;
char buf[rtfBufSiz], *bp;
+char *bs;
char *fn = "ReadStyleSheet";
for (;;)
@@ -1507,8 +1535,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 +2290,7 @@ static RTFKey rtfKey[] =
rtfCharSet, rtfMacCharSet, "mac", 0,
rtfCharSet, rtfAnsiCharSet, "ansi", 0,
+ rtfCharSet, rtfAnsiCpCharSet, "ansicpg", 0,
rtfCharSet, rtfPcCharSet, "pc", 0,
rtfCharSet, rtfPcaCharSet, "pca", 0,
|