~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gc/boehm/leaksoup/tracesoup.java

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, released
 
14
 * March 31, 1998.
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape
 
17
 * Communications Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Patrick C. Beard <beard@netscape.com>
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the
 
26
 * terms of the GNU Public License (the "GPL"), in which case the
 
27
 * provisions of the GPL are applicable instead of those above.
 
28
 * If you wish to allow use of your version of this file only
 
29
 * under the terms of the GPL and not to allow others to use your
 
30
 * version of this file under the NPL, indicate your decision by
 
31
 * deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL.  If you do not delete
 
33
 * the provisions above, a recipient may use your version of this
 
34
 * file under either the NPL or the GPL.
 
35
 */
 
36
 
 
37
import java.io.*;
 
38
import java.util.*;
 
39
 
 
40
public class tracesoup {
 
41
        public static void main(String[] args) {
 
42
                if (args.length == 0) {
 
43
                        System.out.println("usage:  tracesoup [-blame] trace");
 
44
                        System.exit(1);
 
45
                }
 
46
                
 
47
                for (int i = 0; i < args.length; i++) {
 
48
                        String arg = args[i];
 
49
                        if (arg.charAt(0) == '-') {
 
50
                                if (arg.equals("-blame"))
 
51
                                        FileLocator.USE_BLAME = true;
 
52
                        } else {
 
53
                                cook(arg);
 
54
                        }
 
55
                }
 
56
                
 
57
                // quit the application.
 
58
                System.exit(0);
 
59
        }
 
60
 
 
61
        static void cook(String inputName) {
 
62
                String outputName = inputName + ".html";
 
63
 
 
64
                try {
 
65
                        PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputName))));
 
66
                        writer.println("<TITLE>" + outputName + "</TITLE>");
 
67
                        writer.println("<PRE>");
 
68
                        
 
69
                        Hashtable fileTables = new Hashtable();
 
70
                        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputName)));
 
71
                        String line = reader.readLine();
 
72
                        while (line != null) {
 
73
                                if (line.length() > 0) {
 
74
                                        // have to quote '<' & '>' characters.
 
75
                                        if (line.charAt(0) == '<')
 
76
                                                line = quoteTags(line);
 
77
                                        // lines containing square brackets need to be wrapped with <A HREF="..."></A>.
 
78
                                        int leftBracket = line.indexOf('[');
 
79
                                        if (leftBracket >= 0)
 
80
                                                line = FileLocator.getFileLocation(line);
 
81
                                }
 
82
                                writer.println(line);
 
83
                                line = reader.readLine();
 
84
                        }
 
85
                        reader.close();
 
86
                        
 
87
                        writer.println("</PRE>");
 
88
                        writer.close();
 
89
                } catch (Exception e) {
 
90
                        e.printStackTrace(System.err);
 
91
                }
 
92
        }
 
93
        
 
94
        /**
 
95
         * Simply replaces instances of '<' with "&LT;" and '>' with "&GT;".
 
96
         */
 
97
        static String quoteTags(String str) {
 
98
                int length = str.length();
 
99
                StringBuffer buf = new StringBuffer(length);
 
100
                for (int i = 0; i < length; ++i) {
 
101
                        char ch = str.charAt(i);
 
102
                        switch (ch) {
 
103
                        case '<':
 
104
                                buf.append("&LT;");
 
105
                                break;
 
106
                        case '>':
 
107
                                buf.append("&GT;");
 
108
                                break;
 
109
                        default:
 
110
                                buf.append(ch);
 
111
                                break;
 
112
                        }
 
113
                }
 
114
                return buf.toString();
 
115
        }
 
116
}