5 static HashSet set=null;
6 static Hashtable currtable=new Hashtable();
7 static String declaration;
9 static void debug(String str) {
10 System.out.println(str);
13 static public void main(String[] args) {
14 debug("Opening file:"+args[0]);
15 BufferedReader br=null;
16 BufferedWriter bw=null;
18 br=new BufferedReader(new FileReader(args[0]));
22 String line=br.readLine();
25 String replacewith=line+".elem[";
26 if (replacewith==null)
28 currtable.put(line+"[",replacewith);
32 br=new BufferedReader(new FileReader(args[1]));
33 bw=new BufferedWriter(new FileWriter("fixed-"+args[1]));
37 String line=br.readLine();
40 if (line.equals("")) {
44 if (line.equals("DECLARE")) {
49 declaration=br.readLine();
50 bw.write(declaration);
56 for(Iterator it=currtable.keySet().iterator();it.hasNext();) {
57 String str=(String)it.next();
58 String replace=(String)currtable.get(str);
59 line=replace(line,str,replace);
74 br=new BufferedReader(new FileReader(args[2]));
75 bw=new BufferedWriter(new FileWriter("fixed-"+args[2]));
79 String line=br.readLine();
82 if (line.equals("")) {
87 declaration=br.readLine();
88 bw.write(declaration);
94 for(Iterator it=currtable.keySet().iterator();it.hasNext();) {
95 String str=(String)it.next();
96 String replace=(String)currtable.get(str);
97 line=replace(line,str,replace);
110 } catch (Exception e) {
116 static String generatepostfix(String str, int numderefs) {
119 int start=str.length();
120 for(int i=0;i<numderefs;i++) {
121 start=str.lastIndexOf("[",start-1);
125 return str.substring(start);
129 static String generateprefix(String str,int numdots) {
131 for(int i=0;i<numdots;i++) {
132 offset=str.indexOf(".",offset)+1;
134 int nextdot=str.indexOf(".",offset);
136 nextdot=str.indexOf("[",offset);
138 nextdot=str.length();
140 return str.substring(0,nextdot);
143 static String nextfield(String str,int numdots) {
145 for(int i=0;i<=numdots;i++) {
146 offset=str.indexOf(".",offset)+1;
150 int nextdot=str.indexOf(".",offset);
152 nextdot=str.indexOf("[",offset);
154 nextdot=str.length();
156 return "."+str.substring(offset,nextdot);
159 static int count(String str, String tofind) {
163 int newoffset=str.indexOf(tofind,offset);
172 static String replace(String str, String tofind, String toreplace) {
173 if (str.indexOf(tofind)!=-1) {
174 str=str.substring(0,str.indexOf(tofind))+toreplace+str.substring(str.indexOf(tofind)+tofind.length());