4 * Portions Copyright 2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - Need to document error code meanings.
23 * - Need to do something with \* on destinations.
24 * - Make the parameter a long?
26 * reader.c - RTF file reader. Release 1.10.
28 * ASCII 10 (\n) and 13 (\r) are ignored and silently discarded.
29 * Nulls are also discarded.
30 * (although the read hook will still get a look at them.)
32 * "\:" is not a ":", it's a control symbol. But some versions of
33 * Word seem to write "\:" for ":". This reader treats "\:" as a
37 * - Add hack to skip "{\*\keycode ... }" group in stylesheet.
38 * This is probably the wrong thing to do, but it's simple.
40 * - Add THINK C awareness to malloc() declaration. Necessary so
41 * compiler knows the malloc argument is 4 bytes. Ugh.
43 * - Text characters are mapped onto standard codes, which are placed
45 * - Eliminated use of index() function.
47 * - Added zillions of new symbols (those defined in RTF spec 1.2).
49 * - Public functions RTFMsg() and RTFPanic() now take variable arguments.
50 * This means RTFPanic() now is used in place of what was formerly the
51 * internal function Error().
52 * - 8-bit characters are now legal, so they're not converted to \'xx
53 * hex char representation now.
55 * - Added public variables rtfLineNum and rtfLinePos.
56 * - #include string.h or strings.h, avoiding strncmp() problem where
57 * last argument is treated as zero when prototype isn't available.
59 * - Treat style numbers 222 and 0 properly as "no style" and "normal".
61 * Author: Paul DuBois dubois@primate.wisc.edu
63 * This software may be redistributed without restriction and used for
64 * any purpose whatsoever.
74 * include hard coded charsets
87 #include "wine/debug.h"
89 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
91 extern HANDLE RICHED32_hHeap;
93 static int _RTFGetChar(RTF_Info *);
94 static void _RTFGetToken (RTF_Info *);
95 static void _RTFGetToken2 (RTF_Info *);
96 static int GetChar (RTF_Info *);
97 static void ReadFontTbl (RTF_Info *);
98 static void ReadColorTbl (RTF_Info *);
99 static void ReadStyleSheet (RTF_Info *);
100 static void ReadInfoGroup (RTF_Info *);
101 static void ReadPictGroup (RTF_Info *);
102 static void ReadObjGroup (RTF_Info *);
103 static void LookupInit ();
104 static void Lookup (RTF_Info *, char *);
107 static void CharSetInit (RTF_Info *);
108 static void ReadCharSetMaps (RTF_Info *);
112 * This array is used to map standard character names onto their numeric codes.
113 * The position of the name within the array is the code.
114 * stdcharnames.h is generated in the ../h directory.
117 #include "stdcharnames.h"
119 int _RTFGetChar(RTF_Info *info)
125 if(CHARLIST_GetNbItems(&info->inputCharList) == 0)
129 info->editstream.pfnCallback(info->editstream.dwCookie, buff, sizeof(buff), &pcb);
135 for (i = 0; i < pcb; i++)
137 CHARLIST_Enqueue(&info->inputCharList, buff[i]);
141 myChar = CHARLIST_Dequeue(&info->inputCharList);
145 void RTFSetEditStream(RTF_Info *info, EDITSTREAM *es)
149 info->editstream.dwCookie = es->dwCookie;
150 info->editstream.dwError = es->dwError;
151 info->editstream.pfnCallback = es->pfnCallback;
155 * Initialize the reader. This may be called multiple times,
156 * to read multiple files. The only thing not reset is the input
157 * stream; that must be done with RTFSetStream().
160 void RTFInit(RTF_Info *info)
166 RTFStyleElt *eltList, *ep;
170 if (info->rtfTextBuf == (char *) NULL) /* initialize the text buffers */
172 info->rtfTextBuf = RTFAlloc (rtfBufSiz);
173 info->pushedTextBuf = RTFAlloc (rtfBufSiz);
174 if (info->rtfTextBuf == (char *) NULL
175 || info->pushedTextBuf == (char *) NULL)
176 RTFPanic (info,"Cannot allocate text buffers.");
177 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
180 RTFFree (info->inputName);
181 RTFFree (info->outputName);
182 info->inputName = info->outputName = (char *) NULL;
184 /* initialize lookup table */
187 for (i = 0; i < rtfMaxClass; i++)
188 RTFSetClassCallback (info, i, (RTFFuncPtr) NULL);
189 for (i = 0; i < rtfMaxDestination; i++)
190 RTFSetDestinationCallback (info, i, (RTFFuncPtr) NULL);
192 /* install built-in destination readers */
193 RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
194 RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
195 RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
196 RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
197 RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
198 RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
201 RTFSetReadHook (info, (RTFFuncPtr) NULL);
203 /* dump old lists if necessary */
205 while (info->fontList != (RTFFont *) NULL)
207 fp = info->fontList->rtfNextFont;
208 RTFFree (info->fontList->rtfFName);
209 RTFFree ((char *) info->fontList);
212 while (info->colorList != (RTFColor *) NULL)
214 cp = info->colorList->rtfNextColor;
215 RTFFree ((char *) info->colorList);
216 info->colorList = cp;
218 while (info->styleList != (RTFStyle *) NULL)
220 sp = info->styleList->rtfNextStyle;
221 eltList = info->styleList->rtfSSEList;
222 while (eltList != (RTFStyleElt *) NULL)
224 ep = eltList->rtfNextSE;
225 RTFFree (eltList->rtfSEText);
226 RTFFree ((char *) eltList);
229 RTFFree (info->styleList->rtfSName);
230 RTFFree ((char *) info->styleList);
231 info->styleList = sp;
235 info->pushedClass = -1;
236 info->pushedChar = EOF;
238 info->rtfLineNum = 0;
239 info->rtfLinePos = 0;
240 info->prevChar = EOF;
248 * Set or get the input or output file name. These are never guaranteed
249 * to be accurate, only insofar as the calling program makes them so.
252 void RTFSetInputName(RTF_Info *info, char *name)
256 if ((info->inputName = RTFStrSave (name)) == (char *) NULL)
257 RTFPanic (info,"RTFSetInputName: out of memory");
261 char *RTFGetInputName(RTF_Info *info)
263 return (info->inputName);
267 void RTFSetOutputName(RTF_Info *info, char *name)
271 if ((info->outputName = RTFStrSave (name)) == (char *) NULL)
272 RTFPanic (info, "RTFSetOutputName: out of memory");
276 char *RTFGetOutputName(RTF_Info *info)
278 return (info->outputName);
283 /* ---------------------------------------------------------------------- */
286 * Callback table manipulation routines
291 * Install or return a writer callback for a token class
294 void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
296 if (class >= 0 && class < rtfMaxClass)
297 info->ccb[class] = callback;
301 RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class)
303 if (class >= 0 && class < rtfMaxClass)
304 return (info->ccb[class]);
305 return ((RTFFuncPtr) NULL);
310 * Install or return a writer callback for a destination type
313 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
315 if (dest >= 0 && dest < rtfMaxDestination)
316 info->dcb[dest] = callback;
320 RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest)
322 if (dest >= 0 && dest < rtfMaxDestination)
323 return (info->dcb[dest]);
324 return ((RTFFuncPtr) NULL);
328 /* ---------------------------------------------------------------------- */
331 * Token reading routines
336 * Read the input stream, invoking the writer's callbacks
340 void RTFRead(RTF_Info *info)
342 while (RTFGetToken (info) != rtfEOF)
343 RTFRouteToken (info);
348 * Route a token. If it's a destination for which a reader is
349 * installed, process the destination internally, otherwise
350 * pass the token to the writer's class callback.
353 void RTFRouteToken(RTF_Info *info)
359 if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass) /* watchdog */
361 RTFPanic (info,"Unknown class %d: %s (reader malfunction)",
362 info->rtfClass, info->rtfTextBuf);
364 if (RTFCheckCM (info, rtfControl, rtfDestination))
366 /* invoke destination-specific callback if there is one */
367 if ((p = RTFGetDestinationCallback (info, info->rtfMinor))
368 != (RTFFuncPtr) NULL)
374 /* invoke class callback if there is one */
375 if ((p = RTFGetClassCallback (info, info->rtfClass)) != (RTFFuncPtr) NULL)
381 * Skip to the end of the current group. When this returns,
382 * writers that maintain a state stack may want to call their
383 * state unstacker; global vars will still be set to the group's
387 void RTFSkipGroup(RTF_Info *info)
392 while (RTFGetToken (info) != rtfEOF)
394 if (info->rtfClass == rtfGroup)
396 if (info->rtfMajor == rtfBeginGroup)
398 else if (info->rtfMajor == rtfEndGroup)
401 break; /* end of initial group */
409 * Read one token. Call the read hook if there is one. The
410 * token class is the return value. Returns rtfEOF when there
411 * are no more tokens.
414 int RTFGetToken(RTF_Info *info)
422 if ((p = RTFGetReadHook (info)) != (RTFFuncPtr) NULL)
423 (*p) (info); /* give read hook a look at token */
425 /* Silently discard newlines, carriage returns, nulls. */
426 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
427 && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
430 return (info->rtfClass);
435 * Install or return a token reader hook.
438 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
444 RTFFuncPtr RTFGetReadHook(RTF_Info *info)
446 return (info->readHook);
450 void RTFUngetToken(RTF_Info *info)
454 if (info->pushedClass >= 0) /* there's already an ungotten token */
455 RTFPanic (info,"cannot unget two tokens");
456 if (info->rtfClass < 0)
457 RTFPanic (info,"no token to unget");
458 info->pushedClass = info->rtfClass;
459 info->pushedMajor = info->rtfMajor;
460 info->pushedMinor = info->rtfMinor;
461 info->pushedParam = info->rtfParam;
462 (void) strcpy (info->pushedTextBuf, info->rtfTextBuf);
466 int RTFPeekToken(RTF_Info *info)
469 RTFUngetToken (info);
470 return (info->rtfClass);
474 static void _RTFGetToken(RTF_Info *info)
480 if (info->rtfFormat == SF_TEXT) {
481 info->rtfMajor = GetChar (info);
482 info->rtfMinor = rtfSC_nothing;
483 info->rtfParam = rtfNoParam;
484 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
485 if (info->rtfMajor == EOF)
486 info->rtfClass = rtfEOF;
488 info->rtfClass = rtfText;
492 /* first check for pushed token from RTFUngetToken() */
494 if (info->pushedClass >= 0)
496 info->rtfClass = info->pushedClass;
497 info->rtfMajor = info->pushedMajor;
498 info->rtfMinor = info->pushedMinor;
499 info->rtfParam = info->pushedParam;
500 (void) strcpy (info->rtfTextBuf, info->pushedTextBuf);
501 info->rtfTextLen = strlen (info->rtfTextBuf);
502 info->pushedClass = -1;
507 * Beyond this point, no token is ever seen twice, which is
508 * important, e.g., for making sure no "}" pops the font stack twice.
511 _RTFGetToken2 (info);
512 if (info->rtfClass == rtfText) /* map RTF char to standard code */
513 info->rtfMinor = RTFMapChar (info, info->rtfMajor);
516 * If auto-charset stuff is activated, see if anything needs doing,
517 * like reading the charset maps or switching between them.
520 if (info->autoCharSetFlags == 0)
523 if ((info->autoCharSetFlags & rtfReadCharSet)
524 && RTFCheckCM (info, rtfControl, rtfCharSet))
526 ReadCharSetMaps (info);
528 else if ((info->autoCharSetFlags & rtfSwitchCharSet)
529 && RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
531 if ((fp = RTFGetFont (info, info->rtfParam)) != (RTFFont *) NULL)
533 if (strncmp (fp->rtfFName, "Symbol", 6) == 0)
534 info->curCharSet = rtfCSSymbol;
536 info->curCharSet = rtfCSGeneral;
537 RTFSetCharSet (info, info->curCharSet);
540 else if ((info->autoCharSetFlags & rtfSwitchCharSet) && info->rtfClass == rtfGroup)
542 switch (info->rtfMajor)
545 if (info->csTop >= maxCSStack)
546 RTFPanic (info, "_RTFGetToken: stack overflow");
547 info->csStack[info->csTop++] = info->curCharSet;
550 if (info->csTop <= 0)
551 RTFPanic (info,"_RTFGetToken: stack underflow");
552 info->curCharSet = info->csStack[--info->csTop];
553 RTFSetCharSet (info, info->curCharSet);
560 /* this shouldn't be called anywhere but from _RTFGetToken() */
562 static void _RTFGetToken2(RTF_Info *info)
569 /* initialize token vars */
571 info->rtfClass = rtfUnknown;
572 info->rtfParam = rtfNoParam;
573 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
575 /* get first character, which may be a pushback from previous token */
577 if (info->pushedChar != EOF)
579 c = info->pushedChar;
580 info->rtfTextBuf[info->rtfTextLen++] = c;
581 info->rtfTextBuf[info->rtfTextLen] = '\0';
582 info->pushedChar = EOF;
584 else if ((c = GetChar (info)) == EOF)
586 info->rtfClass = rtfEOF;
592 info->rtfClass = rtfGroup;
593 info->rtfMajor = rtfBeginGroup;
598 info->rtfClass = rtfGroup;
599 info->rtfMajor = rtfEndGroup;
605 * Two possibilities here:
606 * 1) ASCII 9, effectively like \tab control symbol
607 * 2) literal text char
609 if (c == '\t') /* ASCII 9 */
611 info->rtfClass = rtfControl;
612 info->rtfMajor = rtfSpecialChar;
613 info->rtfMinor = rtfTab;
617 info->rtfClass = rtfText;
622 if ((c = GetChar (info)) == EOF)
624 /* early eof, whoops (class is rtfUnknown) */
630 * Three possibilities here:
631 * 1) hex encoded text char, e.g., \'d5, \'d3
632 * 2) special escaped text char, e.g., \{, \}
633 * 3) control symbol, e.g., \_, \-, \|, \<10>
635 if (c == '\'') /* hex char */
639 if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF)
641 /* should do isxdigit check! */
642 info->rtfClass = rtfText;
643 info->rtfMajor = RTFCharToHex (c) * 16
647 /* early eof, whoops (class is rtfUnknown) */
652 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
653 if (c == ':' || c == '{' || c == '}' || c == '\\')
655 info->rtfClass = rtfText;
661 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
667 if ((c = GetChar (info)) == EOF)
672 * At this point, the control word is all collected, so the
673 * major/minor numbers are determined before the parameter
674 * (if any) is scanned. There will be one too many characters
675 * in the buffer, though, so fix up before and restore after
680 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
681 Lookup (info, info->rtfTextBuf); /* sets class, major, minor */
683 info->rtfTextBuf[info->rtfTextLen-1] = c;
686 * Should be looking at first digit of parameter if there
687 * is one, unless it's negative. In that case, next char
688 * is '-', so need to gobble next char, and remember sign.
697 if (c != EOF && isdigit (c))
700 while (isdigit (c)) /* gobble parameter */
702 info->rtfParam = info->rtfParam * 10 + c - '0';
703 if ((c = GetChar (info)) == EOF)
706 info->rtfParam *= sign;
709 * If control symbol delimiter was a blank, gobble it.
710 * Otherwise the character is first char of next token, so
711 * push it back for next call. In either case, delete the
712 * delimiter from the token buffer.
717 info->pushedChar = c;
718 info->rtfTextBuf[--info->rtfTextLen] = '\0';
724 * Read the next character from the input. This handles setting the
725 * current line and position-within-line variables. Those variable are
726 * set correctly whether lines end with CR, LF, or CRLF (the last being
729 * bumpLine indicates whether the line number should be incremented on
730 * the *next* input character.
734 static int GetChar(RTF_Info *info)
741 if ((c = _RTFGetChar(info)) != EOF)
743 info->rtfTextBuf[info->rtfTextLen++] = c;
744 info->rtfTextBuf[info->rtfTextLen] = '\0';
746 if (info->prevChar == EOF)
748 oldBumpLine = info->bumpLine; /* non-zero if prev char was line ending */
755 if (info->prevChar == '\r') /* oops, previous \r wasn't */
756 oldBumpLine = 0; /* really a line ending */
759 if (oldBumpLine) /* were we supposed to increment the */
760 { /* line count on this char? */
762 info->rtfLinePos = 1;
770 * Synthesize a token by setting the global variables to the
771 * values supplied. Typically this is followed with a call
772 * to RTFRouteToken().
774 * If a param value other than rtfNoParam is passed, it becomes
775 * part of the token text.
778 void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, char *text)
782 info->rtfClass = class;
783 info->rtfMajor = major;
784 info->rtfMinor = minor;
785 info->rtfParam = param;
786 if (param == rtfNoParam)
787 (void) strcpy (info->rtfTextBuf, text);
789 sprintf (info->rtfTextBuf, "%s%d", text, param);
790 info->rtfTextLen = strlen (info->rtfTextBuf);
794 /* ---------------------------------------------------------------------- */
797 * Routines to handle mapping of RTF character sets
798 * onto standard characters.
800 * RTFStdCharCode(name) given char name, produce numeric code
801 * RTFStdCharName(code) given char code, return name
802 * RTFMapChar(c) map input (RTF) char code to std code
803 * RTFSetCharSet(id) select given charset map
804 * RTFGetCharSet() get current charset map
806 * See ../h/README for more information about charset names and codes.
811 * Initialize charset stuff.
814 static void CharSetInit(RTF_Info *info)
818 info->autoCharSetFlags = (rtfReadCharSet | rtfSwitchCharSet);
819 RTFFree (info->genCharSetFile);
820 info->genCharSetFile = (char *) NULL;
821 info->haveGenCharSet = 0;
822 RTFFree (info->symCharSetFile);
823 info->symCharSetFile = (char *) NULL;
824 info->haveSymCharSet = 0;
825 info->curCharSet = rtfCSGeneral;
826 info->curCharCode = info->genCharCode;
831 * Specify the name of a file to be read when auto-charset-file reading is
835 void RTFSetCharSetMap (RTF_Info *info, char *name, int csId)
839 if ((name = RTFStrSave (name)) == (char *) NULL) /* make copy */
840 RTFPanic (info,"RTFSetCharSetMap: out of memory");
844 RTFFree (info->genCharSetFile); /* free any previous value */
845 info->genCharSetFile = name;
848 RTFFree (info->symCharSetFile); /* free any previous value */
849 info->symCharSetFile = name;
856 * Do auto-charset-file reading.
857 * will always use the ansi charset no mater what the value
858 * of the rtfTextBuf is.
860 * TODO: add support for other charset in the future.
864 static void ReadCharSetMaps(RTF_Info *info)
870 if (info->genCharSetFile != (char *) NULL)
871 (void) strcpy (buf, info->genCharSetFile);
873 sprintf (buf, "%s-gen", &info->rtfTextBuf[1]);
874 if (RTFReadCharSetMap (info, rtfCSGeneral) == 0)
875 RTFPanic (info,"ReadCharSetMaps: Cannot read charset map %s", buf);
876 if (info->symCharSetFile != (char *) NULL)
877 (void) strcpy (buf, info->symCharSetFile);
879 sprintf (buf, "%s-sym", &info->rtfTextBuf[1]);
880 if (RTFReadCharSetMap (info, rtfCSSymbol) == 0)
881 RTFPanic (info,"ReadCharSetMaps: Cannot read charset map %s", buf);
887 * Convert a CaracterSetMap (caracter_name, caracter) into
888 * this form : array[caracter_ident] = caracter;
891 int RTFReadCharSetMap(RTF_Info *info, int csId)
901 return (0); /* illegal charset id */
904 info->haveGenCharSet = 1;
905 stdCodeArray = info->genCharCode;
906 for (i = 0; i < charSetSize; i++)
908 stdCodeArray[i] = rtfSC_nothing;
911 for ( i = 0 ; i< sizeof(ansi_gen)/(sizeof(int));i+=2)
913 stdCodeArray[ ansi_gen[i+1] ] = ansi_gen[i];
919 info->haveSymCharSet = 1;
920 stdCodeArray = info->symCharCode;
921 for (i = 0; i < charSetSize; i++)
923 stdCodeArray[i] = rtfSC_nothing;
926 for ( i = 0 ; i< sizeof(ansi_sym)/(sizeof(int));i+=2)
928 stdCodeArray[ ansi_sym[i+1] ] = ansi_sym[i];
938 * Given a standard character name (a string), find its code (a number).
939 * Return -1 if name is unknown.
942 int RTFStdCharCode(RTF_Info *info, char *name)
948 for (i = 0; i < rtfSC_MaxChar; i++)
950 if (strcmp (name, stdCharName[i]) == 0)
958 * Given a standard character code (a number), find its name (a string).
959 * Return NULL if code is unknown.
962 char *RTFStdCharName(RTF_Info *info, int code)
964 if (code < 0 || code >= rtfSC_MaxChar)
965 return ((char *) NULL);
966 return (stdCharName[code]);
971 * Given an RTF input character code, find standard character code.
972 * The translator should read the appropriate charset maps when it finds a
973 * charset control. However, the file might not contain one. In this
974 * case, no map will be available. When the first attempt is made to
975 * map a character under these circumstances, RTFMapChar() assumes ANSI
976 * and reads the map as necessary.
979 int RTFMapChar(RTF_Info *info, int c)
983 switch (info->curCharSet)
986 if (!info->haveGenCharSet)
988 if (RTFReadCharSetMap (info, rtfCSGeneral) == 0)
989 RTFPanic (info,"RTFMapChar: cannot read ansi-gen");
993 if (!info->haveSymCharSet)
995 if (RTFReadCharSetMap (info, rtfCSSymbol) == 0)
996 RTFPanic (info,"RTFMapChar: cannot read ansi-sym");
1000 if (c < 0 || c >= charSetSize)
1001 return (rtfSC_nothing);
1002 return (info->curCharCode[c]);
1007 * Set the current character set. If csId is illegal, uses general charset.
1010 void RTFSetCharSet(RTF_Info *info, int csId)
1016 default: /* use general if csId unknown */
1018 info->curCharCode = info->genCharCode;
1019 info->curCharSet = csId;
1022 info->curCharCode = info->symCharCode;
1023 info->curCharSet = csId;
1029 int RTFGetCharSet(RTF_Info *info)
1031 return (info->curCharSet);
1035 /* ---------------------------------------------------------------------- */
1038 * Special destination readers. They gobble the destination so the
1039 * writer doesn't have to deal with them. That's wrong for any
1040 * translator that wants to process any of these itself. In that
1041 * case, these readers should be overridden by installing a different
1042 * destination callback.
1044 * NOTE: The last token read by each of these reader will be the
1045 * destination's terminating '}', which will then be the current token.
1046 * That '}' token is passed to RTFRouteToken() - the writer has already
1047 * seen the '{' that began the destination group, and may have pushed a
1048 * state; it also needs to know at the end of the group that a state
1051 * It's important that rtf.h and the control token lookup table list
1052 * as many symbols as possible, because these destination readers
1053 * unfortunately make strict assumptions about the input they expect,
1054 * and a token of class rtfUnknown will throw them off easily.
1059 * Read { \fonttbl ... } destination. Old font tables don't have
1060 * braces around each table entry; try to adjust for that.
1063 static void ReadFontTbl(RTF_Info *info)
1066 char buf[rtfBufSiz], *bp;
1068 char *fn = "ReadFontTbl";
1074 (void) RTFGetToken (info);
1075 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1077 if (old < 0) /* first entry - determine tbl type */
1079 if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
1080 old = 1; /* no brace */
1081 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1082 old = 0; /* brace */
1083 else /* can't tell! */
1084 RTFPanic (info, "%s: Cannot determine format", fn);
1086 if (old == 0) /* need to find "{" here */
1088 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1089 RTFPanic (info, "%s: missing \"{\"", fn);
1090 (void) RTFGetToken (info); /* yes, skip to next token */
1092 if ((fp = New (RTFFont)) == (RTFFont *) NULL)
1093 RTFPanic (info, "%s: cannot allocate font entry", fn);
1095 fp->rtfNextFont = info->fontList;
1096 info->fontList = fp;
1098 fp->rtfFName = (char *) NULL;
1099 fp->rtfFAltName = (char *) NULL;
1102 fp->rtfFCharSet = 0;
1105 fp->rtfFCodePage = 0;
1107 while (info->rtfClass != rtfEOF
1108 && !RTFCheckCM (info, rtfText, ';')
1109 && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
1111 if (info->rtfClass == rtfControl)
1113 switch (info->rtfMajor)
1116 /* ignore token but announce it */
1117 RTFMsg (info,"%s: unknown token \"%s\"\n",
1118 fn, info->rtfTextBuf);
1121 fp->rtfFFamily = info->rtfMinor;
1124 switch (info->rtfMinor)
1127 break; /* ignore unknown? */
1129 fp->rtfFNum = info->rtfParam;
1134 switch (info->rtfMinor)
1137 break; /* ignore unknown? */
1138 case rtfFontCharSet:
1139 fp->rtfFCharSet = info->rtfParam;
1142 fp->rtfFPitch = info->rtfParam;
1144 case rtfFontCodePage:
1145 fp->rtfFCodePage = info->rtfParam;
1148 case rtfFTypeTrueType:
1149 fp->rtfFType = info->rtfParam;
1155 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup)) /* dest */
1157 RTFSkipGroup (info); /* ignore for now */
1159 else if (info->rtfClass == rtfText) /* font name */
1162 while (info->rtfClass == rtfText
1163 && !RTFCheckCM (info, rtfText, ';'))
1165 *bp++ = info->rtfMajor;
1166 (void) RTFGetToken (info);
1169 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
1170 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
1172 RTFUngetToken (info);
1175 fp->rtfFName = RTFStrSave (buf);
1176 if (fp->rtfFName == (char *) NULL)
1177 RTFPanic (info, "%s: cannot allocate font name", fn);
1178 /* already have next token; don't read one */
1179 /* at bottom of loop */
1184 /* ignore token but announce it */
1185 RTFMsg (info, "%s: unknown token \"%s\"\n",
1186 fn,info->rtfTextBuf);
1188 (void) RTFGetToken (info);
1190 if (old == 0) /* need to see "}" here */
1192 (void) RTFGetToken (info);
1193 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1194 RTFPanic (info, "%s: missing \"}\"", fn);
1197 if (fp->rtfFNum == -1)
1198 RTFPanic (info,"%s: missing font number", fn);
1200 * Could check other pieces of structure here, too, I suppose.
1202 RTFRouteToken (info); /* feed "}" back to router */
1207 * The color table entries have color values of -1 if
1208 * the default color should be used for the entry (only
1209 * a semi-colon is given in the definition, no color values).
1210 * There will be a problem if a partial entry (1 or 2 but
1211 * not 3 color values) is given. The possibility is ignored
1215 static void ReadColorTbl(RTF_Info *info)
1219 char *fn = "ReadColorTbl";
1225 (void) RTFGetToken (info);
1226 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1228 if ((cp = New (RTFColor)) == (RTFColor *) NULL)
1229 RTFPanic (info,"%s: cannot allocate color entry", fn);
1230 cp->rtfCNum = cnum++;
1231 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1232 cp->rtfNextColor = info->colorList;
1233 info->colorList = cp;
1234 while (RTFCheckCM (info, rtfControl, rtfColorName))
1236 switch (info->rtfMinor)
1238 case rtfRed: cp->rtfCRed = info->rtfParam; break;
1239 case rtfGreen: cp->rtfCGreen = info->rtfParam; break;
1240 case rtfBlue: cp->rtfCBlue = info->rtfParam; break;
1244 if (!RTFCheckCM (info, rtfText, (int) ';'))
1245 RTFPanic (info,"%s: malformed entry", fn);
1247 RTFRouteToken (info); /* feed "}" back to router */
1252 * The "Normal" style definition doesn't contain any style number,
1253 * all others do. Normal style is given style rtfNormalStyleNum.
1256 static void ReadStyleSheet(RTF_Info *info)
1259 RTFStyleElt *sep, *sepLast;
1260 char buf[rtfBufSiz], *bp;
1261 char *fn = "ReadStyleSheet";
1267 (void) RTFGetToken (info);
1268 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1270 if ((sp = New (RTFStyle)) == (RTFStyle *) NULL)
1271 RTFPanic (info,"%s: cannot allocate stylesheet entry", fn);
1272 sp->rtfSName = (char *) NULL;
1274 sp->rtfSType = rtfParStyle;
1275 sp->rtfSAdditive = 0;
1276 sp->rtfSBasedOn = rtfNoStyleNum;
1277 sp->rtfSNextPar = -1;
1278 sp->rtfSSEList = sepLast = (RTFStyleElt *) NULL;
1279 sp->rtfNextStyle = info->styleList;
1280 sp->rtfExpanding = 0;
1281 info->styleList = sp;
1282 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1283 RTFPanic (info,"%s: missing \"{\"", fn);
1286 (void) RTFGetToken (info);
1287 if (info->rtfClass == rtfEOF
1288 || RTFCheckCM (info, rtfText, ';'))
1290 if (info->rtfClass == rtfControl)
1292 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest))
1293 continue; /* ignore "\*" */
1294 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1296 sp->rtfSNum = info->rtfParam;
1297 sp->rtfSType = rtfParStyle;
1300 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1302 sp->rtfSNum = info->rtfParam;
1303 sp->rtfSType = rtfCharStyle;
1306 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1308 sp->rtfSNum = info->rtfParam;
1309 sp->rtfSType = rtfSectStyle;
1312 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1314 sp->rtfSBasedOn = info->rtfParam;
1317 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1319 sp->rtfSAdditive = 1;
1322 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1324 sp->rtfSNextPar = info->rtfParam;
1327 if ((sep = New (RTFStyleElt)) == (RTFStyleElt *) NULL)
1328 RTFPanic (info,"%s: cannot allocate style element", fn);
1329 sep->rtfSEClass = info->rtfClass;
1330 sep->rtfSEMajor = info->rtfMajor;
1331 sep->rtfSEMinor = info->rtfMinor;
1332 sep->rtfSEParam = info->rtfParam;
1333 if ((sep->rtfSEText = RTFStrSave (info->rtfTextBuf))
1335 RTFPanic (info,"%s: cannot allocate style element text", fn);
1336 if (sepLast == (RTFStyleElt *) NULL)
1337 sp->rtfSSEList = sep; /* first element */
1338 else /* add to end */
1339 sepLast->rtfNextSE = sep;
1340 sep->rtfNextSE = (RTFStyleElt *) NULL;
1343 else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1346 * This passes over "{\*\keycode ... }, among
1347 * other things. A temporary (perhaps) hack.
1349 RTFSkipGroup (info);
1352 else if (info->rtfClass == rtfText) /* style name */
1355 while (info->rtfClass == rtfText)
1357 if (info->rtfMajor == ';')
1359 /* put back for "for" loop */
1360 (void) RTFUngetToken (info);
1363 *bp++ = info->rtfMajor;
1364 (void) RTFGetToken (info);
1367 if ((sp->rtfSName = RTFStrSave (buf)) == (char *) NULL)
1368 RTFPanic (info, "%s: cannot allocate style name", fn);
1370 else /* unrecognized */
1372 /* ignore token but announce it */
1373 RTFMsg (info, "%s: unknown token \"%s\"\n",
1374 fn, info->rtfTextBuf);
1377 (void) RTFGetToken (info);
1378 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1379 RTFPanic (info, "%s: missing \"}\"", fn);
1382 * Check over the style structure. A name is a must.
1383 * If no style number was specified, check whether it's the
1384 * Normal style (in which case it's given style number
1385 * rtfNormalStyleNum). Note that some "normal" style names
1386 * just begin with "Normal" and can have other stuff following,
1387 * e.g., "Normal,Times 10 point". Ugh.
1389 * Some German RTF writers use "Standard" instead of "Normal".
1391 if (sp->rtfSName == (char *) NULL)
1392 RTFPanic (info,"%s: missing style name", fn);
1393 if (sp->rtfSNum < 0)
1395 if (strncmp (buf, "Normal", 6) != 0
1396 && strncmp (buf, "Standard", 8) != 0)
1397 RTFPanic (info,"%s: missing style number", fn);
1398 sp->rtfSNum = rtfNormalStyleNum;
1400 if (sp->rtfSNextPar == -1) /* if \snext not given, */
1401 sp->rtfSNextPar = sp->rtfSNum; /* next is itself */
1403 RTFRouteToken (info); /* feed "}" back to router */
1407 static void ReadInfoGroup(RTF_Info *info)
1409 RTFSkipGroup (info);
1410 RTFRouteToken (info); /* feed "}" back to router */
1414 static void ReadPictGroup(RTF_Info *info)
1416 RTFSkipGroup (info);
1417 RTFRouteToken (info); /* feed "}" back to router */
1421 static void ReadObjGroup(RTF_Info *info)
1423 RTFSkipGroup (info);
1424 RTFRouteToken (info); /* feed "}" back to router */
1428 /* ---------------------------------------------------------------------- */
1431 * Routines to return pieces of stylesheet, or font or color tables.
1432 * References to style 0 are mapped onto the Normal style.
1436 RTFStyle *RTFGetStyle(RTF_Info *info, int num)
1441 return (info->styleList);
1442 for (s = info->styleList; s != (RTFStyle *) NULL; s = s->rtfNextStyle)
1444 if (s->rtfSNum == num)
1447 return (s); /* NULL if not found */
1451 RTFFont *RTFGetFont(RTF_Info *info, int num)
1456 return (info->fontList);
1457 for (f = info->fontList; f != (RTFFont *) NULL; f = f->rtfNextFont)
1459 if (f->rtfFNum == num)
1462 return (f); /* NULL if not found */
1466 RTFColor *RTFGetColor(RTF_Info *info, int num)
1471 return (info->colorList);
1472 for (c = info->colorList; c != (RTFColor *) NULL; c = c->rtfNextColor)
1474 if (c->rtfCNum == num)
1477 return (c); /* NULL if not found */
1481 /* ---------------------------------------------------------------------- */
1485 * Expand style n, if there is such a style.
1488 void RTFExpandStyle(RTF_Info *info, int n)
1495 if (n == -1 || (s = RTFGetStyle (info, n)) == (RTFStyle *) NULL)
1497 if (s->rtfExpanding != 0)
1498 RTFPanic (info,"Style expansion loop, style %d", n);
1499 s->rtfExpanding = 1; /* set expansion flag for loop detection */
1501 * Expand "based-on" style (unless it's the same as the current
1502 * style -- Normal style usually gives itself as its own based-on
1503 * style). Based-on style expansion is done by synthesizing
1504 * the token that the writer needs to see in order to trigger
1505 * another style expansion, and feeding to token back through
1506 * the router so the writer sees it.
1508 if (n != s->rtfSBasedOn)
1510 RTFSetToken (info, rtfControl, rtfParAttr, rtfStyleNum,
1511 s->rtfSBasedOn, "\\s");
1512 RTFRouteToken (info);
1515 * Now route the tokens unique to this style. RTFSetToken()
1516 * isn't used because it would add the param value to the end
1517 * of the token text, which already has it in.
1519 for (se = s->rtfSSEList; se != (RTFStyleElt *) NULL; se = se->rtfNextSE)
1521 info->rtfClass = se->rtfSEClass;
1522 info->rtfMajor = se->rtfSEMajor;
1523 info->rtfMinor = se->rtfSEMinor;
1524 info->rtfParam = se->rtfSEParam;
1525 (void) strcpy (info->rtfTextBuf, se->rtfSEText);
1526 info->rtfTextLen = strlen (info->rtfTextBuf);
1527 RTFRouteToken (info);
1529 s->rtfExpanding = 0; /* done - clear expansion flag */
1533 /* ---------------------------------------------------------------------- */
1536 * Control symbol lookup routines
1540 typedef struct RTFKey RTFKey;
1544 int rtfKMajor; /* major number */
1545 int rtfKMinor; /* minor number */
1546 char *rtfKStr; /* symbol name */
1547 int rtfKHash; /* symbol name hash value */
1551 * A minor number of -1 means the token has no minor number
1552 * (all valid minor numbers are >= 0).
1555 static RTFKey rtfKey[] =
1558 * Special characters
1561 { rtfSpecialChar, rtfIIntVersion, "vern", 0 },
1562 { rtfSpecialChar, rtfICreateTime, "creatim", 0 },
1563 { rtfSpecialChar, rtfIRevisionTime, "revtim", 0 },
1564 { rtfSpecialChar, rtfIPrintTime, "printim", 0 },
1565 { rtfSpecialChar, rtfIBackupTime, "buptim", 0 },
1566 { rtfSpecialChar, rtfIEditTime, "edmins", 0 },
1567 { rtfSpecialChar, rtfIYear, "yr", 0 },
1568 { rtfSpecialChar, rtfIMonth, "mo", 0 },
1569 { rtfSpecialChar, rtfIDay, "dy", 0 },
1570 { rtfSpecialChar, rtfIHour, "hr", 0 },
1571 { rtfSpecialChar, rtfIMinute, "min", 0 },
1572 { rtfSpecialChar, rtfISecond, "sec", 0 },
1573 { rtfSpecialChar, rtfINPages, "nofpages", 0 },
1574 { rtfSpecialChar, rtfINWords, "nofwords", 0 },
1575 { rtfSpecialChar, rtfINChars, "nofchars", 0 },
1576 { rtfSpecialChar, rtfIIntID, "id", 0 },
1578 { rtfSpecialChar, rtfCurHeadDate, "chdate", 0 },
1579 { rtfSpecialChar, rtfCurHeadDateLong, "chdpl", 0 },
1580 { rtfSpecialChar, rtfCurHeadDateAbbrev, "chdpa", 0 },
1581 { rtfSpecialChar, rtfCurHeadTime, "chtime", 0 },
1582 { rtfSpecialChar, rtfCurHeadPage, "chpgn", 0 },
1583 { rtfSpecialChar, rtfSectNum, "sectnum", 0 },
1584 { rtfSpecialChar, rtfCurFNote, "chftn", 0 },
1585 { rtfSpecialChar, rtfCurAnnotRef, "chatn", 0 },
1586 { rtfSpecialChar, rtfFNoteSep, "chftnsep", 0 },
1587 { rtfSpecialChar, rtfFNoteCont, "chftnsepc", 0 },
1588 { rtfSpecialChar, rtfCell, "cell", 0 },
1589 { rtfSpecialChar, rtfRow, "row", 0 },
1590 { rtfSpecialChar, rtfPar, "par", 0 },
1591 /* newline and carriage return are synonyms for */
1592 /* \par when they are preceded by a \ character */
1593 { rtfSpecialChar, rtfPar, "\n", 0 },
1594 { rtfSpecialChar, rtfPar, "\r", 0 },
1595 { rtfSpecialChar, rtfSect, "sect", 0 },
1596 { rtfSpecialChar, rtfPage, "page", 0 },
1597 { rtfSpecialChar, rtfColumn, "column", 0 },
1598 { rtfSpecialChar, rtfLine, "line", 0 },
1599 { rtfSpecialChar, rtfSoftPage, "softpage", 0 },
1600 { rtfSpecialChar, rtfSoftColumn, "softcol", 0 },
1601 { rtfSpecialChar, rtfSoftLine, "softline", 0 },
1602 { rtfSpecialChar, rtfSoftLineHt, "softlheight", 0 },
1603 { rtfSpecialChar, rtfTab, "tab", 0 },
1604 { rtfSpecialChar, rtfEmDash, "emdash", 0 },
1605 { rtfSpecialChar, rtfEnDash, "endash", 0 },
1606 { rtfSpecialChar, rtfEmSpace, "emspace", 0 },
1607 { rtfSpecialChar, rtfEnSpace, "enspace", 0 },
1608 { rtfSpecialChar, rtfBullet, "bullet", 0 },
1609 { rtfSpecialChar, rtfLQuote, "lquote", 0 },
1610 { rtfSpecialChar, rtfRQuote, "rquote", 0 },
1611 { rtfSpecialChar, rtfLDblQuote, "ldblquote", 0 },
1612 { rtfSpecialChar, rtfRDblQuote, "rdblquote", 0 },
1613 { rtfSpecialChar, rtfFormula, "|", 0 },
1614 { rtfSpecialChar, rtfNoBrkSpace, "~", 0 },
1615 { rtfSpecialChar, rtfNoReqHyphen, "-", 0 },
1616 { rtfSpecialChar, rtfNoBrkHyphen, "_", 0 },
1617 { rtfSpecialChar, rtfOptDest, "*", 0 },
1618 { rtfSpecialChar, rtfLTRMark, "ltrmark", 0 },
1619 { rtfSpecialChar, rtfRTLMark, "rtlmark", 0 },
1620 { rtfSpecialChar, rtfNoWidthJoiner, "zwj", 0 },
1621 { rtfSpecialChar, rtfNoWidthNonJoiner, "zwnj", 0 },
1622 /* is this valid? */
1623 { rtfSpecialChar, rtfCurHeadPict, "chpict", 0 },
1626 * Character formatting attributes
1629 { rtfCharAttr, rtfPlain, "plain", 0 },
1630 { rtfCharAttr, rtfBold, "b", 0 },
1631 { rtfCharAttr, rtfAllCaps, "caps", 0 },
1632 { rtfCharAttr, rtfDeleted, "deleted", 0 },
1633 { rtfCharAttr, rtfSubScript, "dn", 0 },
1634 { rtfCharAttr, rtfSubScrShrink, "sub", 0 },
1635 { rtfCharAttr, rtfNoSuperSub, "nosupersub", 0 },
1636 { rtfCharAttr, rtfExpand, "expnd", 0 },
1637 { rtfCharAttr, rtfExpandTwips, "expndtw", 0 },
1638 { rtfCharAttr, rtfKerning, "kerning", 0 },
1639 { rtfCharAttr, rtfFontNum, "f", 0 },
1640 { rtfCharAttr, rtfFontSize, "fs", 0 },
1641 { rtfCharAttr, rtfItalic, "i", 0 },
1642 { rtfCharAttr, rtfOutline, "outl", 0 },
1643 { rtfCharAttr, rtfRevised, "revised", 0 },
1644 { rtfCharAttr, rtfRevAuthor, "revauth", 0 },
1645 { rtfCharAttr, rtfRevDTTM, "revdttm", 0 },
1646 { rtfCharAttr, rtfSmallCaps, "scaps", 0 },
1647 { rtfCharAttr, rtfShadow, "shad", 0 },
1648 { rtfCharAttr, rtfStrikeThru, "strike", 0 },
1649 { rtfCharAttr, rtfUnderline, "ul", 0 },
1650 { rtfCharAttr, rtfDotUnderline, "uld", 0 },
1651 { rtfCharAttr, rtfDbUnderline, "uldb", 0 },
1652 { rtfCharAttr, rtfNoUnderline, "ulnone", 0 },
1653 { rtfCharAttr, rtfWordUnderline, "ulw", 0 },
1654 { rtfCharAttr, rtfSuperScript, "up", 0 },
1655 { rtfCharAttr, rtfSuperScrShrink, "super", 0 },
1656 { rtfCharAttr, rtfInvisible, "v", 0 },
1657 { rtfCharAttr, rtfForeColor, "cf", 0 },
1658 { rtfCharAttr, rtfBackColor, "cb", 0 },
1659 { rtfCharAttr, rtfRTLChar, "rtlch", 0 },
1660 { rtfCharAttr, rtfLTRChar, "ltrch", 0 },
1661 { rtfCharAttr, rtfCharStyleNum, "cs", 0 },
1662 { rtfCharAttr, rtfCharCharSet, "cchs", 0 },
1663 { rtfCharAttr, rtfLanguage, "lang", 0 },
1664 /* this has disappeared from spec 1.2 */
1665 { rtfCharAttr, rtfGray, "gray", 0 },
1668 * Paragraph formatting attributes
1671 { rtfParAttr, rtfParDef, "pard", 0 },
1672 { rtfParAttr, rtfStyleNum, "s", 0 },
1673 { rtfParAttr, rtfHyphenate, "hyphpar", 0 },
1674 { rtfParAttr, rtfInTable, "intbl", 0 },
1675 { rtfParAttr, rtfKeep, "keep", 0 },
1676 { rtfParAttr, rtfNoWidowControl, "nowidctlpar", 0 },
1677 { rtfParAttr, rtfKeepNext, "keepn", 0 },
1678 { rtfParAttr, rtfOutlineLevel, "level", 0 },
1679 { rtfParAttr, rtfNoLineNum, "noline", 0 },
1680 { rtfParAttr, rtfPBBefore, "pagebb", 0 },
1681 { rtfParAttr, rtfSideBySide, "sbys", 0 },
1682 { rtfParAttr, rtfQuadLeft, "ql", 0 },
1683 { rtfParAttr, rtfQuadRight, "qr", 0 },
1684 { rtfParAttr, rtfQuadJust, "qj", 0 },
1685 { rtfParAttr, rtfQuadCenter, "qc", 0 },
1686 { rtfParAttr, rtfFirstIndent, "fi", 0 },
1687 { rtfParAttr, rtfLeftIndent, "li", 0 },
1688 { rtfParAttr, rtfRightIndent, "ri", 0 },
1689 { rtfParAttr, rtfSpaceBefore, "sb", 0 },
1690 { rtfParAttr, rtfSpaceAfter, "sa", 0 },
1691 { rtfParAttr, rtfSpaceBetween, "sl", 0 },
1692 { rtfParAttr, rtfSpaceMultiply, "slmult", 0 },
1694 { rtfParAttr, rtfSubDocument, "subdocument", 0 },
1696 { rtfParAttr, rtfRTLPar, "rtlpar", 0 },
1697 { rtfParAttr, rtfLTRPar, "ltrpar", 0 },
1699 { rtfParAttr, rtfTabPos, "tx", 0 },
1701 * FrameMaker writes \tql (to mean left-justified tab, apparently)
1702 * although it's not in the spec. It's also redundant, since lj
1703 * tabs are the default.
1705 { rtfParAttr, rtfTabLeft, "tql", 0 },
1706 { rtfParAttr, rtfTabRight, "tqr", 0 },
1707 { rtfParAttr, rtfTabCenter, "tqc", 0 },
1708 { rtfParAttr, rtfTabDecimal, "tqdec", 0 },
1709 { rtfParAttr, rtfTabBar, "tb", 0 },
1710 { rtfParAttr, rtfLeaderDot, "tldot", 0 },
1711 { rtfParAttr, rtfLeaderHyphen, "tlhyph", 0 },
1712 { rtfParAttr, rtfLeaderUnder, "tlul", 0 },
1713 { rtfParAttr, rtfLeaderThick, "tlth", 0 },
1714 { rtfParAttr, rtfLeaderEqual, "tleq", 0 },
1716 { rtfParAttr, rtfParLevel, "pnlvl", 0 },
1717 { rtfParAttr, rtfParBullet, "pnlvlblt", 0 },
1718 { rtfParAttr, rtfParSimple, "pnlvlbody", 0 },
1719 { rtfParAttr, rtfParNumCont, "pnlvlcont", 0 },
1720 { rtfParAttr, rtfParNumOnce, "pnnumonce", 0 },
1721 { rtfParAttr, rtfParNumAcross, "pnacross", 0 },
1722 { rtfParAttr, rtfParHangIndent, "pnhang", 0 },
1723 { rtfParAttr, rtfParNumRestart, "pnrestart", 0 },
1724 { rtfParAttr, rtfParNumCardinal, "pncard", 0 },
1725 { rtfParAttr, rtfParNumDecimal, "pndec", 0 },
1726 { rtfParAttr, rtfParNumULetter, "pnucltr", 0 },
1727 { rtfParAttr, rtfParNumURoman, "pnucrm", 0 },
1728 { rtfParAttr, rtfParNumLLetter, "pnlcltr", 0 },
1729 { rtfParAttr, rtfParNumLRoman, "pnlcrm", 0 },
1730 { rtfParAttr, rtfParNumOrdinal, "pnord", 0 },
1731 { rtfParAttr, rtfParNumOrdinalText, "pnordt", 0 },
1732 { rtfParAttr, rtfParNumBold, "pnb", 0 },
1733 { rtfParAttr, rtfParNumItalic, "pni", 0 },
1734 { rtfParAttr, rtfParNumAllCaps, "pncaps", 0 },
1735 { rtfParAttr, rtfParNumSmallCaps, "pnscaps", 0 },
1736 { rtfParAttr, rtfParNumUnder, "pnul", 0 },
1737 { rtfParAttr, rtfParNumDotUnder, "pnuld", 0 },
1738 { rtfParAttr, rtfParNumDbUnder, "pnuldb", 0 },
1739 { rtfParAttr, rtfParNumNoUnder, "pnulnone", 0 },
1740 { rtfParAttr, rtfParNumWordUnder, "pnulw", 0 },
1741 { rtfParAttr, rtfParNumStrikethru, "pnstrike", 0 },
1742 { rtfParAttr, rtfParNumForeColor, "pncf", 0 },
1743 { rtfParAttr, rtfParNumFont, "pnf", 0 },
1744 { rtfParAttr, rtfParNumFontSize, "pnfs", 0 },
1745 { rtfParAttr, rtfParNumIndent, "pnindent", 0 },
1746 { rtfParAttr, rtfParNumSpacing, "pnsp", 0 },
1747 { rtfParAttr, rtfParNumInclPrev, "pnprev", 0 },
1748 { rtfParAttr, rtfParNumCenter, "pnqc", 0 },
1749 { rtfParAttr, rtfParNumLeft, "pnql", 0 },
1750 { rtfParAttr, rtfParNumRight, "pnqr", 0 },
1751 { rtfParAttr, rtfParNumStartAt, "pnstart", 0 },
1753 { rtfParAttr, rtfBorderTop, "brdrt", 0 },
1754 { rtfParAttr, rtfBorderBottom, "brdrb", 0 },
1755 { rtfParAttr, rtfBorderLeft, "brdrl", 0 },
1756 { rtfParAttr, rtfBorderRight, "brdrr", 0 },
1757 { rtfParAttr, rtfBorderBetween, "brdrbtw", 0 },
1758 { rtfParAttr, rtfBorderBar, "brdrbar", 0 },
1759 { rtfParAttr, rtfBorderBox, "box", 0 },
1760 { rtfParAttr, rtfBorderSingle, "brdrs", 0 },
1761 { rtfParAttr, rtfBorderThick, "brdrth", 0 },
1762 { rtfParAttr, rtfBorderShadow, "brdrsh", 0 },
1763 { rtfParAttr, rtfBorderDouble, "brdrdb", 0 },
1764 { rtfParAttr, rtfBorderDot, "brdrdot", 0 },
1765 { rtfParAttr, rtfBorderDot, "brdrdash", 0 },
1766 { rtfParAttr, rtfBorderHair, "brdrhair", 0 },
1767 { rtfParAttr, rtfBorderWidth, "brdrw", 0 },
1768 { rtfParAttr, rtfBorderColor, "brdrcf", 0 },
1769 { rtfParAttr, rtfBorderSpace, "brsp", 0 },
1771 { rtfParAttr, rtfShading, "shading", 0 },
1772 { rtfParAttr, rtfBgPatH, "bghoriz", 0 },
1773 { rtfParAttr, rtfBgPatV, "bgvert", 0 },
1774 { rtfParAttr, rtfFwdDiagBgPat, "bgfdiag", 0 },
1775 { rtfParAttr, rtfBwdDiagBgPat, "bgbdiag", 0 },
1776 { rtfParAttr, rtfHatchBgPat, "bgcross", 0 },
1777 { rtfParAttr, rtfDiagHatchBgPat, "bgdcross", 0 },
1778 { rtfParAttr, rtfDarkBgPatH, "bgdkhoriz", 0 },
1779 { rtfParAttr, rtfDarkBgPatV, "bgdkvert", 0 },
1780 { rtfParAttr, rtfFwdDarkBgPat, "bgdkfdiag", 0 },
1781 { rtfParAttr, rtfBwdDarkBgPat, "bgdkbdiag", 0 },
1782 { rtfParAttr, rtfDarkHatchBgPat, "bgdkcross", 0 },
1783 { rtfParAttr, rtfDarkDiagHatchBgPat, "bgdkdcross", 0 },
1784 { rtfParAttr, rtfBgPatLineColor, "cfpat", 0 },
1785 { rtfParAttr, rtfBgPatColor, "cbpat", 0 },
1788 * Section formatting attributes
1791 { rtfSectAttr, rtfSectDef, "sectd", 0 },
1792 { rtfSectAttr, rtfENoteHere, "endnhere", 0 },
1793 { rtfSectAttr, rtfPrtBinFirst, "binfsxn", 0 },
1794 { rtfSectAttr, rtfPrtBin, "binsxn", 0 },
1795 { rtfSectAttr, rtfSectStyleNum, "ds", 0 },
1797 { rtfSectAttr, rtfNoBreak, "sbknone", 0 },
1798 { rtfSectAttr, rtfColBreak, "sbkcol", 0 },
1799 { rtfSectAttr, rtfPageBreak, "sbkpage", 0 },
1800 { rtfSectAttr, rtfEvenBreak, "sbkeven", 0 },
1801 { rtfSectAttr, rtfOddBreak, "sbkodd", 0 },
1803 { rtfSectAttr, rtfColumns, "cols", 0 },
1804 { rtfSectAttr, rtfColumnSpace, "colsx", 0 },
1805 { rtfSectAttr, rtfColumnNumber, "colno", 0 },
1806 { rtfSectAttr, rtfColumnSpRight, "colsr", 0 },
1807 { rtfSectAttr, rtfColumnWidth, "colw", 0 },
1808 { rtfSectAttr, rtfColumnLine, "linebetcol", 0 },
1810 { rtfSectAttr, rtfLineModulus, "linemod", 0 },
1811 { rtfSectAttr, rtfLineDist, "linex", 0 },
1812 { rtfSectAttr, rtfLineStarts, "linestarts", 0 },
1813 { rtfSectAttr, rtfLineRestart, "linerestart", 0 },
1814 { rtfSectAttr, rtfLineRestartPg, "lineppage", 0 },
1815 { rtfSectAttr, rtfLineCont, "linecont", 0 },
1817 { rtfSectAttr, rtfSectPageWid, "pgwsxn", 0 },
1818 { rtfSectAttr, rtfSectPageHt, "pghsxn", 0 },
1819 { rtfSectAttr, rtfSectMarginLeft, "marglsxn", 0 },
1820 { rtfSectAttr, rtfSectMarginRight, "margrsxn", 0 },
1821 { rtfSectAttr, rtfSectMarginTop, "margtsxn", 0 },
1822 { rtfSectAttr, rtfSectMarginBottom, "margbsxn", 0 },
1823 { rtfSectAttr, rtfSectMarginGutter, "guttersxn", 0 },
1824 { rtfSectAttr, rtfSectLandscape, "lndscpsxn", 0 },
1825 { rtfSectAttr, rtfTitleSpecial, "titlepg", 0 },
1826 { rtfSectAttr, rtfHeaderY, "headery", 0 },
1827 { rtfSectAttr, rtfFooterY, "footery", 0 },
1829 { rtfSectAttr, rtfPageStarts, "pgnstarts", 0 },
1830 { rtfSectAttr, rtfPageCont, "pgncont", 0 },
1831 { rtfSectAttr, rtfPageRestart, "pgnrestart", 0 },
1832 { rtfSectAttr, rtfPageNumRight, "pgnx", 0 },
1833 { rtfSectAttr, rtfPageNumTop, "pgny", 0 },
1834 { rtfSectAttr, rtfPageDecimal, "pgndec", 0 },
1835 { rtfSectAttr, rtfPageURoman, "pgnucrm", 0 },
1836 { rtfSectAttr, rtfPageLRoman, "pgnlcrm", 0 },
1837 { rtfSectAttr, rtfPageULetter, "pgnucltr", 0 },
1838 { rtfSectAttr, rtfPageLLetter, "pgnlcltr", 0 },
1839 { rtfSectAttr, rtfPageNumHyphSep, "pgnhnsh", 0 },
1840 { rtfSectAttr, rtfPageNumSpaceSep, "pgnhnsp", 0 },
1841 { rtfSectAttr, rtfPageNumColonSep, "pgnhnsc", 0 },
1842 { rtfSectAttr, rtfPageNumEmdashSep, "pgnhnsm", 0 },
1843 { rtfSectAttr, rtfPageNumEndashSep, "pgnhnsn", 0 },
1845 { rtfSectAttr, rtfTopVAlign, "vertalt", 0 },
1846 /* misspelled as "vertal" in specification 1.0 */
1847 { rtfSectAttr, rtfBottomVAlign, "vertalb", 0 },
1848 { rtfSectAttr, rtfCenterVAlign, "vertalc", 0 },
1849 { rtfSectAttr, rtfJustVAlign, "vertalj", 0 },
1851 { rtfSectAttr, rtfRTLSect, "rtlsect", 0 },
1852 { rtfSectAttr, rtfLTRSect, "ltrsect", 0 },
1854 /* I've seen these in an old spec, but not in real files... */
1855 /*rtfSectAttr, rtfNoBreak, "nobreak", 0,*/
1856 /*rtfSectAttr, rtfColBreak, "colbreak", 0,*/
1857 /*rtfSectAttr, rtfPageBreak, "pagebreak", 0,*/
1858 /*rtfSectAttr, rtfEvenBreak, "evenbreak", 0,*/
1859 /*rtfSectAttr, rtfOddBreak, "oddbreak", 0,*/
1862 * Document formatting attributes
1865 { rtfDocAttr, rtfDefTab, "deftab", 0 },
1866 { rtfDocAttr, rtfHyphHotZone, "hyphhotz", 0 },
1867 { rtfDocAttr, rtfHyphConsecLines, "hyphconsec", 0 },
1868 { rtfDocAttr, rtfHyphCaps, "hyphcaps", 0 },
1869 { rtfDocAttr, rtfHyphAuto, "hyphauto", 0 },
1870 { rtfDocAttr, rtfLineStart, "linestart", 0 },
1871 { rtfDocAttr, rtfFracWidth, "fracwidth", 0 },
1872 /* \makeback was given in old version of spec, it's now */
1873 /* listed as \makebackup */
1874 { rtfDocAttr, rtfMakeBackup, "makeback", 0 },
1875 { rtfDocAttr, rtfMakeBackup, "makebackup", 0 },
1876 { rtfDocAttr, rtfRTFDefault, "defformat", 0 },
1877 { rtfDocAttr, rtfPSOverlay, "psover", 0 },
1878 { rtfDocAttr, rtfDocTemplate, "doctemp", 0 },
1879 { rtfDocAttr, rtfDefLanguage, "deflang", 0 },
1881 { rtfDocAttr, rtfFENoteType, "fet", 0 },
1882 { rtfDocAttr, rtfFNoteEndSect, "endnotes", 0 },
1883 { rtfDocAttr, rtfFNoteEndDoc, "enddoc", 0 },
1884 { rtfDocAttr, rtfFNoteText, "ftntj", 0 },
1885 { rtfDocAttr, rtfFNoteBottom, "ftnbj", 0 },
1886 { rtfDocAttr, rtfENoteEndSect, "aendnotes", 0 },
1887 { rtfDocAttr, rtfENoteEndDoc, "aenddoc", 0 },
1888 { rtfDocAttr, rtfENoteText, "aftntj", 0 },
1889 { rtfDocAttr, rtfENoteBottom, "aftnbj", 0 },
1890 { rtfDocAttr, rtfFNoteStart, "ftnstart", 0 },
1891 { rtfDocAttr, rtfENoteStart, "aftnstart", 0 },
1892 { rtfDocAttr, rtfFNoteRestartPage, "ftnrstpg", 0 },
1893 { rtfDocAttr, rtfFNoteRestart, "ftnrestart", 0 },
1894 { rtfDocAttr, rtfFNoteRestartCont, "ftnrstcont", 0 },
1895 { rtfDocAttr, rtfENoteRestart, "aftnrestart", 0 },
1896 { rtfDocAttr, rtfENoteRestartCont, "aftnrstcont", 0 },
1897 { rtfDocAttr, rtfFNoteNumArabic, "ftnnar", 0 },
1898 { rtfDocAttr, rtfFNoteNumLLetter, "ftnnalc", 0 },
1899 { rtfDocAttr, rtfFNoteNumULetter, "ftnnauc", 0 },
1900 { rtfDocAttr, rtfFNoteNumLRoman, "ftnnrlc", 0 },
1901 { rtfDocAttr, rtfFNoteNumURoman, "ftnnruc", 0 },
1902 { rtfDocAttr, rtfFNoteNumChicago, "ftnnchi", 0 },
1903 { rtfDocAttr, rtfENoteNumArabic, "aftnnar", 0 },
1904 { rtfDocAttr, rtfENoteNumLLetter, "aftnnalc", 0 },
1905 { rtfDocAttr, rtfENoteNumULetter, "aftnnauc", 0 },
1906 { rtfDocAttr, rtfENoteNumLRoman, "aftnnrlc", 0 },
1907 { rtfDocAttr, rtfENoteNumURoman, "aftnnruc", 0 },
1908 { rtfDocAttr, rtfENoteNumChicago, "aftnnchi", 0 },
1910 { rtfDocAttr, rtfPaperWidth, "paperw", 0 },
1911 { rtfDocAttr, rtfPaperHeight, "paperh", 0 },
1912 { rtfDocAttr, rtfPaperSize, "psz", 0 },
1913 { rtfDocAttr, rtfLeftMargin, "margl", 0 },
1914 { rtfDocAttr, rtfRightMargin, "margr", 0 },
1915 { rtfDocAttr, rtfTopMargin, "margt", 0 },
1916 { rtfDocAttr, rtfBottomMargin, "margb", 0 },
1917 { rtfDocAttr, rtfFacingPage, "facingp", 0 },
1918 { rtfDocAttr, rtfGutterWid, "gutter", 0 },
1919 { rtfDocAttr, rtfMirrorMargin, "margmirror", 0 },
1920 { rtfDocAttr, rtfLandscape, "landscape", 0 },
1921 { rtfDocAttr, rtfPageStart, "pgnstart", 0 },
1922 { rtfDocAttr, rtfWidowCtrl, "widowctrl", 0 },
1924 { rtfDocAttr, rtfLinkStyles, "linkstyles", 0 },
1926 { rtfDocAttr, rtfNoAutoTabIndent, "notabind", 0 },
1927 { rtfDocAttr, rtfWrapSpaces, "wraptrsp", 0 },
1928 { rtfDocAttr, rtfPrintColorsBlack, "prcolbl", 0 },
1929 { rtfDocAttr, rtfNoExtraSpaceRL, "noextrasprl", 0 },
1930 { rtfDocAttr, rtfNoColumnBalance, "nocolbal", 0 },
1931 { rtfDocAttr, rtfCvtMailMergeQuote, "cvmme", 0 },
1932 { rtfDocAttr, rtfSuppressTopSpace, "sprstsp", 0 },
1933 { rtfDocAttr, rtfSuppressPreParSpace, "sprsspbf", 0 },
1934 { rtfDocAttr, rtfCombineTblBorders, "otblrul", 0 },
1935 { rtfDocAttr, rtfTranspMetafiles, "transmf", 0 },
1936 { rtfDocAttr, rtfSwapBorders, "swpbdr", 0 },
1937 { rtfDocAttr, rtfShowHardBreaks, "brkfrm", 0 },
1939 { rtfDocAttr, rtfFormProtected, "formprot", 0 },
1940 { rtfDocAttr, rtfAllProtected, "allprot", 0 },
1941 { rtfDocAttr, rtfFormShading, "formshade", 0 },
1942 { rtfDocAttr, rtfFormDisplay, "formdisp", 0 },
1943 { rtfDocAttr, rtfPrintData, "printdata", 0 },
1945 { rtfDocAttr, rtfRevProtected, "revprot", 0 },
1946 { rtfDocAttr, rtfRevisions, "revisions", 0 },
1947 { rtfDocAttr, rtfRevDisplay, "revprop", 0 },
1948 { rtfDocAttr, rtfRevBar, "revbar", 0 },
1950 { rtfDocAttr, rtfAnnotProtected, "annotprot", 0 },
1952 { rtfDocAttr, rtfRTLDoc, "rtldoc", 0 },
1953 { rtfDocAttr, rtfLTRDoc, "ltrdoc", 0 },
1959 { rtfStyleAttr, rtfAdditive, "additive", 0 },
1960 { rtfStyleAttr, rtfBasedOn, "sbasedon", 0 },
1961 { rtfStyleAttr, rtfNext, "snext", 0 },
1964 * Picture attributes
1967 { rtfPictAttr, rtfMacQD, "macpict", 0 },
1968 { rtfPictAttr, rtfPMMetafile, "pmmetafile", 0 },
1969 { rtfPictAttr, rtfWinMetafile, "wmetafile", 0 },
1970 { rtfPictAttr, rtfDevIndBitmap, "dibitmap", 0 },
1971 { rtfPictAttr, rtfWinBitmap, "wbitmap", 0 },
1972 { rtfPictAttr, rtfPixelBits, "wbmbitspixel", 0 },
1973 { rtfPictAttr, rtfBitmapPlanes, "wbmplanes", 0 },
1974 { rtfPictAttr, rtfBitmapWid, "wbmwidthbytes", 0 },
1976 { rtfPictAttr, rtfPicWid, "picw", 0 },
1977 { rtfPictAttr, rtfPicHt, "pich", 0 },
1978 { rtfPictAttr, rtfPicGoalWid, "picwgoal", 0 },
1979 { rtfPictAttr, rtfPicGoalHt, "pichgoal", 0 },
1980 /* these two aren't in the spec, but some writers emit them */
1981 { rtfPictAttr, rtfPicGoalWid, "picwGoal", 0 },
1982 { rtfPictAttr, rtfPicGoalHt, "pichGoal", 0 },
1983 { rtfPictAttr, rtfPicScaleX, "picscalex", 0 },
1984 { rtfPictAttr, rtfPicScaleY, "picscaley", 0 },
1985 { rtfPictAttr, rtfPicScaled, "picscaled", 0 },
1986 { rtfPictAttr, rtfPicCropTop, "piccropt", 0 },
1987 { rtfPictAttr, rtfPicCropBottom, "piccropb", 0 },
1988 { rtfPictAttr, rtfPicCropLeft, "piccropl", 0 },
1989 { rtfPictAttr, rtfPicCropRight, "piccropr", 0 },
1991 { rtfPictAttr, rtfPicMFHasBitmap, "picbmp", 0 },
1992 { rtfPictAttr, rtfPicMFBitsPerPixel, "picbpp", 0 },
1994 { rtfPictAttr, rtfPicBinary, "bin", 0 },
1997 * NeXT graphic attributes
2000 { rtfNeXTGrAttr, rtfNeXTGWidth, "width", 0 },
2001 { rtfNeXTGrAttr, rtfNeXTGHeight, "height", 0 },
2007 { rtfDestination, rtfFontTbl, "fonttbl", 0 },
2008 { rtfDestination, rtfFontAltName, "falt", 0 },
2009 { rtfDestination, rtfEmbeddedFont, "fonteb", 0 },
2010 { rtfDestination, rtfFontFile, "fontfile", 0 },
2011 { rtfDestination, rtfFileTbl, "filetbl", 0 },
2012 { rtfDestination, rtfFileInfo, "file", 0 },
2013 { rtfDestination, rtfColorTbl, "colortbl", 0 },
2014 { rtfDestination, rtfStyleSheet, "stylesheet", 0 },
2015 { rtfDestination, rtfKeyCode, "keycode", 0 },
2016 { rtfDestination, rtfRevisionTbl, "revtbl", 0 },
2017 { rtfDestination, rtfInfo, "info", 0 },
2018 { rtfDestination, rtfITitle, "title", 0 },
2019 { rtfDestination, rtfISubject, "subject", 0 },
2020 { rtfDestination, rtfIAuthor, "author", 0 },
2021 { rtfDestination, rtfIOperator, "operator", 0 },
2022 { rtfDestination, rtfIKeywords, "keywords", 0 },
2023 { rtfDestination, rtfIComment, "comment", 0 },
2024 { rtfDestination, rtfIVersion, "version", 0 },
2025 { rtfDestination, rtfIDoccomm, "doccomm", 0 },
2026 /* \verscomm may not exist -- was seen in earlier spec version */
2027 { rtfDestination, rtfIVerscomm, "verscomm", 0 },
2028 { rtfDestination, rtfNextFile, "nextfile", 0 },
2029 { rtfDestination, rtfTemplate, "template", 0 },
2030 { rtfDestination, rtfFNSep, "ftnsep", 0 },
2031 { rtfDestination, rtfFNContSep, "ftnsepc", 0 },
2032 { rtfDestination, rtfFNContNotice, "ftncn", 0 },
2033 { rtfDestination, rtfENSep, "aftnsep", 0 },
2034 { rtfDestination, rtfENContSep, "aftnsepc", 0 },
2035 { rtfDestination, rtfENContNotice, "aftncn", 0 },
2036 { rtfDestination, rtfPageNumLevel, "pgnhn", 0 },
2037 { rtfDestination, rtfParNumLevelStyle, "pnseclvl", 0 },
2038 { rtfDestination, rtfHeader, "header", 0 },
2039 { rtfDestination, rtfFooter, "footer", 0 },
2040 { rtfDestination, rtfHeaderLeft, "headerl", 0 },
2041 { rtfDestination, rtfHeaderRight, "headerr", 0 },
2042 { rtfDestination, rtfHeaderFirst, "headerf", 0 },
2043 { rtfDestination, rtfFooterLeft, "footerl", 0 },
2044 { rtfDestination, rtfFooterRight, "footerr", 0 },
2045 { rtfDestination, rtfFooterFirst, "footerf", 0 },
2046 { rtfDestination, rtfParNumText, "pntext", 0 },
2047 { rtfDestination, rtfParNumbering, "pn", 0 },
2048 { rtfDestination, rtfParNumTextAfter, "pntexta", 0 },
2049 { rtfDestination, rtfParNumTextBefore, "pntextb", 0 },
2050 { rtfDestination, rtfBookmarkStart, "bkmkstart", 0 },
2051 { rtfDestination, rtfBookmarkEnd, "bkmkend", 0 },
2052 { rtfDestination, rtfPict, "pict", 0 },
2053 { rtfDestination, rtfObject, "object", 0 },
2054 { rtfDestination, rtfObjClass, "objclass", 0 },
2055 { rtfDestination, rtfObjName, "objname", 0 },
2056 { rtfObjAttr, rtfObjTime, "objtime", 0 },
2057 { rtfDestination, rtfObjData, "objdata", 0 },
2058 { rtfDestination, rtfObjAlias, "objalias", 0 },
2059 { rtfDestination, rtfObjSection, "objsect", 0 },
2060 /* objitem and objtopic aren't documented in the spec! */
2061 { rtfDestination, rtfObjItem, "objitem", 0 },
2062 { rtfDestination, rtfObjTopic, "objtopic", 0 },
2063 { rtfDestination, rtfObjResult, "result", 0 },
2064 { rtfDestination, rtfDrawObject, "do", 0 },
2065 { rtfDestination, rtfFootnote, "footnote", 0 },
2066 { rtfDestination, rtfAnnotRefStart, "atrfstart", 0 },
2067 { rtfDestination, rtfAnnotRefEnd, "atrfend", 0 },
2068 { rtfDestination, rtfAnnotID, "atnid", 0 },
2069 { rtfDestination, rtfAnnotAuthor, "atnauthor", 0 },
2070 { rtfDestination, rtfAnnotation, "annotation", 0 },
2071 { rtfDestination, rtfAnnotRef, "atnref", 0 },
2072 { rtfDestination, rtfAnnotTime, "atntime", 0 },
2073 { rtfDestination, rtfAnnotIcon, "atnicn", 0 },
2074 { rtfDestination, rtfField, "field", 0 },
2075 { rtfDestination, rtfFieldInst, "fldinst", 0 },
2076 { rtfDestination, rtfFieldResult, "fldrslt", 0 },
2077 { rtfDestination, rtfDataField, "datafield", 0 },
2078 { rtfDestination, rtfIndex, "xe", 0 },
2079 { rtfDestination, rtfIndexText, "txe", 0 },
2080 { rtfDestination, rtfIndexRange, "rxe", 0 },
2081 { rtfDestination, rtfTOC, "tc", 0 },
2082 { rtfDestination, rtfNeXTGraphic, "NeXTGraphic", 0 },
2088 { rtfFontFamily, rtfFFNil, "fnil", 0 },
2089 { rtfFontFamily, rtfFFRoman, "froman", 0 },
2090 { rtfFontFamily, rtfFFSwiss, "fswiss", 0 },
2091 { rtfFontFamily, rtfFFModern, "fmodern", 0 },
2092 { rtfFontFamily, rtfFFScript, "fscript", 0 },
2093 { rtfFontFamily, rtfFFDecor, "fdecor", 0 },
2094 { rtfFontFamily, rtfFFTech, "ftech", 0 },
2095 { rtfFontFamily, rtfFFBidirectional, "fbidi", 0 },
2101 { rtfFontAttr, rtfFontCharSet, "fcharset", 0 },
2102 { rtfFontAttr, rtfFontPitch, "fprq", 0 },
2103 { rtfFontAttr, rtfFontCodePage, "cpg", 0 },
2104 { rtfFontAttr, rtfFTypeNil, "ftnil", 0 },
2105 { rtfFontAttr, rtfFTypeTrueType, "fttruetype", 0 },
2108 * File table attributes
2111 { rtfFileAttr, rtfFileNum, "fid", 0 },
2112 { rtfFileAttr, rtfFileRelPath, "frelative", 0 },
2113 { rtfFileAttr, rtfFileOSNum, "fosnum", 0 },
2119 { rtfFileSource, rtfSrcMacintosh, "fvalidmac", 0 },
2120 { rtfFileSource, rtfSrcDOS, "fvaliddos", 0 },
2121 { rtfFileSource, rtfSrcNTFS, "fvalidntfs", 0 },
2122 { rtfFileSource, rtfSrcHPFS, "fvalidhpfs", 0 },
2123 { rtfFileSource, rtfSrcNetwork, "fnetwork", 0 },
2129 { rtfColorName, rtfRed, "red", 0 },
2130 { rtfColorName, rtfGreen, "green", 0 },
2131 { rtfColorName, rtfBlue, "blue", 0 },
2137 { rtfCharSet, rtfMacCharSet, "mac", 0 },
2138 { rtfCharSet, rtfAnsiCharSet, "ansi", 0 },
2139 { rtfCharSet, rtfPcCharSet, "pc", 0 },
2140 { rtfCharSet, rtfPcaCharSet, "pca", 0 },
2146 { rtfTblAttr, rtfRowDef, "trowd", 0 },
2147 { rtfTblAttr, rtfRowGapH, "trgaph", 0 },
2148 { rtfTblAttr, rtfCellPos, "cellx", 0 },
2149 { rtfTblAttr, rtfMergeRngFirst, "clmgf", 0 },
2150 { rtfTblAttr, rtfMergePrevious, "clmrg", 0 },
2152 { rtfTblAttr, rtfRowLeft, "trql", 0 },
2153 { rtfTblAttr, rtfRowRight, "trqr", 0 },
2154 { rtfTblAttr, rtfRowCenter, "trqc", 0 },
2155 { rtfTblAttr, rtfRowLeftEdge, "trleft", 0 },
2156 { rtfTblAttr, rtfRowHt, "trrh", 0 },
2157 { rtfTblAttr, rtfRowHeader, "trhdr", 0 },
2158 { rtfTblAttr, rtfRowKeep, "trkeep", 0 },
2160 { rtfTblAttr, rtfRTLRow, "rtlrow", 0 },
2161 { rtfTblAttr, rtfLTRRow, "ltrrow", 0 },
2163 { rtfTblAttr, rtfRowBordTop, "trbrdrt", 0 },
2164 { rtfTblAttr, rtfRowBordLeft, "trbrdrl", 0 },
2165 { rtfTblAttr, rtfRowBordBottom, "trbrdrb", 0 },
2166 { rtfTblAttr, rtfRowBordRight, "trbrdrr", 0 },
2167 { rtfTblAttr, rtfRowBordHoriz, "trbrdrh", 0 },
2168 { rtfTblAttr, rtfRowBordVert, "trbrdrv", 0 },
2170 { rtfTblAttr, rtfCellBordBottom, "clbrdrb", 0 },
2171 { rtfTblAttr, rtfCellBordTop, "clbrdrt", 0 },
2172 { rtfTblAttr, rtfCellBordLeft, "clbrdrl", 0 },
2173 { rtfTblAttr, rtfCellBordRight, "clbrdrr", 0 },
2175 { rtfTblAttr, rtfCellShading, "clshdng", 0 },
2176 { rtfTblAttr, rtfCellBgPatH, "clbghoriz", 0 },
2177 { rtfTblAttr, rtfCellBgPatV, "clbgvert", 0 },
2178 { rtfTblAttr, rtfCellFwdDiagBgPat, "clbgfdiag", 0 },
2179 { rtfTblAttr, rtfCellBwdDiagBgPat, "clbgbdiag", 0 },
2180 { rtfTblAttr, rtfCellHatchBgPat, "clbgcross", 0 },
2181 { rtfTblAttr, rtfCellDiagHatchBgPat, "clbgdcross", 0 },
2183 * The spec lists "clbgdkhor", but the corresponding non-cell
2184 * control is "bgdkhoriz". At any rate Macintosh Word seems
2185 * to accept both "clbgdkhor" and "clbgdkhoriz".
2187 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhoriz", 0 },
2188 { rtfTblAttr, rtfCellDarkBgPatH, "clbgdkhor", 0 },
2189 { rtfTblAttr, rtfCellDarkBgPatV, "clbgdkvert", 0 },
2190 { rtfTblAttr, rtfCellFwdDarkBgPat, "clbgdkfdiag", 0 },
2191 { rtfTblAttr, rtfCellBwdDarkBgPat, "clbgdkbdiag", 0 },
2192 { rtfTblAttr, rtfCellDarkHatchBgPat, "clbgdkcross", 0 },
2193 { rtfTblAttr, rtfCellDarkDiagHatchBgPat, "clbgdkdcross", 0 },
2194 { rtfTblAttr, rtfCellBgPatLineColor, "clcfpat", 0 },
2195 { rtfTblAttr, rtfCellBgPatColor, "clcbpat", 0 },
2201 { rtfFieldAttr, rtfFieldDirty, "flddirty", 0 },
2202 { rtfFieldAttr, rtfFieldEdited, "fldedit", 0 },
2203 { rtfFieldAttr, rtfFieldLocked, "fldlock", 0 },
2204 { rtfFieldAttr, rtfFieldPrivate, "fldpriv", 0 },
2205 { rtfFieldAttr, rtfFieldAlt, "fldalt", 0 },
2208 * Positioning attributes
2211 { rtfPosAttr, rtfAbsWid, "absw", 0 },
2212 { rtfPosAttr, rtfAbsHt, "absh", 0 },
2214 { rtfPosAttr, rtfRPosMargH, "phmrg", 0 },
2215 { rtfPosAttr, rtfRPosPageH, "phpg", 0 },
2216 { rtfPosAttr, rtfRPosColH, "phcol", 0 },
2217 { rtfPosAttr, rtfPosX, "posx", 0 },
2218 { rtfPosAttr, rtfPosNegX, "posnegx", 0 },
2219 { rtfPosAttr, rtfPosXCenter, "posxc", 0 },
2220 { rtfPosAttr, rtfPosXInside, "posxi", 0 },
2221 { rtfPosAttr, rtfPosXOutSide, "posxo", 0 },
2222 { rtfPosAttr, rtfPosXRight, "posxr", 0 },
2223 { rtfPosAttr, rtfPosXLeft, "posxl", 0 },
2225 { rtfPosAttr, rtfRPosMargV, "pvmrg", 0 },
2226 { rtfPosAttr, rtfRPosPageV, "pvpg", 0 },
2227 { rtfPosAttr, rtfRPosParaV, "pvpara", 0 },
2228 { rtfPosAttr, rtfPosY, "posy", 0 },
2229 { rtfPosAttr, rtfPosNegY, "posnegy", 0 },
2230 { rtfPosAttr, rtfPosYInline, "posyil", 0 },
2231 { rtfPosAttr, rtfPosYTop, "posyt", 0 },
2232 { rtfPosAttr, rtfPosYCenter, "posyc", 0 },
2233 { rtfPosAttr, rtfPosYBottom, "posyb", 0 },
2235 { rtfPosAttr, rtfNoWrap, "nowrap", 0 },
2236 { rtfPosAttr, rtfDistFromTextAll, "dxfrtext", 0 },
2237 { rtfPosAttr, rtfDistFromTextX, "dfrmtxtx", 0 },
2238 { rtfPosAttr, rtfDistFromTextY, "dfrmtxty", 0 },
2239 /* \dyfrtext no longer exists in spec 1.2, apparently */
2240 /* replaced by \dfrmtextx and \dfrmtexty. */
2241 { rtfPosAttr, rtfTextDistY, "dyfrtext", 0 },
2243 { rtfPosAttr, rtfDropCapLines, "dropcapli", 0 },
2244 { rtfPosAttr, rtfDropCapType, "dropcapt", 0 },
2250 { rtfObjAttr, rtfObjEmb, "objemb", 0 },
2251 { rtfObjAttr, rtfObjLink, "objlink", 0 },
2252 { rtfObjAttr, rtfObjAutoLink, "objautlink", 0 },
2253 { rtfObjAttr, rtfObjSubscriber, "objsub", 0 },
2254 { rtfObjAttr, rtfObjPublisher, "objpub", 0 },
2255 { rtfObjAttr, rtfObjICEmb, "objicemb", 0 },
2257 { rtfObjAttr, rtfObjLinkSelf, "linkself", 0 },
2258 { rtfObjAttr, rtfObjLock, "objupdate", 0 },
2259 { rtfObjAttr, rtfObjUpdate, "objlock", 0 },
2261 { rtfObjAttr, rtfObjHt, "objh", 0 },
2262 { rtfObjAttr, rtfObjWid, "objw", 0 },
2263 { rtfObjAttr, rtfObjSetSize, "objsetsize", 0 },
2264 { rtfObjAttr, rtfObjAlign, "objalign", 0 },
2265 { rtfObjAttr, rtfObjTransposeY, "objtransy", 0 },
2266 { rtfObjAttr, rtfObjCropTop, "objcropt", 0 },
2267 { rtfObjAttr, rtfObjCropBottom, "objcropb", 0 },
2268 { rtfObjAttr, rtfObjCropLeft, "objcropl", 0 },
2269 { rtfObjAttr, rtfObjCropRight, "objcropr", 0 },
2270 { rtfObjAttr, rtfObjScaleX, "objscalex", 0 },
2271 { rtfObjAttr, rtfObjScaleY, "objscaley", 0 },
2273 { rtfObjAttr, rtfObjResRTF, "rsltrtf", 0 },
2274 { rtfObjAttr, rtfObjResPict, "rsltpict", 0 },
2275 { rtfObjAttr, rtfObjResBitmap, "rsltbmp", 0 },
2276 { rtfObjAttr, rtfObjResText, "rslttxt", 0 },
2277 { rtfObjAttr, rtfObjResMerge, "rsltmerge", 0 },
2279 { rtfObjAttr, rtfObjBookmarkPubObj, "bkmkpub", 0 },
2280 { rtfObjAttr, rtfObjPubAutoUpdate, "pubauto", 0 },
2283 * Associated character formatting attributes
2286 { rtfACharAttr, rtfACBold, "ab", 0 },
2287 { rtfACharAttr, rtfACAllCaps, "caps", 0 },
2288 { rtfACharAttr, rtfACForeColor, "acf", 0 },
2289 { rtfACharAttr, rtfACSubScript, "adn", 0 },
2290 { rtfACharAttr, rtfACExpand, "aexpnd", 0 },
2291 { rtfACharAttr, rtfACFontNum, "af", 0 },
2292 { rtfACharAttr, rtfACFontSize, "afs", 0 },
2293 { rtfACharAttr, rtfACItalic, "ai", 0 },
2294 { rtfACharAttr, rtfACLanguage, "alang", 0 },
2295 { rtfACharAttr, rtfACOutline, "aoutl", 0 },
2296 { rtfACharAttr, rtfACSmallCaps, "ascaps", 0 },
2297 { rtfACharAttr, rtfACShadow, "ashad", 0 },
2298 { rtfACharAttr, rtfACStrikeThru, "astrike", 0 },
2299 { rtfACharAttr, rtfACUnderline, "aul", 0 },
2300 { rtfACharAttr, rtfACDotUnderline, "auld", 0 },
2301 { rtfACharAttr, rtfACDbUnderline, "auldb", 0 },
2302 { rtfACharAttr, rtfACNoUnderline, "aulnone", 0 },
2303 { rtfACharAttr, rtfACWordUnderline, "aulw", 0 },
2304 { rtfACharAttr, rtfACSuperScript, "aup", 0 },
2307 * Footnote attributes
2310 { rtfFNoteAttr, rtfFNAlt, "ftnalt", 0 },
2313 * Key code attributes
2316 { rtfKeyCodeAttr, rtfAltKey, "alt", 0 },
2317 { rtfKeyCodeAttr, rtfShiftKey, "shift", 0 },
2318 { rtfKeyCodeAttr, rtfControlKey, "ctrl", 0 },
2319 { rtfKeyCodeAttr, rtfFunctionKey, "fn", 0 },
2322 * Bookmark attributes
2325 { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf", 0 },
2326 { rtfBookmarkAttr, rtfBookmarkLastCol, "bkmkcoll", 0 },
2329 * Index entry attributes
2332 { rtfIndexAttr, rtfIndexNumber, "xef", 0 },
2333 { rtfIndexAttr, rtfIndexBold, "bxe", 0 },
2334 { rtfIndexAttr, rtfIndexItalic, "ixe", 0 },
2337 * Table of contents attributes
2340 { rtfTOCAttr, rtfTOCType, "tcf", 0 },
2341 { rtfTOCAttr, rtfTOCLevel, "tcl", 0 },
2344 * Drawing object attributes
2347 { rtfDrawAttr, rtfDrawLock, "dolock", 0 },
2348 { rtfDrawAttr, rtfDrawPageRelX, "doxpage", 0 },
2349 { rtfDrawAttr, rtfDrawColumnRelX, "dobxcolumn", 0 },
2350 { rtfDrawAttr, rtfDrawMarginRelX, "dobxmargin", 0 },
2351 { rtfDrawAttr, rtfDrawPageRelY, "dobypage", 0 },
2352 { rtfDrawAttr, rtfDrawColumnRelY, "dobycolumn", 0 },
2353 { rtfDrawAttr, rtfDrawMarginRelY, "dobymargin", 0 },
2354 { rtfDrawAttr, rtfDrawHeight, "dobhgt", 0 },
2356 { rtfDrawAttr, rtfDrawBeginGroup, "dpgroup", 0 },
2357 { rtfDrawAttr, rtfDrawGroupCount, "dpcount", 0 },
2358 { rtfDrawAttr, rtfDrawEndGroup, "dpendgroup", 0 },
2359 { rtfDrawAttr, rtfDrawArc, "dparc", 0 },
2360 { rtfDrawAttr, rtfDrawCallout, "dpcallout", 0 },
2361 { rtfDrawAttr, rtfDrawEllipse, "dpellipse", 0 },
2362 { rtfDrawAttr, rtfDrawLine, "dpline", 0 },
2363 { rtfDrawAttr, rtfDrawPolygon, "dppolygon", 0 },
2364 { rtfDrawAttr, rtfDrawPolyLine, "dppolyline", 0 },
2365 { rtfDrawAttr, rtfDrawRect, "dprect", 0 },
2366 { rtfDrawAttr, rtfDrawTextBox, "dptxbx", 0 },
2368 { rtfDrawAttr, rtfDrawOffsetX, "dpx", 0 },
2369 { rtfDrawAttr, rtfDrawSizeX, "dpxsize", 0 },
2370 { rtfDrawAttr, rtfDrawOffsetY, "dpy", 0 },
2371 { rtfDrawAttr, rtfDrawSizeY, "dpysize", 0 },
2373 { rtfDrawAttr, rtfCOAngle, "dpcoa", 0 },
2374 { rtfDrawAttr, rtfCOAccentBar, "dpcoaccent", 0 },
2375 { rtfDrawAttr, rtfCOBestFit, "dpcobestfit", 0 },
2376 { rtfDrawAttr, rtfCOBorder, "dpcoborder", 0 },
2377 { rtfDrawAttr, rtfCOAttachAbsDist, "dpcodabs", 0 },
2378 { rtfDrawAttr, rtfCOAttachBottom, "dpcodbottom", 0 },
2379 { rtfDrawAttr, rtfCOAttachCenter, "dpcodcenter", 0 },
2380 { rtfDrawAttr, rtfCOAttachTop, "dpcodtop", 0 },
2381 { rtfDrawAttr, rtfCOLength, "dpcolength", 0 },
2382 { rtfDrawAttr, rtfCONegXQuadrant, "dpcominusx", 0 },
2383 { rtfDrawAttr, rtfCONegYQuadrant, "dpcominusy", 0 },
2384 { rtfDrawAttr, rtfCOOffset, "dpcooffset", 0 },
2385 { rtfDrawAttr, rtfCOAttachSmart, "dpcosmarta", 0 },
2386 { rtfDrawAttr, rtfCODoubleLine, "dpcotdouble", 0 },
2387 { rtfDrawAttr, rtfCORightAngle, "dpcotright", 0 },
2388 { rtfDrawAttr, rtfCOSingleLine, "dpcotsingle", 0 },
2389 { rtfDrawAttr, rtfCOTripleLine, "dpcottriple", 0 },
2391 { rtfDrawAttr, rtfDrawTextBoxMargin, "dptxbxmar", 0 },
2392 { rtfDrawAttr, rtfDrawTextBoxText, "dptxbxtext", 0 },
2393 { rtfDrawAttr, rtfDrawRoundRect, "dproundr", 0 },
2395 { rtfDrawAttr, rtfDrawPointX, "dpptx", 0 },
2396 { rtfDrawAttr, rtfDrawPointY, "dppty", 0 },
2397 { rtfDrawAttr, rtfDrawPolyCount, "dppolycount", 0 },
2399 { rtfDrawAttr, rtfDrawArcFlipX, "dparcflipx", 0 },
2400 { rtfDrawAttr, rtfDrawArcFlipY, "dparcflipy", 0 },
2402 { rtfDrawAttr, rtfDrawLineBlue, "dplinecob", 0 },
2403 { rtfDrawAttr, rtfDrawLineGreen, "dplinecog", 0 },
2404 { rtfDrawAttr, rtfDrawLineRed, "dplinecor", 0 },
2405 { rtfDrawAttr, rtfDrawLinePalette, "dplinepal", 0 },
2406 { rtfDrawAttr, rtfDrawLineDashDot, "dplinedado", 0 },
2407 { rtfDrawAttr, rtfDrawLineDashDotDot, "dplinedadodo", 0 },
2408 { rtfDrawAttr, rtfDrawLineDash, "dplinedash", 0 },
2409 { rtfDrawAttr, rtfDrawLineDot, "dplinedot", 0 },
2410 { rtfDrawAttr, rtfDrawLineGray, "dplinegray", 0 },
2411 { rtfDrawAttr, rtfDrawLineHollow, "dplinehollow", 0 },
2412 { rtfDrawAttr, rtfDrawLineSolid, "dplinesolid", 0 },
2413 { rtfDrawAttr, rtfDrawLineWidth, "dplinew", 0 },
2415 { rtfDrawAttr, rtfDrawHollowEndArrow, "dpaendhol", 0 },
2416 { rtfDrawAttr, rtfDrawEndArrowLength, "dpaendl", 0 },
2417 { rtfDrawAttr, rtfDrawSolidEndArrow, "dpaendsol", 0 },
2418 { rtfDrawAttr, rtfDrawEndArrowWidth, "dpaendw", 0 },
2419 { rtfDrawAttr, rtfDrawHollowStartArrow,"dpastarthol", 0 },
2420 { rtfDrawAttr, rtfDrawStartArrowLength,"dpastartl", 0 },
2421 { rtfDrawAttr, rtfDrawSolidStartArrow, "dpastartsol", 0 },
2422 { rtfDrawAttr, rtfDrawStartArrowWidth, "dpastartw", 0 },
2424 { rtfDrawAttr, rtfDrawBgFillBlue, "dpfillbgcb", 0 },
2425 { rtfDrawAttr, rtfDrawBgFillGreen, "dpfillbgcg", 0 },
2426 { rtfDrawAttr, rtfDrawBgFillRed, "dpfillbgcr", 0 },
2427 { rtfDrawAttr, rtfDrawBgFillPalette, "dpfillbgpal", 0 },
2428 { rtfDrawAttr, rtfDrawBgFillGray, "dpfillbggray", 0 },
2429 { rtfDrawAttr, rtfDrawFgFillBlue, "dpfillfgcb", 0 },
2430 { rtfDrawAttr, rtfDrawFgFillGreen, "dpfillfgcg", 0 },
2431 { rtfDrawAttr, rtfDrawFgFillRed, "dpfillfgcr", 0 },
2432 { rtfDrawAttr, rtfDrawFgFillPalette, "dpfillfgpal", 0 },
2433 { rtfDrawAttr, rtfDrawFgFillGray, "dpfillfggray", 0 },
2434 { rtfDrawAttr, rtfDrawFillPatIndex, "dpfillpat", 0 },
2436 { rtfDrawAttr, rtfDrawShadow, "dpshadow", 0 },
2437 { rtfDrawAttr, rtfDrawShadowXOffset, "dpshadx", 0 },
2438 { rtfDrawAttr, rtfDrawShadowYOffset, "dpshady", 0 },
2440 { rtfVersion, -1, "rtf", 0 },
2441 { rtfDefFont, -1, "deff", 0 },
2443 { 0, -1, (char *) NULL, 0 }
2448 * Initialize lookup table hash values. Only need to do this once.
2451 static void LookupInit()
2453 static int inited = 0;
2458 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2459 rp->rtfKHash = Hash (rp->rtfKStr);
2466 * Determine major and minor number of control token. If it's
2467 * not found, the class turns into rtfUnknown.
2470 static void Lookup(RTF_Info *info, char *s)
2476 ++s; /* skip over the leading \ character */
2478 for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
2480 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2482 info->rtfClass = rtfControl;
2483 info->rtfMajor = rp->rtfKMajor;
2484 info->rtfMinor = rp->rtfKMinor;
2488 info->rtfClass = rtfUnknown;
2493 * Compute hash value of symbol
2496 static int Hash(char *s)
2501 while ((c = *s++) != '\0')
2507 /* ---------------------------------------------------------------------- */
2510 * Memory allocation routines
2515 * Return pointer to block of size bytes, or NULL if there's
2516 * not enough memory available.
2518 * This is called through RTFAlloc(), a define which coerces the
2519 * argument to int. This avoids the persistent problem of allocation
2520 * failing under THINK C when a long is passed.
2523 char *_RTFAlloc(int size)
2525 return HeapAlloc(RICHED32_hHeap, 0, size);
2530 * Saves a string on the heap and returns a pointer to it.
2534 char *RTFStrSave(char *s)
2538 if ((p = RTFAlloc ((int) (strlen (s) + 1))) == (char *) NULL)
2539 return ((char *) NULL);
2540 return (strcpy (p, s));
2544 void RTFFree(char *p)
2546 if (p != (char *) NULL)
2547 HeapFree(RICHED32_hHeap, 0, p);
2551 /* ---------------------------------------------------------------------- */
2555 * Token comparison routines
2558 int RTFCheckCM(RTF_Info *info, int class, int major)
2560 return (info->rtfClass == class && info->rtfMajor == major);
2564 int RTFCheckCMM(RTF_Info *info, int class, int major, int minor)
2566 return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2570 int RTFCheckMM(RTF_Info *info, int major, int minor)
2572 return (info->rtfMajor == major && info->rtfMinor == minor);
2576 /* ---------------------------------------------------------------------- */
2579 int RTFCharToHex(char c)
2584 return (c - '0'); /* '0'..'9' */
2585 return (c - 'a' + 10); /* 'a'..'f' */
2589 int RTFHexToChar(int i)
2593 return (i - 10 + 'a');
2597 /* ---------------------------------------------------------------------- */
2600 * RTFReadOutputMap() -- Read output translation map
2604 * Read in an array describing the relation between the standard character set
2605 * and an RTF translator's corresponding output sequences. Each line consists
2606 * of a standard character name and the output sequence for that character.
2608 * outMap is an array of strings into which the sequences should be placed.
2609 * It should be declared like this in the calling program:
2611 * char *outMap[rtfSC_MaxChar];
2613 * reinit should be non-zero if outMap should be initialized
2618 int RTFReadOutputMap(RTF_Info *info, char *outMap[], int reinit)
2626 for (i = 0; i < rtfSC_MaxChar; i++)
2628 outMap[i] = (char *) NULL;
2632 for (i=0 ;i< sizeof(text_map)/sizeof(char*); i+=2)
2635 seq = text_map[i+1];
2636 stdCode = RTFStdCharCode( info, name );
2637 outMap[stdCode] = seq;
2643 /* ---------------------------------------------------------------------- */
2646 * Open a library file.
2650 void RTFSetOpenLibFileProc(RTF_Info *info, FILE *(*proc)())
2652 info->libFileOpen = proc;
2656 FILE *RTFOpenLibFile (RTF_Info *info, char *file, char *mode)
2658 if (info->libFileOpen == NULL)
2659 return ((FILE *) NULL);
2660 return ((*info->libFileOpen) (file, mode));
2664 /* ---------------------------------------------------------------------- */
2667 * Print message. Default is to send message to stderr
2668 * but this may be overridden with RTFSetMsgProc().
2670 * Message should include linefeeds as necessary. If the default
2671 * function is overridden, the overriding function may want to
2672 * map linefeeds to another line ending character or sequence if
2673 * the host system doesn't use linefeeds.
2677 void RTFMsg (RTF_Info *info, char *fmt, ...)
2679 char buf[rtfBufSiz];
2682 va_start (args,fmt);
2683 vsprintf (buf, fmt, args);
2685 MESSAGE( "%s", buf);
2689 /* ---------------------------------------------------------------------- */
2693 * Process termination. Print error message and exit. Also prints
2694 * current token, and current input line number and position within
2695 * line if any input has been read from the current file. (No input
2696 * has been read if prevChar is EOF).
2699 static void DefaultPanicProc(RTF_Info *info, char *s)
2707 void RTFPanic(RTF_Info *info, char *fmt, ...)
2709 char buf[rtfBufSiz];
2712 va_start (args,fmt);
2713 vsprintf (buf, fmt, args);
2715 (void) strcat (buf, "\n");
2716 if (info->prevChar != EOF && info->rtfTextBuf != (char *) NULL)
2718 sprintf (buf + strlen (buf),
2719 "Last token read was \"%s\" near line %ld, position %d.\n",
2720 info->rtfTextBuf, info->rtfLineNum, info->rtfLinePos);
2722 DefaultPanicProc(info, buf);