Split apart large function into multiple parts.

This commit is contained in:
jakeg00dwin 2024-03-09 12:16:31 -08:00
parent e26db1673a
commit 9d619fc16f
1 changed files with 39 additions and 25 deletions

64
otto.sh
View File

@ -3,6 +3,7 @@
# Date: 2024
# Filename: otto.sh
USERNAME="Jake G"
CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake"
CMAKE_VERBOSE="ON"
CROSS_COMPILE=1
@ -85,6 +86,40 @@ git_remove_module () {
git rm -r ./tests/CMakeLists.txt
}
add_new_source_files () {
local modname="$1"
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
modsrc_dir="./src/${modname}"
mkdir $modsrc_dir
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c |
sed "3s/todays_date/$(date +%Y)/" |
sed "s/username/${USERNAME}/" > $modsrc_dir/${modname}.c
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h |
sed "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h |
sed "s/username/${USERNAME}/" > $modsrc_dir/${modname}.h
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
}
add_new_test_files () {
local modname="$1"
modtest_dir="./tests/${modname}"
mkdir $modtest_dir
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.c
sed "3s/todays_date/$(date +%Y)/" |
sed "s/username/${USERNAME}/" > $modsrc_dir/test_${modname}.c
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
}
add_new_module () {
read -p "Enter the name of the module:" modname
@ -96,40 +131,19 @@ add_new_module () {
echo "Exiting without changing anything"
exit
fi
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
modsrc_dir="./src/${modname}"
modtest_dir="./tests/${modname}"
echo "creating: ${modsrc_dir}, ${modtest_dir}"
mkdir $modsrc_dir
mkdir $modtest_dir
#copy the template files.
echo "copying & customizing template files..."
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
sed "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c > $modsrc_dir/${modname}.c
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
sed "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h > $modsrc_dir/${modname}.h
sed "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.c > $modtest_dir/test_${modname}.c
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
add_new_source_files "$modname"
add_new_test_files "$modname"
# Add the module to the cmake lists files.
# Add the module to the cmake lists files in /src/ and /tests/
add_module_to_cmakes "${modname}"
echo "Resulting files/dirs:"
tree -L 2 $modsrc_dir
tree -L 2 $modtest_dir
# Now we add the new files to the git tracked files
git_add_module "${modname}"
}