doxygen-colorize-output.sh は、Doxygen の出力メッセージに ANSI カラーコードを適用し、エラーとワーニングを視覚的に区別しやすくするフィルタースクリプトです。
doxygen-colorize-output.sh
実行可能 (chmod +x)
標準入力から受け取った各行を解析し、エラーまたはワーニングメッセージを検出して着色します。
| メッセージタイプ | 検出パターン | ANSI カラーコード | 表示色 |
|---|---|---|---|
| エラー | error: |
\033[0;31m |
🔴 赤 |
| ワーニング | warning: |
\033[0;33m |
🟡 黄 |
| その他 | (該当なし) | (なし) | デフォルト |
RED='\033[0;31m'
YELLOW='\033[0;33m'
RESET='\033[0m'if [[ "$line" == *" error: "* ]]; then行内に error: (前後にスペースを含む) が含まれる場合にマッチします。
elif [[ "$line" == *" warning: "* ]]; then行内に warning: (前後にスペースを含む) が含まれる場合にマッチします。
スペースを含むパターンマッチングにより、以下のような誤検知を防止します。
show_error_flag, warning_countprint_error(), handle_warning()// This is an error exampledoxygen Doxyfile 2>&1 | ../doxyfw/doxygen-colorize-output.sh2>&1: stderr を stdout にリダイレクトして結合|: パイプでフィルタースクリプトに渡すdoxygen Doxyfile 2>&1 | ../doxyfw/doxygen-colorize-output.sh;
DOXYGEN_EXIT=${PIPESTATUS[0]};
exit $DOXYGEN_EXIT;PIPESTATUS[0] を使用して、パイプの最初のコマンド (doxygen) の終了コードを取得し、ビルドの成否を正しく判定します。
/path/to/file.c:42: warning: undocumented parameter 'foo'
/path/to/file.c:100: error: invalid syntax
Normal output line
(ターミナルでは以下のように表示されます)
/path/to/file.c:42: warning: undocumented parameter ‘foo’
/path/to/file.c:100: error: invalid syntax
Normal output line
Windows コマンドプロンプトなど、ANSI カラーコードに対応していないターミナルでは、エスケープシーケンスがそのまま表示される可能性があります。
ANSI カラーコードを含む出力をファイルにリダイレクトすると、エスケープシーケンスがそのまま記録されます。
ログファイルに保存する場合は、以下のいずれかの方法を推奨します。
WARN_LOGFILE 設定を使用して Doxygen が直接ログファイルに出力以下のコマンドでスクリプト単体のテストが可能です。
cat <<'EOF' | doxygen-colorize-output.sh
Normal output line
/path/to/file.c:42: warning: undocumented parameter 'foo'
Another normal line
/path/to/file.c:100: error: invalid syntax
More normal output
EOF期待される結果: warning 行が黄色、error 行が赤色で表示されます。
makefile: 本スクリプトを doxygen 実行時に適用Doxyfile: Doxygen の警告フォーマット設定 (WARN_FORMAT)docs-src/doxygen-colored-output-research.md: 調査結果と背景情報