about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-09-14T08·54+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-09-14T08·54+0200
commite07c0dcf5c128875bf8af740b2c4bc81918713c9 (patch)
tree10cbe40f35fafb3a25c0802679f6c33f72b78be6 /src/libstore
parent2c8c103ef80378bfcfa29ae054fd878305b5e275 (diff)
Move some .drv parsing functions out of util
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/derivations.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index f051f10bd018..3b6a62e13df2 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -87,6 +87,38 @@ Path writeDerivation(ref<Store> store,
 }
 
 
+MakeError(FormatError, Error)
+
+
+/* Read string `s' from stream `str'. */
+static void expect(std::istream & str, const string & s)
+{
+    char s2[s.size()];
+    str.read(s2, s.size());
+    if (string(s2, s.size()) != s)
+        throw FormatError(format("expected string ‘%1%’") % s);
+}
+
+
+/* Read a C-style string from stream `str'. */
+static string parseString(std::istream & str)
+{
+    string res;
+    expect(str, "\"");
+    int c;
+    while ((c = str.get()) != '"')
+        if (c == '\\') {
+            c = str.get();
+            if (c == 'n') res += '\n';
+            else if (c == 'r') res += '\r';
+            else if (c == 't') res += '\t';
+            else res += c;
+        }
+        else res += c;
+    return res;
+}
+
+
 static Path parsePath(std::istream & str)
 {
     string s = parseString(str);
@@ -96,6 +128,20 @@ static Path parsePath(std::istream & str)
 }
 
 
+static bool endOfList(std::istream & str)
+{
+    if (str.peek() == ',') {
+        str.get();
+        return false;
+    }
+    if (str.peek() == ']') {
+        str.get();
+        return true;
+    }
+    return false;
+}
+
+
 static StringSet parseStrings(std::istream & str, bool arePaths)
 {
     StringSet res;