Meow meow! Applied patches sent by LadySerenaKitty for improved FreeBSD compatibility.
[citadel.git] / webcit / scripts / get_ical_data.sh
1 #!/bin/sh
2
3 echo Running $0
4
5
6 ICAL=/usr/local/ctdlsupport/include/libical/ical.h
7 if test -f /usr/include/libical/ical.h; then 
8     ICAL=/usr/include/libical/ical.h
9 elif test -f /usr/local/include/libical/ical.h; then
10         ICAL=/usr/local/include/libical/ical.h
11 fi
12
13 if test ! -f ${ICAL}; then 
14     echo "failed to locate libical headers - please install the libical development packages or heardes"
15     exit 500
16 fi
17
18 ICALTYPES="icalproperty_kind"\
19 " icalcomponent_kind"\
20 " icalrequeststatus"\
21 " ical_unknown_token_handling"\
22 " icalrecurrencetype_frequency"\
23 " icalrecurrencetype_weekday"\
24 " icalvalue_kind"\
25 " icalproperty_action"\
26 " icalproperty_carlevel"\
27 " icalproperty_class"\
28 " icalproperty_cmd"\
29 " icalproperty_method"\
30 " icalproperty_querylevel"\
31 " icalproperty_status"\
32 " icalproperty_transp"\
33 " icalproperty_xlicclass"\
34 " icalparameter_kind"\
35 " icalparameter_action"\
36 " icalparameter_cutype"\
37 " icalparameter_enable"\
38 " icalparameter_encoding"\
39 " icalparameter_fbtype"\
40 " icalparameter_local"\
41 " icalparameter_partstat"\
42 " icalparameter_range"\
43 " icalparameter_related"\
44 " icalparameter_reltype"\
45 " icalparameter_role"\
46 " icalparameter_rsvp"\
47 " icalparameter_value"\
48 " icalparameter_xliccomparetype"\
49 " icalparameter_xlicerrortype"\
50 " icalparser_state"\
51 " icalerrorenum"\
52 " icalerrorstate"\
53 " icalrestriction_kind"
54
55 (
56     printf '#include "webcit.h"\n\n\n'
57
58     for icaltype in $ICALTYPES; do 
59         printf "typedef struct _Ical_${icaltype} {\n"\
60 "       const char *Name;\n"\
61 "       long NameLen;\n"\
62 "       ${icaltype} map;\n"\
63 "} Ical_${icaltype};\n\n\n"
64
65     done
66
67     for icaltype in $ICALTYPES; do 
68         cat ./scripts/get_ical_data__template.sed | \
69             gsed -e "s;__ICALTYPE__;$icaltype;g" > \
70             /tmp/get_ical_data.sed
71     
72         printf "Ical_${icaltype} ${icaltype}_map[] = {\n"
73         cat ${ICAL} |\
74 gsed -e 's;/\*.*\*/;;' -e 's;\t;;g' |\
75 gsed -nf /tmp/get_ical_data.sed |\
76 gsed -e "s;.*typedef *enum *${icaltype} *{\(.*\)} ${icaltype} *\;.*;\1,;" \
77             -e 's;/\*.*\*/;;' \
78             -e 's;/;\n/\n;g' \
79             -e 's;,;,\n;g' \
80             -e 's; *;;g' \
81             -e 's;^t*;;g' \
82             -e 's;\=[0-9]*;;g'|\
83 gsed -e 's;\(.*\),;{HKEY("\1"), \1},;'
84         printf '{"", 0, 0}\n};\n\n\n' 
85         
86     done
87
88
89     printf "void \nInitModule_ICAL_MAPS\n(void)\n{\n\tint i;\n"
90     for icaltype in $ICALTYPES; do 
91         printf "\tfor (i=0; ${icaltype}_map[i].NameLen > 0; i++)\n"\
92 "               RegisterTokenParamDefine (\n"\
93 "                       ${icaltype}_map[i].Name,\n"\
94 "                       ${icaltype}_map[i].NameLen,\n"\
95 "                       ${icaltype}_map[i].map);\n"\
96
97     done
98     printf "\n}\n\n"
99
100 ) > ical_maps.c