diff --git a/figlet.awk b/figlet.awk new file mode 100644 index 0000000..a9ae184 --- /dev/null +++ b/figlet.awk @@ -0,0 +1,12 @@ +BEGIN { char_cnt=32; line_cnt=0; print "#!/bin/bash\ndeclare -A a" } # echo bash shebang + declaring associative array for string keys +NR==1 {height=$2; start=$6; print "height=" $2} # interpreting flf first line variables +NR-start-1>0 && char_cnt<123 { # for every line with characters definitions: + line=$0; + gsub("@","",line); # replace all "@" with blank + gsub("\$"," ",line); # replace all dollar signs with blank space + gsub("'","'\"'\"'",line); # replace every occurance of single quote, with escape + printf "a[\"%i,%i\"]='%s';", char_cnt, line_cnt, substr(line,2) # print array formated characters + line_cnt++; +} +char_cnt<123 && match($0, /@@$/) { char_cnt++; line_cnt=0; print "" } + diff --git a/generate.sh b/generate.sh new file mode 100755 index 0000000..2ea8dbc --- /dev/null +++ b/generate.sh @@ -0,0 +1,23 @@ +#!/bin/bash +if [ $# -eq 0 ]; then + echo "No arguments supplied" + exit 1 +fi + +if [[ "$1" != *.flf ]]; then + echo "Are you sure you supplied FIGlet font file?" + exit 1 +fi + +f=`basename "$1"` +output="${f%.flf}.sh" + +if [ -f $output ]; then + echo "File $output already exists. Aborting." + exit 1 +fi + +awk -f figlet.awk $1 > $output +cat prettyPrintSnippet.sh >> $output +chmod +x $output +echo "Successfuly written to file $output" diff --git a/prettyPrintSnippet.sh b/prettyPrintSnippet.sh new file mode 100755 index 0000000..1343e25 --- /dev/null +++ b/prettyPrintSnippet.sh @@ -0,0 +1,16 @@ + +function prettyPrint { + str=$1 + strarr=() + for (( i=0; i<${#str}; i++ )); do + strarr+=(`printf '%d\n' "'${str:$i:1}"`) + done + for ((i=0;i<$height;i++)) do + for j in "${strarr[@]}"; do + printf "%s" "${a["$j,$i"]}" + done + printf "\n" + done +} +prettyPrint $1 +