blob: 7ca51dda1f9f98ddfaf05c24b8e7feb9b764ceb1 (
plain)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
#!/bin/bash
#
# Copyright, the authors of the Linux man-pages project
# SPDX-License-Identifier: GPL-3.0-or-later
set -Eefuo pipefail;
# Defaults:
t='no';
t_e='no';
t_fp='no';
t_fd='no';
t_flp='no';
t_fld='no';
t_fgp='no';
t_fgd_libm='no';
t_fgd_libio='no';
t_mf='no';
t_mo='no';
t_t_braced='no';
t_t_td_simple='no';
t_t_td_braced='no';
t_t_td_func='no';
t_ue='no';
t_uf_def='no';
t_uf_linux_def='no';
t_umf='no';
t_umo='no';
t_ut_su='no';
t_ut_td_simple='no';
grepc_err()
{
>&2 printf '%s\n' "$(basename "$0"): error: $*";
exit 1;
}
while getopts "t:" opt; do
case "$opt" in
t)
case "$OPTARG" in
e) t_e='yes'; ;;&
f | fp) t_fp='yes'; ;;&
f | fd) t_fd='yes'; ;;&
f | fl | flp) t_flp='yes'; ;;&
f | fl | fld) t_fld='yes'; ;;&
f | fg | fgp) t_fgp='yes'; ;;&
f | fg | fgd) t_fgd_libm='yes';
t_fgd_libio='yes'; ;;&
m | mf) t_mf='yes'; ;;&
m | mo) t_mo='yes'; ;;&
t) t_t_braced='yes';
t_t_td_simple='yes';
t_t_td_braced='yes';
t_t_td_func='yes'; ;;&
u | ue) t_ue='yes'; ;;&
u | uf) t_uf_def='yes';
t_uf_linux_def='yes'; ;;&
u | um) t_umf='yes';
t_umo='yes'; ;;&
u | ut) t_ut_su='yes';
t_ut_td_simple='yes'; ;;&
[efmtu] | f[pdlg] | fl[pd] | fg[pd] | m[fo] | u[efmt])
t='yes';
;;
*)
grepc_err "-$opt: $OPTARG: Unknown argument.";
;;
esac;
;;
\? | *)
exit 1;
;;
esac;
done;
shift $((OPTIND-1));
if test $# -lt 1; then
grepc_err "Missing identifier.";
fi;
identifier="$1";
shift;
if test $# -gt 0; then
grepc_err "$1: Unexpected argument.";
fi;
if test "$t" = 'no'; then
t_e='yes';
t_fp='yes';
t_fd='yes';
t_flp='yes';
t_fld='yes';
t_fgp='yes';
t_fgd_libm='yes';
t_fgd_libio='yes';
t_mf='yes';
t_mo='yes';
t_t_braced='yes';
t_t_td_simple='yes';
t_t_td_braced='yes';
t_t_td_func='yes';
fi;
grepc_c_t_sue_decl_() { printf '%s' '(?s)^(?:[\w[](?:[\w\s\(,\)[\]*]|::)*[\w\s\)*\]]\s+)?\b(?:'"$1"')\b[\w \t[\]:]*(?<!\w)'"$2"'(?!\w)'; }
grepc_c_f_return_() { printf '%s' '(?s)^[\w[](?:[\w\s\(,\)[\]*]|::)+[\w\s\)*\]]\s+\**'; }
grepc_c_f_params_() { printf '%s' '\s*(?<params>\((?:[\w\s,;[\]*\?:+-]|(?¶ms))*(?:\.\.\.)?\))'; }
grepc_c_f_decl_() { grepc_c_f_return_;
printf '%s' '\(?'"$1"'\)?';
grepc_c_f_params_; }
grepc_c_body_() { printf '%s' '[ \t]*\n*(?<space>[ \t]*){.*?^\k<space>}'; }
grepc_c_u_body_() { printf '%s' '[ \t]*\n*(?<space>[ \t]*){(?:(?!^\k<space>?}).)*'"$1"'.*?^\k<space>}'; }
grepc_c_fld_decl_() { printf '%s' '(?s)^(?:COMPAT_)?SYSCALL_DEFINE.\('"$1"'\b[\w\s,;[\]*\?:+-]*\)'; }
grepc_c_m_decl_() { printf '%s' '(?s)^[ \t]*#\s*define\s[\s\\]*'"$1"'\b'; }
grepc_c_mf_decl_() { grepc_c_m_decl_ "$1";
printf '%s' '\([^\(]*\)'; }
grepc_c_mo_decl_() { grepc_c_m_decl_ "$1";
printf '%s' '(?!\()'; }
grepc_c_m_repl_() { printf '%s' '(?:(?![^\\]$).)*'"$1"'.*?(?<!\\)$'; }
grepc_c_e() { grepc_c_t_sue_decl_ 'enum' '';
grepc_c_u_body_ '^[ \t]*'"$1"'\b\s*[=,]';
echo '[^;]*;'; }
grepc_c_fp() { grepc_c_f_decl_ "$1";
echo '(?:[\w\s\(,\)[\]]|::)*;'; }
grepc_c_fd() { grepc_c_f_decl_ "$1";
grepc_c_body_;
echo; }
grepc_c_fgd_libm() { grepc_c_fd "M_DECL_FUNC \(__$1\)"; }
grepc_c_fgd_libio() { grepc_c_fd "_IO_$1"; }
grepc_c_fgp_libio() { grepc_c_fp "_IO_$1"; }
grepc_c_fgp() { grepc_c_fgp_libio "$1"; }
grepc_c_flp() { grepc_c_fp "(?:compat_)?sys_$1"; }
grepc_c_fld() { grepc_c_fld_decl_ "$1";
grepc_c_body_;
echo; }
grepc_c_mf() { grepc_c_mf_decl_ "$1";
grepc_c_m_repl_ '';
echo; }
grepc_c_mo() { grepc_c_mo_decl_ "$1";
grepc_c_m_repl_ '';
echo; }
grepc_c_t_braced() { grepc_c_t_sue_decl_ 'struct|union|enum' "$1";
grepc_c_body_;
echo '[^;]*;'; }
grepc_c_t_td_simple() { echo '(?s)^[ \t]*typedef\s+[^{};]+\b'"$1"';'; }
grepc_c_t_td_braced() { printf '%s' '(?s)^[ \t]*typedef\s+(?:struct|union|enum)\b[\w \t[\]:]*';
grepc_c_body_;
echo '\s*'"$1"'(?:\[[\w\(,\)]\])*;'; }
grepc_c_t_td_func() { echo '(?s)^[ \t]*typedef\s+[^{};]+\(\**'"$1"'\)\s*\([^{};]+;'; }
grepc_c_ue() { grepc_c_t_sue_decl_ 'enum' '';
grepc_c_u_body_ "$1";
echo '[^;]*;'; }
grepc_c_uf_def() { grepc_c_f_decl_ '\w+';
grepc_c_u_body_ "$1";
echo; }
grepc_c_uf_linux_def() { grepc_c_fld_decl_ '\w+';
grepc_c_u_body_ "$1";
echo; }
grepc_c_umf() { grepc_c_mf_decl_ '\w+'
grepc_c_m_repl_ "$1";
echo; }
grepc_c_umo() { grepc_c_mo_decl_ '\w+'
grepc_c_m_repl_ "$1";
echo; }
grepc_c_ut_su() { grepc_c_t_sue_decl_ 'struct|union' '';
grepc_c_u_body_ "$1";
echo '[^;]*;'; }
grepc_c_ut_td_simple() { echo '(?s)^[ \t]*typedef\s+[^{};]*'"$1"'[^{};]+;'; }
if test "$t_e" = yes; then grepc_c_e "$identifier"; fi;
if test "$t_fp" = yes; then grepc_c_fp "$identifier"; fi;
if test "$t_fd" = yes; then grepc_c_fd "$identifier"; fi;
if test "$t_flp" = yes; then grepc_c_flp "$identifier"; fi;
if test "$t_fld" = yes; then grepc_c_fld "$identifier"; fi;
if test "$t_fgp" = yes; then grepc_c_fgp "$identifier"; fi;
if test "$t_fgd_libm" = yes; then grepc_c_fgd_libm "$identifier"; fi;
if test "$t_fgd_libio" = yes; then grepc_c_fgd_libio "$identifier"; fi;
if test "$t_mf" = yes; then grepc_c_mf "$identifier"; fi;
if test "$t_mo" = yes; then grepc_c_mo "$identifier"; fi;
if test "$t_t_braced" = yes; then grepc_c_t_braced "$identifier"; fi;
if test "$t_t_td_simple" = yes; then grepc_c_t_td_simple "$identifier"; fi;
if test "$t_t_td_braced" = yes; then grepc_c_t_td_braced "$identifier"; fi;
if test "$t_t_td_func" = yes; then grepc_c_t_td_func "$identifier"; fi;
if test "$t_ue" = yes; then grepc_c_ue "$identifier"; fi;
if test "$t_uf_def" = yes; then grepc_c_uf_def "$identifier"; fi;
if test "$t_uf_linux_def" = yes; then grepc_c_uf_linux_def "$identifier"; fi;
if test "$t_umf" = yes; then grepc_c_umf "$identifier"; fi;
if test "$t_umo" = yes; then grepc_c_umo "$identifier"; fi;
if test "$t_ut_su" = yes; then grepc_c_ut_su "$identifier"; fi;
if test "$t_ut_td_simple" = yes; then grepc_c_ut_td_simple "$identifier"; fi;
|