Skip to content

Instantly share code, notes, and snippets.

@nori26
nori26 / 42header.py
Last active September 2, 2021 22:32
add_42header
import sys
import os
from datetime import datetime
def main():
name = "unko"
mail = f"{name}@student.42tokyo.jp"
files = sys.argv[1:]
start = '/* ************************************************************************** */'
for file in files:
@nori26
nori26 / add.sh
Last active May 14, 2021 06:28
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"