-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpproto
executable file
·182 lines (150 loc) · 3.33 KB
/
pproto
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/sh
#-------------------------------------------------------------------------------
# Phorward Foundation Toolkit
# Copyright (C) 2006-2017 by Phorward Software Technologies, Jan Max Meyer
# http://www.phorward-software.com ++ contact<at>phorward<dash>software<dot>com
# All rights reserved. See LICENSE for more information.
#
# Script: pproto
# Author: Jan Max Meyer
# Usage: C function prototype generator
#-------------------------------------------------------------------------------
#assemble options
options=""
while [ "$1" ]
do
case "$1" in
-s)
options="$options -vwith_static=1"
;;
-S)
options="$options -vonly_static=1"
;;
*)
break
;;
esac
shift
done
if [ $# -lt 1 ]
then
echo "usage: $0 [OPTION...] FILE..."
echo
echo " -s Output static declarations also"
echo " -S Only output static declarations"
exit 1
fi
#build the prototypes
while [ "$1" != "" ]
do
echo "/* $1 */"
premcomments < $1 | awk $options '
BEGIN { FS = "[ \t]+"
same_line = 0
if( only_static )
with_static = 1
entry = 1
}
END {
in_block = 0
begin_at[ 1 ] = 0
/* First, delete all empty preprocessor blocks */
for( i = 1; i < entry; i++ )
{
if( match( entries[ i ], /^# ?if/ ) == 1 )
{
in_block++
begin_at[ in_block ] = i
}
else if( match( entries[ i ], /^# ?(else|elif)/ ) \
== 1 )
{
#ok, better to do nothing here...
if( 0 && !in_block )
{
in_block++
begin_at[ in_block ] = i
}
#This may run into an error, but I
#dont want to fix this now ;( ...
}
else if( match( entries[ i ], /^# ?endif/ ) == 1 \
&& in_block )
{
for( j = begin_at[ in_block ]; j <= i; j++ )
entries[j] = ""
in_block--
}
else if( in_block )
{
in_block = 0
}
}
/* Then, print the remaining lines */
for( i = 1; i < entry; i++ )
{
if( entries[ i ] != "" )
print entries[ i ]
}
}
/#[ \t]*(if|else|elif|ifdef|ifndef|endif)/ {
line = $0
gsub( "[ \t]+", " ", line )
gsub( "^[ \t]+", "", line )
entries[ entry++ ] = line
next
}
/^[ \t]*([A-Za-z_]+[ \t]+)?[A-Za-z_][A-Za-z0-9_]*[ \t*]+[A-Za-z_][A-Za-z0-9_]*[ \t]*\(/ \
{
if( $1 == "static" \
|| $1 == "PRIVATE" \
|| $1 == "UNICC_STATIC" \
|| $1 == "RB_FCT" )
{
if( !with_static )
next
}
else if( only_static )
next
if( match( $2, /^main/ ) == 1 )
next
akt_proto = akt_proto $0
same_line = 1
}
/RB_FCT/ {
akt_proto = akt_proto $0
same_line = 1
}
/^{[ \t]*$/ {
if( akt_proto != "" )
{
gsub( "[ \t]+", " ", akt_proto )
entries[ entry++ ] = akt_proto ";"
akt_proto = ""
}
next
}
{
if( akt_proto != "" )
{
if( !same_line )
akt_proto = akt_proto $0
test_line = $0
gsub( "[ \t]+", "", test_line )
test_chr = substr( test_line, \
length( test_line ), 1 )
if( test_chr == ";" )
{
akt_proto = ""
}
}
same_line = 0
}
'
if [ $? -ne 0 ]
then
exit 1
fi
echo
shift
done