remove most of the debug code: often makes the code unreadable, for little
[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 -l -t -C -F,0
53 %{
54 `do_hdr`
55
56 #include <lib-lib/str.h>
57 #include "mime-token.h"
58
59 %}
60 struct tok { const char *name; int val; };
61 %%
62 `awk '{print $0 ", " NR }'`
63 %%
64
65 enum mime_token mime_which_token(const char *s, ssize_t len) {
66     const struct tok *res;
67
68     if (len < 0)
69         len = m_strlen(s);
70     if (!len)
71         return MUTT_MIME_TOKEN_UNKNOWN;
72
73     res = in_word_set(s, len);
74     return res ? res->val : MUTT_MIME_TOKEN_UNKNOWN;
75 }
76 EOF
77 }
78
79 trap "rm -f $1" 1 2 3 15
80
81 case "$1" in
82     *.h) do_h > "$1";;
83     *.c) do_c > "$1";;
84     *)  die "you must ask for the 'h' or 'c' generation";;
85 esac
86
87 exit 0