__include_level__ マクロ

Perl の __FILE__ eq $0 、 Ruby の __FILE__ == $0 、 Python の __name__ == "__main__" みたいなものがほしいなーと思った。

Index: token.cpp
===================================================================
--- token.cpp	(リビジョン 164)
+++ token.cpp	(作業コピー)
@@ -2879,10 +2879,12 @@
 		if ( GetToken() != TK_STRING ) { SetError("invalid include suffix"); return 1; }
 		incinf++;
 		if (incinf>32) { SetError("too many include level"); return 2; }
+		RegistExtMacro("__include_level__", incinf);
 		strcpy( tmp_spath, search_path );
 		res = ExpandFile( wrtbuf, word, word );
 		strcpy( search_path, tmp_spath );
 		incinf--;
+		RegistExtMacro("__include_level__", incinf);
 		if (res) return 3;
 		return 0x1000;
 	}
@@ -2891,12 +2893,14 @@
 		if ( GetToken() != TK_STRING ) { SetError("invalid addition suffix"); return 1; }
 		incinf++;
 		if (incinf>32) { SetError("too many include level"); return 2; }
+		RegistExtMacro("__include_level__", incinf);
 		strcpy( tmp_spath, search_path );
 		add_bak = SetAdditionMode( 1 );
 		res = ExpandFile( wrtbuf, word, word );
 		SetAdditionMode( add_bak );
 		strcpy( search_path, tmp_spath );
 		incinf--;
+		RegistExtMacro("__include_level__", incinf);
 		if (res) {
 			if ( res == -1 ) return 0;
 			return 3;

追記 ( 2008-08-12 23:53:08 +0900 )

これは hspdef.as の #addition "userdef.as" がないとトップレベルのファイルで正しく動かないのでよろしくないですね。
本来は最初に RegistExtMacro("__include_level__", 0); をしておくべき。