Skip to content

Instantly share code, notes, and snippets.

@nori26
Last active May 14, 2021 06:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nori26/7eebc884892d36ba3368384c1a973aa4 to your computer and use it in GitHub Desktop.
Save nori26/7eebc884892d36ba3368384c1a973aa4 to your computer and use it in GitHub Desktop.
automatically add prototypes to header with suitable tabs for 42 norminette
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