2004-08-16 17:41:11 +01:00
|
|
|
// =================================================================
|
|
|
|
// Logtalk - Object oriented extension to Prolog
|
2006-03-26 18:31:34 +01:00
|
|
|
// Release 2.27.1
|
2004-08-16 17:41:11 +01:00
|
|
|
//
|
2006-02-10 17:44:05 +00:00
|
|
|
// Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
2004-08-16 17:41:11 +01:00
|
|
|
// =================================================================
|
|
|
|
|
|
|
|
var WshShell = new ActiveXObject("WScript.Shell");
|
|
|
|
|
|
|
|
var format = "xhtml";
|
|
|
|
// var format = "html";
|
|
|
|
|
|
|
|
var directory = WshShell.CurrentDirectory;
|
|
|
|
|
|
|
|
var index_file = "index.html";
|
|
|
|
var index_title = "Entity documentation index";
|
|
|
|
|
|
|
|
var processor = "msxsl";
|
|
|
|
// var processor = "xsltproc";
|
|
|
|
// var processor = "xalan";
|
|
|
|
// var processor = "sabcmd";
|
|
|
|
|
|
|
|
if (WScript.Arguments.Unnamed.Length > 0) {
|
|
|
|
usage_help();
|
|
|
|
WScript.Quit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var WshSystemEnv = WshShell.Environment("SYSTEM");
|
|
|
|
var WshUserEnv = WshShell.Environment("USER");
|
2005-12-24 18:00:21 +00:00
|
|
|
|
2004-08-16 17:41:11 +01:00
|
|
|
var logtalk_home;
|
2005-12-24 18:00:21 +00:00
|
|
|
var logtalk_user;
|
|
|
|
|
|
|
|
if (WshSystemEnv.Item("LOGTALKHOME"))
|
|
|
|
logtalk_home = WshSystemEnv.Item("LOGTALKHOME");
|
|
|
|
else if (WshUserEnv.Item("LOGTALKHOME"))
|
|
|
|
logtalk_home = WshUserEnv.Item("LOGTALKHOME")
|
|
|
|
else {
|
|
|
|
WScript.Echo("Error! The environment variable LOGTALKHOME must be defined first!");
|
|
|
|
usage_help();
|
|
|
|
WScript.Quit(1);
|
|
|
|
}
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
if (WshSystemEnv.Item("LOGTALKUSER"))
|
|
|
|
logtalk_user = WshSystemEnv.Item("LOGTALKUSER");
|
2004-12-05 21:52:49 +00:00
|
|
|
else if (WshUserEnv.Item("LOGTALKUSER"))
|
2005-12-24 18:00:21 +00:00
|
|
|
logtalk_user = WshUserEnv.Item("LOGTALKUSER")
|
2004-08-16 17:41:11 +01:00
|
|
|
else {
|
2004-12-05 21:52:49 +00:00
|
|
|
WScript.Echo("Error! The environment variable LOGTALKUSER must be defined first!");
|
2004-08-16 17:41:11 +01:00
|
|
|
usage_help();
|
|
|
|
WScript.Quit(1);
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
var html_xslt = logtalk_user + "\\xml\\lgthtml.xsl";
|
|
|
|
var xhtml_xslt = logtalk_user + "\\xml\\lgtxhtml.xsl";
|
2005-04-23 00:57:45 +01:00
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var xslt;
|
|
|
|
|
2004-08-16 17:41:11 +01:00
|
|
|
var f_arg = "";
|
|
|
|
var d_arg = "";
|
|
|
|
var i_arg = "";
|
|
|
|
var t_arg = "";
|
|
|
|
var p_arg = "";
|
|
|
|
|
|
|
|
if (WScript.Arguments.Named.Exists("f"))
|
|
|
|
f_arg = WScript.Arguments.Named.Item("f");
|
|
|
|
|
|
|
|
if (WScript.Arguments.Named.Exists("d"))
|
|
|
|
d_arg = WScript.Arguments.Named.Item("d");
|
|
|
|
|
|
|
|
if (WScript.Arguments.Named.Exists("i"))
|
|
|
|
i_arg = WScript.Arguments.Named.Item("i");
|
|
|
|
|
|
|
|
if (WScript.Arguments.Named.Exists("t"))
|
|
|
|
t_arg = WScript.Arguments.Named.Item("t");
|
|
|
|
|
|
|
|
if (WScript.Arguments.Named.Exists("p"))
|
|
|
|
p_arg = WScript.Arguments.Named.Item("p");
|
|
|
|
|
|
|
|
if (f_arg != "" && f_arg != "xhtml" && f_arg != "html") {
|
|
|
|
WScript.Echo("Error! Unsupported output format: " + f_arg);
|
|
|
|
WScript.Echo("");
|
|
|
|
usage_help();
|
|
|
|
} else if (f_arg != "")
|
|
|
|
format = f_arg;
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var FSObject = new ActiveXObject("Scripting.FileSystemObject");
|
2004-08-16 17:41:11 +01:00
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
if (d_arg != "" && !FSObject.FolderExists(d_arg)) {
|
2004-08-16 17:41:11 +01:00
|
|
|
WScript.Echo("Error! directory does not exists: " + d_arg);
|
|
|
|
WScript.Echo("");
|
|
|
|
usage_help();
|
|
|
|
} else if (d_arg != "")
|
|
|
|
directory = d_arg;
|
|
|
|
|
|
|
|
if (i_arg != "")
|
|
|
|
index_file=i_arg;
|
|
|
|
|
|
|
|
if (t_arg != "")
|
|
|
|
index_title=t_arg;
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
if (p_arg != "" && p_arg != "msxsl" && p_arg != "xsltproc" && p_arg != "xalan" && p_arg != "sabcmd") {
|
2004-08-16 17:41:11 +01:00
|
|
|
WScript.Echo("Error! Unsupported XSLT processor:" + p_arg);
|
|
|
|
WScript.Echo("");
|
|
|
|
usage_help();
|
|
|
|
} else if (p_arg != "")
|
|
|
|
processor = p_arg;
|
|
|
|
|
|
|
|
if (format == "xhtml")
|
|
|
|
xslt = xhtml_xslt;
|
|
|
|
else
|
|
|
|
xslt = html_xslt;
|
|
|
|
|
2005-12-24 18:00:21 +00:00
|
|
|
if (!FSObject.FileExists(WshShell.CurrentDirectory + "\\logtalk.dtd")) {
|
|
|
|
FSObject.CopyFile(logtalk_home + "\\xml\\logtalk.dtd", WshShell.CurrentDirectory + "\\logtalk.dtd");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FSObject.FileExists(WshShell.CurrentDirectory + "\\logtalk.xsd")) {
|
|
|
|
FSObject.CopyFile(logtalk_home + "\\xml\\logtalk.xsd", WshShell.CurrentDirectory + "\\logtalk.xsd");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FSObject.FileExists(directory + "\\logtalk.css")) {
|
|
|
|
FSObject.CopyFile(logtalk_user + "\\xml\\logtalk.css", directory + "\\logtalk.css");
|
|
|
|
}
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("converting XML files...");
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var files = new Enumerator(FSObject.GetFolder(WshShell.CurrentDirectory).Files);
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
for (files.moveFirst(); !files.atEnd(); files.moveNext()) {
|
|
|
|
var file = files.item().name;
|
2004-08-19 14:46:40 +01:00
|
|
|
if (FSObject.GetExtensionName(file) == "xml") {
|
2004-08-16 17:41:11 +01:00
|
|
|
WScript.Echo(" converting " + file);
|
2004-08-19 14:46:40 +01:00
|
|
|
var html_file = directory + "\\" + FSObject.GetBaseName(file) + ".html";
|
2004-08-16 17:41:11 +01:00
|
|
|
switch (processor) {
|
|
|
|
case "msxsl" :
|
2005-04-23 00:57:45 +01:00
|
|
|
WshShell.Run("msxsl -o \"" + html_file + "\" \"" + file + "\" \"" + xslt + "\"", true);
|
2004-08-16 17:41:11 +01:00
|
|
|
break;
|
|
|
|
case "xsltproc" :
|
2005-04-23 00:57:45 +01:00
|
|
|
WshShell.Run("xsltproc -o \"" + html_file + "\" \"" + xslt + "\" \"" + file + "\"", true);
|
2004-08-16 17:41:11 +01:00
|
|
|
break;
|
|
|
|
case "xalan" :
|
2005-04-23 00:57:45 +01:00
|
|
|
WshShell.Run("xalan -o \"" + html_file + "\" \"" + file + "\" \"" + xslt + "\"", true);
|
2004-08-16 17:41:11 +01:00
|
|
|
break;
|
|
|
|
case "sabcmd" :
|
2005-04-23 00:57:45 +01:00
|
|
|
WshShell.Run("sabcmd \"" + xslt + "\" \"" + file + "\" \"" + html_file + "\"", true);
|
2004-08-16 17:41:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WScript.Echo("conversion done");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("generating index file...");
|
|
|
|
|
|
|
|
index_file = directory + "\\" + index_file;
|
|
|
|
create_index_file();
|
|
|
|
|
|
|
|
WScript.Echo("index file generated");
|
|
|
|
WScript.Echo("");
|
|
|
|
|
|
|
|
WScript.Quit(0);
|
|
|
|
|
|
|
|
function usage_help() {
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("This script converts all Logtalk XML files documenting files in the");
|
|
|
|
WScript.Echo("current directory to XHTML or HTML files");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("Usage:");
|
|
|
|
WScript.Echo(" " + WScript.ScriptName + " [/f:format] [/d:directory] [/i:index] [/t:title] [/p:processor]");
|
|
|
|
WScript.Echo(" " + WScript.ScriptName + " help");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("Optional arguments:");
|
|
|
|
WScript.Echo(" f - output file format (either xhtml or html; default is " + format + ")");
|
|
|
|
WScript.Echo(" d - output directory for the generated files (default is " + directory + ")");
|
|
|
|
WScript.Echo(" i - name of the index file (default is " + index_file + ")");
|
|
|
|
WScript.Echo(" t - title to be used on the index file (default is " + index_title + ")");
|
2005-12-24 18:00:21 +00:00
|
|
|
WScript.Echo(" p - XSLT processor (msxsl, xsltproc, xalan, or sabcmd; default is " + processor + ")");
|
2004-08-16 17:41:11 +01:00
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Quit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_index_file() {
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var f = FSObject.CreateTextFile(index_file, true);
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
switch (format) {
|
|
|
|
case "xhtml" :
|
2005-05-24 00:33:41 +01:00
|
|
|
f.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
2004-08-16 17:41:11 +01:00
|
|
|
f.WriteLine("<?xml-stylesheet href=\"logtalk.css\" type=\"text/css\"?>");
|
|
|
|
f.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
|
|
|
|
f.WriteLine("<html lang=\"en\" xml:lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\">");
|
|
|
|
break;
|
|
|
|
case "html" :
|
|
|
|
f.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
|
|
|
|
f.WriteLine("<html>");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
f.WriteLine("<head>");
|
|
|
|
f.WriteLine(" <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>");
|
|
|
|
f.WriteLine(" <title>" + index_title + "</title>");
|
|
|
|
f.WriteLine(" <link rel=\"stylesheet\" href=\"logtalk.css\" type=\"text/css\"/>");
|
|
|
|
f.WriteLine("</head>");
|
|
|
|
f.WriteLine("<body>");
|
|
|
|
f.WriteLine("<h1>" + index_title + "</h1>");
|
|
|
|
f.WriteLine("<ul>");
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var files = new Enumerator(FSObject.GetFolder(WshShell.CurrentDirectory).Files);
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
for (files.moveFirst(); !files.atEnd(); files.moveNext()) {
|
|
|
|
var file = files.item().name;
|
2004-08-19 14:46:40 +01:00
|
|
|
if (FSObject.GetExtensionName(file) == "xml") {
|
|
|
|
var html_file = FSObject.GetBaseName(file) + ".html";
|
2004-08-16 17:41:11 +01:00
|
|
|
WScript.Echo(" indexing " + html_file);
|
2005-08-08 13:13:45 +01:00
|
|
|
var index = FSObject.GetBaseName(file).lastIndexOf("_");
|
|
|
|
var pars = FSObject.GetBaseName(file).slice(index+1);
|
|
|
|
var entity = FSObject.GetBaseName(file).slice(0, index);
|
|
|
|
if (pars == 0)
|
|
|
|
f.WriteLine(" <li><a href=\"" + html_file + "\">" + entity + "</a></li>");
|
|
|
|
else
|
|
|
|
f.WriteLine(" <li><a href=\"" + html_file + "\">" + entity + "/" + pars + "</a></li>");
|
2004-08-16 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f.WriteLine("</ul>");
|
|
|
|
|
|
|
|
var today = new Date();
|
|
|
|
var year = today.getFullYear();
|
|
|
|
var month = today.getMonth() + 1;
|
|
|
|
if (month < 10)
|
|
|
|
month = "0" + month;
|
|
|
|
day = today.getDate();
|
|
|
|
if (day < 10)
|
|
|
|
day = "0" + day;
|
|
|
|
strToday = year + "/" + month + "/" + day;
|
|
|
|
var hours = today.getHours();
|
|
|
|
if (hours < 10)
|
|
|
|
hours = "0" + hours;
|
|
|
|
var mins = today.getMinutes();
|
|
|
|
if (mins < 10)
|
|
|
|
mins = "0" + mins;
|
|
|
|
var secs = today.getSeconds();
|
|
|
|
if (secs < 10)
|
|
|
|
secs = "0" + secs;
|
|
|
|
strTime = hours + ":" + mins + ":" + secs;
|
|
|
|
f.WriteLine("<p>Generated on " + strToday + " - " + strTime + "</p>");
|
|
|
|
|
|
|
|
f.WriteLine("</body>");
|
|
|
|
f.WriteLine("</html>");
|
|
|
|
|
|
|
|
f.Close();
|
|
|
|
}
|