SourceToHTML にGUIを
「SourceToHTML」と「SourceToRTF」をマージし、
また、"HTA"によるユーザーインターフェースを持たせました。
以下は、「SourceToHtml」の本体です。
.\library\SourceToHtml.js (1/3)
//******************************************************************************
// C++, C#, Java, JavaScript, VB, Delphi, PL/SQL, T-SQL → HTML 変換処理
//******************************************************************************// 雛形ファイル名
var _tempHtmlName = ".\\application\\template.html";
var _tempRtfName = ".\\application\\template.rtf";
var _tempFileName = "";// 行番号
var _lineNo = 0;// ファイルアクセス用オブジェクト
var _fs;// 変換用オブジェクト
var _convert = new Object();// 実行時引数
var _arg;
//*****************************************************************************
// 主処理 --- 各処理の呼び出し
//*****************************************************************************
function main(arg)
{
// 引数の取得
_arg = arg;// 初期処理 --- 引数の取得など、各変数の初期化
if (!initialize()) return false;// 雛形ファイルを 読み込み専用モードで 開く
var tsTemp = _fs.OpenTextFile(_tempFileName, 1);// 出力ファイルを 新規作成モードで 開く
var tsOut = _fs.OpenTextFile(_arg.outFileName, 2, -1);// 雛形ファイルの終わりまで繰り返す
while (!tsTemp.AtEndOfStream)
{
// 雛形ファイルを 1行ずつ読む
var text = tsTemp.ReadLine();// 入力ファイル名 を 出力
if (text.indexOf("%入力ファイル名%") >= 0)
tsOut.WriteLine(text.replace("%入力ファイル名%", _fs.GetFileName(_arg.inFileName)));// 色の指定 を 出力
else if (text == "%色の指定%")
_convert.putColor(tsOut);// プログラムソース を 出力
else if (text == "%プログラムソース%")
putSource(tsOut);// 雛形ファイルを そのまま出力
else
tsOut.WriteLine(text);
}// 出力ファイルを 閉じる
tsOut.Close();// 雛形ファイルを 閉じる
tsTemp.Close();
}
//*****************************************************************************
// 初期処理 --- コマンド引数の取得など、各変数の初期化
//*****************************************************************************
function initialize()
{
// 行番号
_lineNo = 0;// FileSystemObject を 生成する
_fs = new ActiveXObject("Scripting.FileSystemObject");// 入力ファイル名を 取得する
if (_arg.inFileName == "")
{
alert("入力ファイルを 指定して下さい。");
return false;
}
// 入力ファイルを 読み込み専用モードで 開いてみる
var tsTemp;
try
{
tsTemp = _fs.OpenTextFile(_arg.inFileName, 1);
tsTemp.Close();
}
catch (e)
{
alert("入力ファイル\n" + _arg.inFileName + "\n" + e.description);
return false;
}// 出力ファイル名を 取得する
if (_arg.outFileName == "")
{
alert("出力ファイルを 指定して下さい。");
return false;
}
// 出力ファイルを 新規作成モードで 開いてみる
try
{
tsTemp = _fs.OpenTextFile(_arg.outFileName, 2, -1);
tsTemp.Close();
}
catch (e)
{
alert("出力ファイル\n" + _arg.outFileName + "\n" + e.description);
return false;
}// 雛形ファイルを 読み込み専用モードで 開いてみる
_tempFileName = (_arg.formatType == "html" ? _tempHtmlName : _tempRtfName);
try
{
tsTemp = _fs.OpenTextFile(_tempFileName, 1);
tsTemp.Close();
}
catch (e)
{
alert("雛形ファイル\n" + _tempFileName + "\n" + e.description);
return false;
}// 言語タイプに応じて、変換用オブジェクトを設定する
setConvertOption();// 予約語一覧を取得する
getKeywordList();// 出力形式応じて、変換用オブジェクトを設定する
setOutputOption();return true;
}
//=============================================================================
// 出力形式応じて、変換用オブジェクトを設定する
//=============================================================================
function setOutputOption()
{
// 色の指定 を 出力
if (_arg.formatType == "html")
_convert.putColor = putColorCss;
else
_convert.putColor = putColorRtf;// 変換対象の文字を、変換して返す
if (_arg.formatType == "html")
_convert.getEscapeChar = getEscapeCharHtml;
else
_convert.getEscapeChar = getEscapeCharRtf;// 改行コード
if (_arg.formatType == "html")
_convert.NewLine = "";
else
_convert.NewLine = "\\par";
}