#!/bin/bash
#########################################################
#                                                       #
# This is BashStyle-NG                                  #
#                                                       #
# Licensed under GNU GENERAL PUBLIC LICENSE v3          #
#                                                       #
# Copyright Christopher Roy Bratušek                    #
#                                                       #
#########################################################

. gettext.sh
export TEXTDOMAIN="bashstyle-rc"

case ${1} in
    asc | ascii)    echo -e "\0$(printf %o "$2")" ;;
    b32 | base32)   echo "obase=32 ; $2" | bc ;;
    b64 | base64)   echo "obase=64 ; $2" | bc ;;
    bin | binary)   echo "obase=2 ; $2" | bc ;;
    hex | hexadecimal)  echo "obase=16 ; $2" | bc ;;
    oct | octal)    echo "obase=8 ; $2" | bc ;;
    all )
        echo "decimal $2 = binary       $(convdec bin "${2}")
decimal $2 = octal      $(convdec oct "${2}")
decimal $2 = hexadecimal    $(convdec hex "${2}")
decimal $2 = base32     $(convdec b32 "${2}")
decimal $2 = base64     $(convdec b64 "${2}")
decimal $2 = ascii      $(convdec asc "${2}")"
    ;;

    *)
        bashstyle-help -a "Christopher Roy Bratusek" -e "nano@jpberlin.de" -h "https://www.nanolx.org/"\
            -l "GNU GPL v3" -n "convdec" -s "$(eval_gettext "convert decimal to other numerical equivalents")"\
            -v "${BSNG_VERSION}" -y "${BSNG_YEAR}"\
            -o "$(eval_gettext "asc:|convert decimal to ascii equivalent")"\
            -o "$(eval_gettext "b32:|convert decimal to base32 equivalent")"\
            -o "$(eval_gettext "b64:|convert decimal to base64 equivalent")"\
            -o "$(eval_gettext "bin:|convert decimal to binary equivalent")"\
            -o "$(eval_gettext "hex:|convert decimal to hexadecimal equivalent")"\
            -o "$(eval_gettext "oct:|convert decimal to octal equivalent")"\
            -o "$(eval_gettext "all:|convert decimal to other numerical equivalents")"
    ;;
esac

