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