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