Boost.Waveシェル
颯爽と去っていくだけではアレなので、デバッガ上でwaveを動かしてみようと思ったのですが、
何気にwaveにインタラクティブモードがあったので、これで十分な気がしてきました。
C:\Boost>wave.exe -t - Wave: A Standard conformant C++ preprocessor based on the Boost.Wave library Version: 2.0.3.2938 [Win32/Microsoft Visual C++ version 9.0] (20090602) >>> #pragma wave trace(enable) >>> #define HOGE 123 >>> #define STR_I(x) #x >>> #define STR(x) STR_I(x) >>> STR(HOGE) <stdin>:1:1: STR(HOGE) <stdin>:1:9: see macro definition: STR(x) invoked with [ x = HOGE ] [ <stdin>:1:9: see macro definition: HOGE [ 123 rescanning [ 123 ] ] STR_I(123) rescanning [ <stdin>:1:9: see macro definition: STR_I(x) invoked with [ x = 123 ] [ "123" rescanning [ "123" ] ] "123" ] ] "123" >>> ^Z C:\Boost>
「-t」はトレース結果の出力先を指定するオプションで、「-t -」なら標準エラー出力に出力します。
「#pragma wave trace(enable)」でトレースがオンになって、マクロ展開のトレース出力が得られます。
また、「-x」を付けると、pragmaでコマンド置換ができます。
C:\Boost>wave.exe -x Wave: A Standard conformant C++ preprocessor based on the Boost.Wave library Version: 2.0.3.2938 [Win32/Microsoft Visual C++ version 9.0] (20090602) >>> #pragma wave system(dir /B) #line 1 "<stdin>" s8nc s8nc .1 >>> ^Z
シェルっぽいですね。
なお、見えているファイル名はコマンド実行時のリダイレクトに使われる一時ファイルです。
そのままだと権限がなくて一時ファイルを作成できず、以下のように修正した影響です。
Index: trace_macro_expansion.hpp =================================================================== --- trace_macro_expansion.hpp (リビジョン 57536) +++ trace_macro_expansion.hpp (作業コピー) @@ -1091,6 +1091,10 @@ string_type stdout_file(std::tmpnam(0)); string_type stderr_file(std::tmpnam(0)); +#if defined(_MSC_VER) + if (stdout_file[0] == '\\') stdout_file.erase(stdout_file.begin()); + if (stderr_file[0] == '\\') stderr_file.erase(stderr_file.begin()); +#endif string_type system_str(boost::wave::util::impl::as_string(values)); string_type native_cmd(system_str);
VC9のtmpnam()が「\s8nc.1」みたいな文字列を返すのですが、「\」で始まるのに「カレントディレクトリ」の意味らしいので、頭を削っています。