Last active
September 4, 2025 03:56
-
-
Save ImreSamu/834267246d2983c57c1ef10a4bcebf62 to your computer and use it in GitHub Desktop.
check and fix orioledb headers: https://github.com/orioledb/orioledb/pull/550
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Usage: | |
| # ./check-headers.sh [--fix] [rootdir] | |
| # Examples: | |
| # ./check-headers.sh | |
| # ./check-headers.sh --fix . | |
| # ./check-headers.sh --fix path/to/repo | |
| fix=0 | |
| if [ "${1:-}" = "--fix" ]; then | |
| fix=1 | |
| shift | |
| fi | |
| root="${1:-.}" | |
| bad=0 | |
| # Find all .c and .h files | |
| find "$root" -type f \( -name '*.c' -o -name '*.h' \) -print0 | | |
| while IFS= read -r -d '' f; do | |
| fn="$(basename "$f")" | |
| expected_ident="contrib/orioledb/${f#./}" | |
| # --------------------------- | |
| # Check 3rd line: filename | |
| # --------------------------- | |
| line3="$(sed -n '3p' "$f" || true)" | |
| # Normalize to compare (strip leading "* " and trailing ws) | |
| hdr_core="$(printf '%s' "$line3" | sed -E 's/^[[:space:]]*\*[[:space:]]*//; s/[[:space:]]+$//')" | |
| if [ "$hdr_core" != "$fn" ]; then | |
| if [ $fix -eq 1 ]; then | |
| # Replace ONLY the filename token, preserve indentation (" *", tabs/spaces) and any trailing text/ws | |
| # Pattern: ^(indent+*) (filename-token) (tail) | |
| if sed -i -E "3{s|^([[:space:]]*\*[[:space:]]*)([^[:space:]]+)(.*)$|\1$fn\3|}" "$f"; then | |
| echo "FIXED [HEADER]: $f" | |
| else | |
| echo "FAILED [HEADER]: $f" | |
| bad=1 | |
| fi | |
| else | |
| printf '%s: [HEADER] 3rd line is [%s], expected [%s]\n' "$f" "$hdr_core" "$fn" | |
| bad=1 | |
| fi | |
| fi | |
| # --------------------------------------- | |
| # Check IDENTIFICATION line + next line | |
| # --------------------------------------- | |
| ident_ln="$(awk '/^[[:space:]]*\*[[:space:]]*IDENTIFICATION[[:space:]]*$/{print NR; exit}' "$f" || true)" | |
| if [ -z "${ident_ln:-}" ]; then | |
| printf '%s: [IDENT] missing IDENTIFICATION line\n' "$f" | |
| bad=1 | |
| else | |
| next_ln=$((ident_ln + 1)) | |
| next_line="$(sed -n "${next_ln}p" "$f" || true)" | |
| # Normalize to compare (strip leading "* " and trailing ws) | |
| id_core="$(printf '%s' "$next_line" | sed -E 's/^[[:space:]]*\*[[:space:]]*//; s/[[:space:]]+$//')" | |
| if [ "$id_core" != "$expected_ident" ]; then | |
| if [ $fix -eq 1 ]; then | |
| # Replace ONLY the content after leading "* ...", keep indentation and trailing ws | |
| # Pattern: ^(indent+*) (any) (trailing ws) | |
| if sed -i -E "${next_ln}s|^([[:space:]]*\*[[:space:]]*)(.*?)([[:space:]]*)$|\1${expected_ident}\3|" "$f"; then | |
| echo "FIXED [IDENT]: $f" | |
| else | |
| echo "FAILED [IDENT]: $f" | |
| bad=1 | |
| fi | |
| else | |
| printf '%s: [IDENT] got [%s], expected [%s]\n' "$f" "$id_core" "$expected_ident" | |
| bad=1 | |
| fi | |
| fi | |
| fi | |
| done | |
| exit "$bad" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment