forked from karelzak/mutt-kz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hcachever.sh.in
executable file
·89 lines (76 loc) · 1.43 KB
/
hcachever.sh.in
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
#!/bin/sh
BASEVERSION=2
cleanstruct () {
echo "$1" | sed -e 's/} *//' -e 's/;$//'
}
cleanbody () {
echo "$1" | sed -e 's/{ *//'
}
getstruct () {
STRUCT=""
BODY=''
inbody=0
case "$1" in
*'{') inbody=1 ;;
*';') return ;;
esac
while read line
do
if test $inbody -eq 0
then
case "$line" in
'{'*) inbody=1 ;;
*';') return ;;
esac
fi
case "$line" in
'} '*)
STRUCT=`cleanstruct "$line"`
break
;;
'}')
read line
STRUCT=`cleanstruct "$line"`
break
;;
'#'*) continue ;;
*)
if test $inbody -ne 0
then
BODY="$BODY $line"
fi
;;
esac
done
case $STRUCT in
ADDRESS|LIST|BUFFER|PARAMETER|BODY|ENVELOPE|HEADER)
BODY=`cleanbody "$BODY"`
echo "$STRUCT: $BODY"
;;
esac
return
}
DEST="$1"
TMPD="$DEST.tmp"
TEXT="$BASEVERSION"
echo "/* base version: $BASEVERSION" > $TMPD
while read line
do
case "$line" in
'typedef struct'*)
STRUCT=`getstruct "$line"`
if test -n "$STRUCT"
then
NAME=`echo $STRUCT | cut -d: -f1`
BODY=`echo $STRUCT | cut -d' ' -f2-`
echo " * $NAME:" $BODY >> $TMPD
TEXT="$TEXT $NAME {$BODY}"
fi
;;
esac
done
echo " */" >> $TMPD
MD5TEXT=`echo "$TEXT" | ./mutt_md5`
echo "#define HCACHEVER 0x"`echo $MD5TEXT | cut -c-8` >> $TMPD
# TODO: validate we have all structs
mv $TMPD $DEST