Skip to content

Commit

Permalink
Merge branch 'micro5k:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ale5000-git authored Oct 30, 2024
2 parents 7a385e7 + 1b20c66 commit 9d09655
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions tools/bits-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# shellcheck disable=SC3043 # In POSIX sh, local is undefined

SCRIPT_NAME='Bits info'
SCRIPT_VERSION='1.5.15'
SCRIPT_VERSION='1.5.17'

### CONFIGURATION ###

Expand Down Expand Up @@ -36,11 +36,6 @@ command 1> /dev/null 2>&1 -v 'local' || {
if command 1> /dev/null 2>&1 -v 'typeset'; then alias 'local'='typeset'; fi
}

### GLOBAL VARIABLES ###

POSIXLY_CORRECT='y'
export POSIXLY_CORRECT

### SCRIPT ###

convert_max_signed_int_to_bit()
Expand Down Expand Up @@ -79,8 +74,8 @@ convert_max_unsigned_int_to_bit()
'32767') printf '%s\n' "16-bit signed${bug_suffix}" ;;
'65535') printf '%s\n' "16-bit unsigned" ;;
'256446000') printf '%s\n' "32-bit BROKEN" ;;
'2147483647') printf '%s\n' "32-bit signed${bug_suffix}" ;; # Bugged unsigned 'printf' of awk (seen on some versions of Bash)
'2147483648') printf '%s\n' "32-bit signed + 1 (BusyBox unsigned bug)" ;; # Bugged unsigned 'printf' of awk (likely on BusyBox)
'2147483647') printf '%s\n' "32-bit signed${bug_suffix}" ;; # Bugged unsigned 'printf' of awk (seen on some versions of Bash)
'2147483648') printf '%s\n' "32-bit signed + 1 BB BUG" ;; # Bugged unsigned 'printf' of awk (likely on BusyBox)
'4294967295') printf '%s\n' "32-bit unsigned" ;;
'9223372036854775807') printf '%s\n' "64-bit signed${bug_suffix}" ;; # Bugged unsigned 'printf' (seen on Ksh93 / OSH)
'9223372036854775808') printf '%s\n' "64-bit signed + 1${bug_suffix}" ;; # Bugged unsigned 'printf' (seen on Ksh93)
Expand All @@ -104,7 +99,7 @@ convert_max_unsigned_int_to_bit()

