Remove casts and unused code.

This commit is contained in:
Mike McCormack 2005-03-21 11:24:38 +00:00 committed by Alexandre Julliard
parent 75eae135f9
commit 3a0f930ab4
2 changed files with 171 additions and 199 deletions

View File

@ -74,6 +74,51 @@ static void DocAttr(RTF_Info *info);
static void RTFFlushCPOutputBuffer(RTF_Info *info); static void RTFFlushCPOutputBuffer(RTF_Info *info);
static void RTFPutCodePageChar(RTF_Info *info, int c); static void RTFPutCodePageChar(RTF_Info *info, int c);
/* ---------------------------------------------------------------------- */
/*
* Memory allocation routines
*/
/*
* Return pointer to block of size bytes, or NULL if there's
* not enough memory available.
*/
static inline void *RTFAlloc(int size)
{
return HeapAlloc(me_heap, 0, size);
}
static inline void * RTFReAlloc(void *ptr, int size)
{
return HeapReAlloc(me_heap, 0, ptr, size);
}
/*
* Saves a string on the heap and returns a pointer to it.
*/
static inline char *RTFStrSave(char *s)
{
char *p;
p = RTFAlloc (lstrlenA(s) + 1);
if (p == NULL)
return NULL;
return lstrcpyA (p, s);
}
static inline void RTFFree(void *p)
{
HeapFree(me_heap, 0, p);
}
/* ---------------------------------------------------------------------- */
int _RTFGetChar(RTF_Info *info) int _RTFGetChar(RTF_Info *info)
{ {
@ -83,7 +128,8 @@ int _RTFGetChar(RTF_Info *info)
/* if the last buffer wasn't full, it's EOF */ /* if the last buffer wasn't full, it's EOF */
if (info->dwInputSize > 0 && if (info->dwInputSize > 0 &&
info->dwInputSize == info->dwInputUsed && info->dwInputSize < sizeof(info->InputBuffer)) info->dwInputSize == info->dwInputUsed &&
info->dwInputSize < sizeof(info->InputBuffer))
return EOF; return EOF;
if (info->dwInputSize <= info->dwInputUsed) if (info->dwInputSize <= info->dwInputUsed)
{ {
@ -94,7 +140,7 @@ int _RTFGetChar(RTF_Info *info)
if (info->editstream.dwError) if (info->editstream.dwError)
return EOF; return EOF;
/* if no bytes read, it's EOF */ /* if no bytes read, it's EOF */
if(count == 0) if (count == 0)
return EOF; return EOF;
info->dwInputSize = count; info->dwInputSize = count;
info->dwInputUsed = 0; info->dwInputUsed = 0;
@ -122,32 +168,32 @@ RTFDestroyAttrs(RTF_Info *info)
RTFStyle *sp; RTFStyle *sp;
RTFStyleElt *eltList, *ep; RTFStyleElt *eltList, *ep;
while (info->fontList != (RTFFont *) NULL) while (info->fontList)
{ {
fp = info->fontList->rtfNextFont; fp = info->fontList->rtfNextFont;
RTFFree (info->fontList->rtfFName); RTFFree (info->fontList->rtfFName);
RTFFree ((char *) info->fontList); RTFFree (info->fontList);
info->fontList = fp; info->fontList = fp;
} }
while (info->colorList != (RTFColor *) NULL) while (info->colorList)
{ {
cp = info->colorList->rtfNextColor; cp = info->colorList->rtfNextColor;
RTFFree ((char *) info->colorList); RTFFree (info->colorList);
info->colorList = cp; info->colorList = cp;
} }
while (info->styleList != (RTFStyle *) NULL) while (info->styleList)
{ {
sp = info->styleList->rtfNextStyle; sp = info->styleList->rtfNextStyle;
eltList = info->styleList->rtfSSEList; eltList = info->styleList->rtfSSEList;
while (eltList != (RTFStyleElt *) NULL) while (eltList)
{ {
ep = eltList->rtfNextSE; ep = eltList->rtfNextSE;
RTFFree (eltList->rtfSEText); RTFFree (eltList->rtfSEText);
RTFFree ((char *) eltList); RTFFree (eltList);
eltList = ep; eltList = ep;
} }
RTFFree (info->styleList->rtfSName); RTFFree (info->styleList->rtfSName);
RTFFree ((char *) info->styleList); RTFFree (info->styleList);
info->styleList = sp; info->styleList = sp;
} }
} }
@ -178,27 +224,26 @@ void RTFInit(RTF_Info *info)
TRACE("\n"); TRACE("\n");
if (info->rtfTextBuf == (char *) NULL) /* initialize the text buffers */ if (info->rtfTextBuf == NULL) /* initialize the text buffers */
{ {
info->rtfTextBuf = RTFAlloc (rtfBufSiz); info->rtfTextBuf = RTFAlloc (rtfBufSiz);
info->pushedTextBuf = RTFAlloc (rtfBufSiz); info->pushedTextBuf = RTFAlloc (rtfBufSiz);
if (info->rtfTextBuf == (char *) NULL if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL)
|| info->pushedTextBuf == (char *) NULL)
RTFPanic (info,"Cannot allocate text buffers."); RTFPanic (info,"Cannot allocate text buffers.");
info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0'; info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
} }
RTFFree (info->inputName); RTFFree (info->inputName);
RTFFree (info->outputName); RTFFree (info->outputName);
info->inputName = info->outputName = (char *) NULL; info->inputName = info->outputName = NULL;
/* initialize lookup table */ /* initialize lookup table */
LookupInit (); LookupInit ();
for (i = 0; i < rtfMaxClass; i++) for (i = 0; i < rtfMaxClass; i++)
RTFSetClassCallback (info, i, (RTFFuncPtr) NULL); RTFSetClassCallback (info, i, NULL);
for (i = 0; i < rtfMaxDestination; i++) for (i = 0; i < rtfMaxDestination; i++)
RTFSetDestinationCallback (info, i, (RTFFuncPtr) NULL); RTFSetDestinationCallback (info, i, NULL);
/* install built-in destination readers */ /* install built-in destination readers */
RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl); RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
@ -209,7 +254,7 @@ void RTFInit(RTF_Info *info)
RTFSetDestinationCallback (info, rtfObject, ReadObjGroup); RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
RTFSetReadHook (info, (RTFFuncPtr) NULL); RTFSetReadHook (info, NULL);
/* dump old lists if necessary */ /* dump old lists if necessary */
@ -246,7 +291,8 @@ void RTFSetInputName(RTF_Info *info, char *name)
{ {
TRACE("\n"); TRACE("\n");
if ((info->inputName = RTFStrSave (name)) == (char *) NULL) info->inputName = RTFStrSave (name);
if (info->inputName == NULL)
RTFPanic (info,"RTFSetInputName: out of memory"); RTFPanic (info,"RTFSetInputName: out of memory");
} }
@ -261,7 +307,8 @@ void RTFSetOutputName(RTF_Info *info, char *name)
{ {
TRACE("\n"); TRACE("\n");
if ((info->outputName = RTFStrSave (name)) == (char *) NULL) info->outputName = RTFStrSave (name);
if (info->outputName == NULL)
RTFPanic (info, "RTFSetOutputName: out of memory"); RTFPanic (info, "RTFSetOutputName: out of memory");
} }
@ -294,8 +341,8 @@ void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class) RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class)
{ {
if (class >= 0 && class < rtfMaxClass) if (class >= 0 && class < rtfMaxClass)
return (info->ccb[class]); return info->ccb[class];
return ((RTFFuncPtr) NULL); return NULL;
} }
@ -313,8 +360,8 @@ void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest) RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest)
{ {
if (dest >= 0 && dest < rtfMaxDestination) if (dest >= 0 && dest < rtfMaxDestination)
return (info->dcb[dest]); return info->dcb[dest];
return ((RTFFuncPtr) NULL); return NULL;
} }
@ -357,15 +404,16 @@ void RTFRouteToken(RTF_Info *info)
if (RTFCheckCM (info, rtfControl, rtfDestination)) if (RTFCheckCM (info, rtfControl, rtfDestination))
{ {
/* invoke destination-specific callback if there is one */ /* invoke destination-specific callback if there is one */
if ((p = RTFGetDestinationCallback (info, info->rtfMinor)) p = RTFGetDestinationCallback (info, info->rtfMinor);
!= (RTFFuncPtr) NULL) if (p != NULL)
{ {
(*p) (info); (*p) (info);
return; return;
} }
} }
/* invoke class callback if there is one */ /* invoke class callback if there is one */
if ((p = RTFGetClassCallback (info, info->rtfClass)) != (RTFFuncPtr) NULL) p = RTFGetClassCallback (info, info->rtfClass);
if (p != NULL)
(*p) (info); (*p) (info);
} }
@ -414,7 +462,8 @@ int RTFGetToken(RTF_Info *info)
for (;;) for (;;)
{ {
_RTFGetToken (info); _RTFGetToken (info);
if ((p = RTFGetReadHook (info)) != (RTFFuncPtr) NULL) p = RTFGetReadHook (info);
if (p != NULL)
(*p) (info); /* give read hook a look at token */ (*p) (info); /* give read hook a look at token */
/* Silently discard newlines, carriage returns, nulls. */ /* Silently discard newlines, carriage returns, nulls. */
@ -454,7 +503,7 @@ void RTFUngetToken(RTF_Info *info)
info->pushedMajor = info->rtfMajor; info->pushedMajor = info->rtfMajor;
info->pushedMinor = info->rtfMinor; info->pushedMinor = info->rtfMinor;
info->pushedParam = info->rtfParam; info->pushedParam = info->rtfParam;
(void) strcpy (info->pushedTextBuf, info->rtfTextBuf); lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
} }
@ -470,7 +519,8 @@ static void _RTFGetToken(RTF_Info *info)
{ {
TRACE("\n"); TRACE("\n");
if (info->rtfFormat == SF_TEXT) { if (info->rtfFormat == SF_TEXT)
{
info->rtfMajor = GetChar (info); info->rtfMajor = GetChar (info);
info->rtfMinor = 0; info->rtfMinor = 0;
info->rtfParam = rtfNoParam; info->rtfParam = rtfNoParam;
@ -490,8 +540,8 @@ static void _RTFGetToken(RTF_Info *info)
info->rtfMajor = info->pushedMajor; info->rtfMajor = info->pushedMajor;
info->rtfMinor = info->pushedMinor; info->rtfMinor = info->pushedMinor;
info->rtfParam = info->pushedParam; info->rtfParam = info->pushedParam;
(void) strcpy (info->rtfTextBuf, info->pushedTextBuf); lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
info->rtfTextLen = strlen (info->rtfTextBuf); info->rtfTextLen = lstrlenA(info->rtfTextBuf);
info->pushedClass = -1; info->pushedClass = -1;
return; return;
} }
@ -550,7 +600,7 @@ RTFCharSetToCodePage(RTF_Info *info, int charset)
default: default:
{ {
CHARSETINFO csi; CHARSETINFO csi;
DWORD n = (DWORD)charset; DWORD n = charset;
/* FIXME: TranslateCharsetInfo does not work as good as it /* FIXME: TranslateCharsetInfo does not work as good as it
* should, so let's use it only when all else fails */ * should, so let's use it only when all else fails */
@ -790,10 +840,10 @@ void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, con
info->rtfMinor = minor; info->rtfMinor = minor;
info->rtfParam = param; info->rtfParam = param;
if (param == rtfNoParam) if (param == rtfNoParam)
(void) strcpy (info->rtfTextBuf, text); lstrcpyA(info->rtfTextBuf, text);
else else
sprintf (info->rtfTextBuf, "%s%d", text, param); sprintf (info->rtfTextBuf, "%s%d", text, param);
info->rtfTextLen = strlen (info->rtfTextBuf); info->rtfTextLen = lstrlenA (info->rtfTextBuf);
} }
@ -836,7 +886,7 @@ static void ReadFontTbl(RTF_Info *info)
for (;;) for (;;)
{ {
(void) RTFGetToken (info); RTFGetToken (info);
if (RTFCheckCM (info, rtfGroup, rtfEndGroup)) if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
break; break;
if (old < 0) /* first entry - determine tbl type */ if (old < 0) /* first entry - determine tbl type */
@ -852,16 +902,17 @@ static void ReadFontTbl(RTF_Info *info)
{ {
if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup)) if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
RTFPanic (info, "%s: missing \"{\"", fn); RTFPanic (info, "%s: missing \"{\"", fn);
(void) RTFGetToken (info); /* yes, skip to next token */ RTFGetToken (info); /* yes, skip to next token */
} }
if ((fp = New (RTFFont)) == (RTFFont *) NULL) fp = New (RTFFont);
if (fp == NULL)
RTFPanic (info, "%s: cannot allocate font entry", fn); RTFPanic (info, "%s: cannot allocate font entry", fn);
fp->rtfNextFont = info->fontList; fp->rtfNextFont = info->fontList;
info->fontList = fp; info->fontList = fp;
fp->rtfFName = (char *) NULL; fp->rtfFName = NULL;
fp->rtfFAltName = (char *) NULL; fp->rtfFAltName = NULL;
fp->rtfFNum = -1; fp->rtfFNum = -1;
fp->rtfFFamily = 0; fp->rtfFFamily = 0;
fp->rtfFCharSet = 0; fp->rtfFCharSet = 0;
@ -930,7 +981,7 @@ static void ReadFontTbl(RTF_Info *info)
&& !RTFCheckCM (info, rtfText, ';')) && !RTFCheckCM (info, rtfText, ';'))
{ {
*bp++ = info->rtfMajor; *bp++ = info->rtfMajor;
(void) RTFGetToken (info); RTFGetToken (info);
} }
/* FIX: in some cases the <fontinfo> isn't finished with a semi-column */ /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
@ -940,7 +991,7 @@ static void ReadFontTbl(RTF_Info *info)
} }
*bp = '\0'; *bp = '\0';
fp->rtfFName = RTFStrSave (buf); fp->rtfFName = RTFStrSave (buf);
if (fp->rtfFName == (char *) NULL) if (fp->rtfFName == NULL)
RTFPanic (info, "%s: cannot allocate font name", fn); RTFPanic (info, "%s: cannot allocate font name", fn);
/* already have next token; don't read one */ /* already have next token; don't read one */
/* at bottom of loop */ /* at bottom of loop */
@ -952,11 +1003,11 @@ static void ReadFontTbl(RTF_Info *info)
RTFMsg (info, "%s: unknown token \"%s\"\n", RTFMsg (info, "%s: unknown token \"%s\"\n",
fn,info->rtfTextBuf); fn,info->rtfTextBuf);
} }
(void) RTFGetToken (info); RTFGetToken (info);
} }
if (old == 0) /* need to see "}" here */ if (old == 0) /* need to see "}" here */
{ {
(void) RTFGetToken (info); RTFGetToken (info);
if (!RTFCheckCM (info, rtfGroup, rtfEndGroup)) if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
RTFPanic (info, "%s: missing \"}\"", fn); RTFPanic (info, "%s: missing \"}\"", fn);
} }
@ -989,10 +1040,11 @@ static void ReadColorTbl(RTF_Info *info)
for (;;) for (;;)
{ {
(void) RTFGetToken (info); RTFGetToken (info);
if (RTFCheckCM (info, rtfGroup, rtfEndGroup)) if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
break; break;
if ((cp = New (RTFColor)) == (RTFColor *) NULL) cp = New (RTFColor);
if (cp == NULL)
RTFPanic (info,"%s: cannot allocate color entry", fn); RTFPanic (info,"%s: cannot allocate color entry", fn);
cp->rtfCNum = cnum++; cp->rtfCNum = cnum++;
cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1; cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
@ -1008,7 +1060,7 @@ static void ReadColorTbl(RTF_Info *info)
} }
RTFGetToken (info); RTFGetToken (info);
} }
if (!RTFCheckCM (info, rtfText, (int) ';')) if (!RTFCheckCM (info, rtfText, ';'))
RTFPanic (info,"%s: malformed entry", fn); RTFPanic (info,"%s: malformed entry", fn);
} }
RTFRouteToken (info); /* feed "}" back to router */ RTFRouteToken (info); /* feed "}" back to router */
@ -1031,18 +1083,19 @@ static void ReadStyleSheet(RTF_Info *info)
for (;;) for (;;)
{ {
(void) RTFGetToken (info); RTFGetToken (info);
if (RTFCheckCM (info, rtfGroup, rtfEndGroup)) if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
break; break;
if ((sp = New (RTFStyle)) == (RTFStyle *) NULL) sp = New (RTFStyle);
if (sp == NULL)
RTFPanic (info,"%s: cannot allocate stylesheet entry", fn); RTFPanic (info,"%s: cannot allocate stylesheet entry", fn);
sp->rtfSName = (char *) NULL; sp->rtfSName = NULL;
sp->rtfSNum = -1; sp->rtfSNum = -1;
sp->rtfSType = rtfParStyle; sp->rtfSType = rtfParStyle;
sp->rtfSAdditive = 0; sp->rtfSAdditive = 0;
sp->rtfSBasedOn = rtfNoStyleNum; sp->rtfSBasedOn = rtfNoStyleNum;
sp->rtfSNextPar = -1; sp->rtfSNextPar = -1;
sp->rtfSSEList = sepLast = (RTFStyleElt *) NULL; sp->rtfSSEList = sepLast = NULL;
sp->rtfNextStyle = info->styleList; sp->rtfNextStyle = info->styleList;
sp->rtfExpanding = 0; sp->rtfExpanding = 0;
info->styleList = sp; info->styleList = sp;
@ -1050,7 +1103,7 @@ static void ReadStyleSheet(RTF_Info *info)
RTFPanic (info,"%s: missing \"{\"", fn); RTFPanic (info,"%s: missing \"{\"", fn);
for (;;) for (;;)
{ {
(void) RTFGetToken (info); RTFGetToken (info);
if (info->rtfClass == rtfEOF if (info->rtfClass == rtfEOF
|| RTFCheckCM (info, rtfText, ';')) || RTFCheckCM (info, rtfText, ';'))
break; break;
@ -1091,20 +1144,21 @@ static void ReadStyleSheet(RTF_Info *info)
sp->rtfSNextPar = info->rtfParam; sp->rtfSNextPar = info->rtfParam;
continue; continue;
} }
if ((sep = New (RTFStyleElt)) == (RTFStyleElt *) NULL) sep = New (RTFStyleElt);
if (sep == NULL)
RTFPanic (info,"%s: cannot allocate style element", fn); RTFPanic (info,"%s: cannot allocate style element", fn);
sep->rtfSEClass = info->rtfClass; sep->rtfSEClass = info->rtfClass;
sep->rtfSEMajor = info->rtfMajor; sep->rtfSEMajor = info->rtfMajor;
sep->rtfSEMinor = info->rtfMinor; sep->rtfSEMinor = info->rtfMinor;
sep->rtfSEParam = info->rtfParam; sep->rtfSEParam = info->rtfParam;
if ((sep->rtfSEText = RTFStrSave (info->rtfTextBuf)) sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
== (char *) NULL) if (sep->rtfSEText == NULL)
RTFPanic (info,"%s: cannot allocate style element text", fn); RTFPanic (info,"%s: cannot allocate style element text", fn);
if (sepLast == (RTFStyleElt *) NULL) if (sepLast == NULL)
sp->rtfSSEList = sep; /* first element */ sp->rtfSSEList = sep; /* first element */
else /* add to end */ else /* add to end */
sepLast->rtfNextSE = sep; sepLast->rtfNextSE = sep;
sep->rtfNextSE = (RTFStyleElt *) NULL; sep->rtfNextSE = NULL;
sepLast = sep; sepLast = sep;
} }
else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
@ -1124,14 +1178,15 @@ static void ReadStyleSheet(RTF_Info *info)
if (info->rtfMajor == ';') if (info->rtfMajor == ';')
{ {
/* put back for "for" loop */ /* put back for "for" loop */
(void) RTFUngetToken (info); RTFUngetToken (info);
break; break;
} }
*bp++ = info->rtfMajor; *bp++ = info->rtfMajor;
(void) RTFGetToken (info); RTFGetToken (info);
} }
*bp = '\0'; *bp = '\0';
if ((sp->rtfSName = RTFStrSave (buf)) == (char *) NULL) sp->rtfSName = RTFStrSave (buf);
if (sp->rtfSName == NULL)
RTFPanic (info, "%s: cannot allocate style name", fn); RTFPanic (info, "%s: cannot allocate style name", fn);
} }
else /* unrecognized */ else /* unrecognized */
@ -1141,7 +1196,7 @@ static void ReadStyleSheet(RTF_Info *info)
fn, info->rtfTextBuf); fn, info->rtfTextBuf);
} }
} }
(void) RTFGetToken (info); RTFGetToken (info);
if (!RTFCheckCM (info, rtfGroup, rtfEndGroup)) if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
RTFPanic (info, "%s: missing \"}\"", fn); RTFPanic (info, "%s: missing \"}\"", fn);
@ -1155,7 +1210,7 @@ static void ReadStyleSheet(RTF_Info *info)
* *
* Some German RTF writers use "Standard" instead of "Normal". * Some German RTF writers use "Standard" instead of "Normal".
*/ */
if (sp->rtfSName == (char *) NULL) if (sp->rtfSName == NULL)
RTFPanic (info,"%s: missing style name", fn); RTFPanic (info,"%s: missing style name", fn);
if (sp->rtfSNum < 0) if (sp->rtfSNum < 0)
{ {
@ -1206,7 +1261,7 @@ RTFStyle *RTFGetStyle(RTF_Info *info, int num)
if (num == -1) if (num == -1)
return (info->styleList); return (info->styleList);
for (s = info->styleList; s != (RTFStyle *) NULL; s = s->rtfNextStyle) for (s = info->styleList; s != NULL; s = s->rtfNextStyle)
{ {
if (s->rtfSNum == num) if (s->rtfSNum == num)
break; break;
@ -1221,7 +1276,7 @@ RTFFont *RTFGetFont(RTF_Info *info, int num)
if (num == -1) if (num == -1)
return (info->fontList); return (info->fontList);
for (f = info->fontList; f != (RTFFont *) NULL; f = f->rtfNextFont) for (f = info->fontList; f != NULL; f = f->rtfNextFont)
{ {
if (f->rtfFNum == num) if (f->rtfFNum == num)
break; break;
@ -1236,7 +1291,7 @@ RTFColor *RTFGetColor(RTF_Info *info, int num)
if (num == -1) if (num == -1)
return (info->colorList); return (info->colorList);
for (c = info->colorList; c != (RTFColor *) NULL; c = c->rtfNextColor) for (c = info->colorList; c != NULL; c = c->rtfNextColor)
{ {
if (c->rtfCNum == num) if (c->rtfCNum == num)
break; break;
@ -1259,7 +1314,10 @@ void RTFExpandStyle(RTF_Info *info, int n)
TRACE("\n"); TRACE("\n");
if (n == -1 || (s = RTFGetStyle (info, n)) == (RTFStyle *) NULL) if (n == -1)
return;
s = RTFGetStyle (info, n);
if (s == NULL)
return; return;
if (s->rtfExpanding != 0) if (s->rtfExpanding != 0)
RTFPanic (info,"Style expansion loop, style %d", n); RTFPanic (info,"Style expansion loop, style %d", n);
@ -1283,14 +1341,14 @@ void RTFExpandStyle(RTF_Info *info, int n)
* isn't used because it would add the param value to the end * isn't used because it would add the param value to the end
* of the token text, which already has it in. * of the token text, which already has it in.
*/ */
for (se = s->rtfSSEList; se != (RTFStyleElt *) NULL; se = se->rtfNextSE) for (se = s->rtfSSEList; se != NULL; se = se->rtfNextSE)
{ {
info->rtfClass = se->rtfSEClass; info->rtfClass = se->rtfSEClass;
info->rtfMajor = se->rtfSEMajor; info->rtfMajor = se->rtfSEMajor;
info->rtfMinor = se->rtfSEMinor; info->rtfMinor = se->rtfSEMinor;
info->rtfParam = se->rtfSEParam; info->rtfParam = se->rtfSEParam;
(void) strcpy (info->rtfTextBuf, se->rtfSEText); lstrcpyA (info->rtfTextBuf, se->rtfSEText);
info->rtfTextLen = strlen (info->rtfTextBuf); info->rtfTextLen = lstrlenA (info->rtfTextBuf);
RTFRouteToken (info); RTFRouteToken (info);
} }
s->rtfExpanding = 0; /* done - clear expansion flag */ s->rtfExpanding = 0; /* done - clear expansion flag */
@ -2237,15 +2295,15 @@ static void LookupInit(void)
if (inited == 0) if (inited == 0)
{ {
memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable)); memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++) { for (rp = rtfKey; rp->rtfKStr != NULL; rp++) {
int index; int index;
rp->rtfKHash = Hash ((char*)rp->rtfKStr); rp->rtfKHash = Hash ((char*)rp->rtfKStr);
index = rp->rtfKHash % (RTF_KEY_COUNT * 2); index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
if (!rtfHashTable[index].count) if (!rtfHashTable[index].count)
rtfHashTable[index].value = (void *)RTFAlloc(sizeof(RTFKey *)); rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
else else
rtfHashTable[index].value = (void *)RTFReAlloc((void *)rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1)); rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
rtfHashTable[index].value[rtfHashTable[index].count++] = rp; rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
} }
++inited; ++inited;
@ -2294,60 +2352,11 @@ static int Hash(char *s)
int val = 0; int val = 0;
while ((c = *s++) != '\0') while ((c = *s++) != '\0')
val += (int) c; val += c;
return (val); return (val);
} }
/* ---------------------------------------------------------------------- */
/*
* Memory allocation routines
*/
/*
* Return pointer to block of size bytes, or NULL if there's
* not enough memory available.
*
* This is called through RTFAlloc(), a define which coerces the
* argument to int. This avoids the persistent problem of allocation
* failing under THINK C when a long is passed.
*/
char *_RTFAlloc(int size)
{
return HeapAlloc(me_heap, 0, size);
}
char *
RTFReAlloc(char *ptr, int size)
{
return HeapReAlloc(me_heap, 0, ptr, size);
}
/*
* Saves a string on the heap and returns a pointer to it.
*/
char *RTFStrSave(char *s)
{
char *p;
if ((p = RTFAlloc ((int) (strlen (s) + 1))) == (char *) NULL)
return ((char *) NULL);
return (strcpy (p, s));
}
void RTFFree(char *p)
{
HeapFree(me_heap, 0, p);
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
@ -2395,27 +2404,6 @@ int RTFHexToChar(int i)
} }
/* ---------------------------------------------------------------------- */
/*
* Open a library file.
*/
void RTFSetOpenLibFileProc(RTF_Info *info, FILE *(*proc)())
{
info->libFileOpen = proc;
}
FILE *RTFOpenLibFile (RTF_Info *info, char *file, char *mode)
{
if (info->libFileOpen == NULL)
return ((FILE *) NULL);
return ((*info->libFileOpen) (file, mode));
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* /*
@ -2467,10 +2455,10 @@ void RTFPanic(RTF_Info *info, const char *fmt, ...)
va_start (args,fmt); va_start (args,fmt);
vsprintf (buf, fmt, args); vsprintf (buf, fmt, args);
va_end (args); va_end (args);
(void) strcat (buf, "\n"); lstrcatA (buf, "\n");
if (info->prevChar != EOF && info->rtfTextBuf != (char *) NULL) if (info->prevChar != EOF && info->rtfTextBuf != NULL)
{ {
sprintf (buf + strlen (buf), sprintf (buf + lstrlenA (buf),
"Last token read was \"%s\" near line %ld, position %d.\n", "Last token read was \"%s\" near line %ld, position %d.\n",
info->rtfTextBuf, info->rtfLineNum, info->rtfLinePos); info->rtfTextBuf, info->rtfLineNum, info->rtfLinePos);
} }

View File

@ -59,13 +59,7 @@
*/ */
# ifdef THINK_C
# define rtfNoParam (-32768) /* 16-bit max. neg. value */
# endif
# ifndef rtfNoParam
# define rtfNoParam (-1000000) # define rtfNoParam (-1000000)
# endif
@ -1103,8 +1097,6 @@ struct _RTF_Info {
RTFFuncPtr panicProc; RTFFuncPtr panicProc;
FILE *(*libFileOpen) ();
DWORD dwOutputCount; DWORD dwOutputCount;
WCHAR OutputBuffer[0x1000]; WCHAR OutputBuffer[0x1000];
@ -1147,11 +1139,6 @@ int RTFCheckMM (RTF_Info *, int, int);
RTFFont *RTFGetFont (RTF_Info *, int); RTFFont *RTFGetFont (RTF_Info *, int);
RTFColor *RTFGetColor (RTF_Info *, int); RTFColor *RTFGetColor (RTF_Info *, int);
RTFStyle *RTFGetStyle (RTF_Info *, int); RTFStyle *RTFGetStyle (RTF_Info *, int);
# define RTFAlloc(size) _RTFAlloc ((int) size)
char *_RTFAlloc (int);
char *RTFReAlloc(char *ptr, int size);
char *RTFStrSave (char *);
void RTFFree (char *);
int RTFCharToHex ( char); int RTFCharToHex ( char);
int RTFHexToChar ( int ); int RTFHexToChar ( int );
void RTFSetMsgProc ( RTFFuncPtr ); void RTFSetMsgProc ( RTFFuncPtr );
@ -1167,9 +1154,6 @@ void RTFSetPanicProc ( RTF_Info *, RTFFuncPtr);
void RTFMsg (RTF_Info *, const char *fmt, ...); void RTFMsg (RTF_Info *, const char *fmt, ...);
void RTFPanic (RTF_Info *, const char *fmt, ...); void RTFPanic (RTF_Info *, const char *fmt, ...);
void RTFSetOpenLibFileProc ( RTF_Info *, FILE *(*)());
FILE *RTFOpenLibFile ( RTF_Info *, char *, char *);
void RTFFlushOutputBuffer( RTF_Info *info ); void RTFFlushOutputBuffer( RTF_Info *info );
void RTFSetEditStream(RTF_Info *, EDITSTREAM *es); void RTFSetEditStream(RTF_Info *, EDITSTREAM *es);