Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81281 / c2html / c2html.pl
blob: 9479b96f581006753c95b4f7967b12617ad234ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
:- use_module(library(dcg/basics)).
:- use_module(library(readutil)).
:- [tokens, prettify, print, essentials, controlStructures].
:- set_prolog_flag(verbose, silent).

:- initialization(main, main).

main :-
    current_prolog_flag(argv, Argv),
    Argv = [H1, H2|_],
    atom_string(H1, File),
    atom_string(H2, Number),
    mainy(File, Number),
    format('You can see the result in the html file.~n'),
    halt.
main :-
    halt(1).

mainy(File, Number):-

    open(File, read, RFile),
    read_stream_to_codes(RFile, CSource),
    close(RFile),
    phrase(tokens(Tokens), CSource),
    flattenMine(Tokens, TokenStream),
    ((Number == "0", PrettyCode = TokenStream);
    (Number == "1", prettify(TokenStream, Raw),
     flattenMine(Raw, PrettyCode));
    (Number == "2", prettify(TokenStream, Raw),
     identifyControlStructures(Raw, RawF),
     flattenMine(RawF, PrettyCode))),
    open('page.html', write, WFile),
     write(WFile,'<!doctype>
    <html>

        <head>
            <title>hello.c</title>
            <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
            <style>
                .keyword {
                    color: blue;
                }

                .number {
                    color: violet;
                }

                .identifier {
                    color: green;
                }

                .operator {
                    font-style: bold;
                    color: blue;
                }

                .comment {
                    color: lime;
                }

                .string {
                    color: orange;
                }

                .parenthese {
                    font-style: bold;
                    color: brown;
                }

                .quotation {
                    font-style: bold;
                    color: black;
                }

                .unknown {
                    font-style: bold;
                    color: red;
                }

                .function {
                    color: purple;
                }

                .collapsible {
                    background-color: PaleGreen;
                    cursor: pointer;
                    padding: 10px;
                    width: 100%;
                    border: none;
                    text-align: left;
                    outline: none;
                    font-size: 15px;
                }

                .active,
                .collapsible:hover {
                    background-color: PaleGoldenRod;
                }

                .content {
                    padding: 0 18px;
                    display: none;
                    overflow: hidden;
                    background-color: #f1f1f1;
                }
            </style>
        </head>

        <body>
            <pre class=\"code\">'),
    tohtmlfile(WFile, PrettyCode),
    write(WFile, ' <script>
                    var coll = document.getElementsByClassName(\"collapsible\");
                    var i;

                    for (i = 0; i < coll.length; i++) {
                      coll[i].addEventListener(\"click\", function() {
                        this.classList.toggle(\"active\");
                        var content = this.nextElementSibling;
                        if (content.style.display === \"block\") {
                          content.style.display = \"none\";
                        } else {
                          content.style.display = \"block\";
                        }
                      });
                    }
                    </script>
                        </pre>
                    </body>

                    </html>'),
    close(WFile).