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

62
otto.sh
View File

@ -3,6 +3,7 @@
# Date: 2024 # Date: 2024
# Filename: otto.sh # Filename: otto.sh
USERNAME="Jake G"
CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake" CROSS_TC_WIN="$(pwd)/i686-w64-mingw32_toolchain.cmake"
CMAKE_VERBOSE="ON" CMAKE_VERBOSE="ON"
CROSS_COMPILE=1 CROSS_COMPILE=1
@ -85,6 +86,40 @@ git_remove_module () {
git rm -r ./tests/CMakeLists.txt 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 () { add_new_module () {
read -p "Enter the name of the module:" modname read -p "Enter the name of the module:" modname
@ -97,39 +132,18 @@ add_new_module () {
exit exit
fi 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. #copy the template files.
echo "copying & customizing template files..." echo "copying & customizing template files..."
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c add_new_source_files "$modname"
sed "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c > $modsrc_dir/${modname}.c add_new_test_files "$modname"
sed "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h # Add the module to the cmake lists files in /src/ and /tests/
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 the module to the cmake lists files.
add_module_to_cmakes "${modname}" 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 # Now we add the new files to the git tracked files
git_add_module "${modname}" git_add_module "${modname}"
} }