diff trunk/src/cmd/ImportGraph.d @ 391:33b566df6af4

Migrated project to Tango. Decremented the numbers of the format placeholders in the localized messages by one. Replaced all instances of writef/ln with Stdout. Added module common.d with string aliases and a global Layout!(char) instance. Replaced %s format specifiers with index placeholders in html/xml_tags. Changed member Information.arguments to string message. Copied std.metastring, std.uni and std.utf from Phobos.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 15 Sep 2007 17:12:26 +0200
parents 0bd21b746a04
children e2bbc6406a14
line wrap: on
line diff
--- a/trunk/src/cmd/ImportGraph.d	Wed Sep 12 21:03:41 2007 +0200
+++ b/trunk/src/cmd/ImportGraph.d	Sat Sep 15 17:12:26 2007 +0200
@@ -10,11 +10,13 @@
 import dil.File;
 import dil.Module;
 import dil.Settings;
-import std.stdio : writefln, writef;
-import std.path : getDirName, dirSep = sep;
-import std.file : exists;
-import std.string : replace;
-import std.regexp;
+import tango.text.Regex : RegExp = Regex;
+import tango.io.FilePath;
+import tango.io.FileConst;
+import tango.text.Util;
+import common;
+
+alias FileConst.PathSeparatorChar dirSep;
 
 enum IGraphOption
 {
@@ -34,8 +36,9 @@
   string modulePath;
   foreach (path; importPaths)
   {
-    modulePath = path ~ (path[$-1] == dirSep[0] ? "" : dirSep) ~ moduleFQN ~ ".d";
-    if (exists(modulePath))
+    modulePath = path ~ (path[$-1] == dirSep ? "" : [dirSep]) ~ moduleFQN ~ ".d";
+    // TODO: also check for *.di?
+    if ((new FilePath(modulePath)).exists())
       return modulePath;
   }
   return null;
@@ -78,7 +81,7 @@
     regexps ~= new RegExp(strRegexp);
 
   // Add directory of file and global directories to import paths.
-  auto fileDir = getDirName(filePath);
+  auto fileDir = (new FilePath(filePath)).folder();
   if (fileDir.length)
     importPaths ~= fileDir;
   importPaths ~= GlobalSettings.importPaths;
@@ -95,7 +98,7 @@
 
     // Ignore module names matching regular expressions.
     foreach (rx; regexps)
-      if (rx.test(replace(moduleFQNPath, dirSep, ".")))
+      if (rx.test(replace(moduleFQNPath, dirSep, '.')))
         return null;
 
     auto modulePath = findModulePath(moduleFQNPath, importPaths);
@@ -105,7 +108,7 @@
       if (options & IGraphOption.IncludeUnlocatableModules)
       {
         mod = new Vertex(null);
-        mod.setFQN(replace(moduleFQNPath, dirSep, "."));
+        mod.setFQN(replace(moduleFQNPath, dirSep, '.'));
         loadedModules[moduleFQNPath] = mod;
         loadedModulesList ~= mod;
         mod.id = loadedModulesList.length -1;
@@ -173,7 +176,7 @@
     return;
   foreach (vertex; vertices)
   {
-    writefln(indent, vertex.filePath);
+    Stdout(indent)(vertex.filePath).newline;
     if (vertex.outgoing.length)
       printPaths(vertex.outgoing, level-1, indent~"  ");
   }
@@ -185,7 +188,7 @@
     return;
   foreach (vertex; vertices)
   {
-    writefln(indent, vertex.getFQN());
+    Stdout(indent)(vertex.getFQN()).newline;
     if (vertex.outgoing.length)
       printList(vertex.outgoing, level-1, indent~"  ");
   }
@@ -202,28 +205,28 @@
                  IGraphOption.HighlightCyclicEdges))
     analyzeGraph(loadedModulesList, edges.dup);
 
-  writefln("Digraph ModuleDependencies\n{");
+  Stdout("Digraph ModuleDependencies\n{\n");
 
   if (options & IGraphOption.HighlightCyclicVertices)
     foreach (i, module_; loadedModulesList)
-      writefln(`  n%d [label="%s"%s];`, i, module_.getFQN(), (module_.isCyclic ? ",style=filled,fillcolor=tomato" : ""));
+      Stdout.format(`  n{0} [label="{1}"{2}];`, i, module_.getFQN(), (module_.isCyclic ? ",style=filled,fillcolor=tomato" : "")).newline;
   else
     foreach (i, module_; loadedModulesList)
-      writefln(`  n%d [label="%s"];`, i, module_.getFQN());
+      Stdout.format(`  n{0} [label="{1}"];`, i, module_.getFQN()).newline;
 
   foreach (edge; edges)
-    writefln(`  n%d -> n%d%s;`, edge.outgoing.id, edge.incoming.id, (edge.isCyclic ? "[color=red]" : ""));
+    Stdout.format(`  n{0} -> n{1}{2};`, edge.outgoing.id, edge.incoming.id, (edge.isCyclic ? "[color=red]" : "")).newline;
 
   if (options & IGraphOption.GroupByFullPackageName)
     foreach (packageName, vertices; verticesByPckgName)
     {
-      writef(`  subgraph "cluster_%s" {`\n`    label="%s";color=blue;`"\n    ", packageName, packageName);
+      Stdout.format(`  subgraph "cluster_{0}" {`\n`    label="{1}";color=blue;`"\n    ", packageName, packageName);
       foreach (module_; vertices)
-        writef(`n%d;`, module_.id);
-      writefln("\n  }");
+        Stdout.format(`n{0};`, module_.id);
+      Stdout("\n  }\n");
     }
 
-  writefln("}");
+  Stdout("}\n");
 }
 
 void analyzeGraph(Vertex[] vertices, Edge[] edges)