Simplify boolean flag handling

This commit is contained in:
Bob Polis 2025-02-28 09:28:26 +01:00
parent 63d2a2d0e2
commit 7fa2dce9e5

View File

@ -2,12 +2,12 @@
config=$HOME/.config/mkprojrc
source $config
default=0
default=false
mainfile=main.cpp
gitfav=0
library=0
simple=0
usegitroot=0
gitfav=false
library=false
simple=false
usegitroot=false
usage() {
echo "usage: $progname [-f|-l|-n|-s] [[-d] -g <gitroot>|-G] [-t <tplroot>] PROJECTNAME" >&2
@ -34,28 +34,28 @@ while getopts :dfGg:lnst:v opt
do
case $opt in
d)
default=1
default=true
;;
f)
mainfile=filter.cpp
;;
G)
gitfav=1
gitfav=true
;;
g)
gitroot=$OPTARG
usegitroot=1
usegitroot=true
;;
l)
library=1
library=true
;;
n)
mainfile=main.cpp
library=0
simple=0
library=false
simple=false
;;
s)
simple=1
simple=true
;;
t)
tplroot=$OPTARG
@ -83,7 +83,7 @@ shift $(( OPTIND - 1 ))
proj=${1//[- ]/_} # replace all spaces and dashes with underscores
if [ $default = 1 ]
if $default
then
check_gitroot
if grep -q gitroot $config
@ -94,7 +94,7 @@ then
fi
fi
if [ $gitfav = 1 ] || [ $usegitroot = 1 ]
if $gitfav || $usegitroot
then
check_gitroot
git clone "$gitroot/$proj.git" || die "not an existing repo: $proj"
@ -102,7 +102,7 @@ else
mkdir -p "$proj"
fi
if [ $simple = 1 ]
if $simple
then
cp $tplroot/Makefile.simple $proj/Makefile
cp $tplroot/main.simple.cpp $proj/$proj.cpp
@ -115,7 +115,7 @@ else
sed -e "s/{PROJECT}/$proj/" -e "s/{PROJ}/$uproj/" $tplroot/version.hpp > $proj/src/version.hpp
sed -e "s/{PROJECT}/$proj/" $tplroot/version.cpp > $proj/src/version.cpp
if [ $library = 1 ]
if $library
then
mkdir -p $proj/man/man3
sed -e "s/{PROJECT}/$proj/" $tplroot/lib.3 > $proj/man/man3/$proj.3