File: clang_format_wrapper.sh

package info (click to toggle)
cp2k 2025.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 372,052 kB
  • sloc: fortran: 963,262; ansic: 64,495; f90: 21,676; python: 14,419; sh: 11,382; xml: 2,173; makefile: 953; pascal: 845; perl: 492; cpp: 345; lisp: 297; csh: 16
file content (27 lines) | stat: -rwxr-xr-x 819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/bash

# author: Ole Schuett

if (($# != 1)); then
  echo "Usage: clang_format_wrapper.sh <file>"
  exit 1
fi

# For some files the clang-format requires too much memory. As a work-around we
# use the "clang-format off" marker to disable formatting. To actually reduce
# the memory usage this script hides the offending sections from clang-format.

# Look for "clang-format off" markers to split the file into sections.
if csplit --quiet --prefix="section" "$1" "/clang-format off/"; then
  # Format only the first section, ie. the one before "clang-format off".
  clang-format --style=llvm -i section00
  # Join all sections back together.
  cat section* > "$1"
  # Remove intermediary files.
  rm section*
else
  # No markers found, just call clang-format directly.
  clang-format --style=llvm -i "$1"
fi

#EOF