From 401df276a65240543b33b0ded67f18d9f9b67278 Mon Sep 17 00:00:00 2001 From: cozis Date: Thu, 5 May 2022 20:29:09 +0200 Subject: [PATCH] fixed comment output --- BUGS | 1 - README.md | 20 ++++++++++---------- c2html.c | 28 ++++++++++++++++++++++------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/BUGS b/BUGS index df777bb..e69de29 100644 --- a/BUGS +++ b/BUGS @@ -1 +0,0 @@ -- Newlines in multi-line comments arent converted into
s \ No newline at end of file diff --git a/README.md b/README.md index 1404e43..69e433f 100644 --- a/README.md +++ b/README.md @@ -96,23 +96,23 @@ int main() ``` when executed, the output will be: ``` -
-
- int main() {
-     int a = 5;
-     return 0;
+
+
+ int main() {
+     int a = 5;
+     return 0;
}
``` If `table_mode` were `1`, then the output would have been: ``` -
-
+
+
- - - + + +
1int main() {
2  int a = 5;
3  return 0;
1int main() {
2  int a = 5;
3  return 0;
4}
5
diff --git a/c2html.c b/c2html.c index b5c8215..6c2ff57 100644 --- a/c2html.c +++ b/c2html.c @@ -350,7 +350,12 @@ static void print_escaped(buff_t *buff, const char *str, long len) long off = j; - while(j < len && str[j] != '<' && str[j] != '>') + while(j < len + && str[j] != '<' + && str[j] != '>' + && str[j] != ' ' + && str[j] != '\n' + && str[j] != '\t') j += 1; long end = j; @@ -359,11 +364,22 @@ static void print_escaped(buff_t *buff, const char *str, long len) if(j == len) break; - assert(str[j] == '<' || str[j] == '>'); - if(str[j] == '<') - buff_printf(buff, "<"); - else - buff_printf(buff, ">"); + switch(str[j]) { + case '<': buff_printf(buff, "<"); break; + case '>': buff_printf(buff, ">"); break; + case '\n': buff_printf(buff, "
"); break; + case '\t': buff_printf(&buff, "    "); break; + + case ' ': + if(j == 0 || str[j-1] != ' ') + buff_printf(buff, " "); + else + buff_printf(buff, " "); + break; + + default: assert(0); + } + j += 1; } }