Last active
May 14, 2021 06:28
-
-
Save nori26/7eebc884892d36ba3368384c1a973aa4 to your computer and use it in GitHub Desktop.
automatically add prototypes to header with suitable tabs for 42 norminette
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAME_H="libunit.h" | |
prot=$(find . -type d -name libft -prune -o -type f -name '*.c' | xargs cat | sed -e '/^[a-zA-Z].*)$/!d' -e '/^static/d' -e "s/)$/);/g") | |
TABS=$(echo "${prot}" | awk '{sub("[\t ].*", "");print length($0)}' | sort -nr | head -n 1 | xargs -I{} expr {} / 4 + 1) | |
header="$(sed -e "/^[a-zA-Z][a-zA-Z_0-9]*.*);$/d" -e '/#endif/d' -e '/^$/d' ${NAME_H}) | |
$(echo "${prot}" | awk -v tabs=${TABS} '{s=$0; sub("[\t ].*", ""); l=tabs - int(length($0) / 4); t="";for(i=0;i<l;i++){t=t "\t"};sub("[\t ][\t ]*", t, s); print s}') | |
#endif" | |
echo "${header}" > ${NAME_H} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment