timo_moulinette now working quite reliably
This commit is contained in:
parent
66506ce53c
commit
75df19a76f
43
.bashrc
43
.bashrc
|
@ -89,6 +89,10 @@ check () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
safe_guard_name () {
|
||||||
|
printf '%s' "${1}" | tr \\'!@#$%^&*()_+~{}|:">[]?<, ./;=\t\-'\'\` '__________________________________'
|
||||||
|
}
|
||||||
|
|
||||||
timo_moulinette () {
|
timo_moulinette () {
|
||||||
# Set params
|
# Set params
|
||||||
subject="${1}"
|
subject="${1}"
|
||||||
|
@ -144,23 +148,56 @@ timo_moulinette () {
|
||||||
${CC} -dD -E -o "${file_name}.nocomments" -- "${file_name}"
|
${CC} -dD -E -o "${file_name}.nocomments" -- "${file_name}"
|
||||||
|
|
||||||
# Extract function definitions from preprocessed file and append semicolon
|
# Extract function definitions from preprocessed file and append semicolon
|
||||||
prototypes="$(cat -- "${file_name}.nocomments" | grep -v '#' | grep ')$' | grep '[a-zA-Z0-9](' | sed 's/$/;/')"
|
prototypes="$(cat -- "${file_name}.nocomments" | grep -v '#' | grep ')$' | grep '[a-zA-Z0-9](' | grep -v 'int[[:space:]]\+main(' | sed 's/$/;/')"
|
||||||
|
|
||||||
|
# Extract macros from file (ignore the ones with line continuations)
|
||||||
|
macros="$(cat -- "${file_name}" | grep '^#' | grep -v '\\$')"
|
||||||
|
|
||||||
# Remove preprocessed file
|
# Remove preprocessed file
|
||||||
rm -f -- "${file_name}.nocomments"
|
rm -f -- "${file_name}.nocomments"
|
||||||
|
|
||||||
# Write prototypes to beginning of testfile
|
# Write prototypes to beginning of testfile
|
||||||
IFS="$(printf '\n')"
|
IFS="
|
||||||
for proto in "${prototypes}"; do
|
"
|
||||||
|
for proto in ${prototypes}; do
|
||||||
printf '%s\n' "${proto}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
printf '%s\n' "${proto}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Write macros to beginning of testfile
|
||||||
|
IFS="
|
||||||
|
"
|
||||||
|
for macro in ${macros}; do
|
||||||
|
guard_name="$(safe_guard_name "${macro}")"
|
||||||
|
|
||||||
|
# Endif include guard
|
||||||
|
printf '%s\n' "#endif" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
|
|
||||||
|
# The macro itself
|
||||||
|
printf '%s\n' "${macro}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
|
|
||||||
|
# Define include guard
|
||||||
|
printf '%s\n' "# define ${guard_name}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
|
|
||||||
|
# Include guard
|
||||||
|
printf '%s\n' "#ifndef ${guard_name}" | cat -- - "${download_file_name}" > ".tmpaddfirstlinefile.c"
|
||||||
|
mv -- ".tmpaddfirstlinefile.c" "${download_file_name}"
|
||||||
|
done
|
||||||
IFS="$(printf ' \n\t')"
|
IFS="$(printf ' \n\t')"
|
||||||
|
|
||||||
# Compile
|
# Compile
|
||||||
out_binary="timo_moulinette_${subject}_${ex}_$(basename -- "${test_file_name}" .c).out"
|
out_binary="timo_moulinette_${subject}_${ex}_$(basename -- "${test_file_name}" .c).out"
|
||||||
${CC} -Wall -Wextra -Werror -o "${out_binary}" -xc -- *.c
|
${CC} -Wall -Wextra -Werror -o "${out_binary}" -xc -- *.c
|
||||||
|
err_code="${?}"
|
||||||
|
|
||||||
|
if [ ! "${err_code}" = 0 ]; then
|
||||||
|
printf '%s\n' "Could not compile. Exiting"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete testfile
|
# Delete testfile
|
||||||
rm -f -- "${download_file_name}"
|
rm -f -- "${download_file_name}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue