[kaffe] native2ascii for kaffe
Ito Kazumitsu
kaz@maczuka.gcd.org
Fri Apr 25 09:15:02 2003
Kaffe's native2ascii tries to execute sun.tools.native2ascii.Main,
which cannot be found.
Here is my native2ascii which can be used with kaffe.
$ cat kaffe/tools/native2ascii/Main.java
package kaffe.tools.native2ascii;
import java.io.*;
public class Main {
public static void main(String[] args) {
String encoding = System.getProperty("file.encoding");
String input = null;
String output = null;
for (int i=0; i<args.length; i++) {
if(args[i].equals("-encoding")) {
i++;
if (i >= args.length) {
System.err.println("encoding is missing");
}
else {
encoding = args[i];
}
}
else if (args[i].equals("-reverse") || args[i].startsWith("-J")) {
System.err.println(args[i] + ": not supported");
}
else {
if (input == null) {
input = args[i];
}
else if (output == null) {
output = args[i];
}
else {
System.err.println(args[i] + ": ignored");
}
}
}
try {
InputStream is = (input == null ?
System.in :
new FileInputStream(input));
OutputStream os = (output == null ?
(OutputStream)System.out :
new FileOutputStream(output));
BufferedReader rdr =
new BufferedReader(
new InputStreamReader(is, encoding));
PrintWriter wtr =
new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(os, encoding)));
while (true) {
String s = rdr.readLine();
if (s == null) break;
StringBuffer sb = new StringBuffer(s.length() + 80);
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c <= 0xff) {
sb.append(c);
}
else {
sb.append("\\u" + Integer.toHexString((int)c));
}
}
wtr.println(sb.toString());
}
rdr.close();
wtr.flush();
wtr.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}