Fixes for -Wmissing-declaration and -Wwrite-string warnings.
[wine] / dlls / riched20 / reader.c
1 /*
2  * WINE RTF file reader
3  *
4  * Portions Copyright 2004 Mike McCormack for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 /*
22  * Derived from RTF Tools by Paul DuBois (dubois@primate.wisc.edu)
23  * Homepage: http://www.snake.net/software/RTF/
24  * Original license follows:
25  */
26
27 /*
28  * reader.c - RTF file reader.  Release 1.10.
29  *
30  * ....
31  *
32  * Author: Paul DuBois  dubois@primate.wisc.edu
33  *
34  * This software may be redistributed without restriction and used for
35  * any purpose whatsoever.
36  */
37
38 #include <stdio.h>
39 #include <ctype.h>
40 #include <string.h>
41 #include <stdarg.h>
42 #include <stdlib.h>
43 #include <assert.h>
44
45 #include "windef.h"
46 #include "winbase.h"
47 #include "wine/debug.h"
48
49 #include "editor.h"
50 #include "rtf.h"
51
52 WINE_DEFAULT_DEBUG_CHANNEL(richedit);
53
54 extern HANDLE me_heap;
55
56 static int      _RTFGetChar(RTF_Info *);
57 static void     _RTFGetToken (RTF_Info *);
58 static void     _RTFGetToken2 (RTF_Info *);
59 static int      GetChar (RTF_Info *);
60 static void     ReadFontTbl (RTF_Info *);
61 static void     ReadColorTbl (RTF_Info *);
62 static void     ReadStyleSheet (RTF_Info *);
63 static void     ReadInfoGroup (RTF_Info *);
64 static void     ReadPictGroup (RTF_Info *);
65 static void     ReadObjGroup (RTF_Info *);
66 static void     LookupInit (void);
67 static void     Lookup (RTF_Info *, char *);
68 static int      Hash (char*);
69
70 static void     CharAttr(RTF_Info *info);
71 static void     CharSet(RTF_Info *info);
72 static void     DocAttr(RTF_Info *info);
73
74 static void     RTFFlushCPOutputBuffer(RTF_Info *info);
75 static void     RTFPutCodePageChar(RTF_Info *info, int c);
76
77 /* ---------------------------------------------------------------------- */
78
79 /*
80  * Memory allocation routines
81  */
82
83
84 /*
85  * Return pointer to block of size bytes, or NULL if there's
86  * not enough memory available.
87  */
88 static inline void *RTFAlloc(int size)
89 {
90         return HeapAlloc(me_heap, 0, size);
91 }
92
93
94 static inline void * RTFReAlloc(void *ptr, int size)
95 {
96         return HeapReAlloc(me_heap, 0, ptr, size);
97 }
98
99
100 /*
101  * Saves a string on the heap and returns a pointer to it.
102  */
103 static inline char *RTFStrSave(char *s)
104 {
105         char    *p;
106
107         p = RTFAlloc (lstrlenA(s) + 1);
108         if (p == NULL)
109                 return NULL;
110         return lstrcpyA (p, s);
111 }
112
113
114 static inline void RTFFree(void *p)
115 {
116         HeapFree(me_heap, 0, p);
117 }
118
119
120 /* ---------------------------------------------------------------------- */
121
122
123 int _RTFGetChar(RTF_Info *info)
124 {
125         int ch;
126         ME_InStream *stream = info->stream;
127
128         TRACE("\n");
129
130         /* if the last buffer wasn't full, it's EOF */
131         if (stream->dwSize > 0 && stream->dwSize == stream->dwUsed
132             && stream->dwSize < sizeof(stream->buffer))
133                 return EOF;
134         if (stream->dwSize <= stream->dwUsed)
135         {
136                 ME_StreamInFill(stream);
137                 /* if error, it's EOF */
138                 if (stream->editstream->dwError)
139                         return EOF;
140                 /* if no bytes read, it's EOF */
141                 if (stream->dwSize == 0)
142                         return EOF;
143         }
144         ch = stream->buffer[stream->dwUsed++];
145         if (!ch)
146                  return EOF;
147         return ch;
148 }
149
150 void RTFSetEditStream(RTF_Info *info, ME_InStream *stream)
151 {
152         TRACE("\n");
153
154         info->stream = stream;
155 }
156
157 static void
158 RTFDestroyAttrs(RTF_Info *info)
159 {
160         RTFColor        *cp;
161         RTFFont         *fp;
162         RTFStyle        *sp;
163         RTFStyleElt     *eltList, *ep;
164
165         while (info->fontList)
166         {
167                 fp = info->fontList->rtfNextFont;
168                 RTFFree (info->fontList->rtfFName);
169                 RTFFree (info->fontList);
170                 info->fontList = fp;
171         }
172         while (info->colorList)
173         {
174                 cp = info->colorList->rtfNextColor;
175                 RTFFree (info->colorList);
176                 info->colorList = cp;
177         }
178         while (info->styleList)
179         {
180                 sp = info->styleList->rtfNextStyle;
181                 eltList = info->styleList->rtfSSEList;
182                 while (eltList)
183                 {
184                         ep = eltList->rtfNextSE;
185                         RTFFree (eltList->rtfSEText);
186                         RTFFree (eltList);
187                         eltList = ep;
188                 }
189                 RTFFree (info->styleList->rtfSName);
190                 RTFFree (info->styleList);
191                 info->styleList = sp;
192         }
193 }
194
195
196 void
197 RTFDestroy(RTF_Info *info)
198 {
199         if (info->rtfTextBuf)
200         {
201                 RTFFree(info->rtfTextBuf);
202                 RTFFree(info->pushedTextBuf);
203         }
204         RTFDestroyAttrs(info);
205         RTFFree(info->cpOutputBuffer);
206 }
207
208
209 /*
210  * Initialize the reader.  This may be called multiple times,
211  * to read multiple files.  The only thing not reset is the input
212  * stream; that must be done with RTFSetStream().
213  */
214
215 void RTFInit(RTF_Info *info)
216 {
217         int     i;
218
219         TRACE("\n");
220
221         if (info->rtfTextBuf == NULL)   /* initialize the text buffers */
222         {
223                 info->rtfTextBuf = RTFAlloc (rtfBufSiz);
224                 info->pushedTextBuf = RTFAlloc (rtfBufSiz);
225                 if (info->rtfTextBuf == NULL || info->pushedTextBuf == NULL)
226                         RTFPanic (info,"Cannot allocate text buffers.");
227                 info->rtfTextBuf[0] = info->pushedTextBuf[0] = '\0';
228         }
229
230         RTFFree (info->inputName);
231         RTFFree (info->outputName);
232         info->inputName = info->outputName = NULL;
233
234         /* initialize lookup table */
235         LookupInit ();
236
237         for (i = 0; i < rtfMaxClass; i++)
238                 RTFSetClassCallback (info, i, NULL);
239         for (i = 0; i < rtfMaxDestination; i++)
240                 RTFSetDestinationCallback (info, i, NULL);
241
242         /* install built-in destination readers */
243         RTFSetDestinationCallback (info, rtfFontTbl, ReadFontTbl);
244         RTFSetDestinationCallback (info, rtfColorTbl, ReadColorTbl);
245         RTFSetDestinationCallback (info, rtfStyleSheet, ReadStyleSheet);
246         RTFSetDestinationCallback (info, rtfInfo, ReadInfoGroup);
247         RTFSetDestinationCallback (info, rtfPict, ReadPictGroup);
248         RTFSetDestinationCallback (info, rtfObject, ReadObjGroup);
249
250
251         RTFSetReadHook (info, NULL);
252
253         /* dump old lists if necessary */
254
255         RTFDestroyAttrs(info);
256
257         info->ansiCodePage = 1252; /* Latin-1; actually unused */
258         info->unicodeLength = 1; /* \uc1 is the default */
259         info->codePage = info->ansiCodePage;
260
261         info->rtfClass = -1;
262         info->pushedClass = -1;
263         info->pushedChar = EOF;
264
265         info->rtfLineNum = 0;
266         info->rtfLinePos = 0;
267         info->prevChar = EOF;
268         info->bumpLine = 0;
269
270         info->dwCPOutputCount = 0;
271         if (!info->cpOutputBuffer)
272         {
273                 info->dwMaxCPOutputCount = 0x1000;
274                 info->cpOutputBuffer = RTFAlloc(info->dwMaxCPOutputCount);
275         }
276 }
277
278 /*
279  * Set or get the input or output file name.  These are never guaranteed
280  * to be accurate, only insofar as the calling program makes them so.
281  */
282
283 void RTFSetInputName(RTF_Info *info, char *name)
284 {
285         TRACE("\n");
286
287         info->inputName = RTFStrSave (name);
288         if (info->inputName == NULL)
289                 RTFPanic (info,"RTFSetInputName: out of memory");
290 }
291
292
293 char *RTFGetInputName(RTF_Info *info)
294 {
295         return (info->inputName);
296 }
297
298
299 void RTFSetOutputName(RTF_Info *info, char *name)
300 {
301         TRACE("\n");
302
303         info->outputName = RTFStrSave (name);
304         if (info->outputName == NULL)
305                 RTFPanic (info, "RTFSetOutputName: out of memory");
306 }
307
308
309 char *RTFGetOutputName(RTF_Info *info)
310 {
311         return (info->outputName);
312 }
313
314
315
316 /* ---------------------------------------------------------------------- */
317
318 /*
319  * Callback table manipulation routines
320  */
321
322
323 /*
324  * Install or return a writer callback for a token class
325  */
326
327 void RTFSetClassCallback(RTF_Info *info, int class, RTFFuncPtr callback)
328 {
329         if (class >= 0 && class < rtfMaxClass)
330                 info->ccb[class] = callback;
331 }
332
333
334 RTFFuncPtr RTFGetClassCallback(RTF_Info *info, int class)
335 {
336         if (class >= 0 && class < rtfMaxClass)
337                 return info->ccb[class];
338         return NULL;
339 }
340
341
342 /*
343  * Install or return a writer callback for a destination type
344  */
345
346 void RTFSetDestinationCallback(RTF_Info *info, int dest, RTFFuncPtr callback)
347 {
348         if (dest >= 0 && dest < rtfMaxDestination)
349                 info->dcb[dest] = callback;
350 }
351
352
353 RTFFuncPtr RTFGetDestinationCallback(RTF_Info *info, int dest)
354 {
355         if (dest >= 0 && dest < rtfMaxDestination)
356                 return info->dcb[dest];
357         return NULL;
358 }
359
360
361 /* ---------------------------------------------------------------------- */
362
363 /*
364  * Token reading routines
365  */
366
367
368 /*
369  * Read the input stream, invoking the writer's callbacks
370  * where appropriate.
371  */
372
373 void RTFRead(RTF_Info *info)
374 {
375         while (RTFGetToken (info) != rtfEOF)
376                 RTFRouteToken (info);
377 }
378
379
380 /*
381  * Route a token.  If it's a destination for which a reader is
382  * installed, process the destination internally, otherwise
383  * pass the token to the writer's class callback.
384  */
385
386 void RTFRouteToken(RTF_Info *info)
387 {
388         RTFFuncPtr      p;
389
390         TRACE("\n");
391
392         if (info->rtfClass < 0 || info->rtfClass >= rtfMaxClass)        /* watchdog */
393         {
394                 RTFPanic (info,"Unknown class %d: %s (reader malfunction)",
395                                                         info->rtfClass, info->rtfTextBuf);
396         }
397         if (RTFCheckCM (info, rtfControl, rtfDestination))
398         {
399                 /* invoke destination-specific callback if there is one */
400                 p = RTFGetDestinationCallback (info, info->rtfMinor);
401                 if (p != NULL)
402                 {
403                         (*p) (info);
404                         return;
405                 }
406         }
407         /* invoke class callback if there is one */
408         p = RTFGetClassCallback (info, info->rtfClass);
409         if (p != NULL)
410                 (*p) (info);
411 }
412
413
414 /*
415  * Skip to the end of the current group.  When this returns,
416  * writers that maintain a state stack may want to call their
417  * state unstacker; global vars will still be set to the group's
418  * closing brace.
419  */
420
421 void RTFSkipGroup(RTF_Info *info)
422 {
423         int     level = 1;
424
425         TRACE("\n");
426
427         while (RTFGetToken (info) != rtfEOF)
428         {
429                 if (info->rtfClass == rtfGroup)
430                 {
431                         if (info->rtfMajor == rtfBeginGroup)
432                                 ++level;
433                         else if (info->rtfMajor == rtfEndGroup)
434                         {
435                                 if (--level < 1)
436                                         break;  /* end of initial group */
437                         }
438                 }
439         }
440 }
441
442
443 /*
444  * Read one token.  Call the read hook if there is one.  The
445  * token class is the return value.  Returns rtfEOF when there
446  * are no more tokens.
447  */
448
449 int RTFGetToken(RTF_Info *info)
450 {
451         RTFFuncPtr      p;
452
453         TRACE("\n");
454
455         for (;;)
456         {
457                 _RTFGetToken (info);
458                 p = RTFGetReadHook (info);
459                 if (p != NULL)
460                         (*p) (info);    /* give read hook a look at token */
461
462                 /* Silently discard newlines, carriage returns, nulls.  */
463                 if (!(info->rtfClass == rtfText && info->rtfFormat != SF_TEXT
464                         && (info->rtfMajor == '\r' || info->rtfMajor == '\n' || info->rtfMajor == '\0')))
465                         break;
466         }
467         return (info->rtfClass);
468 }
469
470
471 /*
472  * Install or return a token reader hook.
473  */
474
475 void RTFSetReadHook(RTF_Info *info, RTFFuncPtr f)
476 {
477         info->readHook = f;
478 }
479
480
481 RTFFuncPtr RTFGetReadHook(RTF_Info *info)
482 {
483         return (info->readHook);
484 }
485
486
487 void RTFUngetToken(RTF_Info *info)
488 {
489         TRACE("\n");
490
491         if (info->pushedClass >= 0)     /* there's already an ungotten token */
492                 RTFPanic (info,"cannot unget two tokens");
493         if (info->rtfClass < 0)
494                 RTFPanic (info,"no token to unget");
495         info->pushedClass = info->rtfClass;
496         info->pushedMajor = info->rtfMajor;
497         info->pushedMinor = info->rtfMinor;
498         info->pushedParam = info->rtfParam;
499         lstrcpyA (info->pushedTextBuf, info->rtfTextBuf);
500 }
501
502
503 int RTFPeekToken(RTF_Info *info)
504 {
505         _RTFGetToken (info);
506         RTFUngetToken (info);
507         return (info->rtfClass);
508 }
509
510
511 static void _RTFGetToken(RTF_Info *info)
512 {
513         TRACE("\n");
514
515         if (info->rtfFormat == SF_TEXT)
516         {
517                 info->rtfMajor = GetChar (info);
518                 info->rtfMinor = 0;
519                 info->rtfParam = rtfNoParam;
520                 info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
521                 if (info->rtfMajor == EOF)
522                         info->rtfClass = rtfEOF;
523                 else
524                         info->rtfClass = rtfText;
525                 return;
526         }
527
528         /* first check for pushed token from RTFUngetToken() */
529
530         if (info->pushedClass >= 0)
531         {
532                 info->rtfClass = info->pushedClass;
533                 info->rtfMajor = info->pushedMajor;
534                 info->rtfMinor = info->pushedMinor;
535                 info->rtfParam = info->pushedParam;
536                 lstrcpyA (info->rtfTextBuf, info->pushedTextBuf);
537                 info->rtfTextLen = lstrlenA(info->rtfTextBuf);
538                 info->pushedClass = -1;
539                 return;
540         }
541
542         /*
543          * Beyond this point, no token is ever seen twice, which is
544          * important, e.g., for making sure no "}" pops the font stack twice.
545          */
546
547         _RTFGetToken2 (info);
548 }
549
550
551 int
552 RTFCharSetToCodePage(RTF_Info *info, int charset)
553 {
554         switch (charset)
555         {
556                 case ANSI_CHARSET:
557                         return 1252;
558                 case DEFAULT_CHARSET:
559                         return CP_ACP;
560                 case SYMBOL_CHARSET:
561                         return CP_SYMBOL;
562                 case MAC_CHARSET:
563                         return CP_MACCP;
564                 case SHIFTJIS_CHARSET:
565                         return 932;
566                 case HANGEUL_CHARSET:
567                         return 949;
568                 case JOHAB_CHARSET:
569                         return 1361;
570                 case GB2312_CHARSET:
571                         return 936;
572                 case CHINESEBIG5_CHARSET:
573                         return 950;
574                 case GREEK_CHARSET:
575                         return 1253;
576                 case TURKISH_CHARSET:
577                         return 1254;
578                 case VIETNAMESE_CHARSET:
579                         return 1258;
580                 case HEBREW_CHARSET:
581                         return 1255;
582                 case ARABIC_CHARSET:
583                         return 1256;
584                 case BALTIC_CHARSET:
585                         return 1257;
586                 case RUSSIAN_CHARSET:
587                         return 1251;
588                 case THAI_CHARSET:
589                         return 874;
590                 case EASTEUROPE_CHARSET:
591                         return 1250;
592                 case OEM_CHARSET:
593                         return CP_OEMCP;
594                 default:
595                 {
596                         CHARSETINFO csi;
597                         DWORD n = charset;
598                         
599                         /* FIXME: TranslateCharsetInfo does not work as good as it
600                          * should, so let's use it only when all else fails */
601                         if (!TranslateCharsetInfo(&n, &csi, TCI_SRCCHARSET))
602                                 RTFMsg(info, "%s: unknown charset %u\n", __FUNCTION__, charset);
603                         else
604                                 return csi.ciACP;
605                 }
606         }
607         return 0;
608 }
609
610
611 /* this shouldn't be called anywhere but from _RTFGetToken() */
612
613 static void _RTFGetToken2(RTF_Info *info)
614 {
615         int     sign;
616         int     c;
617
618         TRACE("\n");
619
620         /* initialize token vars */
621
622         info->rtfClass = rtfUnknown;
623         info->rtfParam = rtfNoParam;
624         info->rtfTextBuf[info->rtfTextLen = 0] = '\0';
625
626         /* get first character, which may be a pushback from previous token */
627
628         if (info->pushedChar != EOF)
629         {
630                 c = info->pushedChar;
631                 info->rtfTextBuf[info->rtfTextLen++] = c;
632                 info->rtfTextBuf[info->rtfTextLen] = '\0';
633                 info->pushedChar = EOF;
634         }
635         else if ((c = GetChar (info)) == EOF)
636         {
637                 info->rtfClass = rtfEOF;
638                 return;
639         }
640
641         if (c == '{')
642         {
643                 info->rtfClass = rtfGroup;
644                 info->rtfMajor = rtfBeginGroup;
645                 return;
646         }
647         if (c == '}')
648         {
649                 info->rtfClass = rtfGroup;
650                 info->rtfMajor = rtfEndGroup;
651                 return;
652         }
653         if (c != '\\')
654         {
655                 /*
656                  * Two possibilities here:
657                  * 1) ASCII 9, effectively like \tab control symbol
658                  * 2) literal text char
659                  */
660                 if (c == '\t')                  /* ASCII 9 */
661                 {
662                         info->rtfClass = rtfControl;
663                         info->rtfMajor = rtfSpecialChar;
664                         info->rtfMinor = rtfTab;
665                 }
666                 else
667                 {
668                         info->rtfClass = rtfText;
669                         info->rtfMajor = c;
670                 }
671                 return;
672         }
673         if ((c = GetChar (info)) == EOF)
674         {
675                 /* early eof, whoops (class is rtfUnknown) */
676                 return;
677         }
678         if (!isalpha (c))
679         {
680                 /*
681                  * Three possibilities here:
682                  * 1) hex encoded text char, e.g., \'d5, \'d3
683                  * 2) special escaped text char, e.g., \{, \}
684                  * 3) control symbol, e.g., \_, \-, \|, \<10>
685                  */
686                 if (c == '\'')                          /* hex char */
687                 {
688                 int     c2;
689
690                         if ((c = GetChar (info)) != EOF && (c2 = GetChar (info)) != EOF)
691                         {
692                                 /* should do isxdigit check! */
693                                 info->rtfClass = rtfText;
694                                 info->rtfMajor = RTFCharToHex (c) * 16 + RTFCharToHex (c2);
695                                 return;
696                         }
697                         /* early eof, whoops (class is rtfUnknown) */
698                         return;
699                 }
700
701                 /* escaped char */
702                 /*if (index (":{}\\", c) != (char *) NULL)*/ /* escaped char */
703                 if (c == ':' || c == '{' || c == '}' || c == '\\')
704                 {
705                         info->rtfClass = rtfText;
706                         info->rtfMajor = c;
707                         return;
708                 }
709
710                 /* control symbol */
711                 Lookup (info, info->rtfTextBuf);        /* sets class, major, minor */
712                 return;
713         }
714         /* control word */
715         while (isalpha (c))
716         {
717                 if ((c = GetChar (info)) == EOF)
718                         break;
719         }
720
721         /*
722          * At this point, the control word is all collected, so the
723          * major/minor numbers are determined before the parameter
724          * (if any) is scanned.  There will be one too many characters
725          * in the buffer, though, so fix up before and restore after
726          * looking up.
727          */
728
729         if (c != EOF)
730                 info->rtfTextBuf[info->rtfTextLen-1] = '\0';
731         Lookup (info, info->rtfTextBuf);        /* sets class, major, minor */
732         if (c != EOF)
733                 info->rtfTextBuf[info->rtfTextLen-1] = c;
734
735         /*
736          * Should be looking at first digit of parameter if there
737          * is one, unless it's negative.  In that case, next char
738          * is '-', so need to gobble next char, and remember sign.
739          */
740
741         sign = 1;
742         if (c == '-')
743         {
744                 sign = -1;
745                 c = GetChar (info);
746         }
747         if (c != EOF && isdigit (c))
748         {
749                 info->rtfParam = 0;
750                 while (isdigit (c))     /* gobble parameter */
751                 {
752                         info->rtfParam = info->rtfParam * 10 + c - '0';
753                         if ((c = GetChar (info)) == EOF)
754                                 break;
755                 }
756                 info->rtfParam *= sign;
757         }
758         /*
759          * If control symbol delimiter was a blank, gobble it.
760          * Otherwise the character is first char of next token, so
761          * push it back for next call.  In either case, delete the
762          * delimiter from the token buffer.
763          */
764         if (c != EOF)
765         {
766                 if (c != ' ')
767                         info->pushedChar = c;
768                 info->rtfTextBuf[--info->rtfTextLen] = '\0';
769         }
770 }
771
772
773 /*
774  * Read the next character from the input.  This handles setting the
775  * current line and position-within-line variables.  Those variable are
776  * set correctly whether lines end with CR, LF, or CRLF (the last being
777  * the tricky case).
778  *
779  * bumpLine indicates whether the line number should be incremented on
780  * the *next* input character.
781  */
782
783
784 static int GetChar(RTF_Info *info)
785 {
786         int     c;
787         int     oldBumpLine;
788
789         TRACE("\n");
790
791         if ((c = _RTFGetChar(info)) != EOF)
792         {
793                 info->rtfTextBuf[info->rtfTextLen++] = c;
794                 info->rtfTextBuf[info->rtfTextLen] = '\0';
795         }
796         if (info->prevChar == EOF)
797                 info->bumpLine = 1;
798         oldBumpLine = info->bumpLine;   /* non-zero if prev char was line ending */
799         info->bumpLine = 0;
800         if (c == '\r')
801                 info->bumpLine = 1;
802         else if (c == '\n')
803         {
804                 info->bumpLine = 1;
805                 if (info->prevChar == '\r')             /* oops, previous \r wasn't */
806                         oldBumpLine = 0;        /* really a line ending */
807         }
808         ++info->rtfLinePos;
809         if (oldBumpLine)        /* were we supposed to increment the */
810         {                       /* line count on this char? */
811                 ++info->rtfLineNum;
812                 info->rtfLinePos = 1;
813         }
814         info->prevChar = c;
815         return (c);
816 }
817
818
819 /*
820  * Synthesize a token by setting the global variables to the
821  * values supplied.  Typically this is followed with a call
822  * to RTFRouteToken().
823  *
824  * If a param value other than rtfNoParam is passed, it becomes
825  * part of the token text.
826  */
827
828 void RTFSetToken(RTF_Info *info, int class, int major, int minor, int param, const char *text)
829 {
830         TRACE("\n");
831
832         info->rtfClass = class;
833         info->rtfMajor = major;
834         info->rtfMinor = minor;
835         info->rtfParam = param;
836         if (param == rtfNoParam)
837                 lstrcpyA(info->rtfTextBuf, text);
838         else
839                 sprintf (info->rtfTextBuf, "%s%d", text, param);
840         info->rtfTextLen = lstrlenA (info->rtfTextBuf);
841 }
842
843
844 /* ---------------------------------------------------------------------- */
845
846 /*
847  * Special destination readers.  They gobble the destination so the
848  * writer doesn't have to deal with them.  That's wrong for any
849  * translator that wants to process any of these itself.  In that
850  * case, these readers should be overridden by installing a different
851  * destination callback.
852  *
853  * NOTE: The last token read by each of these reader will be the
854  * destination's terminating '}', which will then be the current token.
855  * That '}' token is passed to RTFRouteToken() - the writer has already
856  * seen the '{' that began the destination group, and may have pushed a
857  * state; it also needs to know at the end of the group that a state
858  * should be popped.
859  *
860  * It's important that rtf.h and the control token lookup table list
861  * as many symbols as possible, because these destination readers
862  * unfortunately make strict assumptions about the input they expect,
863  * and a token of class rtfUnknown will throw them off easily.
864  */
865
866
867 /*
868  * Read { \fonttbl ... } destination.  Old font tables don't have
869  * braces around each table entry; try to adjust for that.
870  */
871
872 static void ReadFontTbl(RTF_Info *info)
873 {
874         RTFFont         *fp = NULL;
875         char            buf[rtfBufSiz], *bp;
876         int             old = -1;
877         const char      *fn = "ReadFontTbl";
878
879         TRACE("\n");
880
881         for (;;)
882         {
883                 RTFGetToken (info);
884                 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
885                         break;
886                 if (old < 0)            /* first entry - determine tbl type */
887                 {
888                         if (RTFCheckCMM (info, rtfControl, rtfCharAttr, rtfFontNum))
889                                 old = 1;        /* no brace */
890                         else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
891                                 old = 0;        /* brace */
892                         else                    /* can't tell! */
893                                 RTFPanic (info, "%s: Cannot determine format", fn);
894                 }
895                 if (old == 0)           /* need to find "{" here */
896                 {
897                         if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
898                                 RTFPanic (info, "%s: missing \"{\"", fn);
899                         RTFGetToken (info);     /* yes, skip to next token */
900                 }
901                 fp = New (RTFFont);
902                 if (fp == NULL)
903                         RTFPanic (info, "%s: cannot allocate font entry", fn);
904
905                 fp->rtfNextFont = info->fontList;
906                 info->fontList = fp;
907
908                 fp->rtfFName = NULL;
909                 fp->rtfFAltName = NULL;
910                 fp->rtfFNum = -1;
911                 fp->rtfFFamily = 0;
912                 fp->rtfFCharSet = DEFAULT_CHARSET; /* 1 */
913                 fp->rtfFPitch = 0;
914                 fp->rtfFType = 0;
915                 fp->rtfFCodePage = CP_ACP;
916
917                 while (info->rtfClass != rtfEOF
918                        && !RTFCheckCM (info, rtfText, ';')
919                        && !RTFCheckCM (info, rtfGroup, rtfEndGroup))
920                 {
921                         if (info->rtfClass == rtfControl)
922                         {
923                                 switch (info->rtfMajor)
924                                 {
925                                 default:
926                                         /* ignore token but announce it */
927                                         RTFMsg (info,"%s: unknown token \"%s\"\n",
928                                                         fn, info->rtfTextBuf);
929                                         break;
930                                 case rtfFontFamily:
931                                         fp->rtfFFamily = info->rtfMinor;
932                                         break;
933                                 case rtfCharAttr:
934                                         switch (info->rtfMinor)
935                                         {
936                                         default:
937                                                 break;  /* ignore unknown? */
938                                         case rtfFontNum:
939                                                 fp->rtfFNum = info->rtfParam;
940                                                 break;
941                                         }
942                                         break;
943                                 case rtfFontAttr:
944                                         switch (info->rtfMinor)
945                                         {
946                                         default:
947                                                 break;  /* ignore unknown? */
948                                         case rtfFontCharSet:
949                                                 fp->rtfFCharSet = info->rtfParam;
950                                                 if (!fp->rtfFCodePage)
951                                                         fp->rtfFCodePage = RTFCharSetToCodePage(info, info->rtfParam);
952                                                 break;
953                                         case rtfFontPitch:
954                                                 fp->rtfFPitch = info->rtfParam;
955                                                 break;
956                                         case rtfFontCodePage:
957                                                 fp->rtfFCodePage = info->rtfParam;
958                                                 break;
959                                         case rtfFTypeNil:
960                                         case rtfFTypeTrueType:
961                                                 fp->rtfFType = info->rtfParam;
962                                                 break;
963                                         }
964                                         break;
965                                 }
966                         }
967                         else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))    /* dest */
968                         {
969                                 RTFSkipGroup (info);    /* ignore for now */
970                         }
971                         else if (info->rtfClass == rtfText)     /* font name */
972                         {
973                                 bp = buf;
974                                 while (info->rtfClass == rtfText
975                                         && !RTFCheckCM (info, rtfText, ';'))
976                                 {
977                                         *bp++ = info->rtfMajor;
978                                         RTFGetToken (info);
979                                 }
980
981                                 /* FIX: in some cases the <fontinfo> isn't finished with a semi-column */
982                                 if(RTFCheckCM (info, rtfGroup, rtfEndGroup))
983                                 {
984                                         RTFUngetToken (info);
985                                 }
986                                 *bp = '\0';
987                                 fp->rtfFName = RTFStrSave (buf);
988                                 if (fp->rtfFName == NULL)
989                                         RTFPanic (info, "%s: cannot allocate font name", fn);
990                                 /* already have next token; don't read one */
991                                 /* at bottom of loop */
992                                 continue;
993                         }
994                         else
995                         {
996                                 /* ignore token but announce it */
997                                 RTFMsg (info, "%s: unknown token \"%s\"\n",
998                                                         fn,info->rtfTextBuf);
999                         }
1000                         RTFGetToken (info);
1001                 }
1002                 if (old == 0)   /* need to see "}" here */
1003                 {
1004                         RTFGetToken (info);
1005                         if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1006                                 RTFPanic (info, "%s: missing \"}\"", fn);
1007                 }
1008         }
1009         if (fp->rtfFNum == -1)
1010                 RTFPanic (info,"%s: missing font number", fn);
1011 /*
1012  * Could check other pieces of structure here, too, I suppose.
1013  */
1014         RTFRouteToken (info);   /* feed "}" back to router */
1015 }
1016
1017
1018 /*
1019  * The color table entries have color values of -1 if
1020  * the default color should be used for the entry (only
1021  * a semi-colon is given in the definition, no color values).
1022  * There will be a problem if a partial entry (1 or 2 but
1023  * not 3 color values) is given.  The possibility is ignored
1024  * here.
1025  */
1026
1027 static void ReadColorTbl(RTF_Info *info)
1028 {
1029         RTFColor        *cp;
1030         int             cnum = 0;
1031         const char      *fn = "ReadColorTbl";
1032
1033         TRACE("\n");
1034
1035         for (;;)
1036         {
1037                 RTFGetToken (info);
1038                 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1039                         break;
1040                 cp = New (RTFColor);
1041                 if (cp == NULL)
1042                         RTFPanic (info,"%s: cannot allocate color entry", fn);
1043                 cp->rtfCNum = cnum++;
1044                 cp->rtfCRed = cp->rtfCGreen = cp->rtfCBlue = -1;
1045                 cp->rtfNextColor = info->colorList;
1046                 info->colorList = cp;
1047                 while (RTFCheckCM (info, rtfControl, rtfColorName))
1048                 {
1049                         switch (info->rtfMinor)
1050                         {
1051                         case rtfRed:    cp->rtfCRed = info->rtfParam; break;
1052                         case rtfGreen:  cp->rtfCGreen = info->rtfParam; break;
1053                         case rtfBlue:   cp->rtfCBlue = info->rtfParam; break;
1054                         }
1055                         RTFGetToken (info);
1056                 }
1057                 if (!RTFCheckCM (info, rtfText, ';'))
1058                         RTFPanic (info,"%s: malformed entry", fn);
1059         }
1060         RTFRouteToken (info);   /* feed "}" back to router */
1061 }
1062
1063
1064 /*
1065  * The "Normal" style definition doesn't contain any style number,
1066  * all others do.  Normal style is given style rtfNormalStyleNum.
1067  */
1068
1069 static void ReadStyleSheet(RTF_Info *info)
1070 {
1071         RTFStyle        *sp;
1072         RTFStyleElt     *sep, *sepLast;
1073         char            buf[rtfBufSiz], *bp;
1074         const char      *fn = "ReadStyleSheet";
1075
1076         TRACE("\n");
1077
1078         for (;;)
1079         {
1080                 RTFGetToken (info);
1081                 if (RTFCheckCM (info, rtfGroup, rtfEndGroup))
1082                         break;
1083                 sp = New (RTFStyle);
1084                 if (sp == NULL)
1085                         RTFPanic (info,"%s: cannot allocate stylesheet entry", fn);
1086                 sp->rtfSName = NULL;
1087                 sp->rtfSNum = -1;
1088                 sp->rtfSType = rtfParStyle;
1089                 sp->rtfSAdditive = 0;
1090                 sp->rtfSBasedOn = rtfNoStyleNum;
1091                 sp->rtfSNextPar = -1;
1092                 sp->rtfSSEList = sepLast = NULL;
1093                 sp->rtfNextStyle = info->styleList;
1094                 sp->rtfExpanding = 0;
1095                 info->styleList = sp;
1096                 if (!RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1097                         RTFPanic (info,"%s: missing \"{\"", fn);
1098                 for (;;)
1099                 {
1100                         RTFGetToken (info);
1101                         if (info->rtfClass == rtfEOF
1102                                 || RTFCheckCM (info, rtfText, ';'))
1103                                 break;
1104                         if (info->rtfClass == rtfControl)
1105                         {
1106                                 if (RTFCheckMM (info, rtfSpecialChar, rtfOptDest))
1107                                         continue;       /* ignore "\*" */
1108                                 if (RTFCheckMM (info, rtfParAttr, rtfStyleNum))
1109                                 {
1110                                         sp->rtfSNum = info->rtfParam;
1111                                         sp->rtfSType = rtfParStyle;
1112                                         continue;
1113                                 }
1114                                 if (RTFCheckMM (info, rtfCharAttr, rtfCharStyleNum))
1115                                 {
1116                                         sp->rtfSNum = info->rtfParam;
1117                                         sp->rtfSType = rtfCharStyle;
1118                                         continue;
1119                                 }
1120                                 if (RTFCheckMM (info, rtfSectAttr, rtfSectStyleNum))
1121                                 {
1122                                         sp->rtfSNum = info->rtfParam;
1123                                         sp->rtfSType = rtfSectStyle;
1124                                         continue;
1125                                 }
1126                                 if (RTFCheckMM (info, rtfStyleAttr, rtfBasedOn))
1127                                 {
1128                                         sp->rtfSBasedOn = info->rtfParam;
1129                                         continue;
1130                                 }
1131                                 if (RTFCheckMM (info, rtfStyleAttr, rtfAdditive))
1132                                 {
1133                                         sp->rtfSAdditive = 1;
1134                                         continue;
1135                                 }
1136                                 if (RTFCheckMM (info, rtfStyleAttr, rtfNext))
1137                                 {
1138                                         sp->rtfSNextPar = info->rtfParam;
1139                                         continue;
1140                                 }
1141                                 sep = New (RTFStyleElt);
1142                                 if (sep == NULL)
1143                                         RTFPanic (info,"%s: cannot allocate style element", fn);
1144                                 sep->rtfSEClass = info->rtfClass;
1145                                 sep->rtfSEMajor = info->rtfMajor;
1146                                 sep->rtfSEMinor = info->rtfMinor;
1147                                 sep->rtfSEParam = info->rtfParam;
1148                                 sep->rtfSEText = RTFStrSave (info->rtfTextBuf);
1149                                 if (sep->rtfSEText == NULL)
1150                                         RTFPanic (info,"%s: cannot allocate style element text", fn);
1151                                 if (sepLast == NULL)
1152                                         sp->rtfSSEList = sep;   /* first element */
1153                                 else                            /* add to end */
1154                                         sepLast->rtfNextSE = sep;
1155                                 sep->rtfNextSE = NULL;
1156                                 sepLast = sep;
1157                         }
1158                         else if (RTFCheckCM (info, rtfGroup, rtfBeginGroup))
1159                         {
1160                                 /*
1161                                  * This passes over "{\*\keycode ... }, among
1162                                  * other things. A temporary (perhaps) hack.
1163                                  */
1164                                 RTFSkipGroup (info);
1165                                 continue;
1166                         }
1167                         else if (info->rtfClass == rtfText)     /* style name */
1168                         {
1169                                 bp = buf;
1170                                 while (info->rtfClass == rtfText)
1171                                 {
1172                                         if (info->rtfMajor == ';')
1173                                         {
1174                                                 /* put back for "for" loop */
1175                                                 RTFUngetToken (info);
1176                                                 break;
1177                                         }
1178                                         *bp++ = info->rtfMajor;
1179                                         RTFGetToken (info);
1180                                 }
1181                                 *bp = '\0';
1182                                 sp->rtfSName = RTFStrSave (buf);
1183                                 if (sp->rtfSName == NULL)
1184                                         RTFPanic (info, "%s: cannot allocate style name", fn);
1185                         }
1186                         else            /* unrecognized */
1187                         {
1188                                 /* ignore token but announce it */
1189                                 RTFMsg (info, "%s: unknown token \"%s\"\n",
1190                                                         fn, info->rtfTextBuf);
1191                         }
1192                 }
1193                 RTFGetToken (info);
1194                 if (!RTFCheckCM (info, rtfGroup, rtfEndGroup))
1195                         RTFPanic (info, "%s: missing \"}\"", fn);
1196
1197                 /*
1198                  * Check over the style structure.  A name is a must.
1199                  * If no style number was specified, check whether it's the
1200                  * Normal style (in which case it's given style number
1201                  * rtfNormalStyleNum).  Note that some "normal" style names
1202                  * just begin with "Normal" and can have other stuff following,
1203                  * e.g., "Normal,Times 10 point".  Ugh.
1204                  *
1205                  * Some German RTF writers use "Standard" instead of "Normal".
1206                  */
1207                 if (sp->rtfSName == NULL)
1208                         RTFPanic (info,"%s: missing style name", fn);
1209                 if (sp->rtfSNum < 0)
1210                 {
1211                         if (strncmp (buf, "Normal", 6) != 0
1212                                 && strncmp (buf, "Standard", 8) != 0)
1213                                 RTFPanic (info,"%s: missing style number", fn);
1214                         sp->rtfSNum = rtfNormalStyleNum;
1215                 }
1216                 if (sp->rtfSNextPar == -1)      /* if \snext not given, */
1217                         sp->rtfSNextPar = sp->rtfSNum;  /* next is itself */
1218         }
1219         RTFRouteToken (info);   /* feed "}" back to router */
1220 }
1221
1222
1223 static void ReadInfoGroup(RTF_Info *info)
1224 {
1225         RTFSkipGroup (info);
1226         RTFRouteToken (info);   /* feed "}" back to router */
1227 }
1228
1229
1230 static void ReadPictGroup(RTF_Info *info)
1231 {
1232         RTFSkipGroup (info);
1233         RTFRouteToken (info);   /* feed "}" back to router */
1234 }
1235
1236
1237 static void ReadObjGroup(RTF_Info *info)
1238 {
1239         RTFSkipGroup (info);
1240         RTFRouteToken (info);   /* feed "}" back to router */
1241 }
1242
1243
1244 /* ---------------------------------------------------------------------- */
1245
1246 /*
1247  * Routines to return pieces of stylesheet, or font or color tables.
1248  * References to style 0 are mapped onto the Normal style.
1249  */
1250
1251
1252 RTFStyle *RTFGetStyle(RTF_Info *info, int num)
1253 {
1254         RTFStyle        *s;
1255
1256         if (num == -1)
1257                 return (info->styleList);
1258         for (s = info->styleList; s != NULL; s = s->rtfNextStyle)
1259         {
1260                 if (s->rtfSNum == num)
1261                         break;
1262         }
1263         return (s);             /* NULL if not found */
1264 }
1265
1266
1267 RTFFont *RTFGetFont(RTF_Info *info, int num)
1268 {
1269         RTFFont *f;
1270
1271         if (num == -1)
1272                 return (info->fontList);
1273         for (f = info->fontList; f != NULL; f = f->rtfNextFont)
1274         {
1275                 if (f->rtfFNum == num)
1276                         break;
1277         }
1278         return (f);             /* NULL if not found */
1279 }
1280
1281
1282 RTFColor *RTFGetColor(RTF_Info *info, int num)
1283 {
1284         RTFColor        *c;
1285
1286         if (num == -1)
1287                 return (info->colorList);
1288         for (c = info->colorList; c != NULL; c = c->rtfNextColor)
1289         {
1290                 if (c->rtfCNum == num)
1291                         break;
1292         }
1293         return (c);             /* NULL if not found */
1294 }
1295
1296
1297 /* ---------------------------------------------------------------------- */
1298
1299
1300 /*
1301  * Expand style n, if there is such a style.
1302  */
1303
1304 void RTFExpandStyle(RTF_Info *info, int n)
1305 {
1306         RTFStyle        *s;
1307         RTFStyleElt     *se;
1308
1309         TRACE("\n");
1310
1311         if (n == -1)
1312                 return;
1313         s = RTFGetStyle (info, n);
1314         if (s == NULL)
1315                 return;
1316         if (s->rtfExpanding != 0)
1317                 RTFPanic (info,"Style expansion loop, style %d", n);
1318         s->rtfExpanding = 1;    /* set expansion flag for loop detection */
1319         /*
1320          * Expand "based-on" style (unless it's the same as the current
1321          * style -- Normal style usually gives itself as its own based-on
1322          * style).  Based-on style expansion is done by synthesizing
1323          * the token that the writer needs to see in order to trigger
1324          * another style expansion, and feeding to token back through
1325          * the router so the writer sees it.
1326          */
1327         if (n != s->rtfSBasedOn)
1328         {
1329                 RTFSetToken (info, rtfControl, rtfParAttr, rtfStyleNum,
1330                                                         s->rtfSBasedOn, "\\s");
1331                 RTFRouteToken (info);
1332         }
1333         /*
1334          * Now route the tokens unique to this style.  RTFSetToken()
1335          * isn't used because it would add the param value to the end
1336          * of the token text, which already has it in.
1337          */
1338         for (se = s->rtfSSEList; se != NULL; se = se->rtfNextSE)
1339         {
1340                 info->rtfClass = se->rtfSEClass;
1341                 info->rtfMajor = se->rtfSEMajor;
1342                 info->rtfMinor = se->rtfSEMinor;
1343                 info->rtfParam = se->rtfSEParam;
1344                 lstrcpyA (info->rtfTextBuf, se->rtfSEText);
1345                 info->rtfTextLen = lstrlenA (info->rtfTextBuf);
1346                 RTFRouteToken (info);
1347         }
1348         s->rtfExpanding = 0;    /* done - clear expansion flag */
1349 }
1350
1351
1352 /* ---------------------------------------------------------------------- */
1353
1354 /*
1355  * Control symbol lookup routines
1356  */
1357
1358
1359 typedef struct RTFKey   RTFKey;
1360
1361 struct RTFKey
1362 {
1363         int        rtfKMajor;   /* major number */
1364         int        rtfKMinor;   /* minor number */
1365         const char *rtfKStr;    /* symbol name */
1366         int        rtfKHash;    /* symbol name hash value */
1367 };
1368
1369 /*
1370  * A minor number of -1 means the token has no minor number
1371  * (all valid minor numbers are >= 0).
1372  */
1373
1374 static RTFKey   rtfKey[] =
1375 {
1376         /*
1377          * Special characters
1378          */
1379
1380         { rtfSpecialChar,       rtfIIntVersion,         "vern",         0 },
1381         { rtfSpecialChar,       rtfICreateTime,         "creatim",      0 },
1382         { rtfSpecialChar,       rtfIRevisionTime,       "revtim",       0 },
1383         { rtfSpecialChar,       rtfIPrintTime,          "printim",      0 },
1384         { rtfSpecialChar,       rtfIBackupTime,         "buptim",       0 },
1385         { rtfSpecialChar,       rtfIEditTime,           "edmins",       0 },
1386         { rtfSpecialChar,       rtfIYear,               "yr",           0 },
1387         { rtfSpecialChar,       rtfIMonth,              "mo",           0 },
1388         { rtfSpecialChar,       rtfIDay,                "dy",           0 },
1389         { rtfSpecialChar,       rtfIHour,               "hr",           0 },
1390         { rtfSpecialChar,       rtfIMinute,             "min",          0 },
1391         { rtfSpecialChar,       rtfISecond,             "sec",          0 },
1392         { rtfSpecialChar,       rtfINPages,             "nofpages",     0 },
1393         { rtfSpecialChar,       rtfINWords,             "nofwords",     0 },
1394         { rtfSpecialChar,       rtfINChars,             "nofchars",     0 },
1395         { rtfSpecialChar,       rtfIIntID,              "id",           0 },
1396
1397         { rtfSpecialChar,       rtfCurHeadDate,         "chdate",       0 },
1398         { rtfSpecialChar,       rtfCurHeadDateLong,     "chdpl",        0 },
1399         { rtfSpecialChar,       rtfCurHeadDateAbbrev,   "chdpa",        0 },
1400         { rtfSpecialChar,       rtfCurHeadTime,         "chtime",       0 },
1401         { rtfSpecialChar,       rtfCurHeadPage,         "chpgn",        0 },
1402         { rtfSpecialChar,       rtfSectNum,             "sectnum",      0 },
1403         { rtfSpecialChar,       rtfCurFNote,            "chftn",        0 },
1404         { rtfSpecialChar,       rtfCurAnnotRef,         "chatn",        0 },
1405         { rtfSpecialChar,       rtfFNoteSep,            "chftnsep",     0 },
1406         { rtfSpecialChar,       rtfFNoteCont,           "chftnsepc",    0 },
1407         { rtfSpecialChar,       rtfCell,                "cell",         0 },
1408         { rtfSpecialChar,       rtfRow,                 "row",          0 },
1409         { rtfSpecialChar,       rtfPar,                 "par",          0 },
1410         /* newline and carriage return are synonyms for */
1411         /* \par when they are preceded by a \ character */
1412         { rtfSpecialChar,       rtfPar,                 "\n",           0 },
1413         { rtfSpecialChar,       rtfPar,                 "\r",           0 },
1414         { rtfSpecialChar,       rtfSect,                "sect",         0 },
1415         { rtfSpecialChar,       rtfPage,                "page",         0 },
1416         { rtfSpecialChar,       rtfColumn,              "column",       0 },
1417         { rtfSpecialChar,       rtfLine,                "line",         0 },
1418         { rtfSpecialChar,       rtfSoftPage,            "softpage",     0 },
1419         { rtfSpecialChar,       rtfSoftColumn,          "softcol",      0 },
1420         { rtfSpecialChar,       rtfSoftLine,            "softline",     0 },
1421         { rtfSpecialChar,       rtfSoftLineHt,          "softlheight",  0 },
1422         { rtfSpecialChar,       rtfTab,                 "tab",          0 },
1423         { rtfSpecialChar,       rtfEmDash,              "emdash",       0 },
1424         { rtfSpecialChar,       rtfEnDash,              "endash",       0 },
1425         { rtfSpecialChar,       rtfEmSpace,             "emspace",      0 },
1426         { rtfSpecialChar,       rtfEnSpace,             "enspace",      0 },
1427         { rtfSpecialChar,       rtfBullet,              "bullet",       0 },
1428         { rtfSpecialChar,       rtfLQuote,              "lquote",       0 },
1429         { rtfSpecialChar,       rtfRQuote,              "rquote",       0 },
1430         { rtfSpecialChar,       rtfLDblQuote,           "ldblquote",    0 },
1431         { rtfSpecialChar,       rtfRDblQuote,           "rdblquote",    0 },
1432         { rtfSpecialChar,       rtfFormula,             "|",            0 },
1433         { rtfSpecialChar,       rtfNoBrkSpace,          "~",            0 },
1434         { rtfSpecialChar,       rtfNoReqHyphen,         "-",            0 },
1435         { rtfSpecialChar,       rtfNoBrkHyphen,         "_",            0 },
1436         { rtfSpecialChar,       rtfOptDest,             "*",            0 },
1437         { rtfSpecialChar,       rtfLTRMark,             "ltrmark",      0 },
1438         { rtfSpecialChar,       rtfRTLMark,             "rtlmark",      0 },
1439         { rtfSpecialChar,       rtfNoWidthJoiner,       "zwj",          0 },
1440         { rtfSpecialChar,       rtfNoWidthNonJoiner,    "zwnj",         0 },
1441         /* is this valid? */
1442         { rtfSpecialChar,       rtfCurHeadPict,         "chpict",       0 },
1443         { rtfSpecialChar,       rtfUnicode,             "u",            0 },
1444
1445         /*
1446          * Character formatting attributes
1447          */
1448
1449         { rtfCharAttr,  rtfPlain,               "plain",        0 },
1450         { rtfCharAttr,  rtfBold,                "b",            0 },
1451         { rtfCharAttr,  rtfAllCaps,             "caps",         0 },
1452         { rtfCharAttr,  rtfDeleted,             "deleted",      0 },
1453         { rtfCharAttr,  rtfSubScript,           "dn",           0 },
1454         { rtfCharAttr,  rtfSubScrShrink,        "sub",          0 },
1455         { rtfCharAttr,  rtfNoSuperSub,          "nosupersub",   0 },
1456         { rtfCharAttr,  rtfExpand,              "expnd",        0 },
1457         { rtfCharAttr,  rtfExpandTwips,         "expndtw",      0 },
1458         { rtfCharAttr,  rtfKerning,             "kerning",      0 },
1459         { rtfCharAttr,  rtfFontNum,             "f",            0 },
1460         { rtfCharAttr,  rtfFontSize,            "fs",           0 },
1461         { rtfCharAttr,  rtfItalic,              "i",            0 },
1462         { rtfCharAttr,  rtfOutline,             "outl",         0 },
1463         { rtfCharAttr,  rtfRevised,             "revised",      0 },
1464         { rtfCharAttr,  rtfRevAuthor,           "revauth",      0 },
1465         { rtfCharAttr,  rtfRevDTTM,             "revdttm",      0 },
1466         { rtfCharAttr,  rtfSmallCaps,           "scaps",        0 },
1467         { rtfCharAttr,  rtfShadow,              "shad",         0 },
1468         { rtfCharAttr,  rtfStrikeThru,          "strike",       0 },
1469         { rtfCharAttr,  rtfUnderline,           "ul",           0 },
1470         { rtfCharAttr,  rtfDotUnderline,        "uld",          0 },
1471         { rtfCharAttr,  rtfDbUnderline,         "uldb",         0 },
1472         { rtfCharAttr,  rtfNoUnderline,         "ulnone",       0 },
1473         { rtfCharAttr,  rtfWordUnderline,       "ulw",          0 },
1474         { rtfCharAttr,  rtfSuperScript,         "up",           0 },
1475         { rtfCharAttr,  rtfSuperScrShrink,      "super",        0 },
1476         { rtfCharAttr,  rtfInvisible,           "v",            0 },
1477         { rtfCharAttr,  rtfForeColor,           "cf",           0 },
1478         { rtfCharAttr,  rtfBackColor,           "cb",           0 },
1479         { rtfCharAttr,  rtfRTLChar,             "rtlch",        0 },
1480         { rtfCharAttr,  rtfLTRChar,             "ltrch",        0 },
1481         { rtfCharAttr,  rtfCharStyleNum,        "cs",           0 },
1482         { rtfCharAttr,  rtfCharCharSet,         "cchs",         0 },
1483         { rtfCharAttr,  rtfLanguage,            "lang",         0 },
1484         /* this has disappeared from spec 1.2 */
1485         { rtfCharAttr,  rtfGray,                "gray",         0 },
1486         { rtfCharAttr,  rtfUnicodeLength,       "uc",           0 },
1487
1488         /*
1489          * Paragraph formatting attributes
1490          */
1491
1492         { rtfParAttr,   rtfParDef,              "pard",         0 },
1493         { rtfParAttr,   rtfStyleNum,            "s",            0 },
1494         { rtfParAttr,   rtfHyphenate,           "hyphpar",      0 },
1495         { rtfParAttr,   rtfInTable,             "intbl",        0 },
1496         { rtfParAttr,   rtfKeep,                "keep",         0 },
1497         { rtfParAttr,   rtfNoWidowControl,      "nowidctlpar",  0 },
1498         { rtfParAttr,   rtfKeepNext,            "keepn",        0 },
1499         { rtfParAttr,   rtfOutlineLevel,        "level",        0 },
1500         { rtfParAttr,   rtfNoLineNum,           "noline",       0 },
1501         { rtfParAttr,   rtfPBBefore,            "pagebb",       0 },
1502         { rtfParAttr,   rtfSideBySide,          "sbys",         0 },
1503         { rtfParAttr,   rtfQuadLeft,            "ql",           0 },
1504         { rtfParAttr,   rtfQuadRight,           "qr",           0 },
1505         { rtfParAttr,   rtfQuadJust,            "qj",           0 },
1506         { rtfParAttr,   rtfQuadCenter,          "qc",           0 },
1507         { rtfParAttr,   rtfFirstIndent,         "fi",           0 },
1508         { rtfParAttr,   rtfLeftIndent,          "li",           0 },
1509         { rtfParAttr,   rtfRightIndent,         "ri",           0 },
1510         { rtfParAttr,   rtfSpaceBefore,         "sb",           0 },
1511         { rtfParAttr,   rtfSpaceAfter,          "sa",           0 },
1512         { rtfParAttr,   rtfSpaceBetween,        "sl",           0 },
1513         { rtfParAttr,   rtfSpaceMultiply,       "slmult",       0 },
1514
1515         { rtfParAttr,   rtfSubDocument,         "subdocument",  0 },
1516
1517         { rtfParAttr,   rtfRTLPar,              "rtlpar",       0 },
1518         { rtfParAttr,   rtfLTRPar,              "ltrpar",       0 },
1519
1520         { rtfParAttr,   rtfTabPos,              "tx",           0 },
1521         /*
1522          * FrameMaker writes \tql (to mean left-justified tab, apparently)
1523          * although it's not in the spec.  It's also redundant, since lj
1524          * tabs are the default.
1525          */
1526         { rtfParAttr,   rtfTabLeft,             "tql",          0 },
1527         { rtfParAttr,   rtfTabRight,            "tqr",          0 },
1528         { rtfParAttr,   rtfTabCenter,           "tqc",          0 },
1529         { rtfParAttr,   rtfTabDecimal,          "tqdec",        0 },
1530         { rtfParAttr,   rtfTabBar,              "tb",           0 },
1531         { rtfParAttr,   rtfLeaderDot,           "tldot",        0 },
1532         { rtfParAttr,   rtfLeaderHyphen,        "tlhyph",       0 },
1533         { rtfParAttr,   rtfLeaderUnder,         "tlul",         0 },
1534         { rtfParAttr,   rtfLeaderThick,         "tlth",         0 },
1535         { rtfParAttr,   rtfLeaderEqual,         "tleq",         0 },
1536
1537         { rtfParAttr,   rtfParLevel,            "pnlvl",        0 },
1538         { rtfParAttr,   rtfParBullet,           "pnlvlblt",     0 },
1539         { rtfParAttr,   rtfParSimple,           "pnlvlbody",    0 },
1540         { rtfParAttr,   rtfParNumCont,          "pnlvlcont",    0 },
1541         { rtfParAttr,   rtfParNumOnce,          "pnnumonce",    0 },
1542         { rtfParAttr,   rtfParNumAcross,        "pnacross",     0 },
1543         { rtfParAttr,   rtfParHangIndent,       "pnhang",       0 },
1544         { rtfParAttr,   rtfParNumRestart,       "pnrestart",    0 },
1545         { rtfParAttr,   rtfParNumCardinal,      "pncard",       0 },
1546         { rtfParAttr,   rtfParNumDecimal,       "pndec",        0 },
1547         { rtfParAttr,   rtfParNumULetter,       "pnucltr",      0 },
1548         { rtfParAttr,   rtfParNumURoman,        "pnucrm",       0 },
1549         { rtfParAttr,   rtfParNumLLetter,       "pnlcltr",      0 },
1550         { rtfParAttr,   rtfParNumLRoman,        "pnlcrm",       0 },
1551         { rtfParAttr,   rtfParNumOrdinal,       "pnord",        0 },
1552         { rtfParAttr,   rtfParNumOrdinalText,   "pnordt",       0 },
1553         { rtfParAttr,   rtfParNumBold,          "pnb",          0 },
1554         { rtfParAttr,   rtfParNumItalic,        "pni",          0 },
1555         { rtfParAttr,   rtfParNumAllCaps,       "pncaps",       0 },
1556         { rtfParAttr,   rtfParNumSmallCaps,     "pnscaps",      0 },
1557         { rtfParAttr,   rtfParNumUnder,         "pnul",         0 },
1558         { rtfParAttr,   rtfParNumDotUnder,      "pnuld",        0 },
1559         { rtfParAttr,   rtfParNumDbUnder,       "pnuldb",       0 },
1560         { rtfParAttr,   rtfParNumNoUnder,       "pnulnone",     0 },
1561         { rtfParAttr,   rtfParNumWordUnder,     "pnulw",        0 },
1562         { rtfParAttr,   rtfParNumStrikethru,    "pnstrike",     0 },
1563         { rtfParAttr,   rtfParNumForeColor,     "pncf",         0 },
1564         { rtfParAttr,   rtfParNumFont,          "pnf",          0 },
1565         { rtfParAttr,   rtfParNumFontSize,      "pnfs",         0 },
1566         { rtfParAttr,   rtfParNumIndent,        "pnindent",     0 },
1567         { rtfParAttr,   rtfParNumSpacing,       "pnsp",         0 },
1568         { rtfParAttr,   rtfParNumInclPrev,      "pnprev",       0 },
1569         { rtfParAttr,   rtfParNumCenter,        "pnqc",         0 },
1570         { rtfParAttr,   rtfParNumLeft,          "pnql",         0 },
1571         { rtfParAttr,   rtfParNumRight,         "pnqr",         0 },
1572         { rtfParAttr,   rtfParNumStartAt,       "pnstart",      0 },
1573
1574         { rtfParAttr,   rtfBorderTop,           "brdrt",        0 },
1575         { rtfParAttr,   rtfBorderBottom,        "brdrb",        0 },
1576         { rtfParAttr,   rtfBorderLeft,          "brdrl",        0 },
1577         { rtfParAttr,   rtfBorderRight,         "brdrr",        0 },
1578         { rtfParAttr,   rtfBorderBetween,       "brdrbtw",      0 },
1579         { rtfParAttr,   rtfBorderBar,           "brdrbar",      0 },
1580         { rtfParAttr,   rtfBorderBox,           "box",          0 },
1581         { rtfParAttr,   rtfBorderSingle,        "brdrs",        0 },
1582         { rtfParAttr,   rtfBorderThick,         "brdrth",       0 },
1583         { rtfParAttr,   rtfBorderShadow,        "brdrsh",       0 },
1584         { rtfParAttr,   rtfBorderDouble,        "brdrdb",       0 },
1585         { rtfParAttr,   rtfBorderDot,           "brdrdot",      0 },
1586         { rtfParAttr,   rtfBorderDot,           "brdrdash",     0 },
1587         { rtfParAttr,   rtfBorderHair,          "brdrhair",     0 },
1588         { rtfParAttr,   rtfBorderWidth,         "brdrw",        0 },
1589         { rtfParAttr,   rtfBorderColor,         "brdrcf",       0 },
1590         { rtfParAttr,   rtfBorderSpace,         "brsp",         0 },
1591
1592         { rtfParAttr,   rtfShading,             "shading",      0 },
1593         { rtfParAttr,   rtfBgPatH,              "bghoriz",      0 },
1594         { rtfParAttr,   rtfBgPatV,              "bgvert",       0 },
1595         { rtfParAttr,   rtfFwdDiagBgPat,        "bgfdiag",      0 },
1596         { rtfParAttr,   rtfBwdDiagBgPat,        "bgbdiag",      0 },
1597         { rtfParAttr,   rtfHatchBgPat,          "bgcross",      0 },
1598         { rtfParAttr,   rtfDiagHatchBgPat,      "bgdcross",     0 },
1599         { rtfParAttr,   rtfDarkBgPatH,          "bgdkhoriz",    0 },
1600         { rtfParAttr,   rtfDarkBgPatV,          "bgdkvert",     0 },
1601         { rtfParAttr,   rtfFwdDarkBgPat,        "bgdkfdiag",    0 },
1602         { rtfParAttr,   rtfBwdDarkBgPat,        "bgdkbdiag",    0 },
1603         { rtfParAttr,   rtfDarkHatchBgPat,      "bgdkcross",    0 },
1604         { rtfParAttr,   rtfDarkDiagHatchBgPat,  "bgdkdcross",   0 },
1605         { rtfParAttr,   rtfBgPatLineColor,      "cfpat",        0 },
1606         { rtfParAttr,   rtfBgPatColor,          "cbpat",        0 },
1607
1608         /*
1609          * Section formatting attributes
1610          */
1611
1612         { rtfSectAttr,  rtfSectDef,             "sectd",        0 },
1613         { rtfSectAttr,  rtfENoteHere,           "endnhere",     0 },
1614         { rtfSectAttr,  rtfPrtBinFirst,         "binfsxn",      0 },
1615         { rtfSectAttr,  rtfPrtBin,              "binsxn",       0 },
1616         { rtfSectAttr,  rtfSectStyleNum,        "ds",           0 },
1617
1618         { rtfSectAttr,  rtfNoBreak,             "sbknone",      0 },
1619         { rtfSectAttr,  rtfColBreak,            "sbkcol",       0 },
1620         { rtfSectAttr,  rtfPageBreak,           "sbkpage",      0 },
1621         { rtfSectAttr,  rtfEvenBreak,           "sbkeven",      0 },
1622         { rtfSectAttr,  rtfOddBreak,            "sbkodd",       0 },
1623
1624         { rtfSectAttr,  rtfColumns,             "cols",         0 },
1625         { rtfSectAttr,  rtfColumnSpace,         "colsx",        0 },
1626         { rtfSectAttr,  rtfColumnNumber,        "colno",        0 },
1627         { rtfSectAttr,  rtfColumnSpRight,       "colsr",        0 },
1628         { rtfSectAttr,  rtfColumnWidth,         "colw",         0 },
1629         { rtfSectAttr,  rtfColumnLine,          "linebetcol",   0 },
1630
1631         { rtfSectAttr,  rtfLineModulus,         "linemod",      0 },
1632         { rtfSectAttr,  rtfLineDist,            "linex",        0 },
1633         { rtfSectAttr,  rtfLineStarts,          "linestarts",   0 },
1634         { rtfSectAttr,  rtfLineRestart,         "linerestart",  0 },
1635         { rtfSectAttr,  rtfLineRestartPg,       "lineppage",    0 },
1636         { rtfSectAttr,  rtfLineCont,            "linecont",     0 },
1637
1638         { rtfSectAttr,  rtfSectPageWid,         "pgwsxn",       0 },
1639         { rtfSectAttr,  rtfSectPageHt,          "pghsxn",       0 },
1640         { rtfSectAttr,  rtfSectMarginLeft,      "marglsxn",     0 },
1641         { rtfSectAttr,  rtfSectMarginRight,     "margrsxn",     0 },
1642         { rtfSectAttr,  rtfSectMarginTop,       "margtsxn",     0 },
1643         { rtfSectAttr,  rtfSectMarginBottom,    "margbsxn",     0 },
1644         { rtfSectAttr,  rtfSectMarginGutter,    "guttersxn",    0 },
1645         { rtfSectAttr,  rtfSectLandscape,       "lndscpsxn",    0 },
1646         { rtfSectAttr,  rtfTitleSpecial,        "titlepg",      0 },
1647         { rtfSectAttr,  rtfHeaderY,             "headery",      0 },
1648         { rtfSectAttr,  rtfFooterY,             "footery",      0 },
1649
1650         { rtfSectAttr,  rtfPageStarts,          "pgnstarts",    0 },
1651         { rtfSectAttr,  rtfPageCont,            "pgncont",      0 },
1652         { rtfSectAttr,  rtfPageRestart,         "pgnrestart",   0 },
1653         { rtfSectAttr,  rtfPageNumRight,        "pgnx",         0 },
1654         { rtfSectAttr,  rtfPageNumTop,          "pgny",         0 },
1655         { rtfSectAttr,  rtfPageDecimal,         "pgndec",       0 },
1656         { rtfSectAttr,  rtfPageURoman,          "pgnucrm",      0 },
1657         { rtfSectAttr,  rtfPageLRoman,          "pgnlcrm",      0 },
1658         { rtfSectAttr,  rtfPageULetter,         "pgnucltr",     0 },
1659         { rtfSectAttr,  rtfPageLLetter,         "pgnlcltr",     0 },
1660         { rtfSectAttr,  rtfPageNumHyphSep,      "pgnhnsh",      0 },
1661         { rtfSectAttr,  rtfPageNumSpaceSep,     "pgnhnsp",      0 },
1662         { rtfSectAttr,  rtfPageNumColonSep,     "pgnhnsc",      0 },
1663         { rtfSectAttr,  rtfPageNumEmdashSep,    "pgnhnsm",      0 },
1664         { rtfSectAttr,  rtfPageNumEndashSep,    "pgnhnsn",      0 },
1665
1666         { rtfSectAttr,  rtfTopVAlign,           "vertalt",      0 },
1667         /* misspelled as "vertal" in specification 1.0 */
1668         { rtfSectAttr,  rtfBottomVAlign,        "vertalb",      0 },
1669         { rtfSectAttr,  rtfCenterVAlign,        "vertalc",      0 },
1670         { rtfSectAttr,  rtfJustVAlign,          "vertalj",      0 },
1671
1672         { rtfSectAttr,  rtfRTLSect,             "rtlsect",      0 },
1673         { rtfSectAttr,  rtfLTRSect,             "ltrsect",      0 },
1674
1675         /* I've seen these in an old spec, but not in real files... */
1676         /*rtfSectAttr,  rtfNoBreak,             "nobreak",      0,*/
1677         /*rtfSectAttr,  rtfColBreak,            "colbreak",     0,*/
1678         /*rtfSectAttr,  rtfPageBreak,           "pagebreak",    0,*/
1679         /*rtfSectAttr,  rtfEvenBreak,           "evenbreak",    0,*/
1680         /*rtfSectAttr,  rtfOddBreak,            "oddbreak",     0,*/
1681
1682         /*
1683          * Document formatting attributes
1684          */
1685
1686         { rtfDocAttr,   rtfDefTab,              "deftab",       0 },
1687         { rtfDocAttr,   rtfHyphHotZone,         "hyphhotz",     0 },
1688         { rtfDocAttr,   rtfHyphConsecLines,     "hyphconsec",   0 },
1689         { rtfDocAttr,   rtfHyphCaps,            "hyphcaps",     0 },
1690         { rtfDocAttr,   rtfHyphAuto,            "hyphauto",     0 },
1691         { rtfDocAttr,   rtfLineStart,           "linestart",    0 },
1692         { rtfDocAttr,   rtfFracWidth,           "fracwidth",    0 },
1693         /* \makeback was given in old version of spec, it's now */
1694         /* listed as \makebackup */
1695         { rtfDocAttr,   rtfMakeBackup,          "makeback",     0 },
1696         { rtfDocAttr,   rtfMakeBackup,          "makebackup",   0 },
1697         { rtfDocAttr,   rtfRTFDefault,          "defformat",    0 },
1698         { rtfDocAttr,   rtfPSOverlay,           "psover",       0 },
1699         { rtfDocAttr,   rtfDocTemplate,         "doctemp",      0 },
1700         { rtfDocAttr,   rtfDefLanguage,         "deflang",      0 },
1701
1702         { rtfDocAttr,   rtfFENoteType,          "fet",          0 },
1703         { rtfDocAttr,   rtfFNoteEndSect,        "endnotes",     0 },
1704         { rtfDocAttr,   rtfFNoteEndDoc,         "enddoc",       0 },
1705         { rtfDocAttr,   rtfFNoteText,           "ftntj",        0 },
1706         { rtfDocAttr,   rtfFNoteBottom,         "ftnbj",        0 },
1707         { rtfDocAttr,   rtfENoteEndSect,        "aendnotes",    0 },
1708         { rtfDocAttr,   rtfENoteEndDoc,         "aenddoc",      0 },
1709         { rtfDocAttr,   rtfENoteText,           "aftntj",       0 },
1710         { rtfDocAttr,   rtfENoteBottom,         "aftnbj",       0 },
1711         { rtfDocAttr,   rtfFNoteStart,          "ftnstart",     0 },
1712         { rtfDocAttr,   rtfENoteStart,          "aftnstart",    0 },
1713         { rtfDocAttr,   rtfFNoteRestartPage,    "ftnrstpg",     0 },
1714         { rtfDocAttr,   rtfFNoteRestart,        "ftnrestart",   0 },
1715         { rtfDocAttr,   rtfFNoteRestartCont,    "ftnrstcont",   0 },
1716         { rtfDocAttr,   rtfENoteRestart,        "aftnrestart",  0 },
1717         { rtfDocAttr,   rtfENoteRestartCont,    "aftnrstcont",  0 },
1718         { rtfDocAttr,   rtfFNoteNumArabic,      "ftnnar",       0 },
1719         { rtfDocAttr,   rtfFNoteNumLLetter,     "ftnnalc",      0 },
1720         { rtfDocAttr,   rtfFNoteNumULetter,     "ftnnauc",      0 },
1721         { rtfDocAttr,   rtfFNoteNumLRoman,      "ftnnrlc",      0 },
1722         { rtfDocAttr,   rtfFNoteNumURoman,      "ftnnruc",      0 },
1723         { rtfDocAttr,   rtfFNoteNumChicago,     "ftnnchi",      0 },
1724         { rtfDocAttr,   rtfENoteNumArabic,      "aftnnar",      0 },
1725         { rtfDocAttr,   rtfENoteNumLLetter,     "aftnnalc",     0 },
1726         { rtfDocAttr,   rtfENoteNumULetter,     "aftnnauc",     0 },
1727         { rtfDocAttr,   rtfENoteNumLRoman,      "aftnnrlc",     0 },
1728         { rtfDocAttr,   rtfENoteNumURoman,      "aftnnruc",     0 },
1729         { rtfDocAttr,   rtfENoteNumChicago,     "aftnnchi",     0 },
1730
1731         { rtfDocAttr,   rtfPaperWidth,          "paperw",       0 },
1732         { rtfDocAttr,   rtfPaperHeight,         "paperh",       0 },
1733         { rtfDocAttr,   rtfPaperSize,           "psz",          0 },
1734         { rtfDocAttr,   rtfLeftMargin,          "margl",        0 },
1735         { rtfDocAttr,   rtfRightMargin,         "margr",        0 },
1736         { rtfDocAttr,   rtfTopMargin,           "margt",        0 },
1737         { rtfDocAttr,   rtfBottomMargin,        "margb",        0 },
1738         { rtfDocAttr,   rtfFacingPage,          "facingp",      0 },
1739         { rtfDocAttr,   rtfGutterWid,           "gutter",       0 },
1740         { rtfDocAttr,   rtfMirrorMargin,        "margmirror",   0 },
1741         { rtfDocAttr,   rtfLandscape,           "landscape",    0 },
1742         { rtfDocAttr,   rtfPageStart,           "pgnstart",     0 },
1743         { rtfDocAttr,   rtfWidowCtrl,           "widowctrl",    0 },
1744
1745         { rtfDocAttr,   rtfLinkStyles,          "linkstyles",   0 },
1746
1747         { rtfDocAttr,   rtfNoAutoTabIndent,     "notabind",     0 },
1748         { rtfDocAttr,   rtfWrapSpaces,          "wraptrsp",     0 },
1749         { rtfDocAttr,   rtfPrintColorsBlack,    "prcolbl",      0 },
1750         { rtfDocAttr,   rtfNoExtraSpaceRL,      "noextrasprl",  0 },
1751         { rtfDocAttr,   rtfNoColumnBalance,     "nocolbal",     0 },
1752         { rtfDocAttr,   rtfCvtMailMergeQuote,   "cvmme",        0 },
1753         { rtfDocAttr,   rtfSuppressTopSpace,    "sprstsp",      0 },
1754         { rtfDocAttr,   rtfSuppressPreParSpace, "sprsspbf",     0 },
1755         { rtfDocAttr,   rtfCombineTblBorders,   "otblrul",      0 },
1756         { rtfDocAttr,   rtfTranspMetafiles,     "transmf",      0 },
1757         { rtfDocAttr,   rtfSwapBorders,         "swpbdr",       0 },
1758         { rtfDocAttr,   rtfShowHardBreaks,      "brkfrm",       0 },
1759
1760         { rtfDocAttr,   rtfFormProtected,       "formprot",     0 },
1761         { rtfDocAttr,   rtfAllProtected,        "allprot",      0 },
1762         { rtfDocAttr,   rtfFormShading,         "formshade",    0 },
1763         { rtfDocAttr,   rtfFormDisplay,         "formdisp",     0 },
1764         { rtfDocAttr,   rtfPrintData,           "printdata",    0 },
1765
1766         { rtfDocAttr,   rtfRevProtected,        "revprot",      0 },
1767         { rtfDocAttr,   rtfRevisions,           "revisions",    0 },
1768         { rtfDocAttr,   rtfRevDisplay,          "revprop",      0 },
1769         { rtfDocAttr,   rtfRevBar,              "revbar",       0 },
1770
1771         { rtfDocAttr,   rtfAnnotProtected,      "annotprot",    0 },
1772
1773         { rtfDocAttr,   rtfRTLDoc,              "rtldoc",       0 },
1774         { rtfDocAttr,   rtfLTRDoc,              "ltrdoc",       0 },
1775        
1776         { rtfDocAttr,   rtfAnsiCodePage,        "ansicpg",      0 },
1777         { rtfDocAttr,   rtfUTF8RTF,             "urtf",         0 },
1778
1779         /*
1780          * Style attributes
1781          */
1782
1783         { rtfStyleAttr, rtfAdditive,            "additive",     0 },
1784         { rtfStyleAttr, rtfBasedOn,             "sbasedon",     0 },
1785         { rtfStyleAttr, rtfNext,                "snext",        0 },
1786
1787         /*
1788          * Picture attributes
1789          */
1790
1791         { rtfPictAttr,  rtfMacQD,               "macpict",      0 },
1792         { rtfPictAttr,  rtfPMMetafile,          "pmmetafile",   0 },
1793         { rtfPictAttr,  rtfWinMetafile,         "wmetafile",    0 },
1794         { rtfPictAttr,  rtfDevIndBitmap,        "dibitmap",     0 },
1795         { rtfPictAttr,  rtfWinBitmap,           "wbitmap",      0 },
1796         { rtfPictAttr,  rtfPixelBits,           "wbmbitspixel", 0 },
1797         { rtfPictAttr,  rtfBitmapPlanes,        "wbmplanes",    0 },
1798         { rtfPictAttr,  rtfBitmapWid,           "wbmwidthbytes", 0 },
1799
1800         { rtfPictAttr,  rtfPicWid,              "picw",         0 },
1801         { rtfPictAttr,  rtfPicHt,               "pich",         0 },
1802         { rtfPictAttr,  rtfPicGoalWid,          "picwgoal",     0 },
1803         { rtfPictAttr,  rtfPicGoalHt,           "pichgoal",     0 },
1804         /* these two aren't in the spec, but some writers emit them */
1805         { rtfPictAttr,  rtfPicGoalWid,          "picwGoal",     0 },
1806         { rtfPictAttr,  rtfPicGoalHt,           "pichGoal",     0 },
1807         { rtfPictAttr,  rtfPicScaleX,           "picscalex",    0 },
1808         { rtfPictAttr,  rtfPicScaleY,           "picscaley",    0 },
1809         { rtfPictAttr,  rtfPicScaled,           "picscaled",    0 },
1810         { rtfPictAttr,  rtfPicCropTop,          "piccropt",     0 },
1811         { rtfPictAttr,  rtfPicCropBottom,       "piccropb",     0 },
1812         { rtfPictAttr,  rtfPicCropLeft,         "piccropl",     0 },
1813         { rtfPictAttr,  rtfPicCropRight,        "piccropr",     0 },
1814
1815         { rtfPictAttr,  rtfPicMFHasBitmap,      "picbmp",       0 },
1816         { rtfPictAttr,  rtfPicMFBitsPerPixel,   "picbpp",       0 },
1817
1818         { rtfPictAttr,  rtfPicBinary,           "bin",          0 },
1819
1820         /*
1821          * NeXT graphic attributes
1822          */
1823
1824         { rtfNeXTGrAttr,        rtfNeXTGWidth,          "width",        0 },
1825         { rtfNeXTGrAttr,        rtfNeXTGHeight,         "height",       0 },
1826
1827         /*
1828          * Destinations
1829          */
1830
1831         { rtfDestination,       rtfFontTbl,             "fonttbl",      0 },
1832         { rtfDestination,       rtfFontAltName,         "falt",         0 },
1833         { rtfDestination,       rtfEmbeddedFont,        "fonteb",       0 },
1834         { rtfDestination,       rtfFontFile,            "fontfile",     0 },
1835         { rtfDestination,       rtfFileTbl,             "filetbl",      0 },
1836         { rtfDestination,       rtfFileInfo,            "file",         0 },
1837         { rtfDestination,       rtfColorTbl,            "colortbl",     0 },
1838         { rtfDestination,       rtfStyleSheet,          "stylesheet",   0 },
1839         { rtfDestination,       rtfKeyCode,             "keycode",      0 },
1840         { rtfDestination,       rtfRevisionTbl,         "revtbl",       0 },
1841         { rtfDestination,       rtfGenerator,           "generator",    0 },
1842         { rtfDestination,       rtfInfo,                "info",         0 },
1843         { rtfDestination,       rtfITitle,              "title",        0 },
1844         { rtfDestination,       rtfISubject,            "subject",      0 },
1845         { rtfDestination,       rtfIAuthor,             "author",       0 },
1846         { rtfDestination,       rtfIOperator,           "operator",     0 },
1847         { rtfDestination,       rtfIKeywords,           "keywords",     0 },
1848         { rtfDestination,       rtfIComment,            "comment",      0 },
1849         { rtfDestination,       rtfIVersion,            "version",      0 },
1850         { rtfDestination,       rtfIDoccomm,            "doccomm",      0 },
1851         /* \verscomm may not exist -- was seen in earlier spec version */
1852         { rtfDestination,       rtfIVerscomm,           "verscomm",     0 },
1853         { rtfDestination,       rtfNextFile,            "nextfile",     0 },
1854         { rtfDestination,       rtfTemplate,            "template",     0 },
1855         { rtfDestination,       rtfFNSep,               "ftnsep",       0 },
1856         { rtfDestination,       rtfFNContSep,           "ftnsepc",      0 },
1857         { rtfDestination,       rtfFNContNotice,        "ftncn",        0 },
1858         { rtfDestination,       rtfENSep,               "aftnsep",      0 },
1859         { rtfDestination,       rtfENContSep,           "aftnsepc",     0 },
1860         { rtfDestination,       rtfENContNotice,        "aftncn",       0 },
1861         { rtfDestination,       rtfPageNumLevel,        "pgnhn",        0 },
1862         { rtfDestination,       rtfParNumLevelStyle,    "pnseclvl",     0 },
1863         { rtfDestination,       rtfHeader,              "header",       0 },
1864         { rtfDestination,       rtfFooter,              "footer",       0 },
1865         { rtfDestination,       rtfHeaderLeft,          "headerl",      0 },
1866         { rtfDestination,       rtfHeaderRight,         "headerr",      0 },
1867         { rtfDestination,       rtfHeaderFirst,         "headerf",      0 },
1868         { rtfDestination,       rtfFooterLeft,          "footerl",      0 },
1869         { rtfDestination,       rtfFooterRight,         "footerr",      0 },
1870         { rtfDestination,       rtfFooterFirst,         "footerf",      0 },
1871         { rtfDestination,       rtfParNumText,          "pntext",       0 },
1872         { rtfDestination,       rtfParNumbering,        "pn",           0 },
1873         { rtfDestination,       rtfParNumTextAfter,     "pntexta",      0 },
1874         { rtfDestination,       rtfParNumTextBefore,    "pntextb",      0 },
1875         { rtfDestination,       rtfBookmarkStart,       "bkmkstart",    0 },
1876         { rtfDestination,       rtfBookmarkEnd,         "bkmkend",      0 },
1877         { rtfDestination,       rtfPict,                "pict",         0 },
1878         { rtfDestination,       rtfObject,              "object",       0 },
1879         { rtfDestination,       rtfObjClass,            "objclass",     0 },
1880         { rtfDestination,       rtfObjName,             "objname",      0 },
1881         { rtfObjAttr,   rtfObjTime,             "objtime",      0 },
1882         { rtfDestination,       rtfObjData,             "objdata",      0 },
1883         { rtfDestination,       rtfObjAlias,            "objalias",     0 },
1884         { rtfDestination,       rtfObjSection,          "objsect",      0 },
1885         /* objitem and objtopic aren't documented in the spec! */
1886         { rtfDestination,       rtfObjItem,             "objitem",      0 },
1887         { rtfDestination,       rtfObjTopic,            "objtopic",     0 },
1888         { rtfDestination,       rtfObjResult,           "result",       0 },
1889         { rtfDestination,       rtfDrawObject,          "do",           0 },
1890         { rtfDestination,       rtfFootnote,            "footnote",     0 },
1891         { rtfDestination,       rtfAnnotRefStart,       "atrfstart",    0 },
1892         { rtfDestination,       rtfAnnotRefEnd,         "atrfend",      0 },
1893         { rtfDestination,       rtfAnnotID,             "atnid",        0 },
1894         { rtfDestination,       rtfAnnotAuthor,         "atnauthor",    0 },
1895         { rtfDestination,       rtfAnnotation,          "annotation",   0 },
1896         { rtfDestination,       rtfAnnotRef,            "atnref",       0 },
1897         { rtfDestination,       rtfAnnotTime,           "atntime",      0 },
1898         { rtfDestination,       rtfAnnotIcon,           "atnicn",       0 },
1899         { rtfDestination,       rtfField,               "field",        0 },
1900         { rtfDestination,       rtfFieldInst,           "fldinst",      0 },
1901         { rtfDestination,       rtfFieldResult,         "fldrslt",      0 },
1902         { rtfDestination,       rtfDataField,           "datafield",    0 },
1903         { rtfDestination,       rtfIndex,               "xe",           0 },
1904         { rtfDestination,       rtfIndexText,           "txe",          0 },
1905         { rtfDestination,       rtfIndexRange,          "rxe",          0 },
1906         { rtfDestination,       rtfTOC,                 "tc",           0 },
1907         { rtfDestination,       rtfNeXTGraphic,         "NeXTGraphic",  0 },
1908
1909         /*
1910          * Font families
1911          */
1912
1913         { rtfFontFamily,        rtfFFNil,               "fnil",         0 },
1914         { rtfFontFamily,        rtfFFRoman,             "froman",       0 },
1915         { rtfFontFamily,        rtfFFSwiss,             "fswiss",       0 },
1916         { rtfFontFamily,        rtfFFModern,            "fmodern",      0 },
1917         { rtfFontFamily,        rtfFFScript,            "fscript",      0 },
1918         { rtfFontFamily,        rtfFFDecor,             "fdecor",       0 },
1919         { rtfFontFamily,        rtfFFTech,              "ftech",        0 },
1920         { rtfFontFamily,        rtfFFBidirectional,     "fbidi",        0 },
1921
1922         /*
1923          * Font attributes
1924          */
1925
1926         { rtfFontAttr,  rtfFontCharSet,         "fcharset",     0 },
1927         { rtfFontAttr,  rtfFontPitch,           "fprq",         0 },
1928         { rtfFontAttr,  rtfFontCodePage,        "cpg",          0 },
1929         { rtfFontAttr,  rtfFTypeNil,            "ftnil",        0 },
1930         { rtfFontAttr,  rtfFTypeTrueType,       "fttruetype",   0 },
1931
1932         /*
1933          * File table attributes
1934          */
1935
1936         { rtfFileAttr,  rtfFileNum,             "fid",          0 },
1937         { rtfFileAttr,  rtfFileRelPath,         "frelative",    0 },
1938         { rtfFileAttr,  rtfFileOSNum,           "fosnum",       0 },
1939
1940         /*
1941          * File sources
1942          */
1943
1944         { rtfFileSource,        rtfSrcMacintosh,        "fvalidmac",    0 },
1945         { rtfFileSource,        rtfSrcDOS,              "fvaliddos",    0 },
1946         { rtfFileSource,        rtfSrcNTFS,             "fvalidntfs",   0 },
1947         { rtfFileSource,        rtfSrcHPFS,             "fvalidhpfs",   0 },
1948         { rtfFileSource,        rtfSrcNetwork,          "fnetwork",     0 },
1949
1950         /*
1951          * Color names
1952          */
1953
1954         { rtfColorName, rtfRed,                 "red",          0 },
1955         { rtfColorName, rtfGreen,               "green",        0 },
1956         { rtfColorName, rtfBlue,                "blue",         0 },
1957
1958         /*
1959          * Charset names
1960          */
1961
1962         { rtfCharSet,   rtfMacCharSet,          "mac",          0 },
1963         { rtfCharSet,   rtfAnsiCharSet,         "ansi",         0 },
1964         { rtfCharSet,   rtfPcCharSet,           "pc",           0 },
1965         { rtfCharSet,   rtfPcaCharSet,          "pca",          0 },
1966
1967         /*
1968          * Table attributes
1969          */
1970
1971         { rtfTblAttr,   rtfRowDef,              "trowd",        0 },
1972         { rtfTblAttr,   rtfRowGapH,             "trgaph",       0 },
1973         { rtfTblAttr,   rtfCellPos,             "cellx",        0 },
1974         { rtfTblAttr,   rtfMergeRngFirst,       "clmgf",        0 },
1975         { rtfTblAttr,   rtfMergePrevious,       "clmrg",        0 },
1976
1977         { rtfTblAttr,   rtfRowLeft,             "trql",         0 },
1978         { rtfTblAttr,   rtfRowRight,            "trqr",         0 },
1979         { rtfTblAttr,   rtfRowCenter,           "trqc",         0 },
1980         { rtfTblAttr,   rtfRowLeftEdge,         "trleft",       0 },
1981         { rtfTblAttr,   rtfRowHt,               "trrh",         0 },
1982         { rtfTblAttr,   rtfRowHeader,           "trhdr",        0 },
1983         { rtfTblAttr,   rtfRowKeep,             "trkeep",       0 },
1984
1985         { rtfTblAttr,   rtfRTLRow,              "rtlrow",       0 },
1986         { rtfTblAttr,   rtfLTRRow,              "ltrrow",       0 },
1987
1988         { rtfTblAttr,   rtfRowBordTop,          "trbrdrt",      0 },
1989         { rtfTblAttr,   rtfRowBordLeft,         "trbrdrl",      0 },
1990         { rtfTblAttr,   rtfRowBordBottom,       "trbrdrb",      0 },
1991         { rtfTblAttr,   rtfRowBordRight,        "trbrdrr",      0 },
1992         { rtfTblAttr,   rtfRowBordHoriz,        "trbrdrh",      0 },
1993         { rtfTblAttr,   rtfRowBordVert,         "trbrdrv",      0 },
1994
1995         { rtfTblAttr,   rtfCellBordBottom,      "clbrdrb",      0 },
1996         { rtfTblAttr,   rtfCellBordTop,         "clbrdrt",      0 },
1997         { rtfTblAttr,   rtfCellBordLeft,        "clbrdrl",      0 },
1998         { rtfTblAttr,   rtfCellBordRight,       "clbrdrr",      0 },
1999
2000         { rtfTblAttr,   rtfCellShading,         "clshdng",      0 },
2001         { rtfTblAttr,   rtfCellBgPatH,          "clbghoriz",    0 },
2002         { rtfTblAttr,   rtfCellBgPatV,          "clbgvert",     0 },
2003         { rtfTblAttr,   rtfCellFwdDiagBgPat,    "clbgfdiag",    0 },
2004         { rtfTblAttr,   rtfCellBwdDiagBgPat,    "clbgbdiag",    0 },
2005         { rtfTblAttr,   rtfCellHatchBgPat,      "clbgcross",    0 },
2006         { rtfTblAttr,   rtfCellDiagHatchBgPat,  "clbgdcross",   0 },
2007         /*
2008          * The spec lists "clbgdkhor", but the corresponding non-cell
2009          * control is "bgdkhoriz".  At any rate Macintosh Word seems
2010          * to accept both "clbgdkhor" and "clbgdkhoriz".
2011          */
2012         { rtfTblAttr,   rtfCellDarkBgPatH,      "clbgdkhoriz",  0 },
2013         { rtfTblAttr,   rtfCellDarkBgPatH,      "clbgdkhor",    0 },
2014         { rtfTblAttr,   rtfCellDarkBgPatV,      "clbgdkvert",   0 },
2015         { rtfTblAttr,   rtfCellFwdDarkBgPat,    "clbgdkfdiag",  0 },
2016         { rtfTblAttr,   rtfCellBwdDarkBgPat,    "clbgdkbdiag",  0 },
2017         { rtfTblAttr,   rtfCellDarkHatchBgPat,  "clbgdkcross",  0 },
2018         { rtfTblAttr,   rtfCellDarkDiagHatchBgPat, "clbgdkdcross",      0 },
2019         { rtfTblAttr,   rtfCellBgPatLineColor, "clcfpat",       0 },
2020         { rtfTblAttr,   rtfCellBgPatColor,      "clcbpat",      0 },
2021
2022         /*
2023          * Field attributes
2024          */
2025
2026         { rtfFieldAttr, rtfFieldDirty,          "flddirty",     0 },
2027         { rtfFieldAttr, rtfFieldEdited,         "fldedit",      0 },
2028         { rtfFieldAttr, rtfFieldLocked,         "fldlock",      0 },
2029         { rtfFieldAttr, rtfFieldPrivate,        "fldpriv",      0 },
2030         { rtfFieldAttr, rtfFieldAlt,            "fldalt",       0 },
2031
2032         /*
2033          * Positioning attributes
2034          */
2035
2036         { rtfPosAttr,   rtfAbsWid,              "absw",         0 },
2037         { rtfPosAttr,   rtfAbsHt,               "absh",         0 },
2038
2039         { rtfPosAttr,   rtfRPosMargH,           "phmrg",        0 },
2040         { rtfPosAttr,   rtfRPosPageH,           "phpg",         0 },
2041         { rtfPosAttr,   rtfRPosColH,            "phcol",        0 },
2042         { rtfPosAttr,   rtfPosX,                "posx",         0 },
2043         { rtfPosAttr,   rtfPosNegX,             "posnegx",      0 },
2044         { rtfPosAttr,   rtfPosXCenter,          "posxc",        0 },
2045         { rtfPosAttr,   rtfPosXInside,          "posxi",        0 },
2046         { rtfPosAttr,   rtfPosXOutSide,         "posxo",        0 },
2047         { rtfPosAttr,   rtfPosXRight,           "posxr",        0 },
2048         { rtfPosAttr,   rtfPosXLeft,            "posxl",        0 },
2049
2050         { rtfPosAttr,   rtfRPosMargV,           "pvmrg",        0 },
2051         { rtfPosAttr,   rtfRPosPageV,           "pvpg",         0 },
2052         { rtfPosAttr,   rtfRPosParaV,           "pvpara",       0 },
2053         { rtfPosAttr,   rtfPosY,                "posy",         0 },
2054         { rtfPosAttr,   rtfPosNegY,             "posnegy",      0 },
2055         { rtfPosAttr,   rtfPosYInline,          "posyil",       0 },
2056         { rtfPosAttr,   rtfPosYTop,             "posyt",        0 },
2057         { rtfPosAttr,   rtfPosYCenter,          "posyc",        0 },
2058         { rtfPosAttr,   rtfPosYBottom,          "posyb",        0 },
2059
2060         { rtfPosAttr,   rtfNoWrap,              "nowrap",       0 },
2061         { rtfPosAttr,   rtfDistFromTextAll,     "dxfrtext",     0 },
2062         { rtfPosAttr,   rtfDistFromTextX,       "dfrmtxtx",     0 },
2063         { rtfPosAttr,   rtfDistFromTextY,       "dfrmtxty",     0 },
2064         /* \dyfrtext no longer exists in spec 1.2, apparently */
2065         /* replaced by \dfrmtextx and \dfrmtexty. */
2066         { rtfPosAttr,   rtfTextDistY,           "dyfrtext",     0 },
2067
2068         { rtfPosAttr,   rtfDropCapLines,        "dropcapli",    0 },
2069         { rtfPosAttr,   rtfDropCapType,         "dropcapt",     0 },
2070
2071         /*
2072          * Object controls
2073          */
2074
2075         { rtfObjAttr,   rtfObjEmb,              "objemb",       0 },
2076         { rtfObjAttr,   rtfObjLink,             "objlink",      0 },
2077         { rtfObjAttr,   rtfObjAutoLink,         "objautlink",   0 },
2078         { rtfObjAttr,   rtfObjSubscriber,       "objsub",       0 },
2079         { rtfObjAttr,   rtfObjPublisher,        "objpub",       0 },
2080         { rtfObjAttr,   rtfObjICEmb,            "objicemb",     0 },
2081
2082         { rtfObjAttr,   rtfObjLinkSelf,         "linkself",     0 },
2083         { rtfObjAttr,   rtfObjLock,             "objupdate",    0 },
2084         { rtfObjAttr,   rtfObjUpdate,           "objlock",      0 },
2085
2086         { rtfObjAttr,   rtfObjHt,               "objh",         0 },
2087         { rtfObjAttr,   rtfObjWid,              "objw",         0 },
2088         { rtfObjAttr,   rtfObjSetSize,          "objsetsize",   0 },
2089         { rtfObjAttr,   rtfObjAlign,            "objalign",     0 },
2090         { rtfObjAttr,   rtfObjTransposeY,       "objtransy",    0 },
2091         { rtfObjAttr,   rtfObjCropTop,          "objcropt",     0 },
2092         { rtfObjAttr,   rtfObjCropBottom,       "objcropb",     0 },
2093         { rtfObjAttr,   rtfObjCropLeft,         "objcropl",     0 },
2094         { rtfObjAttr,   rtfObjCropRight,        "objcropr",     0 },
2095         { rtfObjAttr,   rtfObjScaleX,           "objscalex",    0 },
2096         { rtfObjAttr,   rtfObjScaleY,           "objscaley",    0 },
2097
2098         { rtfObjAttr,   rtfObjResRTF,           "rsltrtf",      0 },
2099         { rtfObjAttr,   rtfObjResPict,          "rsltpict",     0 },
2100         { rtfObjAttr,   rtfObjResBitmap,        "rsltbmp",      0 },
2101         { rtfObjAttr,   rtfObjResText,          "rslttxt",      0 },
2102         { rtfObjAttr,   rtfObjResMerge,         "rsltmerge",    0 },
2103
2104         { rtfObjAttr,   rtfObjBookmarkPubObj,   "bkmkpub",      0 },
2105         { rtfObjAttr,   rtfObjPubAutoUpdate,    "pubauto",      0 },
2106
2107         /*
2108          * Associated character formatting attributes
2109          */
2110
2111         { rtfACharAttr, rtfACBold,              "ab",           0 },
2112         { rtfACharAttr, rtfACAllCaps,           "caps",         0 },
2113         { rtfACharAttr, rtfACForeColor,         "acf",          0 },
2114         { rtfACharAttr, rtfACSubScript,         "adn",          0 },
2115         { rtfACharAttr, rtfACExpand,            "aexpnd",       0 },
2116         { rtfACharAttr, rtfACFontNum,           "af",           0 },
2117         { rtfACharAttr, rtfACFontSize,          "afs",          0 },
2118         { rtfACharAttr, rtfACItalic,            "ai",           0 },
2119         { rtfACharAttr, rtfACLanguage,          "alang",        0 },
2120         { rtfACharAttr, rtfACOutline,           "aoutl",        0 },
2121         { rtfACharAttr, rtfACSmallCaps,         "ascaps",       0 },
2122         { rtfACharAttr, rtfACShadow,            "ashad",        0 },
2123         { rtfACharAttr, rtfACStrikeThru,        "astrike",      0 },
2124         { rtfACharAttr, rtfACUnderline,         "aul",          0 },
2125         { rtfACharAttr, rtfACDotUnderline,      "auld",         0 },
2126         { rtfACharAttr, rtfACDbUnderline,       "auldb",        0 },
2127         { rtfACharAttr, rtfACNoUnderline,       "aulnone",      0 },
2128         { rtfACharAttr, rtfACWordUnderline,     "aulw",         0 },
2129         { rtfACharAttr, rtfACSuperScript,       "aup",          0 },
2130
2131         /*
2132          * Footnote attributes
2133          */
2134
2135         { rtfFNoteAttr, rtfFNAlt,               "ftnalt",       0 },
2136
2137         /*
2138          * Key code attributes
2139          */
2140
2141         { rtfKeyCodeAttr,       rtfAltKey,              "alt",          0 },
2142         { rtfKeyCodeAttr,       rtfShiftKey,            "shift",        0 },
2143         { rtfKeyCodeAttr,       rtfControlKey,          "ctrl",         0 },
2144         { rtfKeyCodeAttr,       rtfFunctionKey,         "fn",           0 },
2145
2146         /*
2147          * Bookmark attributes
2148          */
2149
2150         { rtfBookmarkAttr, rtfBookmarkFirstCol, "bkmkcolf",     0 },
2151         { rtfBookmarkAttr, rtfBookmarkLastCol,  "bkmkcoll",     0 },
2152
2153         /*
2154          * Index entry attributes
2155          */
2156
2157         { rtfIndexAttr, rtfIndexNumber,         "xef",          0 },
2158         { rtfIndexAttr, rtfIndexBold,           "bxe",          0 },
2159         { rtfIndexAttr, rtfIndexItalic,         "ixe",          0 },
2160
2161         /*
2162          * Table of contents attributes
2163          */
2164
2165         { rtfTOCAttr,   rtfTOCType,             "tcf",          0 },
2166         { rtfTOCAttr,   rtfTOCLevel,            "tcl",          0 },
2167
2168         /*
2169          * Drawing object attributes
2170          */
2171
2172         { rtfDrawAttr,  rtfDrawLock,            "dolock",       0 },
2173         { rtfDrawAttr,  rtfDrawPageRelX,        "doxpage",      0 },
2174         { rtfDrawAttr,  rtfDrawColumnRelX,      "dobxcolumn",   0 },
2175         { rtfDrawAttr,  rtfDrawMarginRelX,      "dobxmargin",   0 },
2176         { rtfDrawAttr,  rtfDrawPageRelY,        "dobypage",     0 },
2177         { rtfDrawAttr,  rtfDrawColumnRelY,      "dobycolumn",   0 },
2178         { rtfDrawAttr,  rtfDrawMarginRelY,      "dobymargin",   0 },
2179         { rtfDrawAttr,  rtfDrawHeight,          "dobhgt",       0 },
2180
2181         { rtfDrawAttr,  rtfDrawBeginGroup,      "dpgroup",      0 },
2182         { rtfDrawAttr,  rtfDrawGroupCount,      "dpcount",      0 },
2183         { rtfDrawAttr,  rtfDrawEndGroup,        "dpendgroup",   0 },
2184         { rtfDrawAttr,  rtfDrawArc,             "dparc",        0 },
2185         { rtfDrawAttr,  rtfDrawCallout,         "dpcallout",    0 },
2186         { rtfDrawAttr,  rtfDrawEllipse,         "dpellipse",    0 },
2187         { rtfDrawAttr,  rtfDrawLine,            "dpline",       0 },
2188         { rtfDrawAttr,  rtfDrawPolygon,         "dppolygon",    0 },
2189         { rtfDrawAttr,  rtfDrawPolyLine,        "dppolyline",   0 },
2190         { rtfDrawAttr,  rtfDrawRect,            "dprect",       0 },
2191         { rtfDrawAttr,  rtfDrawTextBox,         "dptxbx",       0 },
2192
2193         { rtfDrawAttr,  rtfDrawOffsetX,         "dpx",          0 },
2194         { rtfDrawAttr,  rtfDrawSizeX,           "dpxsize",      0 },
2195         { rtfDrawAttr,  rtfDrawOffsetY,         "dpy",          0 },
2196         { rtfDrawAttr,  rtfDrawSizeY,           "dpysize",      0 },
2197
2198         { rtfDrawAttr,  rtfCOAngle,             "dpcoa",        0 },
2199         { rtfDrawAttr,  rtfCOAccentBar,         "dpcoaccent",   0 },
2200         { rtfDrawAttr,  rtfCOBestFit,           "dpcobestfit",  0 },
2201         { rtfDrawAttr,  rtfCOBorder,            "dpcoborder",   0 },
2202         { rtfDrawAttr,  rtfCOAttachAbsDist,     "dpcodabs",     0 },
2203         { rtfDrawAttr,  rtfCOAttachBottom,      "dpcodbottom",  0 },
2204         { rtfDrawAttr,  rtfCOAttachCenter,      "dpcodcenter",  0 },
2205         { rtfDrawAttr,  rtfCOAttachTop,         "dpcodtop",     0 },
2206         { rtfDrawAttr,  rtfCOLength,            "dpcolength",   0 },
2207         { rtfDrawAttr,  rtfCONegXQuadrant,      "dpcominusx",   0 },
2208         { rtfDrawAttr,  rtfCONegYQuadrant,      "dpcominusy",   0 },
2209         { rtfDrawAttr,  rtfCOOffset,            "dpcooffset",   0 },
2210         { rtfDrawAttr,  rtfCOAttachSmart,       "dpcosmarta",   0 },
2211         { rtfDrawAttr,  rtfCODoubleLine,        "dpcotdouble",  0 },
2212         { rtfDrawAttr,  rtfCORightAngle,        "dpcotright",   0 },
2213         { rtfDrawAttr,  rtfCOSingleLine,        "dpcotsingle",  0 },
2214         { rtfDrawAttr,  rtfCOTripleLine,        "dpcottriple",  0 },
2215
2216         { rtfDrawAttr,  rtfDrawTextBoxMargin,   "dptxbxmar",    0 },
2217         { rtfDrawAttr,  rtfDrawTextBoxText,     "dptxbxtext",   0 },
2218         { rtfDrawAttr,  rtfDrawRoundRect,       "dproundr",     0 },
2219
2220         { rtfDrawAttr,  rtfDrawPointX,          "dpptx",        0 },
2221         { rtfDrawAttr,  rtfDrawPointY,          "dppty",        0 },
2222         { rtfDrawAttr,  rtfDrawPolyCount,       "dppolycount",  0 },
2223
2224         { rtfDrawAttr,  rtfDrawArcFlipX,        "dparcflipx",   0 },
2225         { rtfDrawAttr,  rtfDrawArcFlipY,        "dparcflipy",   0 },
2226
2227         { rtfDrawAttr,  rtfDrawLineBlue,        "dplinecob",    0 },
2228         { rtfDrawAttr,  rtfDrawLineGreen,       "dplinecog",    0 },
2229         { rtfDrawAttr,  rtfDrawLineRed,         "dplinecor",    0 },
2230         { rtfDrawAttr,  rtfDrawLinePalette,     "dplinepal",    0 },
2231         { rtfDrawAttr,  rtfDrawLineDashDot,     "dplinedado",   0 },
2232         { rtfDrawAttr,  rtfDrawLineDashDotDot,  "dplinedadodo", 0 },
2233         { rtfDrawAttr,  rtfDrawLineDash,        "dplinedash",   0 },
2234         { rtfDrawAttr,  rtfDrawLineDot,         "dplinedot",    0 },
2235         { rtfDrawAttr,  rtfDrawLineGray,        "dplinegray",   0 },
2236         { rtfDrawAttr,  rtfDrawLineHollow,      "dplinehollow", 0 },
2237         { rtfDrawAttr,  rtfDrawLineSolid,       "dplinesolid",  0 },
2238         { rtfDrawAttr,  rtfDrawLineWidth,       "dplinew",      0 },
2239
2240         { rtfDrawAttr,  rtfDrawHollowEndArrow,  "dpaendhol",    0 },
2241         { rtfDrawAttr,  rtfDrawEndArrowLength,  "dpaendl",      0 },
2242         { rtfDrawAttr,  rtfDrawSolidEndArrow,   "dpaendsol",    0 },
2243         { rtfDrawAttr,  rtfDrawEndArrowWidth,   "dpaendw",      0 },
2244         { rtfDrawAttr,  rtfDrawHollowStartArrow,"dpastarthol",  0 },
2245         { rtfDrawAttr,  rtfDrawStartArrowLength,"dpastartl",    0 },
2246         { rtfDrawAttr,  rtfDrawSolidStartArrow, "dpastartsol",  0 },
2247         { rtfDrawAttr,  rtfDrawStartArrowWidth, "dpastartw",    0 },
2248
2249         { rtfDrawAttr,  rtfDrawBgFillBlue,      "dpfillbgcb",   0 },
2250         { rtfDrawAttr,  rtfDrawBgFillGreen,     "dpfillbgcg",   0 },
2251         { rtfDrawAttr,  rtfDrawBgFillRed,       "dpfillbgcr",   0 },
2252         { rtfDrawAttr,  rtfDrawBgFillPalette,   "dpfillbgpal",  0 },
2253         { rtfDrawAttr,  rtfDrawBgFillGray,      "dpfillbggray", 0 },
2254         { rtfDrawAttr,  rtfDrawFgFillBlue,      "dpfillfgcb",   0 },
2255         { rtfDrawAttr,  rtfDrawFgFillGreen,     "dpfillfgcg",   0 },
2256         { rtfDrawAttr,  rtfDrawFgFillRed,       "dpfillfgcr",   0 },
2257         { rtfDrawAttr,  rtfDrawFgFillPalette,   "dpfillfgpal",  0 },
2258         { rtfDrawAttr,  rtfDrawFgFillGray,      "dpfillfggray", 0 },
2259         { rtfDrawAttr,  rtfDrawFillPatIndex,    "dpfillpat",    0 },
2260
2261         { rtfDrawAttr,  rtfDrawShadow,          "dpshadow",     0 },
2262         { rtfDrawAttr,  rtfDrawShadowXOffset,   "dpshadx",      0 },
2263         { rtfDrawAttr,  rtfDrawShadowYOffset,   "dpshady",      0 },
2264
2265         { rtfVersion,   -1,                     "rtf",          0 },
2266         { rtfDefFont,   -1,                     "deff",         0 },
2267
2268         { 0,            -1,                     (char *) NULL,  0 }
2269 };
2270 #define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
2271
2272 typedef struct tagRTFHashTableEntry {
2273         int count;
2274         RTFKey **value;
2275 } RTFHashTableEntry;
2276
2277 static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT * 2];
2278
2279
2280 /*
2281  * Initialize lookup table hash values.  Only need to do this once.
2282  */
2283
2284 static void LookupInit(void)
2285 {
2286         static int      inited = 0;
2287         RTFKey  *rp;
2288
2289         if (inited == 0)
2290         {
2291                 memset(rtfHashTable, 0, RTF_KEY_COUNT * 2 * sizeof(*rtfHashTable));
2292                 for (rp = rtfKey; rp->rtfKStr != NULL; rp++) {
2293                         int index;
2294                         
2295                         rp->rtfKHash = Hash ((char*)rp->rtfKStr);
2296                         index = rp->rtfKHash % (RTF_KEY_COUNT * 2);
2297                         if (!rtfHashTable[index].count)
2298                                 rtfHashTable[index].value = RTFAlloc(sizeof(RTFKey *));
2299                         else
2300                                 rtfHashTable[index].value = RTFReAlloc(rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
2301                         rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
2302                 }
2303                 ++inited;
2304         }
2305 }
2306
2307
2308 /*
2309  * Determine major and minor number of control token.  If it's
2310  * not found, the class turns into rtfUnknown.
2311  */
2312
2313 static void Lookup(RTF_Info *info, char *s)
2314 {
2315         RTFKey  *rp;
2316         int     hash;
2317         RTFHashTableEntry *entry;
2318         int i;
2319
2320         TRACE("\n");
2321         ++s;                    /* skip over the leading \ character */
2322         hash = Hash (s);
2323         entry = &rtfHashTable[hash % (RTF_KEY_COUNT * 2)];
2324         for (i = 0; i < entry->count; i++)
2325         {
2326                 rp = entry->value[i];
2327                 if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
2328                 {
2329                         info->rtfClass = rtfControl;
2330                         info->rtfMajor = rp->rtfKMajor;
2331                         info->rtfMinor = rp->rtfKMinor;
2332                         return;
2333                 }
2334         }
2335         info->rtfClass = rtfUnknown;
2336 }
2337
2338
2339 /*
2340  * Compute hash value of symbol
2341  */
2342
2343 static int Hash(char *s)
2344 {
2345         char    c;
2346         int     val = 0;
2347
2348         while ((c = *s++) != '\0')
2349                 val += c;
2350         return (val);
2351 }
2352
2353
2354
2355 /* ---------------------------------------------------------------------- */
2356
2357
2358 /*
2359  * Token comparison routines
2360  */
2361
2362 int RTFCheckCM(RTF_Info *info, int class, int major)
2363 {
2364         return (info->rtfClass == class && info->rtfMajor == major);
2365 }
2366
2367
2368 int RTFCheckCMM(RTF_Info *info, int class, int major, int minor)
2369 {
2370         return (info->rtfClass == class && info->rtfMajor == major && info->rtfMinor == minor);
2371 }
2372
2373
2374 int RTFCheckMM(RTF_Info *info, int major, int minor)
2375 {
2376         return (info->rtfMajor == major && info->rtfMinor == minor);
2377 }
2378
2379
2380 /* ---------------------------------------------------------------------- */
2381
2382
2383 int RTFCharToHex(char c)
2384 {
2385         if (isupper (c))
2386                 c = tolower (c);
2387         if (isdigit (c))
2388                 return (c - '0');       /* '0'..'9' */
2389         return (c - 'a' + 10);          /* 'a'..'f' */
2390 }
2391
2392
2393 int RTFHexToChar(int i)
2394 {
2395         if (i < 10)
2396                 return (i + '0');
2397         return (i - 10 + 'a');
2398 }
2399
2400
2401 /* ---------------------------------------------------------------------- */
2402
2403 /*
2404  * Print message.
2405  *
2406  * Message should include linefeeds as necessary.
2407  */
2408
2409
2410 void RTFMsg (RTF_Info *info, const char *fmt, ...)
2411 {
2412         char    buf[rtfBufSiz];
2413
2414         va_list args;
2415         va_start (args,fmt);
2416         vsprintf (buf, fmt, args);
2417         va_end (args);
2418         MESSAGE( "%s", buf);
2419 }
2420
2421
2422 /* ---------------------------------------------------------------------- */
2423
2424
2425 /*
2426  * Process termination.  Print error message and exit.  Also prints
2427  * current token, and current input line number and position within
2428  * line if any input has been read from the current file.  (No input
2429  * has been read if prevChar is EOF).
2430  */
2431
2432 static void DefaultPanicProc(RTF_Info *info, char *s)
2433 {
2434         MESSAGE( "%s", s);
2435         /*exit (1);*/
2436 }
2437
2438
2439
2440 void RTFPanic(RTF_Info *info, const char *fmt, ...)
2441 {
2442         char    buf[rtfBufSiz];
2443
2444         va_list args;
2445         va_start (args,fmt);
2446         vsprintf (buf, fmt, args);
2447         va_end (args);
2448         lstrcatA (buf, "\n");
2449         if (info->prevChar != EOF && info->rtfTextBuf != NULL)
2450         {
2451                 sprintf (buf + lstrlenA (buf),
2452                         "Last token read was \"%s\" near line %ld, position %d.\n",
2453                         info->rtfTextBuf, info->rtfLineNum, info->rtfLinePos);
2454         }
2455         DefaultPanicProc(info, buf);
2456 }
2457
2458 /* ---------------------------------------------------------------------- */
2459
2460 /*
2461  * originally from RTF tools' text-writer.c
2462  *
2463  * text-writer -- RTF-to-text translation writer code.
2464  *
2465  * Read RTF input, write text of document (text extraction).
2466  */
2467
2468 static void     TextClass (RTF_Info *info);
2469 static void     ControlClass (RTF_Info *info);
2470 static void     Destination (RTF_Info *info);
2471 static void     SpecialChar (RTF_Info *info);
2472 static void     RTFPutUnicodeChar (RTF_Info *info, int c);
2473
2474 /*
2475  * Initialize the writer.
2476  */
2477
2478 void
2479 WriterInit (RTF_Info *info )
2480 {
2481 }
2482
2483
2484 int
2485 BeginFile (RTF_Info *info )
2486 {
2487         /* install class callbacks */
2488
2489         RTFSetClassCallback (info, rtfText, TextClass);
2490         RTFSetClassCallback (info, rtfControl, ControlClass);
2491
2492         return (1);
2493 }
2494
2495 /*
2496  * Write out a character.
2497  */
2498
2499 static void
2500 TextClass (RTF_Info *info)
2501 {
2502         RTFPutCodePageChar(info, info->rtfMajor);
2503 }
2504
2505
2506 static void
2507 ControlClass (RTF_Info *info)
2508 {
2509         TRACE("\n");
2510
2511         switch (info->rtfMajor)
2512         {
2513         case rtfCharAttr:
2514                 CharAttr(info);
2515                 break;
2516         case rtfCharSet:
2517                 CharSet(info);
2518                 break;
2519         case rtfDestination:
2520                 Destination (info);
2521                 break;
2522         case rtfDocAttr:
2523                 DocAttr(info);
2524                 break;
2525         case rtfSpecialChar:
2526                 SpecialChar (info);
2527                 break;
2528         }
2529 }
2530
2531
2532 static void
2533 CharAttr(RTF_Info *info)
2534 {
2535         RTFFont *font;
2536         
2537         switch (info->rtfMinor)
2538         {
2539         case rtfFontNum:
2540                 font = RTFGetFont(info, info->rtfParam);
2541                 if (font)
2542                 {
2543                         if (info->ansiCodePage != CP_UTF8)
2544                                 info->codePage = font->rtfFCodePage;
2545                 }
2546                 else
2547                         RTFMsg(info, "unknown font %d\n", info->rtfParam);
2548                 break;
2549         case rtfUnicodeLength:
2550                 info->unicodeLength = info->rtfParam;
2551                 break;
2552         }
2553 }
2554
2555
2556 static void
2557 CharSet(RTF_Info *info)
2558 {
2559         switch (info->rtfMinor)
2560         {
2561         case rtfAnsiCharSet:
2562                 info->ansiCodePage = 1252; /* Latin-1 */
2563                 break;
2564         case rtfMacCharSet:
2565                 info->ansiCodePage = 10000; /* MacRoman */
2566                 break;
2567         case rtfPcCharSet:
2568                 info->ansiCodePage = 437;
2569                 break;
2570         case rtfPcaCharSet:
2571                 info->ansiCodePage = 850;
2572                 break;
2573         }
2574 }
2575
2576 /*
2577  * This function notices destinations that aren't explicitly handled
2578  * and skips to their ends.  This keeps, for instance, picture
2579  * data from being considered as plain text.
2580  */
2581
2582 static void
2583 Destination (RTF_Info *info)
2584 {
2585         TRACE("\n");
2586         if (!RTFGetDestinationCallback(info, info->rtfMinor))
2587                 RTFSkipGroup (info);    
2588 }
2589
2590
2591 static void
2592 DocAttr(RTF_Info *info)
2593 {
2594         switch (info->rtfMinor)
2595         {
2596         case rtfAnsiCodePage:
2597                 info->ansiCodePage = info->rtfParam;
2598                 break;
2599         case rtfUTF8RTF:
2600                 info->ansiCodePage = CP_UTF8;
2601                 break;
2602         }
2603 }
2604
2605
2606 static void SpecialChar (RTF_Info *info)
2607 {
2608
2609         TRACE("\n");
2610
2611         switch (info->rtfMinor)
2612         {
2613         case rtfOptDest:
2614                 /* the next token determines destination, if it's unknown, skip the group */
2615                 /* this way we filter out the garbage coming from unknown destinations */ 
2616                 RTFGetToken(info); 
2617                 if (info->rtfClass != rtfDestination)
2618                         RTFSkipGroup(info);
2619                 else
2620                         RTFRouteToken(info); /* "\*" is ignored with known destinations */
2621                 break;
2622         case rtfUnicode:
2623         {
2624                 int i;
2625                
2626                 RTFPutUnicodeChar(info, info->rtfParam);
2627                 
2628                 /* After \u we must skip number of character tokens set by \ucN */
2629                 for (i = 0; i < info->unicodeLength; i++)
2630                 {
2631                         RTFGetToken(info);
2632                         if (info->rtfClass != rtfText)
2633                         {
2634                                 ERR("The token behind \\u is not text, but (%d,%d,%d)\n",
2635                                 info->rtfClass, info->rtfMajor, info->rtfMinor);
2636                                 RTFUngetToken(info);
2637                                 break;
2638                         }
2639                 }
2640                 break;
2641         }
2642         case rtfPage:
2643         case rtfSect:
2644         case rtfRow:
2645         case rtfLine:
2646         case rtfPar:
2647                 RTFPutUnicodeChar (info, '\n');
2648                 break;
2649         case rtfCell:
2650                 RTFPutUnicodeChar (info, ' ');  /* make sure cells are separated */
2651                 break;
2652         case rtfNoBrkSpace:
2653                 RTFPutUnicodeChar (info, 0x00A0);
2654                 break;
2655         case rtfTab:
2656                 RTFPutUnicodeChar (info, '\t');
2657                 break;
2658         case rtfNoBrkHyphen:
2659                 RTFPutUnicodeChar (info, 0x2011);
2660                 break;
2661         case rtfBullet:
2662                 RTFPutUnicodeChar (info, 0x2022);
2663                 break;
2664         case rtfEmDash:
2665                 RTFPutUnicodeChar (info, 0x2014);
2666                 break;
2667         case rtfEnDash:
2668                 RTFPutUnicodeChar (info, 0x2013);
2669                 break;
2670         case rtfLQuote:
2671                 RTFPutUnicodeChar (info, 0x2018);
2672                 break;
2673         case rtfRQuote:
2674                 RTFPutUnicodeChar (info, 0x2019);
2675                 break;
2676         case rtfLDblQuote:
2677                 RTFPutUnicodeChar (info, 0x201C);
2678                 break;
2679         case rtfRDblQuote:
2680                 RTFPutUnicodeChar (info, 0x201D);
2681                 break;
2682         }
2683 }
2684
2685
2686 static void
2687 RTFFlushUnicodeOutputBuffer(RTF_Info *info)
2688 {
2689         if (info->dwOutputCount)
2690         {
2691                 ME_InsertTextFromCursor(info->editor, 0, info->OutputBuffer,
2692                                         info->dwOutputCount, info->style);
2693                 info->dwOutputCount = 0;
2694         }
2695 }
2696
2697 static void
2698 RTFPutUnicodeString(RTF_Info *info, WCHAR *string, int length)
2699 {
2700         if (info->dwCPOutputCount)
2701                 RTFFlushCPOutputBuffer(info);
2702         while (length)
2703         {
2704                 int fit = min(length, sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount);
2705
2706                 memmove(info->OutputBuffer + info->dwOutputCount, string, fit * sizeof(WCHAR));
2707                 if (fit == sizeof(info->OutputBuffer) / sizeof(WCHAR) - info->dwOutputCount)
2708                         RTFFlushUnicodeOutputBuffer(info);
2709                 else
2710                         info->dwOutputCount += fit;
2711                 length -= fit;
2712                 string += fit;
2713         }
2714 }
2715
2716 static void
2717 RTFFlushCPOutputBuffer(RTF_Info *info)
2718 {
2719         int bufferMax = info->dwCPOutputCount * 2 * sizeof(WCHAR);
2720         WCHAR *buffer = (WCHAR *)RTFAlloc(bufferMax);
2721         int length;
2722
2723         length = MultiByteToWideChar(info->codePage, 0, info->cpOutputBuffer,
2724                                      info->dwCPOutputCount, buffer, bufferMax);
2725         info->dwCPOutputCount = 0;
2726
2727         RTFPutUnicodeString(info, buffer, length);
2728         RTFFree((char *)buffer);
2729 }
2730
2731 void
2732 RTFFlushOutputBuffer(RTF_Info *info)
2733 {
2734         if (info->dwCPOutputCount)
2735                 RTFFlushCPOutputBuffer(info);
2736         RTFFlushUnicodeOutputBuffer(info);
2737 }
2738
2739 static void
2740 RTFPutUnicodeChar(RTF_Info *info, int c)
2741 {
2742         if (info->dwCPOutputCount)
2743                 RTFFlushCPOutputBuffer(info);
2744         if (info->dwOutputCount * sizeof(WCHAR) >= ( sizeof info->OutputBuffer - 1 ) )
2745                 RTFFlushUnicodeOutputBuffer( info );
2746         info->OutputBuffer[info->dwOutputCount++] = c;
2747 }
2748
2749 static void
2750 RTFPutCodePageChar(RTF_Info *info, int c)
2751 {
2752         /* Use dynamic buffer here because it's the best way to handle
2753          * MBCS codepages without having to worry about partial chars */
2754         if (info->dwCPOutputCount >= info->dwMaxCPOutputCount)
2755         {
2756                 info->dwMaxCPOutputCount *= 2;
2757                 info->cpOutputBuffer = RTFReAlloc(info->cpOutputBuffer, info->dwMaxCPOutputCount);
2758         }
2759         info->cpOutputBuffer[info->dwCPOutputCount++] = c;
2760 }