44 lines
1.7 KiB
Bash
Executable File
44 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
wd="/nfs/homes/tischmid/repos/piscine"
|
|
if [ ! "$(pwd)" = "${wd}" ]; then
|
|
echo "# Your current working directory is:"
|
|
pwd
|
|
echo "# But you must be in:"
|
|
echo "${wd}"
|
|
fi
|
|
|
|
out_dir="./timoulinette"
|
|
count="0"
|
|
|
|
for file in $(find . | grep -v .git | grep '^\./c[[:digit:]][[:digit:]].*.c$'); do
|
|
comment_start="$(( $(grep -n -m 1 '////' "${file}" | cut -f1 -d:) + 1))" || { echo "Could not extract comment start. Exiting"; exit 1; }
|
|
comment_end="$(( $(grep -n -m 2 '////' "${file}" | tail -n1 | cut -f1 -d:) - 1))" || { echo "Could not extract comment end. Exiting"; exit 2; }
|
|
|
|
if [ "${comment_start}" -lt 1 ]; then
|
|
echo "Comment start ${comment_start} is smaller than 1. Exiting"
|
|
continue
|
|
elif [ "${comment_end}" -lt 1 ]; then
|
|
echo "Comment start ${comment_end} is smaller than 1. Exiting"
|
|
continue
|
|
elif [ "${comment_end}" -le "${comment_start}" ]; then
|
|
echo "Comment start ${comment_end} is smaller than or equal to comment end ${comment_start}. Exiting"
|
|
continue
|
|
elif [ "$(( ${comment_end} + 2 ))" -eq "${comment_start}" ]; then
|
|
echo "Comment start ${comment_end} is 2 less than comment start ${comment_start}, which is probably an error. Exiting"
|
|
continue
|
|
fi
|
|
|
|
out_dirpath="${out_dir}/$(dirname "${file}")"
|
|
out_filepath="${out_dir}/$(echo "${file}" | sed 's/\.c$/_test.c/g')"
|
|
mkdir -p "${out_dirpath}" || { echo "Could not create dir ${out_filepath}. Exiting"; exit 3; }
|
|
sed -n "${comment_start},${comment_end}p" "${file}" > "${out_filepath}.tmp"
|
|
diff "${out_filepath}.tmp" "${out_filepath}" >/dev/null
|
|
if [ ! "${?}" = "0" ]; then
|
|
count="$((count + 1))"
|
|
fi
|
|
mv "${out_filepath}.tmp" "${out_filepath}"
|
|
done
|
|
|
|
printf '\033[32m%s\033[m\n' "Done, changed ${count} files"
|