curl-extract-opt.sh (1187B)
1 #!/bin/sh
2
3 if [ $# -ne 1 ]; then
4 echo "Usage: curl-extract-opt.sh /path/to/include/curl"
5 exit 1
6 fi
7
8 if [ ! -d $1 ]; then
9 echo "given argument is not a directory"
10 exit 1
11 fi
12
13 if [ ! -f "$1/curl.h" ]; then
14 echo "$1 does not contain curl.h"
15 exit 1
16 fi
17
18 if [ ! -f "$1/curlver.h" ]; then
19 echo "$1 does not contain curlver.h"
20 fi
21
22 version=`egrep "#define LIBCURL_VERSION " "$1/curlver.h" | awk '{ print $3 }' | sed s/\"//g`
23
24 echo "/* Auto generated on `date` from $version */"
25
26 cat << __EOF
27
28 struct {
29 const char *name;
30 int value;
31 PyObject *(*cb)(struct pycurl_handle *, int, PyObject *);
32 } py_curlopt[] = {
33 __EOF
34
35 egrep "^.*CURLOPT\(.*\),$" "$1/curl.h" | \
36 cut -d'(' -f 2 | cut -d ')' -f 1 | sed 's/,/ /g' | \
37 sed 's/CURLOPTTYPE_OBJECTPOINT/NULL/g' | \
38 sed 's/CURLOPTTYPE_STRINGPOINT/pycurl_handle_setopt_string/g' | \
39 sed 's/CURLOPTTYPE_LONG/pycurl_handle_setopt_long/g' | \
40 sed 's/CURLOPTTYPE_SLISTPOINT/pycurl_handle_setopt_slist/g' | \
41 sed 's/CURLOPTTYPE_FUNCTIONPOINT/NULL/g' | \
42 sed 's/CURLOPTTYPE_OFF_T/NULL/g' | \
43 sed 's/CURLOPTTYPE_BLOB/NULL/g' | \
44 awk '{ printf "\t{ \"%s\", %s, %s },\n", $1, $3, $2 } '
45
46 echo "\t{ NULL, 0, 0 }"
47 echo "};"