-
Notifications
You must be signed in to change notification settings - Fork 0
/
mulle-objc-encode
executable file
·141 lines (114 loc) · 2.33 KB
/
mulle-objc-encode
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
#! /usr/bin/env mulle-bash
encode_usage()
{
grep -E '^#\ ' "$0" >&2
exit 1
}
#
# TODO: check MULLE_VIRTUAL_ROOT and search for mulle-objc headers
#
# A small utility to see that @encode does.
# You will have to declare classes ahead though.
#
# e.g. mulle-objc-encode "struct foo { long a; long b; }[ 1]"
# e.g. mulle-objc-encode -c NSArray "NSArray *"
#
main()
{
local tmpfile
local declarations
local includes
local includepath
#
# simple option handling
#
while [ $# -ne 0 ]
do
if options_technical_flags "$1"
then
shift
continue
fi
case "$1" in
-h*|--help|help)
encode_usage
;;
-c|--class-name)
shift
declarations="${declarations}
@interface $1
@end
"
;;
-i)
shift
if [ -z "${includes}" ]
then
includes="#include $1"
else
includes="${includes}
'#include $1"
fi
;;
-I)
shift
if [ -z "${includepath}" ]
then
includepath="'$1'"
else
includepath="${includepath} '$1'"
fi
;;
-d|--declaration)
shift
declarations="${declarations}
$1
"
;;
-p|--protocol-name)
shift
declarations="${declarations}
@protocol $1
@end
" ;;
-*)
echo "Unknown option \"$1\"" 2>&1
;;
*)
break
;;
esac
shift
done
tmpfile="/tmp/`uuidgen`"
local srcfile
local exefile
srcfile="${tmpfile}.m"
exefile="${tmpfile}.exe"
cat <<EOF > "${srcfile}"
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
${includes}
${declarations}
int main( int argc, char *argv[])
{
printf( "%s\n", @encode( $*));
return( 0);
}
EOF
local sdkpath
case "`uname`" in
Darwin)
sdkpath="`xcrun --show-sdk-path`"
eval mulle-clang -w -isysroot "'${sdkpath}'" ${includepath} -o "'${exefile}'" "'${srcfile}'" || exit 1
;;
*)
eval mulle-clang -o "'${exefile}'" ${includepath} "'${srcfile}'" || exit 1
;;
esac
"${exefile}" && rm "${exefile}" "${srcfile}"
}
main "$@"