/* 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 # 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); }