Debian Codegraph @

regen-defs.zsh

raw symbols SCIP
1 #!/bin/zsh
2
3 # Input the path of cpplint here
4 cpplint="$HOME/Documents/cpplint/cpplint.py"
5
6 cd samples/ || exit 74 # EX_IOERROR
7
8 # Loop through all .def files in the given directories
9 folders=(${(f)"$(cat)"})
10 for folder in $folders; do
11 cd "$folder-sample/" || exit 66 # EX_NOINPUT
12 for file in ./*.def; do
13 if [[ ! -s "$file" ]]; then
14 echo "Skipping empty file: $file"
15 continue
16 fi
17 echo "Processing $file..."
18
19 # Extract the command from the first line of the file
20 cmd=$(head -n 1 "$file")
21
22 # Create temporary files for stdout and stderr
23 stdout_file=$(mktemp)
24 stderr_file=$(mktemp)
25
26 # Execute the command and capture stdout and stderr
27 uv run "$cpplint" $cmd > "$stdout_file" 2> "$stderr_file"
28 ret_code=$?
29
30 # Count the number of lines in stdout
31 (( num_lines=$(wc -l < "$stdout_file") + 1 ))
32
33 # Overwrite the original definition file
34 {
35 echo "$cmd"
36 echo "$ret_code"
37 echo "$num_lines"
38 cat "$stdout_file"
39 echo
40 cat "$stderr_file"
41 echo
42 } > "$file"
43
44 # Clean up temporary files
45 rm "$stdout_file" "$stderr_file"
46 done
47 cd ..
48 done