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