source: trunk/src/riched32/reader.c@ 22012

Last change on this file since 22012 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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