1124536e5e80d4167d1577e65e3a24b65a979b17
[apps/madmutt.git] / lib-mime / rfc822hdrs.sh
1 #! /bin/sh
2
3 die() {
4     echo "$@" 1>&2
5     exit 2
6 }
7
8 do_h() {
9     echo "#ifndef MUTT_LIB_MIME_RFC822HDRS_H"
10     echo "#define MUTT_LIB_MIME_RFC822HDRS_H"
11     echo "/* THIS FILE IS AUTOGENERATED FROM $< DO NOT MODIFY */"
12     echo "enum rfc822hdr {"
13     echo "    HDR_UNKNOWN,"
14     tr 'a-z-' 'A-Z_' | sed -e 's/.*/    HDR_&,/'
15     echo "};"
16     echo
17     echo "enum rfc822hdr rfc822_well_known(const char *s);"
18     echo "#endif /* MUTT_LIB_MIME_RFC822HDRS_H */"
19 }
20
21 do_c() {
22     echo "%{"
23     echo "#include <string.h>"
24     echo "#include \"rfc822hdrs.h\""
25     echo "%}"
26     echo "struct hdr { const char *name; int val; };"
27     echo "%%"
28     awk '{print $$0 ", " NR }'
29     echo "%%"
30     echo "enum rfc822hdr rfc822_well_known(const char *s) {"
31     echo "    const struct hdr *res = in_word_set(s, strlen(s));"
32     echo "    return res ? res->val : HDR_UNKNOWN;"
33     echo "}"
34 }
35
36 case "$1" in
37     *.h) do_h > "$1" ;;
38     *.c) do_c | gperf --ignore-case -t -C -F,0 > "$1" ;;
39     *)  die "you must ask for the 'h' or 'c' generation" ;;
40 esac
41
42 exit 0