From 92af14c2faf527f15469e4c804e2d4ecc3f8b302 Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Sun, 7 Jan 2024 10:59:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Script/parse_arg_lib | 68 +++++++++++++++++++++++++++------------------------- Script/pdf2video | 25 +------------------ Script/txt2mp3 | 25 +------------------ 3 files changed, 38 insertions(+), 80 deletions(-) diff --git a/Script/parse_arg_lib b/Script/parse_arg_lib index dc4e8d9..7aefba9 100755 --- a/Script/parse_arg_lib +++ b/Script/parse_arg_lib @@ -39,58 +39,37 @@ function ProcessParams { IFS=$SAVE_IFS } +param_var='local small_cmd="$1";local large_cmd="$2";local comment="$3";local use_param="$4";local default="$5";local custom_cmd="$6";local custom_arg1="$7";local custom_arg2="$8";' + function Params2InitVar { - local small_cmd="$1" - local large_cmd="$2" - local comment="$3" - local use_param="$4" - local default="$5" - local custom_cmd="$6" + eval "$param_var" + if [ "$use_param" != '' ]; then eval "${large_cmd}=${default}" fi } function Params2Help { - local small_cmd="$1" - local large_cmd="$2" - local comment="$3" - local use_param="$4" - local default="$5" - local custom_cmd="$6" + eval "$param_var" + echo "-${small_cmd}, -${large_cmd}, --${large_cmd}" echo " ${comment/"!DEFAULT!"/"${!large_cmd}"}" } function Params2small_list { - local small_cmd="$1" - local large_cmd="$2" - local comment="$3" - local use_param="$4" - local default="$5" - local custom_cmd="$6" + eval "$param_var" + echo -n "${small_cmd}${use_param}" } function Params2large_list { - local small_cmd="$1" - local large_cmd="$2" - local comment="$3" - local use_param="$4" - local default="$5" - local custom_cmd="$6" + eval "$param_var" + echo -n ",${large_cmd}${use_param}" } function Params2Case { - local small_cmd="$1" - local large_cmd="$2" - local comment="$3" - local use_param="$4" - local default="$5" - local custom_cmd="$6" - local custom_arg1="$7" - local custom_arg2="$8" + eval "$param_var" if [ "$custom_arg1" = "-${small_cmd}" ] || [ "$custom_arg1" = "-${large_cmd}" ] || [ "$custom_arg1" = "--${large_cmd}" ]; then clear_custom_cmd="${custom_cmd//[$'\t\r\n ']/}" @@ -102,3 +81,28 @@ function Params2Case { fi } +# Инициализация переменных +ProcessParams all_params Params2InitVar + +# $@ is all command line parameters passed to the script. +# -o is for short options like -v +# -l is for long options with double dash like --version +# the comma separates different long options +# -a is for long options with single dash like -version +# Example +# 'h' is a no-value option. +# 'v:' implies that option -v has value and is a mandatory option. ':' means has a value. +# 't::' implies that option -t has value but is optional. '::' means optional. +small_params_list=$(ProcessParams all_params Params2small_list) +small_params_list="${small_params_list:1}" + +large_params_list=$(ProcessParams all_params Params2large_list) +large_params_list="${large_params_list:1}" + +options=$(getopt --long "$large_params_list" -o "$small_params_list" -a -- "$@") + +# set --: +# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters +# are set to the arguments, even if some of them begin with a ‘-’. +eval set -- "$options" + diff --git a/Script/pdf2video b/Script/pdf2video index 1e939c0..e28c9d5 100755 --- a/Script/pdf2video +++ b/Script/pdf2video @@ -55,9 +55,6 @@ function GetExec { eval "source $(GetExec "parse_arg_lib")" -# Инициализация переменных -ProcessParams all_params Params2InitVar - function ShowHelp() { cat << EOF Использование: pdf2video -i [-o ] [-hV] @@ -74,27 +71,7 @@ $(ProcessParams video_params Params2Help) EOF } -# $@ is all command line parameters passed to the script. -# -o is for short options like -v -# -l is for long options with double dash like --version -# the comma separates different long options -# -a is for long options with single dash like -version -# Example -# 'h' is a no-value option. -# 'v:' implies that option -v has value and is a mandatory option. ':' means has a value. -# 't::' implies that option -t has value but is optional. '::' means optional. -small_params_list=$(ProcessParams all_params Params2small_list) -small_params_list="${small_params_list:1}" - -large_params_list=$(ProcessParams all_params Params2large_list) -large_params_list="${large_params_list:1}" - -options=$(getopt --long "$large_params_list" -o "$small_params_list" -a -- "$@") - -# set --: -# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters -# are set to the arguments, even if some of them begin with a ‘-’. -eval set -- "$options" +# ------------------------------------------- while true do diff --git a/Script/txt2mp3 b/Script/txt2mp3 index ed13682..df0a468 100755 --- a/Script/txt2mp3 +++ b/Script/txt2mp3 @@ -44,9 +44,6 @@ function GetExec { eval "source $(GetExec "parse_arg_lib")" -# Инициализация переменных -ProcessParams all_params Params2InitVar - function ShowHelp() { cat << EOF Использование: pdf2mp3 -i [-o ] [-hV] @@ -60,27 +57,7 @@ $(ProcessParams sound_params Params2Help) EOF } -# $@ is all command line parameters passed to the script. -# -o is for short options like -v -# -l is for long options with double dash like --version -# the comma separates different long options -# -a is for long options with single dash like -version -# Example -# 'h' is a no-value option. -# 'v:' implies that option -v has value and is a mandatory option. ':' means has a value. -# 't::' implies that option -t has value but is optional. '::' means optional. -small_params_list=$(ProcessParams all_params Params2small_list) -small_params_list="${small_params_list:1}" - -large_params_list=$(ProcessParams all_params Params2large_list) -large_params_list="${large_params_list:1}" - -options=$(getopt --long "$large_params_list" -o "$small_params_list" -a -- "$@") - -# set --: -# If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters -# are set to the arguments, even if some of them begin with a ‘-’. -eval set -- "$options" +# ------------------------------------------- while true do