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_CPP=0
WITH_BASH=0 WITH_BASH=0
WITH_PYTHON=0 WITH_PYTHON=0
WITH_CMAKE=0
TARGET_DIR="." TARGET_DIR="."
usage() { usage() {
@@ -19,6 +20,7 @@ Optionen:
--cpp Zusätzlich auch C++-Dateien verarbeiten --cpp Zusätzlich auch C++-Dateien verarbeiten
--bash Zusätzlich auch Bash-Skripte (*.sh) verarbeiten --bash Zusätzlich auch Bash-Skripte (*.sh) verarbeiten
--python Zusätzlich auch Python-Skripte (*.py) verarbeiten --python Zusätzlich auch Python-Skripte (*.py) verarbeiten
--cmake Zusätzlich auch CMake-Skripte (*.cmake) verarbeiten
-h, --help Hilfe anzeigen -h, --help Hilfe anzeigen
Argumente: Argumente:
@@ -31,6 +33,7 @@ Beispiele:
./strip_c_comments_safe.sh --cpp src ./strip_c_comments_safe.sh --cpp src
./strip_c_comments_safe.sh --bash scripts ./strip_c_comments_safe.sh --bash scripts
./strip_c_comments_safe.sh --python tools ./strip_c_comments_safe.sh --python tools
./strip_c_comments_safe.sh --cmake cmake
./strip_c_comments_safe.sh --cpp --backup-ext .orig ./project ./strip_c_comments_safe.sh --cpp --backup-ext .orig ./project
EOF EOF
} }
@@ -61,6 +64,10 @@ while [[ $# -gt 0 ]]; do
WITH_PYTHON=1 WITH_PYTHON=1
shift shift
;; ;;
--cmake)
WITH_CMAKE=1
shift
;;
-h|--help) -h|--help)
usage usage
exit 0 exit 0
@@ -397,6 +404,9 @@ detect_mode() {
*.py) *.py)
echo "python" echo "python"
;; ;;
*.cmake)
echo "bash"
;;
*) *)
echo "" echo ""
;; ;;
@@ -418,6 +428,10 @@ if [[ "$WITH_PYTHON" -eq 1 ]]; then
find_expr+=( -o -name "*.py" ) find_expr+=( -o -name "*.py" )
fi fi
if [[ "$WITH_CMAKE" -eq 1 ]]; then
find_expr+=( -o -name "*.cmake" )
fi
find "$TARGET_DIR" -type f \( "${find_expr[@]}" \) -print0 | find "$TARGET_DIR" -type f \( "${find_expr[@]}" \) -print0 |
while IFS= read -r -d '' file; do while IFS= read -r -d '' file; do
mode="$(detect_mode "$file")" mode="$(detect_mode "$file")"