Back to index

lightning-sunbird  0.9+nobinonly
tracesoup.java
Go to the documentation of this file.
00001 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * The contents of this file are subject to the Netscape Public
00004  * License Version 1.1 (the "License"); you may not use this file
00005  * except in compliance with the License. You may obtain a copy of
00006  * the License at http://www.mozilla.org/NPL/
00007  *
00008  * Software distributed under the License is distributed on an "AS
00009  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00010  * implied. See the License for the specific language governing
00011  * rights and limitations under the License.
00012  *
00013  * The Original Code is Mozilla Communicator client code, released
00014  * March 31, 1998.
00015  *
00016  * The Initial Developer of the Original Code is Netscape
00017  * Communications Corporation.  Portions created by Netscape are
00018  * Copyright (C) 1998 Netscape Communications Corporation. All
00019  * Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Patrick C. Beard <beard@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the
00026  * terms of the GNU Public License (the "GPL"), in which case the
00027  * provisions of the GPL are applicable instead of those above.
00028  * If you wish to allow use of your version of this file only
00029  * under the terms of the GPL and not to allow others to use your
00030  * version of this file under the NPL, indicate your decision by
00031  * deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL.  If you do not delete
00033  * the provisions above, a recipient may use your version of this
00034  * file under either the NPL or the GPL.
00035  */
00036 
00037 import java.io.*;
00038 import java.util.*;
00039 
00040 public class tracesoup {
00041        public static void main(String[] args) {
00042               if (args.length == 0) {
00043                      System.out.println("usage:  tracesoup [-blame] trace");
00044                      System.exit(1);
00045               }
00046               
00047               for (int i = 0; i < args.length; i++) {
00048                      String arg = args[i];
00049                      if (arg.charAt(0) == '-') {
00050                             if (arg.equals("-blame"))
00051                                    FileLocator.USE_BLAME = true;
00052                      } else {
00053                             cook(arg);
00054                      }
00055               }
00056               
00057               // quit the application.
00058               System.exit(0);
00059        }
00060 
00061        static void cook(String inputName) {
00062               String outputName = inputName + ".html";
00063 
00064               try {
00065                      PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputName))));
00066                      writer.println("<TITLE>" + outputName + "</TITLE>");
00067                      writer.println("<PRE>");
00068                      
00069                      Hashtable fileTables = new Hashtable();
00070                      BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputName)));
00071                      String line = reader.readLine();
00072                      while (line != null) {
00073                             if (line.length() > 0) {
00074                                    // have to quote '<' & '>' characters.
00075                                    if (line.charAt(0) == '<')
00076                                           line = quoteTags(line);
00077                                    // lines containing square brackets need to be wrapped with <A HREF="..."></A>.
00078                                    int leftBracket = line.indexOf('[');
00079                                    if (leftBracket >= 0)
00080                                           line = FileLocator.getFileLocation(line);
00081                             }
00082                             writer.println(line);
00083                             line = reader.readLine();
00084                      }
00085                      reader.close();
00086                      
00087                      writer.println("</PRE>");
00088                      writer.close();
00089               } catch (Exception e) {
00090                      e.printStackTrace(System.err);
00091               }
00092        }
00093        
00097        static String quoteTags(String str) {
00098               int length = str.length();
00099               StringBuffer buf = new StringBuffer(length);
00100               for (int i = 0; i < length; ++i) {
00101                      char ch = str.charAt(i);
00102                      switch (ch) {
00103                      case '<':
00104                             buf.append("&LT;");
00105                             break;
00106                      case '>':
00107                             buf.append("&GT;");
00108                             break;
00109                      default:
00110                             buf.append(ch);
00111                             break;
00112                      }
00113               }
00114               return buf.toString();
00115        }
00116 }