Jul 99 Challenge
Volume Number: 15
Issue Number: 7
Column Tag: Programmer's Challenge
by Bob Boonstra, Westford, MA
C-to-HTML
This month, your Challenge is simple enough: generate a little HTML. Not just any
HTML, of course, but HTML that displays a C or C++ program the way it looks in your
Metrowerks CodeWarrior editor window. The prototype for the code you should write
is:
#if defined (__cplusplus)
extern "C" {
#endif
typedef struct Settings {
unsigned long commentColor; /*00RRGGBB*/
unsigned long keywordColor; /*00RRGGBB*/
unsigned long stringColor; /*00RRGGBB*/
char fontName[32]; /* font to use for display */
unsigned long fontSize; /* size of font to use */
unsigned long tabSize; /* number of spaces to use for tabs */
} Settings;
long /* output length */ CtoHTML(
const char *inputText, /* text to convert */
char *outputHTML, /* converted text */
const Settings displaySettings /* display parameters */
);
#if defined (__cplusplus)
}
#endif
A syntactically correct C or C++ program will be provided to you as inputText. You
should convert that program to HTML so that, when displayed in the current Netscape
browser (4.6 as of this writing), the code will appear as the input does when opened
in CodeWarrior. The output HTML should be stored in (surprise) outputHTML, and
the number of characters generated should be returned by your CtoHTML routine.
Your CodeWarrior display preferences are provided in displaySettings: the colors
to be used for comments, keywords, and strings, the name and size of the font to be
used. The tabSize parameter should be used to convert tab characters to the
appropriate number of nonbreaking spaces, so that the HTML appears correct no