OpenCores
URL https://opencores.org/ocsvn/ao68000/ao68000/trunk

Subversion Repositories ao68000

[/] [ao68000/] [trunk/] [sw/] [ao68000_tool/] [DocumentationTool.java] - Blame information for rev 16

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 alfik
/*
2
 * Copyright 2010, Aleksander Osman, alfik@poczta.fm. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without modification, are
5
 * permitted provided that the following conditions are met:
6
 *
7
 *  1. Redistributions of source code must retain the above copyright notice, this list of
8
 *     conditions and the following disclaimer.
9
 *
10
 *  2. Redistributions in binary form must reproduce the above copyright notice, this list
11
 *     of conditions and the following disclaimer in the documentation and/or other materials
12
 *     provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
15
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
 */
24
 
25
package ao68000_tool;
26
 
27
import java.io.File;
28
import java.io.FileInputStream;
29
import java.io.FileOutputStream;
30
 
31
public class DocumentationTool {
32
    static void extract(String src, String dest) throws Exception {
33
        File file = new File(src);
34
        if(file.exists() == false || file.isFile() == false || file.canRead() == false) {
35
            throw new Exception("Can not open: " + file.getCanonicalPath());
36
        }
37
        // load file
38
        FileInputStream in = new FileInputStream(file);
39
        byte buf[] = new byte[(int)file.length()];
40
        if(in.read(buf) != buf.length) throw new Exception("Can not read: " + file.getCanonicalPath());
41
 
42
        String all = new String(buf);
43
 
44
        // find <div class="contents"
45
        String start_str = "<div class=\"contents\"";
46
        int start = all.indexOf(start_str);
47
        if(start == -1) throw new Exception("Can not find: " + start_str);
48
 
49
        int start_saved = start;
50
        start += start_str.length();
51
 
52
        // find closing </div
53
        int deep = 1;
54
        while(deep != 0) {
55
            int next_start = all.indexOf("<div", start);
56
            int next_end = all.indexOf("</div", start);
57
            //System.out.println("deep: " + deep + ", next_start: " + next_start + ", next_end: " + next_end);
58
 
59
            if(next_start != -1 && next_end != -1 && next_start < next_end) {
60
                deep++;
61
                start = next_start + 4;
62
            }
63
            else if(next_start != -1 && next_end != -1 && next_start >= next_end) {
64
                deep--;
65
                start = next_end + 5;
66
            }
67
            else if(next_start == -1 && next_end != -1) {
68
                deep--;
69
                start = next_end + 5;
70
            }
71
            else throw new Exception("Error parsing file.");
72
        }
73
        String result = all.substring(start_saved, start) + ">";
74
 
75
        //System.out.println("s: " + start_saved + ", e: " + start);
76
        //System.out.println(result);
77
 
78
        result = result.replaceAll("<h1>", " ");
79
        result = result.replaceAll("</h1>", " ");
80
        result = result.replaceAll("<br/>", "<br>");
81
 
82
        int max=0;
83
        while(result.indexOf("href=\"", max) != -1) {
84
            int i = result.indexOf("href=\"", max);
85
            max = i+6;
86
 
87
            if(result.substring(i).startsWith("href=\"http:")) continue;
88
 
89
            result = result.substring(0, i) + "href=\"file://./doxygen/html/" + result.substring(i+6);
90
        }
91
 
92
        // save output
93
        FileOutputStream out = new FileOutputStream(dest);
94
        out.write(result.getBytes());
95
        out.close();
96
    }
97
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.