summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/src2html.c
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2009-12-23 17:59:08 +0000
committer Aaron Giles <aaron@aarongiles.com>2009-12-23 17:59:08 +0000
commit505f0d7caf85e78aa4d0c4f5f949acc509ff1f4f (patch)
treea93df6edb887efab3b40503a3a7fc01732a630d9 /src/tools/src2html.c
parent668dc94b003a5da110ba6581820aec777fe3535e (diff)
From: Atari Ace <atari_ace@verizon.net>
Date: Tue, Dec 22, 2009 at 4:44 PM Subject: [patch] Fix srcclean/src2html bugs, misbalanced tokens and visible whitespace errors To: submit@mamedev.org Cc: atariace@hotmail.com Hi mamedev, While experimenting with srcclean and src2html as indentation validators, I stumbled across a couple of bugs. The first is that srcclean doesn't properly handle /*...*//. It sees the last / char at the end as the second / of an inline comment, where it might be a division token or the start of either type of comment. The second bug is that src2html improperly handles strings with embedded quotes preceded by escaped backslashes, e.g. "ab\\\"cd". It believes the string terminated in the middle, and the last quote starts a new string. This issue is unlikely in actual code, but should be handled correctly. The first patch fixes these, and a some cases where there are dangling/missing tokens which my validation tools are noticing. These occur in some unused macros, dead code sections, and in some macros that are deliberately misbalanced (v9938.c, psx.c). In the deliberate cases, I balanced the braces by making exactly one open and one close macro and using those throughout. The second patch is then a set of visible whitespace "problems". Cases where the closing brace isn't at the same indent level as the open brace, and some cases where the indent level isn't a multiple of four. In the case of ssv.c I folded the assignments into init_ssv() to simplify the code and restore the brace balance, otherwise I kept to simply adding or removing whitespace. ~aa
Diffstat (limited to 'src/tools/src2html.c')
-rw-r--r--src/tools/src2html.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/tools/src2html.c b/src/tools/src2html.c
index e1126b04957..cedb3f51a16 100644
--- a/src/tools/src2html.c
+++ b/src/tools/src2html.c
@@ -590,6 +590,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
int quotes_are_linked = FALSE;
char in_quotes = 0;
int curcol = 0;
+ int escape = 0;
/* start with the line number */
dstptr += sprintf(dstptr, "<span class=\"linenum\">%5d</span>&nbsp;&nbsp;", linenum++);
@@ -704,7 +705,7 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
}
/* track closing quotes */
- else if (!in_comment && !in_inline_comment && in_quotes && ch == in_quotes && (type != FILE_TYPE_C || srcptr[-2] != '\\' || srcptr[-3] == '\\'))
+ else if (!in_comment && !in_inline_comment && in_quotes && ch == in_quotes && !escape)
{
if (quotes_are_linked)
dstptr += sprintf(dstptr, "</a>");
@@ -727,6 +728,10 @@ static int output_file(file_type type, int srcrootlen, int dstrootlen, const ast
*dstptr++ = ch;
curcol++;
}
+
+ /* Update escape state */
+ if (in_quotes)
+ escape = (ch == '\\' && type == FILE_TYPE_C) ? !escape : 0;
}
/* finish inline comments */