Repository navigation
Expand file tree
/
Copy pathGenHeaders
More file actions
executable file
·148 lines (124 loc) · 2.82 KB
/
Copy pathGenHeaders
File metadata and controls
executable file
·148 lines (124 loc) · 2.82 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env bash
which tac &> /dev/null || tac() { tail -r "$@"; }
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 [ "$1" = "Prototypes.h" ]
then
new="Prototypes.h.new"
old="Prototypes.h"
################################
echo -n "Function prototypes..."
################################
echo "#ifndef Prototypes_HEADER" > "$new"
echo "#define Prototypes_HEADER" >> "$new"
echo >> "$new"
echo '#define _GNU_SOURCE' >> "$new"
echo '#include <stdbool.h>' >> "$new"
echo '#include <stdio.h>' >> "$new"
echo '#include <string.h>' >> "$new"
echo '#include <unistd.h>' >> "$new"
echo >> "$new"
echo '#include "Structures.h"' >> "$new"
echo >> "$new"
includes() {
cat "$1" | grep --text "^#include"
}
defines() {
cat "$1" | grep --text "^#define Display_.*"
}
proto() {
cat "$1" | grep -v "#include" | cpp 2> /dev/null |\
grep --text -v "^static" | grep '^[^ ].*) {$' |\
sed 's,) {$,);,;s,inline,,' >> "$new"
}
{
if [ `ls *.c | wc -l` != `cat order.txt | wc -l` ]
then rm -f order.txt
fi
} &> /dev/null
do_all includes | sort -u | tac >> "$new"
do_all proto
echo "#if HAVE_CURSES" >> "$new"
do_all defines >> "$new"
echo "#endif" >> "$new"
echo >> "$new"
echo '#include <stdlib.h>' >> "$new"
echo '#include "debug.h"' >> "$new"
echo '#include <assert.h>' >> "$new"
echo >> "$new"
echo "#endif" >> "$new"
else
new="Structures.h.new"
old="Structures.h"
#######################
echo -n "Structures..."
#######################
echo "#ifndef Structures_HEADER" > "$new"
echo "#define Structures_HEADER" >> "$new"
echo "#include \"config.h\"" >> "$new"
echo >> "$new"
cat *.c | awk '
BEGIN {
reading=0
}
/\/*{/ {
reading=1
}
/}*\// {
reading=0
}
/^struct .* {$/ {
if (reading)
print "typedef struct " $2 " " substr($2, 1, length($2)-1) ";"
}
' >> "$new"
struct() {
cat "$1" | awk '
BEGIN {
writing=0
}
/\/\*{/ {
writing=1
}
/}\*\// {
writing=0
}
{
if (writing==1)
writing=2
else if (writing == 2)
print
}
' >> "$new"
}
do_all struct
echo "#endif" >> "$new"
fi
####
echo
####
if ! diff -q "$new" "$old"
then mv "$new" "$old"
fi