DEADSOFTWARE

Remove batch
[gpcp-linux.git] / J2CPS / J2CPSFiles.java
1 /**********************************************************************/
2 /* J2CPS Files class for J2CPS */
3 /* */
4 /* (c) copyright QUT */
5 /**********************************************************************/
6 package J2CPS;
8 import java.io.*;
10 public class J2CPSFiles implements FilenameFilter {
12 private static final String classExt = ".class";
13 private static final String symExt = ".cps";
14 private static final String intExt = ".cp";
15 private static final String dbName = "index.dbi";
16 private static final String sepCh = System.getProperty("file.separator");
17 private static final char EOF = '\0';
18 private static final char CR = '\r';
19 private static final char LF = '\n';
20 private static final char SP = ' ';
21 private static final char TAB = '\t';
22 private static String currDir = System.getProperty("user.dir");
23 private static String symDir;
24 private static String[] classPath;
25 private static String[] symPath;
26 private static final char pathSep =
27 System.getProperty("path.separator").charAt(0);
30 /*
31 * Method for FilenameFilter
32 */
34 @Override
35 public boolean accept (File dir, String name) {
36 return name.endsWith(classExt);
37 }
39 public static void SetSymDir(String sDir) {
40 symDir = sDir;
41 if (symDir == null) {
42 symDir = symPath[0];
43 }
44 }
46 public static void GetPaths() {
47 classPath = GetPath("java.class.path");
48 symPath = GetPath("CPSYM");
49 }
51 private static String GetPathFromProperty(String str) {
52 String path = System.getProperty(str);
53 //if (path != null)
54 // System.out.println("Property " + str + " = " + path);
55 return path;
56 }
58 private static String GetPathFromEnvVar(String str) {
59 String path = System.getenv(str);
60 //if (path != null)
61 // System.out.println("Env. variable " + str + " = " + path);
62 return path;
63 }
65 private static String[] GetPath(String prop) {
66 String paths[];
67 // First look for the system property (preferred source)
68 String cPath = GetPathFromProperty(prop);
69 if (cPath == null)
70 cPath = GetPathFromEnvVar(prop);
72 if (cPath == null) {
73 System.out.println("No variable for \"" + prop + "\", using \".\"");
74 cPath = ".";
75 } else
76 System.out.println("Using \"" + prop + "\" path \"" + cPath + "\"");
78 int i,count=1,start,end;
79 for (i=0; i > -1 ; i++ ) {
80 i = cPath.indexOf(pathSep,i);
81 if (i > -1) { count++; } else { i--; }
82 }
83 paths = new String[count+1];
84 paths[0] = currDir;
85 start = 0; i = 1;
86 while (start < cPath.length()) {
87 end = cPath.indexOf(pathSep,start);
88 if (end == -1) {
89 end = cPath.length()+1;
90 paths[i] = cPath.substring(start);
91 } else {
92 paths[i] = cPath.substring(start,end);
93 }
94 if (paths[i].equals(".")) { paths[i] = currDir; }
95 i++;
96 start = end+1;
97 }
98 return paths;
99 }
101 public static File getPackageFile(String name) {
102 File inFile = new File(currDir,name);
103 if (!inFile.exists()) {
104 boolean found = false;
105 for (int i=0; (i < classPath.length) && (!found); i++) {
106 if (ClassDesc.verbose) {
107 System.out.println("<" + classPath[i] + sepCh + name + ">");
109 inFile = new File(classPath[i],name);
110 found = inFile.exists();
112 if (!found) {
113 System.err.println("Cannot open class directory <" + name + ">");
114 System.exit(0);
117 return inFile;
120 public static File OpenClassFile(String name) {
121 if (!name.endsWith(classExt)) { name = name.concat(classExt); }
122 File inFile = new File(currDir,name);
123 if (!inFile.exists()) {
124 inFile = FindClassFile(name);
126 if (!inFile.exists()) {
127 System.err.println("Cannot open class file <" + name + ">");
128 System.exit(0);
130 return inFile;
134 public static File OpenClassFile(File dir, String fName) {
135 File inFile = new File(dir,fName);
136 if (!inFile.exists()) {
137 System.err.println("Cannot open class file <" + dir.getName() +
138 sepCh + fName + ">");
139 System.exit(0);
141 return inFile;
145 public static File FindClassFile(String name) {
146 File inFile = null;
147 boolean found = false;
148 if (!name.endsWith(classExt)) { name = name.concat(classExt); }
149 for (int i=0; (i < classPath.length) && (!found); i++) {
150 if (ClassDesc.verbose) {
151 System.out.println("<" + classPath[i] + sepCh + name + ">");
153 inFile = new File(classPath[i],name);
154 found = inFile.exists();
156 if (!found) {
157 System.err.println("Cannot open class file <" + name + ">");
158 System.exit(0);
160 return inFile;
163 public static File FindSymbolFile(String name)
164 throws FileNotFoundException, IOException {
165 File inFile = null;
166 boolean found = false;
167 if (!name.endsWith(symExt)) { name = name.concat(symExt); }
168 for (int i=0; (i < symPath.length) && (!found); i++) {
169 if (ClassDesc.verbose) {
170 System.out.println("<" + symPath[i] + sepCh + name + ">");
172 inFile = new File(symPath[i],name);
173 found = inFile.exists();
175 if (!found) {
176 if (ClassDesc.verbose)
177 { System.out.println("Cannot find symbol file <" + name + ">"); }
178 return null;
180 return inFile;
183 public static DataOutputStream CreateSymFile(String fileName)
184 throws IOException {
185 String dirName;
186 if (symDir == null) { dirName = currDir; } else { dirName = symDir; }
187 if (ClassDesc.verbose) {
188 System.out.println("Creating symbolfile " + fileName + symExt +
189 " in directory " + dirName);
191 return new DataOutputStream(new FileOutputStream(
192 new File(dirName,fileName + symExt)));