Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81568 / c2html / main.cpp
diff options
context:
space:
mode:
Commit06811744a002f4ab332d94d510475231afcd45a1 (patch)
Author
 Mincho Paskalev <minchopaskal@gmail.com>
2018-11-03 13:36:57 +0200
Committer
 Martin Dobrev <martindobrev0@gmail.com>
2018-11-03 13:36:57 +0200
Files91c41776fbdf899dcb61a8d5df3ac1316c24f3c8 /homework/81568/c2html/main.cpp
IPL-06811744a002f4ab332d94d510475231afcd45a1.tar
IPL-06811744a002f4ab332d94d510475231afcd45a1.tar.gz
IPL-06811744a002f4ab332d94d510475231afcd45a1.zip
Parent26e5f891d537b5d4fc2890c9cdbeb73d5748d568 (diff)
First HW (#9)
* 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
1 files changed, 73 insertions, 0 deletions
-rw-r--r--homework/81568/c2html/main.cpp73
diff --git a/homework/81568/c2html/main.cpp b/homework/81568/c2html/main.cpp
new file mode 100644
index 0000000..eedaee3
--- /dev/null
+++ b/homework/81568/c2html/main.cpp
@@ -0,0 +1,73 @@
+#include <cstdio>
+#include "lexcer.h"
+
+int main(int argc, char *argv[]) {
+
+ if (argc != 2) {
+ printf("Usage: %s <*.{c,h} file>\n", argv[0]);
+ return 1; /* wrong usage */
+ }
+
+ auto fpIn = fopen(argv[1], "r");
+ if (!fpIn) {
+ return 2; /* unable to open file or inavlid file */
+ }
+
+ auto outputName = LexCer::getOutputFileName(argv[1]);
+ auto fpOut = fopen(outputName.c_str(), "w");
+ if (!fpOut) {
+ return 2;
+ }
+
+
+ fputs(
+ "<!doctype>\n"
+ "<html>\n"
+ "<head>\n"
+ " <title>LexCed</title>\n"
+ " <style>\n"
+ " .keyword {\n"
+ " color: purple;\n"
+ " }\n"
+ " .number {\n"
+ " color: darkblue;\n"
+ " }\n"
+ " .string {\n"
+ " color: green;\n"
+ " }\n"
+ " .operator {\n"
+ " font-style: bold;\n"
+ " }\n"
+ " .invalid {\n"
+ " text-decoration: underline;\n"
+ " text-decoration-color: red;\n"
+ " text-decoration-style: wavy;\n"
+ " }\n"
+ " .typename {\n"
+ " color: blue;\n"
+ " }\n"
+ " .preproc {\n"
+ " color: purple;\n"
+ " }\n"
+ " .identifier {\n"
+ " color: black;\n"
+ " }\n"
+ " .string {\n"
+ " color: brown;\n"
+ " }\n"
+ " .comment {\n"
+ " color: green;\n"
+ " }\n"
+ " </style>\n"
+ "</head>\n"
+ "<body>\n"
+ "<pre class=\"code\">\n",
+ fpOut
+ );
+ LexCer::lexCit(fpIn, fpOut);
+ fputs("</pre></body></html>\n", fpOut);
+
+ printf("Highlighted text written in %s!\n", outputName.c_str());
+
+ return 0;
+}