about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-09-03T11·20+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-09-03T11·20+0000
commitc0bbed0959665bc51909b285654db2a3cf120502 (patch)
tree3ee84c43b309f6c81c2f27cd07518ac451d82266 /src
parent0d2bc686817306502b71f5ca2cd49cb1d501247c (diff)
* Factored out dot graph generation into a separate file.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/dotgraph.cc63
-rw-r--r--src/dotgraph.hh8
-rw-r--r--src/nix.cc64
4 files changed, 76 insertions, 61 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 85bf502825ed..cddcae1c66c5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,7 +4,7 @@ check_PROGRAMS = test
 AM_CXXFLAGS = -DSYSTEM=\"@host@\" -Wall -I.. -I../externals/inst/include $(CXXFLAGS)
 AM_LDFLAGS = -L../externals/inst/lib -ldb_cxx -lATerm $(LDFLAGS)
 
-nix_SOURCES = nix.cc
+nix_SOURCES = nix.cc dotgraph.cc
 nix_LDADD = libshared.a libnix.a -ldb_cxx -lATerm
 
 nix_hash_SOURCES = nix-hash.cc
diff --git a/src/dotgraph.cc b/src/dotgraph.cc
new file mode 100644
index 000000000000..9f0182e53096
--- /dev/null
+++ b/src/dotgraph.cc
@@ -0,0 +1,63 @@
+#include "dotgraph.hh"
+
+
+static string dotQuote(const string & s)
+{
+    return "\"" + s + "\"";
+}
+
+
+void printDotGraph(const FSIds & roots)
+{
+    FSIds workList(roots.begin(), roots.end());
+    FSIdSet doneSet;
+            
+    cout << "digraph G {\n";
+
+    while (!workList.empty()) {
+	FSId id = workList.front();
+	workList.pop_front();
+
+	if (doneSet.find(id) == doneSet.end()) {
+	    doneSet.insert(id);
+                    
+	    FState fs = parseFState(termFromId(id));
+
+	    string label, shape;
+                    
+	    if (fs.type == FState::fsDerive) {
+		for (FSIdSet::iterator i = fs.derive.inputs.begin();
+		     i != fs.derive.inputs.end(); i++)
+		{
+		    workList.push_back(*i);
+		    cout << dotQuote(*i) << " -> "
+			 << dotQuote(id) << ";\n";
+		}
+
+		label = "derive";
+		shape = "box";
+		for (StringPairs::iterator i = fs.derive.env.begin();
+		     i != fs.derive.env.end(); i++)
+		    if (i->first == "name") label = i->second;
+	    }
+
+	    else if (fs.type == FState::fsSlice) {
+		label = baseNameOf((*fs.slice.elems.begin()).first);
+		shape = "ellipse";
+		if (isHash(string(label, 0, Hash::hashSize * 2)) && 
+		    label[Hash::hashSize * 2] == '-')
+		    label = string(label, Hash::hashSize * 2 + 1);
+	    }
+
+	    else abort();
+
+	    cout << dotQuote(id) << "[label = "
+		 << dotQuote(label)
+		 << ", shape = " << shape
+		 << "];\n";
+	}
+    }
+
+    cout << "}\n";
+
+}
diff --git a/src/dotgraph.hh b/src/dotgraph.hh
new file mode 100644
index 000000000000..d88e04e09794
--- /dev/null
+++ b/src/dotgraph.hh
@@ -0,0 +1,8 @@
+#ifndef __DOTGRAPH_H
+#define __DOTGRAPH_H
+
+#include "fstate.hh"
+
+void printDotGraph(const FSIds & roots);
+
+#endif /* !__DOTGRAPH_H */
diff --git a/src/nix.cc b/src/nix.cc
index 04195e8d4428..41ed16839725 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -5,6 +5,7 @@
 #include "normalise.hh"
 #include "archive.hh"
 #include "shared.hh"
+#include "dotgraph.hh"
 
 
 typedef void (* Operation) (Strings opFlags, Strings opArgs);
@@ -80,12 +81,6 @@ static void opAdd(Strings opFlags, Strings opArgs)
 }
 
 
-static string dotQuote(const string & s)
-{
-    return "\"" + s + "\"";
-}
-
-
 FSId maybeNormalise(const FSId & id, bool normalise)
 {
     return normalise ? normaliseFState(id) : id;
@@ -170,62 +165,11 @@ static void opQuery(Strings opFlags, Strings opArgs)
         }
 
         case qGraph: {
-
-            FSIds workList;
-
+            FSIds roots;
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
-                workList.push_back(argToId(*i));
-
-            FSIdSet doneSet;
-            
-            cout << "digraph G {\n";
-
-            while (!workList.empty()) {
-                FSId id = workList.front();
-                workList.pop_front();
-
-                if (doneSet.find(id) == doneSet.end()) {
-                    doneSet.insert(id);
-                    
-                    FState fs = parseFState(termFromId(id));
-
-                    string label, shape;
-                    
-                    if (fs.type == FState::fsDerive) {
-                        for (FSIdSet::iterator i = fs.derive.inputs.begin();
-                             i != fs.derive.inputs.end(); i++)
-                        {
-                            workList.push_back(*i);
-                            cout << dotQuote(*i) << " -> "
-                                 << dotQuote(id) << ";\n";
-                        }
-
-                        label = "derive";
-                        shape = "box";
-                        for (StringPairs::iterator i = fs.derive.env.begin();
-                             i != fs.derive.env.end(); i++)
-                            if (i->first == "name") label = i->second;
-                    }
-
-                    else if (fs.type == FState::fsSlice) {
-                        label = baseNameOf((*fs.slice.elems.begin()).first);
-                        shape = "ellipse";
-                        if (isHash(string(label, 0, Hash::hashSize * 2)) && 
-                            label[Hash::hashSize * 2] == '-')
-                            label = string(label, Hash::hashSize * 2 + 1);
-                    }
-
-                    else abort();
-
-                    cout << dotQuote(id) << "[label = "
-                         << dotQuote(label)
-                         << ", shape = " << shape
-                         << "];\n";
-                }
-            }
-
-            cout << "}\n";
+                roots.push_back(argToId(*i));
+	    printDotGraph(roots);
             break;
         }