summaryrefslogtreecommitdiff
path: root/support/RTF-1_06a1/rtfdiag.c
blob: ccc6df9d35c16c83479d885a5786cee4e7561aff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
	rtfdiag - read rtf input, write diagnostic stuff.  Useful for
		testing reader to see if it's finding and classifying
		tokens properly, reading destinations, reprocessing
		styles, etc.

	Options:

	-e	echo tokens as they are read

	03 Feb 91	Paul DuBois	dubois@primate.wisc.edu

	03 Feb 91 V1.0. Created.
	27 Feb 91 V1.01. Updated for distribution 1.05.
*/

# include	<stdio.h>
# include	"rtf.h"


static char	*usage = "rtfdiag [-e] [file]";

static void	TokenEcho ();
static void	PrintTables ();

int main (argc, argv)
int	argc;
char	**argv;
{
	RTFInit ();

	--argc;
	++argv;

	while (argc > 1 && **argv == '-')
	{
		while (*++*argv != '\0')
		{
			switch (**argv)
			{
			case 'e':
				RTFSetReadHook (TokenEcho);
				break;
			default:
				fprintf (stderr, "Unknown option: -%c\n",
							**argv);
				fprintf (stderr, "%s\n", usage);
				exit (1);
			}
		}
		--argc;
		++argv;
	}

	/* not clever; only allows stdin or one named file to be read */

	if (argc > 0)
	{
		if (freopen (argv[0], "r", stdin) == NULL)
		{
			fprintf (stderr, "Can't open \"%s\"\n", argv[0]);
			exit (1);
		}
	}

	/* process the input stream */

	RTFRead ();

	PrintTables ();

	exit (0);
}

static void TokenEcho ()
{
	printf ("%d\t%d\t%d\t%d\t\"%s\"\n",
			rtfClass, rtfMajor, rtfMinor, rtfParam, rtfTextBuf);
}


static void PrintTables ()
{
RTFColor	*cp;
RTFFont		*fp;
RTFStyle	*sp;
RTFStyleElt	*sep;
int	count;

	printf ("Font table:\n");
	count = 0;
	for (fp = RTFGetFont (-1); fp != NULL; fp = fp->rtfNextFont)
	{
		++count;
		printf ("%2d:\t%s\t%d\n", fp->rtfFNum, fp->rtfFName,
			fp->rtfFFamily);
	}
	printf ("Font table entries:\t%d\n\n", count);

	printf ("Color table:\n\tred\tgreen\tblue\n");
	count = 0;
	for (cp = RTFGetColor (-1); cp != NULL; cp = cp->rtfNextColor)
	{
		++count;
		printf ("%2d:\t%d\t%d\t%d\n", cp->rtfCNum, cp->rtfCRed,
			cp->rtfCGreen, cp->rtfCBlue);
	}
	printf ("Color table entries:\t%d\n\n", count);

	printf ("Stylesheet:\n");
	count = 0;
	for (sp = RTFGetStyle (-1); sp != NULL; sp = sp->rtfNextStyle)
	{
		++count;
		printf ("%2d:\t%s\t%d\t%d\n", sp->rtfSNum, sp->rtfSName,
				sp->rtfSBasedOn, sp->rtfSNextPar);
		for (sep = sp->rtfSSEList; sep != NULL; sep = sep->rtfNextSE)
			printf ("\t%s\n", sep->rtfSEText);
	}
	printf ("Style table entries:\t%d\n\n", count);
}