-
Notifications
You must be signed in to change notification settings - Fork 0
/
genhind
executable file
·37 lines (37 loc) · 1.12 KB
/
genhind
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
if [ -z $1 ]
then
cd srcs 2> /dev/null
FILES=$(ls | grep ".c" | grep -v "libft\|\~")
for FILE in $FILES
do
HFILE=$(echo $FILE | cut -d '/' -f 2 | sed 's/\.c/\.h/')
if [ -f $HFILE ]
then
mv $HFILE $HFILE.back
fi
touch $HFILE
~/scripts/header_42 $HFILE "/"
DEFINE=$(echo $HFILE | tr "." "_" | tr a-z A-Z)
echo -e "\n#ifndef "$DEFINE"\n# define "$DEFINE"\n" >> $HFILE
cat $FILE | grep "(" | grep -v ";\|\twhile \|\tif \|sizeof\|static \|->\|=\|\tmain(\|\telse\|\t|" | sed 's/.*/&;/' >> $HFILE
echo -e "\n#endif" >> $HFILE
# echo -e "\n#endif /* !"$DEFINE" */" >> $HFILE
done
else
FILE=$(basename $1)
DIR=$(dirname $1)
cd $DIR
HFILE=$(echo $FILE | cut -d '/' -f 2 | sed 's/\.c/\.h/')
if [ -f $HFILE ]
then
mv $HFILE $HFILE.back
fi
touch $HFILE
~/scripts/header_42 $HFILE "/"
DEFINE=$(echo $HFILE | tr "." "_" | tr a-z A-Z)
echo -e "\n#ifndef "$DEFINE"\n# define "$DEFINE"\n" >> $HFILE
cat $FILE | grep "(" | grep -v ";\|\twhile \|\tif \|sizeof\|static \|->\|=\|\tmain(\|\telse\|\t|" | sed 's/.*/&;/' >> $HFILE
echo -e "\n#endif" >> $HFILE
# echo -e "\n#endif /* !"$DEFINE" */" >> $HFILE
fi