Merge pull request #1 from IghuToh0/copilot/strip-c-comments-cmake

strip_c_comments_safe.sh: add --cmake option for *.cmake files
This commit is contained in:
Torsten Wierschin authored and GitHub committed 2026-07-14 11:47:13 +02:00
commit 98744b340b
1 file changed
+14
+14
View File
@@ -6,6 +6,7 @@ DRY_RUN=0
WITH_CPP=0
WITH_BASH=0
WITH_PYTHON=0
WITH_CMAKE=0
TARGET_DIR="."
usage() {
@@ -19,6 +20,7 @@ Optionen:
--cpp Zusätzlich auch C++-Dateien verarbeiten
--bash Zusätzlich auch Bash-Skripte (*.sh) verarbeiten
--python Zusätzlich auch Python-Skripte (*.py) verarbeiten
--cmake Zusätzlich auch CMake-Skripte (*.cmake) verarbeiten
-h, --help Hilfe anzeigen
Argumente:
@@ -31,6 +33,7 @@ Beispiele:
./strip_c_comments_safe.sh --cpp src
./strip_c_comments_safe.sh --bash scripts
./strip_c_comments_safe.sh --python tools
./strip_c_comments_safe.sh --cmake cmake
./strip_c_comments_safe.sh --cpp --backup-ext .orig ./project
EOF
}
@@ -61,6 +64,10 @@ while [[ $# -gt 0 ]]; do
WITH_PYTHON=1
shift
;;
--cmake)
WITH_CMAKE=1
shift
;;
-h|--help)
usage
exit 0
@@ -397,6 +404,9 @@ detect_mode() {
*.py)
echo "python"
;;
*.cmake)
echo "bash"
;;
*)
echo ""
;;
@@ -418,6 +428,10 @@ if [[ "$WITH_PYTHON" -eq 1 ]]; then
find_expr+=( -o -name "*.py" )
fi
if [[ "$WITH_CMAKE" -eq 1 ]]; then
find_expr+=( -o -name "*.cmake" )
fi
find "$TARGET_DIR" -type f \( "${find_expr[@]}" \) -print0 |
while IFS= read -r -d '' file; do
mode="$(detect_mode "$file")"