#!/bin/env bash # Usage: ./Cleanup [FILE]... lint_file() { cppcheck --enable=all --quiet "$1" } whitespace_cleanup() { sed -i 's/[ \t]*$//' "$1" awk 'BEGIN{ORS=""} {print $0 "\n"} END{}' "$1" > "$1.tmp" && mv "$1.tmp" "$1" } comment_check() { if grep -n -E 'TODO|FIXME' "$1"; then echo "[WARN] $1 contains TODO/FIXME comments." fi } process_file() { clang-format -i "$1" tools/check_header_footer "$1" lint_file "$1" whitespace_cleanup "$1" comment_check "$1" } if [[ $# -gt 0 ]]; then for file in "$@"; do process_file "$file" done else for file in $(find yait core -type f \( -name "*.c" -o -name "*.h" \)); do process_file "$file" done fi