5 static HashSet set=null;
6 static Hashtable currtable=new Hashtable();
7 static String declaration;
10 static void debug(String str) {
11 System.out.println(str);
14 static public void main(String[] args) {
16 debug("Opening file:"+args[0]);
17 BufferedReader br=null;
18 BufferedWriter bw=null;
20 br=new BufferedReader(new FileReader(args[0]));
24 String line=br.readLine();
27 String replacewith=line+".elem";
28 if (replacewith==null)
30 currtable.put(line,replacewith);
34 br=new BufferedReader(new FileReader(args[1]));
35 bw=new BufferedWriter(new FileWriter("fixed-"+args[1]));
39 String line=br.readLine();
42 if (line.equals("")) {
46 if (line.equals("DECLARE")) {
51 declaration=br.readLine();
52 bw.write(declaration);
58 for(Iterator it=currtable.keySet().iterator();it.hasNext();) {
59 String str=(String)it.next();
60 String replace=(String)currtable.get(str);
61 if (line.endsWith(str))
63 line=replace(line,str,replace);
68 copy+=replace(line,"[","_array[")+"\n";
75 if (copy!=null&&((count%4)==0)) {
88 br=new BufferedReader(new FileReader(args[2]));
89 bw=new BufferedWriter(new FileWriter("fixed-"+args[2]));
93 String line=br.readLine();
96 if (line.equals("")) {
101 declaration=br.readLine();
102 bw.write(declaration);
108 for(Iterator it=currtable.keySet().iterator();it.hasNext();) {
109 String str=(String)it.next();
110 String replace=(String)currtable.get(str);
111 if (line.endsWith(str))
113 line=replace(line,str,replace);
115 } else if (copy!=null)
120 if (((count%3)==0)&©!=null) {
131 } catch (Exception e) {
137 static String generatepostfix(String str, int numderefs) {
140 int start=str.length();
141 for(int i=0;i<numderefs;i++) {
142 start=str.lastIndexOf("[",start-1);
146 return str.substring(start);
150 static String generateprefix(String str,int numdots) {
152 for(int i=0;i<numdots;i++) {
153 offset=str.indexOf(".",offset)+1;
155 int nextdot=str.indexOf(".",offset);
157 nextdot=str.indexOf("[",offset);
159 nextdot=str.length();
161 return str.substring(0,nextdot);
164 static String nextfield(String str,int numdots) {
166 for(int i=0;i<=numdots;i++) {
167 offset=str.indexOf(".",offset)+1;
171 int nextdot=str.indexOf(".",offset);
173 nextdot=str.indexOf("[",offset);
175 nextdot=str.length();
177 return "."+str.substring(offset,nextdot);
180 static int count(String str, String tofind) {
184 int newoffset=str.indexOf(tofind,offset);
193 static String replace(String str, String tofind, String toreplace) {
194 if (str.indexOf(tofind)!=-1) {
195 str=str.substring(0,str.indexOf(tofind))+toreplace+str.substring(str.indexOf(tofind)+tofind.length());