File: log2html.g

package info (click to toggle)
gap 4.15.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 110,212 kB
  • sloc: ansic: 97,261; xml: 48,343; cpp: 13,946; sh: 4,900; perl: 1,650; javascript: 255; makefile: 252; ruby: 9
file content (68 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download | duplicates (3)
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
#############################################################################
##
#W  log2html.g             GAP *.log - File --> HTML              Stefan Kohl
##
##
##  Utility to convert GAP log files to XHTML 1.0 Strict.
##
##  Usage:
##
##  - Load this file into GAP.
##
##  - Issue Log2HTML( <logfilename> ), where the path must be relative to
##    your home directory. The extension of the input file must be .log.
##    The name of the output file is the same as the one of the input file
##    except that the extension .log is replaced by .html.
##
##  - Adjust the style file gaplog.css to your taste.
##
WKDir := Directory("~/");

Log2HTML := function ( logfilename )

  local  input, output, s1, s2, header, footer, pos, lastlf, nextlf, prompt;

  header := Concatenation(
              "<?xml version = \"1.0\" encoding = \"ISO-8859-1\"?>\n\n",
              "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n",
              "                      \"http://www.w3.org/TR/xhtml1/DTD/",
              "xhtml1-strict.dtd\">\n<html>\n\n<head>\n  <title> ",
              logfilename, " </title>\n  <link rel = \"stylesheet\" ",
              "type = \"text/css\" href = \"gaplog.css\" />\n",
              "</head>\n\n<body>\n\n<pre class = \"logfile\">\n");
  footer := "</pre> </body> </html>";
  input := InputTextFile(Filename(WKDir,logfilename));
  s1 := ReadAll(input); CloseStream(input);
  pos := PositionSublist(s1,"gap>"); prompt := "gap> ";
  s2 := ReplacedString(s1{[1..pos-1]},"<","&lt;");
  while pos <> fail do
    s2 := Concatenation(s2,"<em class = \"prompt\">",prompt,"</em>");
    s2 := Concatenation(s2,"<em class = \"input\">");
    nextlf := Position(s1,'\n',pos); prompt := "gap>";
    if nextlf = fail then nextlf := Length(s1); fi;
    s2 := Concatenation(s2,ReplacedString(s1{[pos+5..nextlf-1]},"<","&lt;"),
                        "</em>");
    while nextlf < Length(s1) and s1[nextlf+1] = '>' do
      s2 := Concatenation(s2,"\n<em class = \"prompt\">></em>",
                          "<em class = \"input\">");
      lastlf := nextlf;
      nextlf := Position(s1,'\n',lastlf);
      if nextlf = fail then nextlf := Length(s1); fi;
      s2 := Concatenation(s2,ReplacedString(s1{[lastlf+2..nextlf-1]},
                                            "<","&lt;"),"</em>");
    od;
    s2 := Concatenation(s2,"\n");
    pos := PositionSublist(s1,"\ngap>",nextlf-1);
    if pos = fail then pos := Length(s1); fi;
    if pos > nextlf then
      s2 := Concatenation(s2,"<em class = \"output\">",
                          ReplacedString(s1{[nextlf+1..pos-1]},"<","&lt;"),
                          "</em>\n");
    fi;
    if pos > Length(s1) - 3 then break; fi;
  od;
  s2 := Concatenation(header,s2,footer);
  output := OutputTextFile(Filename(WKDir,ReplacedString(logfilename,
                           ".log",".html")),false);
  WriteAll(output,s2); CloseStream(output);
end;