2004-08-16 17:41:11 +01:00
|
|
|
// =================================================================
|
|
|
|
// Logtalk - Object oriented extension to Prolog
|
2005-08-08 13:13:45 +01:00
|
|
|
// Release 2.25.1
|
2004-08-16 17:41:11 +01:00
|
|
|
//
|
2005-01-13 12:22:42 +00:00
|
|
|
// Copyright (c) 1998-2005 Paulo Moura. All Rights Reserved.
|
2004-08-16 17:41:11 +01:00
|
|
|
// =================================================================
|
|
|
|
|
|
|
|
var WshShell = new ActiveXObject("WScript.Shell");
|
|
|
|
|
|
|
|
var format = "a4";
|
|
|
|
// var format = "us";
|
|
|
|
|
|
|
|
var directory = WshShell.CurrentDirectory;
|
|
|
|
|
|
|
|
var processor = "fop";
|
|
|
|
// var processor = "xep";
|
|
|
|
|
|
|
|
if (WScript.Arguments.Unnamed.Length > 0) {
|
|
|
|
usage_help();
|
|
|
|
WScript.Quit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
var WshProcessEnv = WshShell.Environment("PROCESS");
|
|
|
|
var WshSystemEnv = WshShell.Environment("SYSTEM");
|
|
|
|
var WshUserEnv = WshShell.Environment("USER");
|
|
|
|
var logtalk_home;
|
|
|
|
|
2004-12-05 21:52:49 +00:00
|
|
|
if (WshProcessEnv.Item("LOGTALKUSER"))
|
|
|
|
logtalk_home = WshProcessEnv.Item("LOGTALKUSER");
|
|
|
|
else if (WshSystemEnv.Item("LOGTALKUSER"))
|
|
|
|
logtalk_home = WshSystemEnv.Item("LOGTALKUSER");
|
|
|
|
else if (WshUserEnv.Item("LOGTALKUSER"))
|
|
|
|
logtalk_home = 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);
|
|
|
|
}
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
var a4_xsl = logtalk_home + "\\xml\\lgtpdfa4.xsl";
|
|
|
|
var us_xsl = logtalk_home + "\\xml\\lgtpdfus.xsl";
|
|
|
|
var xsl;
|
|
|
|
|
2004-08-16 17:41:11 +01:00
|
|
|
var f_arg = "";
|
|
|
|
var d_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("p"))
|
|
|
|
p_arg = WScript.Arguments.Named.Item("p");
|
|
|
|
|
|
|
|
if (f_arg != "" && f_arg != "a4" && f_arg != "us") {
|
|
|
|
WScript.Echo("Error! Unsupported paper 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 (p_arg != "" && p_arg != "fop" && p_arg != "xep") {
|
|
|
|
WScript.Echo("Error! Unsupported XSL-FO processor:" + p_arg);
|
|
|
|
WScript.Echo("");
|
|
|
|
usage_help();
|
|
|
|
} else if (p_arg != "")
|
|
|
|
processor = p_arg;
|
|
|
|
|
|
|
|
if (format == "a4")
|
|
|
|
xsl = a4_xsl;
|
|
|
|
else
|
|
|
|
xsl = us_xsl;
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
FSObject.CopyFile(logtalk_home + "\\xml\\logtalk.dtd", WshShell.CurrentDirectory + "\\logtalk.dtd");
|
|
|
|
FSObject.CopyFile(logtalk_home + "\\xml\\logtalk.xsd", WshShell.CurrentDirectory + "\\logtalk.xsd");
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("converting XML files to PDF...");
|
|
|
|
|
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);
|
2005-04-23 00:57:45 +01:00
|
|
|
var pdf_file = directory + "\\" + FSObject.GetBaseName(file) + ".pdf";
|
|
|
|
WshShell.Run(processor + " -q -xml \"" + file + "\" -xsl \"" + xsl + "\" -pdf \"" + pdf_file + "\"", true);
|
2004-08-16 17:41:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WScript.Echo("conversion done");
|
|
|
|
WScript.Echo("");
|
|
|
|
|
2004-08-19 14:46:40 +01:00
|
|
|
FSObject.DeleteFile("logtalk.dtd");
|
|
|
|
FSObject.DeleteFile("logtalk.xsd");
|
2004-08-16 17:41:11 +01:00
|
|
|
|
|
|
|
WScript.Quit(0);
|
|
|
|
|
|
|
|
function usage_help() {
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("This script converts all Logtalk XML documenting files in the");
|
|
|
|
WScript.Echo("current directory to PDF files");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("Usage:");
|
|
|
|
WScript.Echo(" " + WScript.ScriptName + " [/f:format] [/d:directory] [/p:processor]");
|
|
|
|
WScript.Echo(" " + WScript.ScriptName + " help");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Echo("Optional arguments:");
|
|
|
|
WScript.Echo(" f - paper format (either a4 or us; default is " + format + ")");
|
|
|
|
WScript.Echo(" d - output directory for the PDF files (default is " + directory + ")");
|
|
|
|
WScript.Echo(" p - XSL-FO processor (either fop or xep; default is " + processor + ")");
|
|
|
|
WScript.Echo("");
|
|
|
|
WScript.Quit(1);
|
|
|
|
}
|