Changed from explicit styles to classes.

This commit is contained in:
Aaron Giles 2008-10-30 15:30:24 +00:00
parent e5183b1d20
commit 5f440c4a63

View File

@ -29,13 +29,9 @@
CONSTANTS & DEFINES CONSTANTS & DEFINES
***************************************************************************/ ***************************************************************************/
#define BASE_STYLE "font-family:'Courier New','Courier',monospace; font-size:12px; background:none; border:none; color:#000000;" #define PREPROC_CLASS "preproc"
#define COMMENT_STYLE "color:#b30000" #define KEYWORD_CLASS "keyword"
#define STRING_STYLE "color:#666" #define CUSTOM_CLASS "custom"
#define PREPROCESSOR_STYLE "color:#0000b3"
#define KEYWORD_STYLE "color:#0000b3"
#define MAMEWORD_STYLE "color:#7f007f"
#define LINENUM_STYLE "color:#999"
@ -107,71 +103,71 @@ static const ext_to_type extension_lookup[] =
static const token_entry dummy_token_table[] = static const token_entry dummy_token_table[] =
{ {
{ NULL, KEYWORD_STYLE } { NULL, KEYWORD_CLASS }
}; };
static const token_entry c_token_table[] = static const token_entry c_token_table[] =
{ {
{ "#define", PREPROCESSOR_STYLE }, { "#define", PREPROC_CLASS },
{ "#elif", PREPROCESSOR_STYLE }, { "#elif", PREPROC_CLASS },
{ "#else", PREPROCESSOR_STYLE }, { "#else", PREPROC_CLASS },
{ "#endif", PREPROCESSOR_STYLE }, { "#endif", PREPROC_CLASS },
{ "#error", PREPROCESSOR_STYLE }, { "#error", PREPROC_CLASS },
{ "#if", PREPROCESSOR_STYLE }, { "#if", PREPROC_CLASS },
{ "#ifdef", PREPROCESSOR_STYLE }, { "#ifdef", PREPROC_CLASS },
{ "#ifndef", PREPROCESSOR_STYLE }, { "#ifndef", PREPROC_CLASS },
{ "#include", PREPROCESSOR_STYLE }, { "#include", PREPROC_CLASS },
{ "#line", PREPROCESSOR_STYLE }, { "#line", PREPROC_CLASS },
{ "#pragma", PREPROCESSOR_STYLE }, { "#pragma", PREPROC_CLASS },
{ "#undef", PREPROCESSOR_STYLE }, { "#undef", PREPROC_CLASS },
{ "auto", KEYWORD_STYLE }, { "auto", KEYWORD_CLASS },
{ "break", KEYWORD_STYLE }, { "break", KEYWORD_CLASS },
{ "case", KEYWORD_STYLE }, { "case", KEYWORD_CLASS },
{ "char", KEYWORD_STYLE }, { "char", KEYWORD_CLASS },
{ "const", KEYWORD_STYLE }, { "const", KEYWORD_CLASS },
{ "continue", KEYWORD_STYLE }, { "continue", KEYWORD_CLASS },
{ "default", KEYWORD_STYLE }, { "default", KEYWORD_CLASS },
{ "do", KEYWORD_STYLE }, { "do", KEYWORD_CLASS },
{ "double", KEYWORD_STYLE }, { "double", KEYWORD_CLASS },
{ "else", KEYWORD_STYLE }, { "else", KEYWORD_CLASS },
{ "enum", KEYWORD_STYLE }, { "enum", KEYWORD_CLASS },
{ "extern", KEYWORD_STYLE }, { "extern", KEYWORD_CLASS },
{ "float", KEYWORD_STYLE }, { "float", KEYWORD_CLASS },
{ "for", KEYWORD_STYLE }, { "for", KEYWORD_CLASS },
{ "goto", KEYWORD_STYLE }, { "goto", KEYWORD_CLASS },
{ "if", KEYWORD_STYLE }, { "if", KEYWORD_CLASS },
{ "int", KEYWORD_STYLE }, { "int", KEYWORD_CLASS },
{ "long", KEYWORD_STYLE }, { "long", KEYWORD_CLASS },
{ "register", KEYWORD_STYLE }, { "register", KEYWORD_CLASS },
{ "return", KEYWORD_STYLE }, { "return", KEYWORD_CLASS },
{ "short", KEYWORD_STYLE }, { "short", KEYWORD_CLASS },
{ "signed", KEYWORD_STYLE }, { "signed", KEYWORD_CLASS },
{ "sizeof", KEYWORD_STYLE }, { "sizeof", KEYWORD_CLASS },
{ "static", KEYWORD_STYLE }, { "static", KEYWORD_CLASS },
{ "struct", KEYWORD_STYLE }, { "struct", KEYWORD_CLASS },
{ "switch", KEYWORD_STYLE }, { "switch", KEYWORD_CLASS },
{ "typedef", KEYWORD_STYLE }, { "typedef", KEYWORD_CLASS },
{ "union", KEYWORD_STYLE }, { "union", KEYWORD_CLASS },
{ "unsigned", KEYWORD_STYLE }, { "unsigned", KEYWORD_CLASS },
{ "void", KEYWORD_STYLE }, { "void", KEYWORD_CLASS },
{ "volatile", KEYWORD_STYLE }, { "volatile", KEYWORD_CLASS },
{ "while", KEYWORD_STYLE }, { "while", KEYWORD_CLASS },
/* /*
{ "INLINE", MAMEWORD_STYLE }, { "INLINE", CUSTOM_CLASS },
{ "INT8", MAMEWORD_STYLE }, { "INT8", CUSTOM_CLASS },
{ "UINT8", MAMEWORD_STYLE }, { "UINT8", CUSTOM_CLASS },
{ "INT16", MAMEWORD_STYLE }, { "INT16", CUSTOM_CLASS },
{ "UINT16", MAMEWORD_STYLE }, { "UINT16", CUSTOM_CLASS },
{ "INT32", MAMEWORD_STYLE }, { "INT32", CUSTOM_CLASS },
{ "UINT32", MAMEWORD_STYLE }, { "UINT32", CUSTOM_CLASS },
{ "INT64", MAMEWORD_STYLE }, { "INT64", CUSTOM_CLASS },
{ "UINT64", MAMEWORD_STYLE }, { "UINT64", CUSTOM_CLASS },
{ "ARRAY_LENGTH", MAMEWORD_STYLE }, { "ARRAY_LENGTH", CUSTOM_CLASS },
*/ */
{ NULL, KEYWORD_STYLE } { NULL, KEYWORD_CLASS }
}; };
@ -560,7 +556,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
core_fprintf(dst, "</h3>"); core_fprintf(dst, "</h3>");
/* start with some tags */ /* start with some tags */
core_fprintf(dst, "\t<pre style=\"" BASE_STYLE "\">\n"); core_fprintf(dst, "\t<pre class=\"source\">\n");
/* iterate over lines in the source file */ /* iterate over lines in the source file */
while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != NULL) while (core_fgets(srcline, ARRAY_LENGTH(srcline), src) != NULL)
@ -574,7 +570,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
int curcol = 0; int curcol = 0;
/* start with the line number */ /* start with the line number */
dstptr += sprintf(dstptr, "<span style=\"" LINENUM_STYLE "\">%5d</span>&nbsp;&nbsp;", linenum++); dstptr += sprintf(dstptr, "<span class=\"linenum\">%5d</span>&nbsp;&nbsp;", linenum++);
/* iterate over characters in the source line */ /* iterate over characters in the source line */
for (srcptr = srcline; *srcptr != 0; ) for (srcptr = srcline; *srcptr != 0; )
@ -586,7 +582,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
{ {
if (!in_comment && ch == comment_start[0] && strncmp(srcptr - 1, comment_start, strlen(comment_start)) == 0) if (!in_comment && ch == comment_start[0] && strncmp(srcptr - 1, comment_start, strlen(comment_start)) == 0)
{ {
dstptr += sprintf(dstptr, "<span style=\"" COMMENT_STYLE "\">%s", comment_start_esc); dstptr += sprintf(dstptr, "<span class=\"comment\">%s", comment_start_esc);
curcol += strlen(comment_start); curcol += strlen(comment_start);
srcptr += strlen(comment_start) - 1; srcptr += strlen(comment_start) - 1;
ch = 0; ch = 0;
@ -605,7 +601,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
/* track whether or not we are within an inline (C++-style) comment */ /* track whether or not we are within an inline (C++-style) comment */
if (!in_quotes && !in_comment && !in_inline_comment && ch == comment_inline[0] && strncmp(srcptr - 1, comment_inline, strlen(comment_inline)) == 0) if (!in_quotes && !in_comment && !in_inline_comment && ch == comment_inline[0] && strncmp(srcptr - 1, comment_inline, strlen(comment_inline)) == 0)
{ {
dstptr += sprintf(dstptr, "<span style=\"" COMMENT_STYLE "\">%s", comment_inline_esc); dstptr += sprintf(dstptr, "<span class=\"comment\">%s", comment_inline_esc);
curcol += strlen(comment_inline); curcol += strlen(comment_inline);
srcptr += strlen(comment_inline) - 1; srcptr += strlen(comment_inline) - 1;
ch = 0; ch = 0;
@ -629,7 +625,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
for (curtoken = token_table; curtoken->token != NULL; curtoken++) for (curtoken = token_table; curtoken->token != NULL; curtoken++)
if (strncmp(srcptr - 1, curtoken->token, toklength) == 0 && strlen(curtoken->token) == toklength) if (strncmp(srcptr - 1, curtoken->token, toklength) == 0 && strlen(curtoken->token) == toklength)
{ {
dstptr += sprintf(dstptr, "<span style=\"%s\">%s</span>", curtoken->color, curtoken->token); dstptr += sprintf(dstptr, "<span class=\"%s\">%s</span>", curtoken->color, curtoken->token);
curcol += strlen(curtoken->token); curcol += strlen(curtoken->token);
srcptr += strlen(curtoken->token) - 1; srcptr += strlen(curtoken->token) - 1;
ch = 0; ch = 0;
@ -661,7 +657,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\'')) if (!in_comment && !in_inline_comment && !in_quotes && (ch == '"' || ch == '\''))
{ {
if (color_quotes) if (color_quotes)
dstptr += sprintf(dstptr, "<span style=\"" STRING_STYLE "\">%c", ch); dstptr += sprintf(dstptr, "<span class=\"string\">%c", ch);
else else
*dstptr++ = ch; *dstptr++ = ch;
in_quotes = ch; in_quotes = ch;