#!/bin/bash
#########################################################
# 							#
# This is BashStyle-NG  				#
#							#
# Licensed under GNU GENERAL PUBLIC LICENSE v3    	#
#							#
# Copyright 2007 - 2017 Christopher Bratusek		#
#							#
#########################################################

case ${1} in

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

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

esac
