Macro/投稿/184 の変更点

http://sakura.qp.land.to/?Macro%2F%C5%EA%B9%C6%2F184


Top > Macro > 投稿 > 184
  • 追加された行はこの色です。
  • 削除された行はこの色です。
  • Macro/投稿/184 へ行く。

* インクルードガードの挿入(GUID使用) [#g11c8a6d]
-ページ: [[Macro/投稿]]
-作者: [[げんた]]
-カテゴリー: js
-投稿日: 2007-11-28 (水) 19:25:34

** メッセージ [#iec806d0]
GUIDを使ったuniqueなインクルードガードを挿入します.ライセンス文を併せて挿入する機能も入っています.
----
#code(javascript){{
//
//  Include Guard Generator
//
//  Copyright (C) 2007, genta
//
// GUIDGen : http://p2p.wrox.com/topic.asp?TOPIC_ID=20339
//

// ------------------------
// Options
var header_prefix = "SAKURA_"
var header_postfix = "_H_"
var license = zlib_license

var EOL = ["\r\n", "\r", "\n" ][Editor.GetLineCode()]

// ------------------------

var filepart = Editor.ExpandParameter("$g").toUpperCase()
var guidpart = GUIDGen().toUpperCase()

var guardkey = header_prefix + filepart + "_" + guidpart + header_postfix

//------------------------

Editor.GoFileTop()
if( license ){
	Editor.InsText( license() )
}
Editor.InsText("#ifndef " + guardkey + EOL )
Editor.InsText("#define " + guardkey + EOL )
Editor.GoFileEnd()
Editor.InsText( EOL + "#endif /* " + guardkey + " */" + EOL + "/*[EOF]*/" + EOL )

//------------------------
function GUIDGen() 
{
    try
    {
        var x = new ActiveXObject("Scriptlet.TypeLib");
        // Note: GUID contains \0 !!
        return x.GUID.replace(/[{}\0]/g, "" ).replace(/-/g,"_");
    }
    catch (e)
    {
        // set default string if GUID is not available
        return ("_GUARD_");
    }
}

function zlib_license (){
	return "/*" + EOL +
	"	Copyright (C) **YEAR**, **AUTHOR**" + EOL +
	"" + EOL +
	"	This software is provided 'as-is', without any express or implied" + EOL +
	"	warranty. In no event will the authors be held liable for any damages" + EOL +
	"	arising from the use of this software." + EOL +
	"" + EOL +
	"	Permission is granted to anyone to use this software for any purpose," + EOL +
	"	including commercial applications, and to alter it and redistribute it" + EOL +
	"	freely, subject to the following restrictions:" + EOL +
	"" + EOL +
	"		1. The origin of this software must not be misrepresented;" + EOL +
	"		   you must not claim that you wrote the original software." + EOL +
	"		   If you use this software in a product, an acknowledgment" + EOL +
	"		   in the product documentation would be appreciated but is" + EOL +
	"		   not required." + EOL +
	"" + EOL +
	"		2. Altered source versions must be plainly marked as such," + EOL +
	"		   and must not be misrepresented as being the original software." + EOL +
	"" + EOL +
	"		3. This notice may not be removed or altered from any source" + EOL +
	"		   distribution." + EOL +
	"*/" + EOL
	;
}
}}

#comment

    ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS