implement am26 support for constants
[fleet.git] / src / edu / berkeley / fleet / doc / ShipDescription.java
index 4031ce1..6ea4241 100644 (file)
@@ -10,14 +10,18 @@ public class ShipDescription implements Iterable<BenkoBoxDescription> {
     public String getSection(String sectionName) { return sections.get(sectionName); }
     public Iterator<BenkoBoxDescription> iterator() { return benkoBoxes.iterator(); }
 
-    public ShipDescription(BufferedReader r) throws IOException {
-        String sectionName = "";
+    public ShipDescription(String name, BufferedReader r) throws IOException {
+        if (name.endsWith(".ship"))
+            name = name.substring(0, name.length() - ".ship".length());
+        while(name.indexOf('/') != -1) name = name.substring(name.indexOf('/')+1);
+        this.name = name;
+        String sectionName = null;
         StringBuffer sb = new StringBuffer();
         while(true) {
             String s = r.readLine();
-            if (s==null) break;
-            if (s.startsWith("==")) {
-                sections.put(sectionName, sb.toString());
+            if (s==null || s.startsWith("==")) {
+                if (sectionName != null) sections.put(sectionName, sb.toString());
+                if (s==null) break;
                 sb = new StringBuffer();
                 sectionName = s.trim();
                 while(sectionName.startsWith("="))
@@ -43,6 +47,13 @@ public class ShipDescription implements Iterable<BenkoBoxDescription> {
 
     private HashMap<String,String> sections = new HashMap<String,String>();
 
+    // FIXME
+    public HashMap<String,Constant> constants = new HashMap<String,Constant>();
+
+    public Constant getConstant(String name) {
+        return constants.get(name);
+    }
+
     private void processSection(String section) throws IOException {
         if (section.equals("")) {
             BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
@@ -53,6 +64,17 @@ public class ShipDescription implements Iterable<BenkoBoxDescription> {
                 if (key.toLowerCase().equals("ship"))
                     name = val.trim();
             }
+        } else if (section.equals("constants")) {
+            BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
+            for(String s = br.readLine(); s != null; s = br.readLine()) {
+                if (s.indexOf(':')==-1) continue;
+                String key = s.substring(0, s.indexOf(':')).trim();
+                if (key.startsWith("constant")) {
+                    String constname = key.substring("constant".length()+1).trim();
+                    String val       = s.substring(s.indexOf(':')+1).trim();
+                    constants.put(constname, new Constant(val));
+                }
+            }
         } else if (section.equals("ports")) {
             BufferedReader br = new BufferedReader(new StringReader(sections.get(section)));
             boolean rightSide = false;
@@ -71,6 +93,9 @@ public class ShipDescription implements Iterable<BenkoBoxDescription> {
                 else if (key.equals("in"))        { tokenOnly = false;  inbox = true;  }
                 else if (key.equals("out"))       { tokenOnly = false;  inbox = false; }
                 else if (key.startsWith("constant")) {
+                    String constname = key.substring("constant".length()+1).trim();
+                    String val       = s.substring(s.indexOf(':')+1).trim();
+                    p.constants.put(constname, new Constant(val));
                     continue;
                 } else if (key.startsWith("shortcut to")) {
                     continue;
@@ -90,5 +115,4 @@ public class ShipDescription implements Iterable<BenkoBoxDescription> {
     }
 
     void add(BenkoBoxDescription b) { benkoBoxes.add(b); }
-
 }
\ No newline at end of file