Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81568 / c2html / main.cpp
diff options
context:
space:
mode:
1 files changed, 46 insertions, 5 deletions
-rw-r--r--homework/81568/c2html/main.cpp51
diff --git a/homework/81568/c2html/main.cpp b/homework/81568/c2html/main.cpp
index eedaee3..d4dbed3 100644
--- a/homework/81568/c2html/main.cpp
+++ b/homework/81568/c2html/main.cpp
@@ -1,4 +1,8 @@
#include <cstdio>
+#include <cstring>
+
+#include "cyclomatic.h"
+#include "html_utils.h"
#include "lexcer.h"
int main(int argc, char *argv[]) {
@@ -13,7 +17,7 @@ int main(int argc, char *argv[]) {
return 2; /* unable to open file or inavlid file */
}
- auto outputName = LexCer::getOutputFileName(argv[1]);
+ auto outputName = HTMLUtils::getOutputFileName(argv[1]);
auto fpOut = fopen(outputName.c_str(), "w");
if (!fpOut) {
return 2;
@@ -21,7 +25,7 @@ int main(int argc, char *argv[]) {
fputs(
- "<!doctype>\n"
+ "<!DOCTYPE html>\n"
"<html>\n"
"<head>\n"
" <title>LexCed</title>\n"
@@ -58,14 +62,51 @@ int main(int argc, char *argv[]) {
" .comment {\n"
" color: green;\n"
" }\n"
+ " .complexity-level-one {\n"
+ " background-color: PaleGreen;\n"
+ " }\n"
+ " .complexity-level-two {\n"
+ " background-color: DarkGreen;\n"
+ " }\n"
+ " .complexity-level-three {\n"
+ " background-color: SaddleBrown;\n"
+ " }\n"
+ " .complexity-level-four {\n"
+ " background-color: Brown;\n"
+ " }\n"
+ " .complexity-level-five {\n"
+ " background-color: Maroon;\n"
+ " }\n"
" </style>\n"
"</head>\n"
- "<body>\n"
+ "<body onload=\"toggleComplexity()\">\n"
"<pre class=\"code\">\n",
fpOut
);
- LexCer::lexCit(fpIn, fpOut);
- fputs("</pre></body></html>\n", fpOut);
+ ParCer::outputWithCyclomaticComplexity(fpIn, fpOut);
+ fputs("</pre>\n"
+ "<script>\n"
+ "function toggleComplexity() {\n"
+ " var funcs = document.getElementsByClassName(\"func\");"
+ " if (funcs.length == 0) return;\n"
+ " var len = funcs.length;\n"
+ " for (var i = 0; i < len; ++i) {\n"
+ " var f = document.getElementsByClassName(\"func\")[0];\n"
+ " var complexity = f.innerHTML.match(\"(<!-- )([0-9]+)( -->)\")[2];\n"
+ " if (complexity < 3)\n"
+ " f.className = \"complexity-level-one\";\n"
+ " else if (complexity < 7)\n"
+ " f.className = \"complexity-level-two\";\n"
+ " else if (complexity < 15)\n"
+ " f.className = \"complexity-level-three\";\n"
+ " else if (complexity < 20)\n"
+ " f.className = \"complexity-level-four\";\n"
+ " else\n"
+ " f.className = \"complexity-level-five\";\n"
+ " }\n"
+ "}\n",
+ fpOut);
+ fputs("</script></body></html>\n", fpOut);
printf("Highlighted text written in %s!\n", outputName.c_str());