about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fix-ng/Makefile.am2
-rw-r--r--src/fix-ng/fix-expr.cc2
-rw-r--r--src/fix-ng/parser.cc55
-rw-r--r--src/fix-ng/parser.hh9
4 files changed, 57 insertions, 11 deletions
diff --git a/src/fix-ng/Makefile.am b/src/fix-ng/Makefile.am
index 3672c3dc94ff..88f1f4fe9e2e 100644
--- a/src/fix-ng/Makefile.am
+++ b/src/fix-ng/Makefile.am
@@ -1,6 +1,6 @@
 bin_PROGRAMS = fix-ng
 
-fix_ng_SOURCES = fix.cc parser.cc
+fix_ng_SOURCES = fix-expr.cc parser.cc fix.cc
 fix_ng_LDADD = ../libmain/libmain.a ../libnix/libnix.a ../boost/format/libformat.a \
  -L../../externals/inst/lib -ldb_cxx -lsglr -lATB -lconversion -lasfix2 -lmept -lATerm
 
diff --git a/src/fix-ng/fix-expr.cc b/src/fix-ng/fix-expr.cc
index 00795da4c427..8d47817ff0f7 100644
--- a/src/fix-ng/fix-expr.cc
+++ b/src/fix-ng/fix-expr.cc
@@ -29,5 +29,5 @@ ATerm bottomupRewrite(TermFun & f, ATerm e)
         return (ATerm) ATreverse(out);
     }
 
-    throw badTerm("cannot rewrite", e);
+    return e;
 }
diff --git a/src/fix-ng/parser.cc b/src/fix-ng/parser.cc
index b2f0ed05df50..e0812817af59 100644
--- a/src/fix-ng/parser.cc
+++ b/src/fix-ng/parser.cc
@@ -1,3 +1,9 @@
+#include <sstream>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 extern "C" {
 #include <sglr.h>
 #include <asfix2.h>
@@ -5,15 +11,58 @@ extern "C" {
 
 #include "parser.hh"
 #include "shared.hh"
+#include "fix-expr.hh"
 #include "expr.hh"
 #include "parse-table.h"
 
 
-Expr parseExprFromFile(const Path & path)
+struct Cleanup : TermFun
+{
+    string basePath;
+
+    virtual ATerm operator () (ATerm e)
+    {
+        char * s;
+
+        if (ATmatch(e, "Str(<str>)", &s)) {
+            string s2(s);
+            return ATmake("Str(<str>)",
+                string(s2, 1, s2.size() - 2).c_str());
+        }
+
+        if (ATmatch(e, "Path(<str>)", &s)) {
+            string path(s);
+            if (path[0] != '/')
+                path = basePath + "/" + path;
+            return ATmake("Str(<str>)", canonPath(path).c_str());
+        }
+
+        if (ATmatch(e, "Int(<str>)", &s)) {
+            istringstream s2(s);
+            int n;
+            s2 >> n;
+            return ATmake("Int(<int>)", n);
+        }
+
+        return e;
+    }
+};
+
+
+Expr parseExprFromFile(Path path)
 {
+#if 0
     /* Perhaps this is already an imploded parse tree? */
     Expr e = ATreadFromNamedFile(path.c_str());
     if (e) return e;
+#endif
+
+    /* If `path' refers to a directory, append `/default.fix'. */
+    struct stat st;
+    if (stat(path.c_str(), &st))
+        throw SysError(format("getting status of `%1%'") % path);
+    if (S_ISDIR(st.st_mode))
+        path = canonPath(path + "/default.fix");
 
     /* Initialise the SDF libraries. */
     static bool initialised = false;
@@ -72,5 +121,7 @@ Expr parseExprFromFile(const Path & path)
     if (!imploded)
         throw Error(format("cannot implode parse tree"));
 
-    return imploded;
+    Cleanup cleanup;
+    cleanup.basePath = dirOf(path);
+    return bottomupRewrite(cleanup, imploded);
 }
diff --git a/src/fix-ng/parser.hh b/src/fix-ng/parser.hh
index 80e266f2d5ae..c56a339a3f7c 100644
--- a/src/fix-ng/parser.hh
+++ b/src/fix-ng/parser.hh
@@ -1,15 +1,10 @@
 #ifndef __PARSER_H
 #define __PARSER_H
 
-#include <string>
-#include <aterm2.h>
+#include "fix-expr.hh"
 
-#include "util.hh"
 
-
-typedef ATerm Expr;
-
-Expr parseExprFromFile(const Path & path);
+Expr parseExprFromFile(Path path);
 
 
 #endif /* !__PARSER_H */