diff -r 2b4ac35d061d -r 1f3835182aeb src/c2html.c
--- a/src/c2html.c Tue Aug 23 15:07:29 2016 +0200
+++ b/src/c2html.c Tue Aug 23 15:28:56 2016 +0200
@@ -47,10 +47,23 @@
"\n");
}
+/* TODO: remove this workaround after refactoring highlighter structure */
+static void plainparseline(char *src, UcxBuffer *dest, highlighter_t* hltr) {
+ size_t dp = 0;
+ char *buf = dest->space + dest->pos;
+ while (*src && *src != '\n') {
+ dp = writeescapedchar(buf, dp, *src);
+ src++;
+ }
+ buf[dp++] = '\n';
+ buf[dp] = '\0';
+ dest->pos += dp;
+ dest->size += dp;
+}
+
int formatfile(
highlighter_t *highlighter,
- UcxList *in,
- write_func out, void *stream,
+ UcxList *in, write_func out, void *stream,
int showlineno) {
/* compute width of line numbering */
@@ -85,23 +98,8 @@
lineno, lineno, lnw, lineno);
}
- /* TODO: backwards compatibility: replace line->space in all occasions
- * and use UcxBuffer functions
- */
- char *buf = line->space + line->pos;
- if (highlighter) {
- highlighter->parser(sourceline->data, buf, highlighter);
- } else {
- char *c = sourceline->data;
- size_t dp = 0;
- while (*c && *c != '\n') {
- dp = writeescapedchar(buf, dp, *c);
- c++;
- }
- buf[dp++] = '\n';
- buf[dp] = '\0';
- }
- line->size = strlen(line->space);
+ /* process code line */
+ highlighter->parser(sourceline->data, line, highlighter);
/* write code line */
out(line->space, 1, line->size, stream);
@@ -115,22 +113,6 @@
return 0;
}
-void init_c_highlighter(highlighter_t *highlighter) {
- memset(highlighter, 0, sizeof(highlighter_t));
- highlighter->isdirective = check_cdirective;
- highlighter->istype = check_ctype;
- highlighter->keywords = ckeywords;
- highlighter->parser = cparseline;
-}
-
-void init_java_highlighter(highlighter_t *highlighter) {
- memset(highlighter, 0, sizeof(highlighter_t));
- highlighter->isdirective = check_jdirective;
- highlighter->istype = check_jtype;
- highlighter->keywords = jkeywords;
- highlighter->parser = jparseline;
-}
-
#define FILEBUF_SIZE 4096
enum source_type {
@@ -192,17 +174,22 @@
return EXIT_FAILURE;
} else {
/* Configure highlighter */
- highlighter_t highlighter;
- highlighter_t *hptr = &highlighter;
+ highlighter_t *highlighter = calloc(1, sizeof(highlighter_t));
switch (sourcetype) {
case SOURCE_C:
- init_c_highlighter(&highlighter);
+ highlighter->isdirective = check_cdirective;
+ highlighter->istype = check_ctype;
+ highlighter->keywords = ckeywords;
+ highlighter->parser = cparseline;
break;
case SOURCE_JAVA:
- init_java_highlighter(&highlighter);
+ highlighter->isdirective = check_jdirective;
+ highlighter->istype = check_jtype;
+ highlighter->keywords = jkeywords;
+ highlighter->parser = jparseline;
break;
case SOURCE_PLAIN:
- hptr = NULL;
+ highlighter->parser = plainparseline;
break;
default: /* should be unreachable */
fprintf(stderr, "error in enum source_type\n");
@@ -268,11 +255,13 @@
}
formatfile(
- hptr,
+ highlighter,
inputlines,
(write_func) fwrite,
fout,
settings.showlinenumbers);
+
+ free(highlighter);
ucx_buffer_free(content);
} else {
perror("Error opening input file");