some simplifications.
[apps/madmutt.git] / lib-mime / mime-token.sh
1 #! /bin/sh -e
2
3 die() {
4     echo "$@" 1>&2
5     exit 2
6 }
7
8 do_hdr() {
9     cat <<EOF
10 /*
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or (at
14  *  your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful, but
17  *  WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  *  General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24  *  MA 02110-1301, USA.
25  *
26  *  Copyright © 2006 Pierre Habouzit
27  */
28
29 /*****     THIS FILE IS AUTOGENERATED DO NOT MODIFY DIRECTLY !    *****/
30
31 EOF
32 }
33
34 do_h() {
35     do_hdr
36     cat <<EOF
37 #ifndef MUTT_LIB_MIME_MIME_TOKEN_H
38 #define MUTT_LIB_MIME_MIME_TOKEN_H
39
40 enum mime_token {
41     MUTT_MIME_TOKEN_UNKNOWN,
42 `tr 'a-z-/' 'A-Z__' | sed -e 's/.*/    MIME_&,/'`
43 };
44
45 __attribute__((pure))
46 enum mime_token mime_which_token(const char *s, ssize_t len);
47 #endif /* MUTT_LIB_MIME_MIME_TOKEN_H */
48 EOF
49 }
50
51 do_c() {
52     cat <<EOF | gperf --ignore-case -m16 -l -t -C -F",0" -Nmime_which_token_aux
53 %{
54 `do_hdr`
55
56 #include <lib-lib/lib-lib.h>
57 #include "mime-token.h"
58
59 static const struct tok *
60 mime_which_token_aux(const char *str, unsigned int len);
61
62 %}
63 struct tok { const char *name; int val; };
64 %%
65 `awk '{print $0 ", " NR }'`
66 %%
67
68 enum mime_token mime_which_token(const char *s, ssize_t len)
69 {
70     if (len < 0)
71         len = m_strlen(s);
72
73     if (len) {
74         const struct tok *res = mime_which_token_aux(s, len);
75         return res ? res->val : MUTT_MIME_TOKEN_UNKNOWN;
76     } else {
77         return MUTT_MIME_TOKEN_UNKNOWN;
78     }
79 }
80 EOF
81 }
82
83 trap "rm -f $1" 1 2 3 15
84
85 case "$1" in
86     *.h) do_h > "$1";;
87     *.c) do_c > "$1";;
88     *)  die "you must ask for the 'h' or 'c' generation";;
89 esac
90
91 exit 0