using NemerleDoc;
using System;
module Nemerledoc {
///
/// This is a test comment.
///
/// This function is for testing purposes only; to test all tags
/// Test list tag.
///
///
/// This programdoes
///
/// - if XML file is an argumentanalyzes this file
/// - if dll file is an argumentanalyzes this file
///
/// End of list tag test. But there is some value:
/// this is value
///
/// Public Access
/// This is arg1
/// This is arg2
/// This is arg3
/// This is an example;
///
/// $ mono nemerledoc.exe
///
/// with arguments.
///
/// This function returns nothing
///
///
public _foo () : void {}
Help () : void {
Console.WriteLine("USAGE:");
Console.WriteLine(" nemerledoc.exe ");
Console.WriteLine(" :");
Console.WriteLine(" -np show non public elements");
Console.WriteLine(" -title:\"title\" title for index page");
Console.WriteLine(" -dest:\"directory\" directory where result files will be written");
Console.WriteLine(" -s simplifies some monster type expressions, functions, tuples etc.");
Console.WriteLine(" -d debug info");
Console.WriteLine(" : a list of *.dll and *.xml files");
}
///
/// Whether to simplify monsters like Function'x[Tuple'20[.....]]
///
public mutable simplify : bool = false;
public mutable debug : bool = false;
public mutable title : string = "";
/// Destination directory
public mutable destDir : string = "";
///
/// Usage:
/// nemerledoc.exe <options> <files>
/// Writing nemerledoc.exe shows this info.
///
public Main(args : array [ string ]) : void
{
def tree = DataTree();
if (args.Length == 0) Help();
else {
mutable publicOnly = true;
mutable fileList = [];
foreach (arg in args)
{
if (arg.Equals("-np")) publicOnly = false
else if (arg.Equals("-s")) simplify = true
else if (arg.Equals("-d")) debug = true
else if (arg.StartsWith("-dest")) destDir = arg.Substring(6)
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);
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();
}
// 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);
}
}
}