File: regen-defs.zsh

package info (click to toggle)
cpplint 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,356 kB
  • sloc: cpp: 13,681; python: 10,095; ansic: 854; sh: 30; makefile: 18
file content (48 lines) | stat: -rwxr-xr-x 1,149 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/zsh

# Input the path of cpplint here
cpplint="$HOME/Documents/cpplint/cpplint.py"

cd samples/ || exit 74  # EX_IOERROR

# Loop through all .def files in the given directories
folders=(${(f)"$(cat)"})
for folder in $folders; do
  cd "$folder-sample/" || exit 66  # EX_NOINPUT
  for file in ./*.def; do
    if [[ ! -s "$file" ]]; then
      echo "Skipping empty file: $file"
      continue
    fi
    echo "Processing $file..."

    # Extract the command from the first line of the file
    cmd=$(head -n 1 "$file")

    # Create temporary files for stdout and stderr
    stdout_file=$(mktemp)
    stderr_file=$(mktemp)

    # Execute the command and capture stdout and stderr
    uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
    ret_code=$?

    # Count the number of lines in stdout
    (( num_lines=$(wc -l < "$stdout_file") + 1 ))

    # Overwrite the original definition file
    {
      echo "$cmd"
      echo "$ret_code"
      echo "$num_lines"
      cat "$stdout_file"
      echo
      cat "$stderr_file"
      echo
    } > "$file"

    # Clean up temporary files
    rm "$stdout_file" "$stderr_file"
  done
  cd ..
done