Skip to content

Commit

Permalink
src/winusb: Use FUNCNAME[1] and eliminate the need to pass the call…
Browse files Browse the repository at this point in the history
…er's name

Signed-off-by: 林博仁 <Buo.Ren.Lin@gmail.com>
  • Loading branch information
brlin-tw committed Jun 3, 2017
1 parent a827b42 commit 2a0ad97
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/winusb
Expand Up @@ -223,17 +223,15 @@ setup_traps(){
# Utility function to check if function parameters quantity is legal
# NOTE: non-static function parameter quantity(e.g. either 2 or 3) is not supported
util_check_function_parameters_quantity(){
if [ "${#}" -ne 3 ]; then
if [ "${#}" -ne 2 ]; then
printf --\
"%s: FATAL: Function requires %u parameters, but %u is given\n"\
"${FUNCNAME[0]}"\
3\
2\
"${#}"
exit 1
fi

# The name of the function, simply pass "${FUNCNAME[0]}" will do
local function_name="${1}"; shift
# The expected given quantity
local -i expected_parameter_quantity="${1}"; shift
# The actual given parameter quantity, simply pass "${#}" will do
Expand All @@ -242,7 +240,7 @@ util_check_function_parameters_quantity(){
if [ "${given_parameter_quantity}" -ne "${expected_parameter_quantity}" ]; then
printf --\
"%s: FATAL: Function requires %u parameters, but %u is given\n"\
"${function_name}"\
"${FUNCNAME[1]}"\
"${expected_parameter_quantity}"\
"${given_parameter_quantity}"\
1>&2
Expand Down Expand Up @@ -399,7 +397,7 @@ switch_terminal_text_color()

# Print message with color
echo_with_color(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 2 "${#}"
util_check_function_parameters_quantity 2 "${#}"
local -r message_color="${1}"; shift
local -r message_body="${1}"

Expand All @@ -417,7 +415,7 @@ echo_with_color(){
# $2: Target mountpoint
# $3: Exit reason
cleanup_mountpoints(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 3 "${#}"
util_check_function_parameters_quantity 3 "${#}"

set +o errexit # We need to clean up everything we can

Expand Down Expand Up @@ -490,7 +488,7 @@ hideNoErr(){

# Copy source_file to dest_file, overwrite file if dest_file exists
copy_file(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 3 "${#}"
util_check_function_parameters_quantity 3 "${#}"
source_file="$1"
dest_file="$2"
whole_current_size="$3"
Expand Down Expand Up @@ -526,7 +524,7 @@ copy_file(){
# $1: Source filesystem's mountpoint
# $2: Target filesystem's mountpoint
copy_filesystem_files(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 2 "${#}"
util_check_function_parameters_quantity 2 "${#}"

# FIXME: Why do we `pulse off` and on here?
pulse off
Expand Down Expand Up @@ -574,7 +572,7 @@ copy_filesystem_files(){
}

print_help(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 0 "${#}"
util_check_function_parameters_quantity 0 "${#}"

echo -e "${RUNTIME_EXECUTABLE_NAME} usage"
echo -e "Install a Windows ISO on an FAT partition and edit MBR of the device"
Expand All @@ -593,7 +591,7 @@ print_help(){
}; declare -fr print_help

process_commandline_parameters(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 0 "${#}"
util_check_function_parameters_quantity 0 "${#}"

if [ "${#RUNTIME_COMMANDLINE_PARAMETERS[@]}" -eq 0 ]; then
return 0
Expand Down Expand Up @@ -653,7 +651,7 @@ process_commandline_parameters(){
}; declare -fr process_commandline_parameters;

shift_array(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 1 "${#}"
util_check_function_parameters_quantity 1 "${#}"

local -n array_ref="${1}"

Expand All @@ -674,7 +672,7 @@ shift_array(){
}; declare -fr shift_array

trap_return(){
util_check_function_parameters_quantity "${FUNCNAME[0]}" 1 "${#}"
util_check_function_parameters_quantity 1 "${#}"

local returning_function="${1}"

Expand Down

0 comments on commit 2a0ad97

Please sign in to comment.