Commit 1b36142d authored by Arnaud Blanchard's avatar Arnaud Blanchard

Improvement of the parsing system

parent 5a29d86e
......@@ -85,7 +85,7 @@ blaar_add_parameter(){
local index=$blaar_parameters_nb
blaar_parameters_variable[$index]="$1"
blaar_parameters_prompt[$index]="$2"
blaar_parameters_name[$index]="$2"
blaar_parameters_required[$index]="$3"
blaar_parameters_help[$index]="$4"
......@@ -102,25 +102,68 @@ blaar_add_parameter(){
blaar_display_help(){
echo
[ $# = 0 ] || { echo "You should not have argument but you have '$*'"; exit 1; }
echo "usage: $(basename $0)"
printf "usage: $(basename $0)"
for ((i = 0; i < $blaar_options_nb; i++))
do
printf " [-${blaar_options_letter[$i]} ${blaar_options_parameter[$i]}]"
done
for ((i = 0; i < $blaar_parameters_nb; i++))
do
if (( ${blaar_parameters_required[$i]} > 0 ))
then
for ((j = 0; j<${blaar_parameters_required[$i]}; j++ ))
do
printf " ${blaar_parameters_name[$i]}"
done
elif (( ${blaar_parameters_required[$i]} == 0 ))
then
printf " [ ${blaar_parameters_name[$i]} ]"
else
printf " [ ${blaar_parameters_name[$i]} ...]"
fi
done
echo
echo
echo $blaar_program_desciption
echo
echo "optional arguments:"
for ((i = 0; i < $blaar_options_nb; i++))
do
echo
if (( $blaar_parameters_nb != 0))
then
echo "positional arguments:"
for ((i = 0; i < $blaar_parameters_nb; i++))
do
if (( ${blaar_parameters_required[$i]} > 0 ))
then
for ((j = 0; j<${blaar_parameters_required[$i]}; j++ ))
do
echo " ${blaar_parameters_name[$i]} ${blaar_parameters_help[$i]} "
done
elif (( ${blaar_parameters_required[$i]} == 0 ))
then
echo " [ ${blaar_parameters_name[$i]} ] ${blaar_parameters_help[$i]}"
else
echo " [ ${blaar_parameters_name[$i]} ...] ${blaar_parameters_help[$i]}"
fi
done
fi
echo
if (( $blaar_options_nb != 0 ))
then
echo "optional arguments:"
for ((i = 0; i < $blaar_options_nb; i++))
do
if [ ${blaar_options_default[$i]} ]; then
default="(default: ${blaar_options_default[$i]})"
else
default=""
fi
echo " -${blaar_options_letter[$i]} ${blaar_options_parameter[$i]} :${blaar_options_help[$i]} $default"
done
default="(default: ${blaar_options_default[$i]})"
else
default=""
fi
echo " -${blaar_options_letter[$i]} ${blaar_options_parameter[$i]} ${blaar_options_help[$i]} $default"
done
fi
}
#
blaar_parse_args(){
#We say we need all default velue to remove them after when we read values
for ((i = 0; i < $blaar_options_nb; i++))
......@@ -174,7 +217,7 @@ if [ -n "${default_needed_indexes:-}" ]; then
do
if (( ${blaar_parameters_required[$i]} > $# ))
then
[ -t 0 ] &&echo "${blaar_parameters_prompt[$i]} ?"
[ -t 0 ] &&echo "${blaar_parameters_name[$i]} ${blaar_parameters_help[$i]} ?"
read ${blaar_parameters_variable[$i]}
export ${blaar_parameters_variable[$i]}
else
......
source blaar.sh
blaar_init_options "Apply a f_filter on black and white camera and display it"
blaar_add_option direction d "" "string" "direction of the gradient (x, y)"
blaar_init_options "Apply a gradient on input grey image"
blaar_add_option direction d "" "x|y" "direction of the gradient"
blaar_add_option gain g "" "real" "gain" "1"
blaar_add_option output o "" "blc_channel-out" "convolution output" :grad$$
blaar_add_option output o "" "blc_channel-out" "convolution output" ":grad<pid>"
blaar_add_option size s "" "(integer)x(interger)" "size of the filter" "3x3"
blaar_add_option sigma S "" "real" "sigma of the filter" -1
blaar_add_option profile p "" "filename" "profile the script" ""
blaar_add_parameter image "blc_channel-in" "1" "image you want to apply the gradient on"
blaar_add_parameter image "blc_channel-in" "1" "input image"
blaar_parse_args "$@"
[ "$direction" = "x" ] && option="-x1" || { [ "$direction" = "y" ] && option="-y1"; } || { echo "Wrong direction option '$direction'"; exit 1; }
......
......@@ -24,6 +24,7 @@ blaar_add_option device D "" "device_name" "device to use for the speaker"
blaar_add_option filename f "" "filename" "file to save the sound to"
blaar_add_option size s "" "integer" "number of items per buffer" "4096"
blaar_add_option samplerate S "" "integer" "samplerate of the sound export" "44100"
blaar_add_parameter sound "blc_channel-in" "sound todiffuse"
blaar_parse_args "$@"
[ $filename ] && file_option="-f=$filename" || file_option=""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment