From 250d50134eb7415b20bc7fbec2c5b1b3ac916b2e Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 10 Jan 2021 16:39:11 -0500 Subject: [PATCH] neofetch-ripper: build usable C code --- src/fetch/ncart.h | 3 +++ tools/neofetch-ripper | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/fetch/ncart.h diff --git a/src/fetch/ncart.h b/src/fetch/ncart.h new file mode 100644 index 000000000..ac47d9555 --- /dev/null +++ b/src/fetch/ncart.h @@ -0,0 +1,3 @@ +#pragma once + +const char* get_neofetch_art(const char* oskey); diff --git a/tools/neofetch-ripper b/tools/neofetch-ripper index ad50d273f..1cb500095 100755 --- a/tools/neofetch-ripper +++ b/tools/neofetch-ripper @@ -33,6 +33,9 @@ while IFS= read -r line ; do if [ -z "$STARTED" ] ; then if [ "$line" = 'get_distro_ascii() {' ] ; then STARTED="$LINE" + echo "#include \"ncart.h\"" + echo "#include " + echo "#include " echo "// Output of \"`basename $0` $1\"" echo "// Generated on `date -u`" echo "// Copyright Dylan Araps under an MIT License" @@ -79,8 +82,29 @@ while IFS= read -r line ; do fi done < "$1" -# if DONE is defined, we ran to completion. yay! -if [ -n "$DONE" ] ; then exit 0 ; fi +# if DONE is defined, we ran to completion. yay! emit a table providing +# access to these strings via key comparison. +if [ -n "$DONE" ] ; then + echo + echo "struct neofetch_art { const char* oskey; const char* ncart; };" + echo + echo "const struct neofetch_art ncarts[] = {" + for k in "${!KEYSSEEN[@]}" ; do + echo " { \"$k\", $k }," + done + echo " { NULL, NULL }" + echo "};" + echo + echo "const char* get_neofetch_art(const char* oskey){" + echo " for(const struct neofetch_art* nfa = ncarts ; nfa->oskey ; ++nfa){" + echo " if(strcmp(nfa->oskey, oskey) == 0){" + echo " return nfa->ncart;" + echo " }" + echo " }" + echo " return NULL;" + echo "}" + exit 0 +fi # unsurprisingly, this incredibly brittle code has broken. crap! if [ -z "$STARTED" ] ; then