From: adam Date: Mon, 12 Feb 2007 09:37:51 +0000 (+0100) Subject: added ShipDescription X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=698b3ed68061fa7f7531c48bebd78f60b1847303;p=fleet.git added ShipDescription --- diff --git a/src/edu/berkeley/fleet/doc/ShipDescription.java b/src/edu/berkeley/fleet/doc/ShipDescription.java new file mode 100644 index 0000000..f32b7ab --- /dev/null +++ b/src/edu/berkeley/fleet/doc/ShipDescription.java @@ -0,0 +1,83 @@ +package edu.berkeley.fleet.doc; + +import java.io.*; +import java.util.*; + +public class ShipDescription { + + public String name; + public String texDocumentation; + public ArrayList benkoBoxes = new ArrayList(); + + public HashMap sections = + new HashMap(); + + public class BenkoBox { + public boolean inbox; + public boolean tokenOnly; + public boolean leftSide; + public String[] ports; + } + + public class Literal { + public String name; + } + + public ShipDescription(BufferedReader r) throws IOException { + String sectionName = ""; + StringBuffer sb = new StringBuffer(); + while(true) { + String s = r.readLine(); + if (s==null) break; + if (s.startsWith("==")) { + sections.put(sectionName, sb.toString()); + sb = new StringBuffer(); + sectionName = s.trim(); + while(sectionName.startsWith("=")) + sectionName = sectionName.substring(1); + while(sectionName.endsWith("=")) + sectionName = sectionName.substring(0, sectionName.length()-1); + sectionName = sectionName.trim().toLowerCase(); + continue; + } + sb.append(s+"\n"); + } + for(String s : sections.keySet()) + processSection(s); + } + + public void processSection(String section) throws IOException { + if (section.equals("")) { + BufferedReader br = new BufferedReader(new StringReader(sections.get(section))); + for(String s = br.readLine(); s != null; s = br.readLine()) { + if (s.trim().length()==0) continue; + String key = s.substring(0, s.indexOf(':')).trim(); + String val = s.substring(s.indexOf(':')+1).trim(); + if (key.toLowerCase().equals("ship")) + name = val.trim(); + } + } else if (section.equals("ports")) { + BufferedReader br = new BufferedReader(new StringReader(sections.get(section))); + boolean rightSide = false; + for(String s = br.readLine(); s != null; s = br.readLine()) { + if (s.trim().length()==0) { rightSide = true; continue; } + String key = s.substring(0, s.indexOf(':')).trim(); + String val = s.substring(s.indexOf(':')+1).trim(); + BenkoBox p = new BenkoBox(); + key = key.replaceAll(" +", " "); + if (key.equals("token in")) { p.tokenOnly = true; p.inbox = true; } + else if (key.equals("token out")) { p.tokenOnly = true; p.inbox = false; } + else if (key.equals("data in")) { p.tokenOnly = false; p.inbox = true; } + else if (key.equals("data out")) { p.tokenOnly = false; p.inbox = false; } + else throw new RuntimeException("unknown port type: \""+key+"\""); + StringTokenizer st = new StringTokenizer(val, " "); + p.ports = new String[st.countTokens()]; + for(int i=0; i