Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81568 / c2html / main.cpp
diff options
context:
space:
mode:
Commit65c7618c2a8834616b009195f10c6cd762f43b8a (patch)
Author
 Mincho Paskalev <minchopaskal@gmail.com>
2018-11-07 10:31:59 +0200
Committer
 dtrendafilov <trendafilov.dn@gmail.com>
2018-11-07 10:31:59 +0200
Files57440acdc2731e7b060928881fa55e983d83f956 /homework/81568/c2html/main.cpp
IPL-65c7618c2a8834616b009195f10c6cd762f43b8a.tar
IPL-65c7618c2a8834616b009195f10c6cd762f43b8a.tar.gz
IPL-65c7618c2a8834616b009195f10c6cd762f43b8a.zip
Parent2044770601dff8f1bd1c6cb9d0617f669b430e1d (diff)
Добавяне на второ домашно (#30)
* Add 1st hw * --amend * moving readme for 1st hw to designated folder * renamed TokenType enum to TokenClass * fixed character constant lexing. added sampe output file * add new line at end-of-file. added gitignore * a bit of refactoring * adding cyclomatic complexity * refactored * adding cyclomatic complexity * refactored
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());