warn_msg()
{
if test "${NO_COLOR:-0}" != 0; then
if test -n "${NO_COLOR-}"; then
printf 1>&2 '%s\n' "WARNING: ${1}"
elif test "${CI:-false}" = 'false'; then
printf 1>&2 '\033[0;33m\r%s\n\033[0m\r \r' "WARNING: ${1}"
Expand Down Expand Up @@ -180,8 +175,10 @@ detect_hex_dump_cmd()
{
if command 1> /dev/null 2>&1 -v 'xxd'; then
printf '%s\n' 'xxd'
elif command 1> /dev/null 2>&1 -v 'hexdump'; then
elif command 1> /dev/null 2>&1 -v 'hexdump' && test "$(printf ' ' | hexdump 2> /dev/null -e '/1 "%02x"' || :)" = '20'; then
printf '%s\n' 'hexdump'
elif command 1> /dev/null 2>&1 -v 'od'; then
printf '%s\n' 'od'
else
return 1
fi
Expand All @@ -191,9 +188,11 @@ detect_hex_dump_cmd()
dump_hex()
{
if test "${HEXDUMP_CMD:=$(detect_hex_dump_cmd || :)}" = 'xxd'; then
xxd -p -c "${3}" -s "${2}" -l "${3}" -- "${1}"
xxd -p -s "${2}" -c "${3}" -l "${3}" -- "${1}"
elif test "${HEXDUMP_CMD?}" = 'hexdump'; then
hexdump -v -e '/1 "%02x"' -s "${2}" -n "${3}" -- "${1}" && printf '\n'
elif test "${HEXDUMP_CMD?}" = 'od'; then
od -v -A 'n' -j "${2}" -N "${3}" -t 'x1' -- "${1}" | tr -d ' \n' && printf '\n'
else
return 1
fi
Expand Down Expand Up @@ -994,13 +993,19 @@ list_available_shells()

pause_if_needed()
{
# shellcheck disable=SC3028 # In POSIX sh, SHLVL is undefined
if test "${NO_PAUSE:-0}" = '0' && test "${CI:-false}" = 'false' && test "${TERM_PROGRAM:-unknown}" != 'vscode' && test "${SHLVL:-1}" = '1' && test -t 0 && test -t 1 && test -t 2; then
printf 1>&2 '\n\033[1;32m%s\033[0m' 'Press any key to exit... ' || :
# shellcheck disable=SC3045
IFS='' read 1> /dev/null 2>&1 -r -s -n 1 _ || IFS='' read 1>&2 -r _ || :
# shellcheck disable=SC3028 # Intended: In POSIX sh, SHLVL is undefined
if test "${NO_PAUSE:-0}" = '0' && test "${no_pause:-0}" = '0' && test "${CI:-false}" = 'false' && test "${TERM_PROGRAM:-unknown}" != 'vscode' && test "${SHLVL:-1}" = '1' && test -t 0 && test -t 1 && test -t 2; then
if test -n "${NO_COLOR-}"; then
printf 1>&2 '\n%s' 'Press any key to exit... ' || :
else
printf 1>&2 '\n\033[1;32m\r%s' 'Press any key to exit... ' || :
fi
# shellcheck disable=SC3045 # Intended: In POSIX sh, read -s / -n is undefined
IFS='' read 2> /dev/null 1>&2 -r -s -n 1 _ || IFS='' read 1>&2 -r _ || :
printf 1>&2 '\n' || :
test -n "${NO_COLOR-}" || printf 1>&2 '\033[0m\r \r' || :
fi
unset no_pause
return "${1}"
}

Expand Down Expand Up @@ -1303,24 +1308,27 @@ main()
printf '%s\n' "Bits of 'date -u' timestamp: ${date_u_bit}"
}

backup_posix="${POSIXLY_CORRECT-unset}"
POSIXLY_CORRECT='y'
export POSIXLY_CORRECT

unset PREFER_INCLUDED_UTILITIES
execute_script='true'
no_pause=0
STATUS=0

while test "${#}" -gt 0; do
case "${1}" in
-V | --version)
execute_script='false'
NO_PAUSE='1'
export NO_PAUSE
no_pause=1
printf '%s\n' "${SCRIPT_NAME} v${SCRIPT_VERSION}"
printf '%s\n' 'Copyright (c) 2024 ale5000'
printf '%s\n' 'License GPLv3+'
;;
-h | --help | '-?')
execute_script='false'
NO_PAUSE='1'
export NO_PAUSE
no_pause=1
printf '%s\n' "${SCRIPT_NAME} v${SCRIPT_VERSION}"

printf '\n%s\n\n' 'Coming soon...'
Expand Down Expand Up @@ -1353,14 +1361,12 @@ while test "${#}" -gt 0; do
export ASH_STANDALONE
;;
--no-pause)
NO_PAUSE='1'
export NO_PAUSE
no_pause=1
;;

-l | --list-available-shells)
execute_script='false'
NO_PAUSE='1'
export NO_PAUSE
no_pause=1
list_available_shells || STATUS="${?}"
;;

Expand Down Expand Up @@ -1391,7 +1397,7 @@ while test "${#}" -gt 0; do
done || :

if test "${execute_script}" = 'true'; then
BACKUP_PATH="${PATH:-%empty}"
backup_path="${PATH-unset}"

shell_is_msys='false'
if is_shell_msys; then
Expand All @@ -1406,10 +1412,11 @@ if test "${execute_script}" = 'true'; then
detect_bitness_of_files "${@}" || STATUS="${?}"
fi

PATH="${BACKUP_PATH}"
if test "${backup_path}" = 'unset'; then unset PATH; else PATH="${backup_path}"; fi
fi

unset SCRIPT_NAME SCRIPT_VERSION POSIXLY_CORRECT BACKUP_PATH shell_is_msys execute_script
test "${PREFER_INCLUDED_UTILITIES:-0}" != '1' || unset PREFER_INCLUDED_UTILITIES ASH_STANDALONE
if test "${backup_posix}" = 'unset'; then unset POSIXLY_CORRECT; else POSIXLY_CORRECT="${backup_posix}"; fi
unset SCRIPT_NAME SCRIPT_VERSION backup_posix backup_path execute_script shell_is_msys

pause_if_needed "${STATUS}"

0 comments on commit 9d09655

Please sign in to comment.