about summary refs log tree commit diff
path: root/src/util.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-07-04T12·18+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-07-04T12·18+0000
commit207ff2caf0f48db0fb539e228ec5c3938a279f2a (patch)
treee4c2c329dcf44db95e36ff4d6872f904e39bc520 /src/util.cc
parent40b5936691fe2448dea0080e2319cc340bc7c65c (diff)
* Caching of expression successors.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/util.cc b/src/util.cc
index a042a65b075c..65ceea938352 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -36,7 +36,7 @@ string absPath(string path, string dir)
         /* !!! canonicalise */
         char resolved[PATH_MAX];
         if (!realpath(path.c_str(), resolved))
-            throw SysError("cannot canonicalise path " + path);
+            throw SysError(format("cannot canonicalise path %1%") % path);
         path = resolved;
     }
     return path;
@@ -46,7 +46,8 @@ string absPath(string path, string dir)
 string dirOf(string path)
 {
     unsigned int pos = path.rfind('/');
-    if (pos == string::npos) throw Error("invalid file name: " + path);
+    if (pos == string::npos)
+        throw Error(format("invalid file name: %1%") % path);
     return string(path, 0, pos);
 }
 
@@ -54,7 +55,8 @@ string dirOf(string path)
 string baseNameOf(string path)
 {
     unsigned int pos = path.rfind('/');
-    if (pos == string::npos) throw Error("invalid file name: " + path);
+    if (pos == string::npos)
+        throw Error(format("invalid file name %1% ") % path);
     return string(path, pos + 1);
 }
 
@@ -63,7 +65,7 @@ void deletePath(string path)
 {
     struct stat st;
     if (lstat(path.c_str(), &st))
-        throw SysError("getting attributes of path " + path);
+        throw SysError(format("getting attributes of path %1%") % path);
 
     if (S_ISDIR(st.st_mode)) {
         DIR * dir = opendir(path.c_str());
@@ -79,11 +81,36 @@ void deletePath(string path)
     }
 
     if (remove(path.c_str()) == -1)
-        throw SysError("cannot unlink " + path);
+        throw SysError(format("cannot unlink %1%") % path);
+}
+
+
+static int nestingLevel = 0;
+
+
+Nest::Nest(bool nest)
+{
+    this->nest = nest;
+    if (nest) nestingLevel++;
+}
+
+
+Nest::~Nest()
+{
+    if (nest) nestingLevel--;
+}
+
+
+void msg(const format & f)
+{
+    string spaces;
+    for (int i = 0; i < nestingLevel; i++)
+        spaces += "  ";
+    cerr << format("%1%%2%\n") % spaces % f.str();
 }
 
 
 void debug(const format & f)
 {
-    cerr << format("debug: %1%\n") % f.str();
+    msg(format("debug: %1%") % f.str());
 }