Skip to content

Commit

Permalink
New plugin charstream/generate.
Browse files Browse the repository at this point in the history
Generates various charstreams.
  • Loading branch information
Roberto Reale committed Nov 16, 2016
1 parent 4f0f254 commit f3ec9e9
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions plugins/charstream/generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!bin/bash

################################################################################
#
# | | | |
# |---.,---.,---.|---.| ,---.|--- ,---.
# | |,---|`---.| || |---'| `---.
# `---'`---^`---'` '`---'`---'`---'`---'
#
#
# Bashlets -- A modular extensible toolbox for Bash
#
# Copyright (c) 2014-6 Roberto Reale
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################


source bashlet datatype/string

function bashlets_charstream_generate_ascii_chart()
{
########################################################################
#
# Code borrowed from: text_convert.sh by Luciano D. Cerere
#
# cf. https://gist.github.com/ldante86/679c2240acd7cc838e1d6fcac97dc4d3
#
########################################################################

# TODO extend to the whole of ASCII set

declare -a ascii=(
\! \" \# \$ % \& \' \( \) '*' + , - . / 0 1 2 3 4 5 6 7 8 9 : \; \< = \> ? @
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \[ \\ \] \^ _ \`
a b c d e f g h i j k l m n o p q r s t u v w x y z \{ \| \} \~ " "
)

declare -a binary=(
00100001 00100010 00100011 00100100 00100101 00100110 00100111 00101000
00101001 00101010 00101011 00101100 00101101 00101110 00101111 00110000
00110001 00110010 00110011 00110100 00110101 00110110 00110111 00111000
00111001 00111010 00111011 00111100 00111101 00111110 00111111 01000000
01000001 01000010 01000011 01000100 01000101 01000110 01000111 01001000
01001001 01001010 01001011 01001100 01001101 01001110 01001111 01010000
01010001 01010010 01010011 01010100 01010101 01010110 01010111 01011000
01011001 01011010 01011011 01011100 01011101 01011110 01011111 01100000
01100001 01100010 01100011 01100100 01100101 01100110 01100111 01101000
01101001 01101010 01101011 01101100 01101101 01101110 01101111 01110000
01110001 01110010 01110011 01110100 01110101 01110110 01110111 01111000
01111001 01111010 01111011 01111100 01111101 01111110 00100000
)

declare -a decimal=( {33..126} 32)

local p="10"
printf "%"-$p"s%"$p"s%"$p"s%"$p"s%"$p"s\n" "ASCII" "BINARY" "DECIMAL" "HEX" "BASE64"

for ((i=0; i<${#ascii[@]}; i++))
do
printf "%"-$p"s%"$p"s%"$p"s%"$p"s%"$p"s\n" \
"${ascii[i]}" \
"${binary[i]}" \
"${decimal[i]}" \
"$(string dec_to_hex "${decimal[i]}")" \
"$(string encode_base64 "${ascii[i]}")"
done
}

# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh

0 comments on commit f3ec9e9

Please sign in to comment.