-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulle-objc-searchid
executable file
·440 lines (344 loc) · 8.87 KB
/
mulle-objc-searchid
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
#! /usr/bin/env mulle-bash
#
# Look through libraries and find a name for the given
# uniqueid. Searches classes and methods at the moment.
#
MULLE_EXECUTABLE_VERSION=0.9.1
MULLE_EXECUTABLE_FUNCTIONS_MIN="3.9"
MULLE_EXECUTABLE_FUNCTIONS_MAX="4"
usage()
{
cat <<EOF >&2
Usage:
${MULLE_USAGE_NAME} [options] <uniqueid> <library>+
Search though libraries for a string matching a uniqueid, This could be
amongst other things, a @selector or the mulle_objc_classid_t of a class.
Options:
EOF
options_technical_flags_usage | sort >&2
exit 1
}
r_prettify_uniqueid()
{
log_entry "r_prettify_uniqueid" "$@"
local uniqueid="$1"
uniqueid="`tr '[A-Z]' '[a-z]' <<< "${uniqueid}"`"
uniqueid="${uniqueid#0x}"
uniqueid="${uniqueid#\$}"
case "${uniqueid}" in
[0-9a-f])
uniqueid="0000000${uniqueid}"
;;
[0-9a-f][0-9a-f])
uniqueid="000000${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f])
uniqueid="00000${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f][0-9a-f])
uniqueid="0000${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
uniqueid="000${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
uniqueid="00${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
uniqueid="0${uniqueid}"
;;
[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
;;
*)
return 1
;;
esac
RVAL="${uniqueid}"
}
grep_library()
{
log_entry "grep_library" "$@"
local uniqueid="$1"
local library="$2"
if [ ! -f "${library}" ]
then
return 1
fi
log_verbose "Searching in \"${library}\" (${PWD#${MULLE_USER_PWD}/})..."
local found
if [ "${MULLE_FLAG_LOG_FLUFF}" = "YES" ]
then
case "${library}" in
*.so|*.dylib)
found="`rexekutor "${MULLE_OBJC_LIST}" -s "${library}" | rexekutor fgrep "${uniqueid}"`"
;;
*)
found="`rexekutor "${MULLE_OBJC_LISTA}" \
${MULLE_TECHNICAL_FLAGS} \
${MULLE_OBJC_LISTA_FLAGS} \
-s "${library}" | rexekutor fgrep "${uniqueid}"`"
;;
esac
else
case "${library}" in
*.so|*.dylib)
found="`rexekutor "${MULLE_OBJC_LIST}" -s "${library}" 2> /dev/null | rexekutor fgrep "${uniqueid}"`"
;;
*)
found="`rexekutor "${MULLE_OBJC_LISTA}" \
${MULLE_TECHNICAL_FLAGS} \
${MULLE_OBJC_LISTA_FLAGS} \
-s "${library}" 2> /dev/null | rexekutor fgrep "${uniqueid}"`"
;;
esac
fi
if [ -z "${found}" ]
then
return 1
fi
log_verbose "${uniqueid} found in \"${library}\""
echo "${found}"
}
grep_libraries()
{
log_entry "grep_libraries" "$@"
local uniqueid="$1"
[ -z "${LIB_PATH}" ] && internal_fail "LIB_PATH is empty"
IFS="
"
for i in `ls -1`
do
IFS="${DEFAULT_IFS}"
case "$i" in
*.a|*.lib)
if grep_library "${uniqueid}" "$i"
then
return 0
fi
;;
*.so|*.dylib)
if grep_library "${uniqueid}" "$i"
then
return 0
fi
;;
*)
log_fluff "Ignored \"$i\""
;;
esac
done
IFS="${DEFAULT_IFS}"
return 1
}
search()
{
log_entry "search" "$@"
local uniqueid="$1"; shift
local folder
local old
old="${PWD}"
if [ $# -eq 0 ]
then
.foreachpath folder in ${LIB_PATH}
.do
if [ -d "${folder}" ]
then
cd "${folder}"
if grep_libraries "${uniqueid}"
then
cd "${old}"
return
fi
fi
.done
cd "${old}"
else
while [ $# -ne 0 ]
do
.foreachpath folder in ${LIB_PATH}
.do
if [ -d "${folder}" ]
then
cd "${folder}"
if grep_library "${uniqueid}" "${1}"
then
cd "${old}"
return
fi
fi
.done
cd "${old}"
shift
done
fi
}
find_in_libraries()
{
log_entry "find_in_libraries" "$@"
local uniqueid="$1"; shift
if [ -z "${LIB_PATH}" ]
then
LIB_PATH="${DEPENDENCY_DIR:-dependency}/lib:${DEPENDENCY_DIR:-dependency}/Debug/lib"
fi
search "${uniqueid}" "$@" | \
sed "s|^${uniqueid};\\([^;]*\\).*$|\\1|" | \
sed "s|^.*;${uniqueid};\\([^;]*\\).*$|\\1|" | \
sed 's|^[-+]||' | \
sort -u
}
find_local_words()
{
rexekutor find . -type f \( -path ./build -prune -o \
-path ./dependency -prune -o \
-path ./addiction -prune -o\
-name "*.[hcm]" -o -name "*.aam" \) \
-exec grep -o -E '\w+' {} \;
}
find_local_unique_words()
{
log_entry "find_local_unique_words" "$@"
find_local_words | sort -u
}
find_local_uniqueids()
{
log_entry "find_local_uniqueids" "$@"
find_local_unique_words | CSV=ON rexekutor xargs "${MULLE_OBJC_UNIQUEID}"
}
main()
{
local LIB_PATH
local OPTION_SELECTOR="NO"
local OPTION_LOCAL="YES"
local OPTION_LIBRARIES="YES"
local OPTION_DUMP_WORDS="NO"
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
# your option handling
case "$1" in
--version)
echo "${MULLE_EXECUTABLE_VERSION}"
exit 0
;;
-L|--librarypath)
[ $# -eq 1 ] && fail "missing argument to $1"
shift
LIB_PATH="`colon_concat "${LIB_PATH}" "$1"`"
;;
--local)
OPTION_LOCAL="YES"
;;
--no-local)
OPTION_LOCAL="NO"
;;
--dump-words)
OPTION_DUMP_WORDS="YES"
;;
--libraries)
OPTION_LIBRARIES="YES"
;;
--no-libraries)
OPTION_LIBRARIES="NO"
;;
--selector)
OPTION_SELECTOR="YES"
;;
-h|--help)
usage
;;
-*)
fail "unknown option $1"
;;
*)
break
;;
esac
shift
done
options_setup_trace "${MULLE_TRACE}" && set -x
if [ -z "${MULLE_VIRTUAL_ROOT}" ]
then
MULLE_VIRTUAL_ROOT="`mulle-sde project-dir`"
[ -z "${MULLE_VIRTUAL_ROOT}" ] && fail "MULLE_VIRTUAL_ROOT can not be determined"
fi
DEPENDENCY_DIR="${DEPENDENCY_DIR:-`mulle-sde dependency-dir`}"
DEPENDENCY_DIR="${DEPENDENCY_DIR:-"${MULLE_VIRTUAL_ROOT}/dependency"}"
if [ "${OPTION_DUMP_WORDS}" = "YES" ]
then
find_local_words
exit $?
fi
local uniqueid
[ $# -eq 0 ] && usage
#
# make uniqueid pretty for various formats
#
[ -z "${1}" ] && usage
# prefer sibling mulle-objc-uniqueid
if [ -z "${MULLE_OBJC_UNIQUEID}" ]
then
MULLE_OBJC_UNIQUEID="${0%/*}/mulle-objc-uniqueid"
if [ ! -x "${MULLE_OBJC_UNIQUEID}" ]
then
MULLE_OBJC_UNIQUEID="`command -v mulle-objc-uniqueid`"
[ -z "${MULLE_OBJC_UNIQUEID}" ] && echo "mulle-objc-uniqueid not in PATH" >&2 && exit 1
fi
fi
if [ -z "${MULLE_OBJC_LIST}" ]
then
MULLE_OBJC_LIST="${0%/*}/mulle-objc-list"
if [ ! -x "${MULLE_OBJC_LIST}" ]
then
MULLE_OBJC_UNIQUEID="`command -v mulle-objc-list`"
[ -z "${MULLE_OBJC_LIST}" ] && echo "mulle-objc-list not in PATH" >&2 && exit 1
fi
fi
if [ -z "${MULLE_OBJC_LISTA}" ]
then
MULLE_OBJC_LISTA="${0%/*}/mulle-objc-lista"
if [ ! -x "${MULLE_OBJC_LISTA}" ]
then
MULLE_OBJC_LISTA="`command -v mulle-objc-lista`"
[ -z "${MULLE_OBJC_LISTA}" ] && echo "mulle-objc-lista not in PATH" >&2 && exit 1
fi
fi
if [ "${OPTION_SELECTOR}" = "YES" ]
then
uniqueid="`${MULLE_OBJC_UNIQUEID} "$1"`"
log_info "@selector( $1) is ${uniqueid}"
else
r_prettify_uniqueid "$1"
uniqueid="${RVAL}"
fi
[ -z "${uniqueid}" ] && fail "malformed input \"$1\""
shift
if [ "${OPTION_LOCAL}" = "YES" ]
then
local escaped
r_escaped_grep_pattern "${uniqueid}"
escaped="${RVAL}"
result="`find_local_uniqueids | rexekutor egrep "^${escaped};" | rexekutor cut -d ';' -f 2`"
fi
if [ -z "${result}" ]
then
if [ "${OPTION_LIBRARIES}" = "YES" ]
then
result="`find_in_libraries "${uniqueid}" `"
fi
fi
if [ -z "${result}" ]
then
log_warning "${uniqueid} is unknown."
return 1
fi
if [ "${OPTION_SELECTOR}" = "NO" ]
then
log_info "@selector( $result) is ${uniqueid}"
fi
echo "${result}"
}
main "$@"