Add space hack to font converter
[jpcrr.git] / ExceptionDefProcessor.java
blob1989c3822ae36d238d84bd1ddaae982cc4c892bf
1 import java.util.*;
2 import java.io.*;
4 class ExceptionDefProcessor
6 private static Map<Class<?>, String> classes;
8 private static void doClass(String line)
10 int split = line.indexOf(32);
11 String clazz = line.substring(0, split);
12 String desc = line.substring(split + 1);
13 Class<?> classObject;
15 try {
16 classObject = Class.forName(clazz);
17 } catch(Exception e) {
18 System.err.println("Warning: Can't find class \"" + clazz + "\", dropping.");
19 return;
21 classes.put(classObject, desc);
24 public static void main(String[] args)
26 classes = new HashMap<Class<?>, String>();
28 if(args == null || args.length < 1) {
29 System.err.println("Syntax: java ExceptionDefProcessor <inputfile>");
30 return;
33 String autoexec = args[0];
34 try {
35 BufferedReader kbd2 = new BufferedReader(new InputStreamReader(
36 new FileInputStream(autoexec), "UTF-8"));
37 while(true) {
38 String cmd = kbd2.readLine();
39 if(cmd == null)
40 break;
41 if(!cmd.equals(""))
42 doClass(cmd);
44 } catch (Exception e) {
45 System.err.println("Failed to load exception defintions: " + e.getMessage());
48 Class<?> failingClass = null;
49 do {
50 if(failingClass != null)
51 classes.put(failingClass, failingClass.getName());
52 failingClass = null;
53 for(Map.Entry<Class<?>, String> x : classes.entrySet()) {
54 Class<?> superclass = x.getKey().getSuperclass();
55 if(x.getKey().getName().equals("java.lang.Error") ||
56 x.getKey().getName().equals("java.lang.RuntimeException"))
57 continue;
58 if(!classes.containsKey(superclass)) {
59 System.err.println("Warning: Missing superclass \"" + superclass.getName() + "\" for \"" +
60 x.getKey().getName() + "\".");
61 failingClass = superclass;
62 break;
65 } while(failingClass != null);
67 PrintStream stream = null;
68 try {
69 stream = new PrintStream("org/jpc/Exceptions.java", "UTF-8");
70 } catch(Exception e) {
71 System.err.println("Can't open org/jpc/Exceptions.java: " + e.getMessage());
72 return;
75 stream.println("package org.jpc;");
76 stream.println("import java.util.*;");
77 stream.println("class Exceptions {");
78 stream.println("public static Map<String,String> classes;");
79 stream.println("static {");
80 stream.println("classes = new HashMap<String,String>();");
81 Class<?> out = null;
82 String desc = null;
83 do {
84 if(out != null) {
85 classes.remove(out);
86 stream.println("classes.put(\"" + out.getName() + "\", \"" + desc + "\");");
88 out = null;
89 for(Map.Entry<Class<?>, String> x : classes.entrySet()) {
90 Class<?> superclass = x.getKey().getSuperclass();
91 if(!classes.containsKey(superclass)) {
92 out = x.getKey();
93 desc = x.getValue();
94 break;
97 } while(out != null);
98 stream.println("}}");
99 stream.close();