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

Last change on this file since 3721 was 3515, checked in by sandervl, 25 years ago

created; wine port

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