[svn] r7753: nemerle/trunk/tools/ndp: DataTree.n Makefile NemerleDoc.n

marcinm svnadmin at nemerle.org
Mon Jul 30 20:22:52 CEST 2007


Log:
- More messages during processing
- Destination directory (for result files) could be set
- The file with a style (nemerle-doc.css) is added to .exe and
  extracted if not exists


Author: marcinm
Date: Mon Jul 30 20:22:51 2007
New Revision: 7753

Modified:
   nemerle/trunk/tools/ndp/DataTree.n
   nemerle/trunk/tools/ndp/Makefile
   nemerle/trunk/tools/ndp/NemerleDoc.n

Modified: nemerle/trunk/tools/ndp/DataTree.n
==============================================================================
--- nemerle/trunk/tools/ndp/DataTree.n	(original)
+++ nemerle/trunk/tools/ndp/DataTree.n	Mon Jul 30 20:22:51 2007
@@ -163,7 +163,7 @@
         // replace(buf);
         _ = buf.Replace("&", "&");
 
-        def outf = IO.StreamWriter(fname);
+        def outf = IO.StreamWriter(Nemerledoc.destDir + fname);
         outf.Write(buf);
         outf.Close();
         // Console.WriteLine("---> zapis do {0}", fname);
@@ -291,7 +291,7 @@
   }  // Atributes
 
   /// <summary>
