--- /dev/null
+package edu.berkeley.fleet.doc;
+
+import java.io.*;
+import java.util.*;
+
+public class ShipDescription {
+
+ public String name;
+ public String texDocumentation;
+ public ArrayList<BenkoBox> benkoBoxes = new ArrayList<BenkoBox>();
+
+ public HashMap<String,String> sections =
+ new HashMap<String,String>();
+
+ 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<p.ports.length; i++)
+ p.ports[i] = st.nextToken();
+ p.leftSide = !rightSide;
+ benkoBoxes.add(p);
+ }
+ }
+ }
+
+}
\ No newline at end of file