forked from hishamhm/dit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenHeaders
executable file
·121 lines (104 loc) · 2.2 KB
/
GenHeaders
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/sh
################################
echo -n "Function prototypes..."
################################
echo "#ifndef Prototypes_HEADER" > Prototypes.h
echo "#define Prototypes_HEADER" >> Prototypes.h
echo >> Prototypes.h
echo '#define _GNU_SOURCE' >> Prototypes.h
echo '#include <stdbool.h>' >> Prototypes.h
echo '#include <stdio.h>' >> Prototypes.h
echo '#include <string.h>' >> Prototypes.h
echo '#include <curses.h>' >> Prototypes.h
echo >> Prototypes.h
echo '#include "Structures.h"' >> Prototypes.h
echo >> Prototypes.h
includes() {
cat "$1" | grep --text "^#include"
}
proto() {
cat "$1" | grep --text -v "^static" | grep '^[^ ].*) {$' | sed 's,) {$,);,' >> Prototypes.h
}
process() {
for proc in "${processed[@]}"
do [ "$proc" == "$1" ] && return
done
for need in `cat "$1" | grep --text '//#needs ' | sed 's,//#needs ,,'`
do process $need.c "$2"
done
"$2" "$1"
processed=("${processed[@]}" "$1")
echo "$1" >> order.txt
}
do_all() {
if [ -e order.txt ]
then
for i in `cat order.txt`
do "$1" "$i"
done
else
processed=( )
for i in *.c
do process "$i" "$1"
done
fi
}
{
if [ `ls *.c | wc -l` != `cat order.txt | wc -l` ]
then rm -f order.txt
fi
} &> /dev/null
do_all includes | sort -u | tac >> Prototypes.h
do_all proto
echo >> Prototypes.h
echo '#include <stdlib.h>' >> Prototypes.h
echo '#include "debug.h"' >> Prototypes.h
echo '#include <assert.h>' >> Prototypes.h
echo >> Prototypes.h
echo "#endif" >> Prototypes.h
#######################
echo
echo -n "Structures..."
#######################
echo "#ifndef Structures_HEADER" > Structures.h
echo "#define Structures_HEADER" >> Structures.h
echo >> Structures.h
cat *.c | awk '
BEGIN {
reading=0
}
/\/*{/ {
reading=1
}
/}*\// {
reading=0
}
/^struct .* {$/ {
if (reading)
print "typedef struct " $2 " " substr($2, 1, length($2)-1) ";"
}
' >> Structures.h
struct() {
cat "$1" | awk '
BEGIN {
writing=0
}
/\/\*{/ {
writing=1
}
/}\*\// {
writing=0
}
{
if (writing==1)
writing=2
else if (writing == 2)
print
}
' >> Structures.h
}
do_all struct
echo "#endif" >> Structures.h
####
echo
####