-  /// Top node of a tree. It must be always namespace, it is a root namespace.
+  /// Top node of a tree. It must be always a namespace, it is a root namespace.
   /// </summary>
   public class TopNode
   {
@@ -479,10 +479,13 @@
     
     /// prefix (i.e. namespaces.classes.etc)
     mutable prefix : string = "";
+    
     /// <summary>True (e.g. monster name with Tuple20) of the element</summary>
     mutable public true_name : string;
+    
     /// <summary>Full name of the element (with namespace path)</summary>
     public full_name : string { get { (if (this.prefix.Length > 0) this.prefix + "." else "") + this.true_name }};
+    
     // after some face_lifting
     mutable lifted_name : string;
     
@@ -495,8 +498,11 @@
     /// <summary>An anchor ref, used in html generation</summary>
     public override href () : string 
     {
+      def res =
       if (XMLattrib.Equals(ElementType.Unknown())) this.ToString() + this.GetHashCode().ToString()
-      else "id" + this.GetHashCode().ToString()
+          else "id" + this.GetHashCode().ToString();
+      // Console.WriteLine("Element {0}, hash-id={1}", true_name, res);
+      res
     }
     
   
@@ -705,7 +711,7 @@
     split (str : string) : char*string { (str[0], str.Substring(2)) }
     
     // top node of the tree
-    mutable tree : TopNode = TopNode(this);
+    mutable tree : TopNode;
     
     // recently added or processed node.
     mutable currentNode : Node;
@@ -713,6 +719,11 @@
     // list of the sources
     mutable sources : list [ string ] = [];
 
+    public this ()
+    {
+      this.tree = TopNode(this);  
+    }
+
     ///<summary>Creates a string (html) representation of the sources of the program</summary>
     public sourcesToString () : string
     {

Modified: nemerle/trunk/tools/ndp/Makefile
==============================================================================
--- nemerle/trunk/tools/ndp/Makefile	(original)
+++ nemerle/trunk/tools/ndp/Makefile	Mon Jul 30 20:22:51 2007
@@ -10,10 +10,10 @@
 DOC = nemerledoc.xml
 
 $(EXE): $(SOURCES) 
-	ncc -g -Ot -texe -doc:$(DOC) -out:$@ $^
+	ncc -g -Ot -texe -resource:nemerle-doc.css -doc:$(DOC) -out:$@ $^
 
 test:
-	mono --debug $(EXE) -title:"Nemerle Documentation Project" -s -np $(EXE) $(DOC)
+	mono --debug $(EXE) -dir:"wynik" -title:"Nemerle Documentation Project" -s -np $(EXE) $(DOC)
 
 clean:
 	rm  $(CLEAN_FILES)

Modified: nemerle/trunk/tools/ndp/NemerleDoc.n
==============================================================================
--- nemerle/trunk/tools/ndp/NemerleDoc.n	(original)
+++ nemerle/trunk/tools/ndp/NemerleDoc.n	Mon Jul 30 20:22:51 2007
@@ -54,30 +54,90 @@
 
   public mutable title : string = "";
 
+  /// <summary>Destination directory</summary>
+  public mutable destDir : string = "";
+
   /// <summary>
   /// Usage:
   /// <code>nemerledoc.exe &amp;lt;options&amp;gt; &amp;lt;files&amp;gt;</code>
   /// Writing <c>nemerledoc.exe</c> shows this info. 
   /// </summary>
-  public Main(arg : array [ string ]) : void
+  public Main(args : array [ string ]) : void
   {
     def tree = DataTree();
-    if (arg.Length == 0) Help();
+    if (args.Length == 0) Help();
     else {
         mutable publicOnly = true;
-        foreach (file in arg)
+        mutable fileList = [];
+        foreach (arg in args)
         {
-          when (file.EndsWith(".dll") || file.EndsWith(".exe"))
-            AssemblyAnalyzer.analyze(file, tree);
+          if (arg.Equals("-np")) publicOnly = false
+          else if (arg.Equals("-s")) simplify = true
+          else if (arg.Equals("-d")) debug = true
+          else if (arg.StartsWith("-dir")) destDir = arg.Substring(5)
+          else if (arg.StartsWith("-title")) title = arg.Substring(7)
+          else 
+              fileList = fileList + [ arg ];
+        }      
+        // prepare destination directory
+        when (destDir.Length > 0)
+        {
+            Console.WriteLine("Writing result to directory: {0}", destDir);
+            when (!System.IO.Directory.Exists(destDir))
+            {
+              _ = System.IO.Directory.CreateDirectory(destDir);
+            }
+            def sep = System.IO.Path.DirectorySeparatorChar.ToString();
+            when (!destDir.EndsWith(sep))
+                destDir = destDir + sep;
+        }
+        // deal with default css file
+        def css_file = "nemerle-doc.css";
+        when (!IO.File.Exists(destDir + css_file)) {
+          def assembly = System.Reflection.Assembly.GetExecutingAssembly();
+          Console.WriteLine("Create css file: " + css_file);
+          def in_stream = IO.BinaryReader(assembly.GetManifestResourceStream(css_file));
+          def fstream = IO.FileStream(destDir + css_file, IO.FileMode.CreateNew);
+          def out_stream = IO.BinaryWriter(fstream);
         
-          when (file.EndsWith(".xml"))
-            _ = XmlDocParser(tree, file);
+          mutable buf = in_stream.ReadBytes(1024);
+          while (buf.Length > 0) {
+              out_stream.Write(buf);
+              buf = in_stream.ReadBytes(1024);
+          }
+          in_stream.Close();
+          out_stream.Close();
+        }
       
-          if (file.Equals("-np")) publicOnly = false
-          else if (file.Equals("-s")) simplify = true
-          else if (file.Equals("-d")) debug = true
-          else if (file.StartsWith("-title")) title = file.Substring(7)
-          else tree.AddSource(file);
+        // process files
+        foreach (file in fileList)
+        {
+            Console.Write("Analyzing file '{0}'....\t", file);
+            if (!IO.File.Exists(file)) Console.Write("File does not exist")
+            else {
+                if (file.EndsWith(".dll") || file.EndsWith(".exe"))
+                {
+                  try {
+                      AssemblyAnalyzer.analyze(file, tree);
+                      tree.AddSource(file);
+                      Console.Write("OK");
+                  } catch {
+                    e is Exception => Console.WriteLine("Broken analysis with message {0}", e);
+                  }
+                } else
+                if (file.EndsWith(".xml"))
+                {
+                  try {
+                      _ = XmlDocParser(tree, file);
+                      tree.AddSource(file);
+                      Console.Write("OK");
+                  } catch {
+                    e is Exception => Console.WriteLine("Broken analysis with message {0}", e);
+                  }
+                } else 
+                    Console.Write("file type is not recognized");
+            }
+            Console.WriteLine("");
         }
         
         tree.ToHtml(publicOnly);



More information about the svn mailing list