package ip.graphics;
import java.awt.*;
import java.io.*;
class WildCardFilter implements FilenameFilter {
String wc = null;
WildCardFilter(String _wc) {
wc = _wc;
}
public boolean accept(File d, String fn) {
return fn.endsWith(wc);
}
}
public class ProtoType {
PrintWriter pw = null;
FileOutputStream fos = null;
File dir;
boolean classFlag = false;
boolean firstClassInFile = true;
boolean openParenthesis = false;
public String[] ls(String wc) {
WildCardFilter wcf = new WildCardFilter(wc);
dir = getDir();
return dir.list(wcf);
}
public String[] lsAbs(String wc) {
String files[] = ls(wc);
for (int i = 0; i < files.length; i++)
files[i] = dir.getAbsolutePath() + files[i];
return files;
}
public File getDir() {
FileDialog fd = new FileDialog(new Frame(), "Open file");
fd.setVisible(true);
fd.setVisible(false);
String fn = fd.getFile();
if (fn == null) return null;
return new File(fd.getDirectory());
}
public String getReadFileName() {
FileDialog fd = new FileDialog(new Frame(), "Open file");
fd.setVisible(true);
fd.setVisible(false);
String fn = fd.getFile();
if (fn == null) return null;
return fd.getDirectory() + fn;
}
public PrintWriter getPrintWriter() throws IOException {
fos = new FileOutputStream(getWriteFileName());
return new PrintWriter(fos);
}
public String getWriteFileName() {
FileDialog fd = new FileDialog(new Frame(), "Open file", FileDialog.SAVE);
fd.setVisible(true);
fd.setVisible(false);
String fn = fd.getFile();
if (fn == null) return null;
return fd.getDirectory() + fn;
}
public void processLine(StreamTokenizer st) throws IOException {
boolean privateFlag = false, functionFlag = false;
String ss = st.sval;
StringBuffer sb = new StringBuffer(40);
if (ss.equals("private"))
privateFlag = true;
int ft = st.nextToken();
if (st.sval.equals("class")) {
if (firstClassInFile == true)
firstClassInFile = false;
else
pw.println('}');
classFlag = true;
}
sb.append(ss);
while (ft != st.TT_EOF && st.ttype != '{' && st.ttype != ';') {
if (ft == st.TT_WORD) {
if (openParenthesis == true)
openParenthesis = false;
else
sb.append(" ");
sb.append(st.sval);
} else if (ft == st.TT_NUMBER) {
sb.append(" " + st.nval);
} else {
if (st.ttype == '(') {
openParenthesis = true;
} else
openParenthesis = false;
sb.append((char) st.ttype);
}
ft = st.nextToken();
}
if (st.ttype == '{')
if (classFlag == true) {
sb.append('{');
classFlag = false;
functionFlag = true;
} else {
sb.append(';');
}
if (privateFlag == true && functionFlag == false)
return;
pw.println(sb);
sb = null;
}
public void process(InputStream is) throws IOException {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StreamTokenizer st = new StreamTokenizer(br);
int ft = 0;
st.eolIsSignificant(true);
while ((ft = st.nextToken()) != st.TT_EOF)
if (ft == st.TT_WORD) {
if (st.sval.equals("public") || st.sval.equals("private")) processLine(st);
}
}
public void process(String fn) {
try {
firstClassInFile = true;
FileInputStream fis = new FileInputStream(fn);
process(fis);
fis.close();
} catch (Exception e) {
}
}
public void process() {
String fn[] = lsAbs(".java");
try {
pw = getPrintWriter();
} catch (Exception e) {
}
for (int i = 0; i < fn.length; i++) {
System.out.println(fn[i]);
pw.println(fn[i] + ":-");
process(fn[i]);
pw.println('}');
pw.println();
}
try {
fos.close();
} catch (Exception e) {
}
}
public static void main(String args[]) {
ProtoType p = new ProtoType();
p.process();
}
}