grindin'
This commit is contained in:
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
c2html
|
c2html
|
||||||
*.html
|
*.html
|
||||||
samples
|
samples
|
||||||
|
vgcore.*
|
||||||
@@ -1 +1 @@
|
|||||||
gcc cli.c c2html.c -o c2html -Wall -Wextra
|
gcc cli.c c2html.c -o c2html -Wall -Wextra -g
|
||||||
@@ -106,6 +106,7 @@ static Token *tokenize(const char *str, long len)
|
|||||||
long curly_bracket_depth = 0;
|
long curly_bracket_depth = 0;
|
||||||
bool only_spaces_since_line_start = 1;
|
bool only_spaces_since_line_start = 1;
|
||||||
bool prev_nonspace_was_directive = 0;
|
bool prev_nonspace_was_directive = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(i == len) {
|
if(i == len) {
|
||||||
T.kind = T_DONE;
|
T.kind = T_DONE;
|
||||||
@@ -191,7 +192,7 @@ static Token *tokenize(const char *str, long len)
|
|||||||
// We allow an 'x' if it's after a '0'.
|
// We allow an 'x' if it's after a '0'.
|
||||||
if(i+2 < len && str[i] == '0' && str[i+1] == 'x' && isdigit(str[i+2]))
|
if(i+2 < len && str[i] == '0' && str[i+1] == 'x' && isdigit(str[i+2]))
|
||||||
i += 2; // Skip the '0x'.
|
i += 2; // Skip the '0x'.
|
||||||
|
|
||||||
while(i < len && isdigit(str[i]))
|
while(i < len && isdigit(str[i]))
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
||||||
@@ -459,7 +460,6 @@ static void print_escaped(buff_t *buff, const char *str, long len)
|
|||||||
&& str[j] != '<'
|
&& str[j] != '<'
|
||||||
&& str[j] != '>'
|
&& str[j] != '>'
|
||||||
&& str[j] != ' '
|
&& str[j] != ' '
|
||||||
&& str[j] != '\n'
|
|
||||||
&& str[j] != '\t')
|
&& str[j] != '\t')
|
||||||
j += 1;
|
j += 1;
|
||||||
|
|
||||||
@@ -472,14 +472,12 @@ static void print_escaped(buff_t *buff, const char *str, long len)
|
|||||||
switch(str[j]) {
|
switch(str[j]) {
|
||||||
case '<': buff_printf(buff, "<"); break;
|
case '<': buff_printf(buff, "<"); break;
|
||||||
case '>': buff_printf(buff, ">"); break;
|
case '>': buff_printf(buff, ">"); break;
|
||||||
case '\n': buff_printf(buff, "<br />\n"); break;
|
|
||||||
case '\t': buff_printf(buff, "    "); break;
|
case '\t': buff_printf(buff, "    "); break;
|
||||||
|
|
||||||
case ' ':
|
case ' ':
|
||||||
if(j == 0 || str[j-1] != ' ')
|
if(j == 0 || j == len-1 || (str[j-1] == ' ' || str[j-1] == '\t'))
|
||||||
buff_printf(buff, " ");
|
|
||||||
else
|
|
||||||
buff_printf(buff, " ");
|
buff_printf(buff, " ");
|
||||||
|
else
|
||||||
|
buff_printf(buff, " ");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: assert(0);
|
default: assert(0);
|
||||||
@@ -598,10 +596,33 @@ char *c2html(const char *str, long len, _Bool table_mode, const char *class_pref
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case T_COMMENT:
|
case T_COMMENT:
|
||||||
buff_printf(&buff, "<span class=\"%scomment\">", class_prefix);
|
{
|
||||||
print_escaped(&buff, str + tokens[i].off, tokens[i].len);
|
long j = tokens[i].off;
|
||||||
buff_printf(&buff, "</span>");
|
long end = j + tokens[i].len;
|
||||||
break;
|
while(1) {
|
||||||
|
|
||||||
|
long line_off = j;
|
||||||
|
while(j < end && str[j] != '\n')
|
||||||
|
j += 1;
|
||||||
|
long line_len = j - line_off;
|
||||||
|
|
||||||
|
buff_printf(&buff, "<span class=\"%scomment\">", class_prefix);
|
||||||
|
print_escaped(&buff, str + line_off, line_len);
|
||||||
|
buff_printf(&buff, "</span>");
|
||||||
|
|
||||||
|
if(j == end)
|
||||||
|
break;
|
||||||
|
|
||||||
|
j += 1; // Skip the '\n'.
|
||||||
|
|
||||||
|
lineno += 1;
|
||||||
|
if(table_mode)
|
||||||
|
buff_printf(&buff, "</td></tr>\n <tr><td>%d</td><td>", lineno);
|
||||||
|
else
|
||||||
|
buff_printf(&buff, "<br />\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case T_OPERATOR:
|
case T_OPERATOR:
|
||||||
buff_printf(&buff, "<span class=\"%soperator\">", class_prefix);
|
buff_printf(&buff, "<span class=\"%soperator\">", class_prefix);
|
||||||
|
|||||||
Reference in New Issue
Block a user