package baf.guide; import java.io.*; import java.util.*; public class Listing { // Vector files = new Vector(1024); Hashtable files = new Hashtable(1024); String dirs[] = { "games", "solutions" }; String ignoredirs[] = { "games/adventions", "games/appleII/eamon", "games/competition96", "games/pc/eamon", "solutions/jgunness", "solutions/tools", "solutions/uhs", }; /** A dummy value for a hashtable. (We're using the Hashtable here * for lookup speed alone.) */ static Object val = new Object(); /** Reads the Master-Index file from GMD and extracts filenames */ public void readGMD(InputStream in) { boolean grabbing = false, gooddir = false; String directory = ""; try { BufferedReader din = new BufferedReader(new InputStreamReader(in)); String s; while ((s = din.readLine()) != null) { if (s.equals("")) continue; int firstspace = s.indexOf(' '); int firsttab = s.indexOf('\t'); if (firsttab != -1 && firsttab < firstspace) firstspace = firsttab; /* First, check for directory headers. These are single lines consisting of a directory name followed by a colon, with no spaces. */ if (firstspace == -1) { if (s.charAt(s.length()-1) == ':') { grabbing = false; directory = s.substring("if-archive/".length(), s.length()-1); } gooddir = checkdir(directory); continue; } /* If we're grabbing filenames, check to see if the next line is indented. If it isn't, we assume it starts with a filename. */ if (grabbing) { if (gooddir) { if (!Character.isWhitespace(s.charAt(0))) { String f = s.substring(0, firstspace); addFile(directory, f); } } /* If we're not grabbing filenames, we have to see if we should start. This is heralded by the Index line. */ } else { if (s.startsWith("Index")) { grabbing = true; } } } } catch (IOException e) { e.printStackTrace(); } } /** Reads a Game file from Baf's Guide and extracts filenames */ public void readGuide(InputStream in, String fname) { BufferedReader din = new BufferedReader(new InputStreamReader(in)); String s; try { while ((s = din.readLine()) != null) { try { StringTokenizer t = new StringTokenizer(s); String tok = t.nextToken(); if (tok.equals(":") || tok.equals(":i")) addFileVal(t.nextToken(), fname); } catch (NoSuchElementException e) { } } } catch (IOException e) { e.printStackTrace(); } } /** Reads a file containing nothing but a list of filenames to ignore */ public void readPlain(InputStream in) { BufferedReader din = new BufferedReader(new InputStreamReader(in)); String s; try { while ((s = din.readLine()) != null) { if (s.length() > 0) addFile(s); } } catch (IOException e) { e.printStackTrace(); } } public void addFile(String dir, String file) { addFile(dir+'/'+file); } public void addFile(String file) { //files.addElement(file); if (checkdir(file)) files.put(file, val); } public void addFileVal(String file, String val) { if (checkdir(file)) files.put(file, val); } public boolean checkdir(String s) { for (int i=0; i