[lua] More madmutt package upgrades:
[apps/madmutt.git] / lib-lua / lua-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 © 2007 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_LUA_LUA_TOKEN_H
38 #define MUTT_LIB_LUA_LUA_TOKEN_H
39
40 enum lua_token {
41     LTK_UNKNOWN,
42 `tr 'a-z-/' 'A-Z__' | sed -e 's/.*/    LTK_&,/'`
43 };
44
45 __attribute__((pure))
46 enum lua_token lua_which_token(const char *s, ssize_t len);
47 #endif /* MUTT_LIB_LUA_LUA_TOKEN_H */
48 EOF
49 }
50
51 do_c() {
52     cat <<EOF | gperf -m16 -l -t -C -F",0" -Nlua_which_token_aux
53 %{
54 `do_hdr`
55
56 #include <lib-lib/lib-lib.h>
57 #include "lua-token.h"
58
59 static const struct tok *
60 lua_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 lua_token lua_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 = lua_which_token_aux(s, len);
75         return res ? res->val : LTK_UNKNOWN;
76     } else {
77         return LTK_UNKNOWN;
78     }
79 }
80 EOF
81 }
82
83 grep_self() {
84     grep '^## ' "$1" | cut -d' ' -f2
85 }
86
87 trap "rm -f $1" 1 2 3 15
88
89 rm -f $1
90 case "$1" in
91     *.h) grep_self "$0" | do_h > $1;;
92     *.c) grep_self "$0" | do_c > $1;;
93     *)  die "you must ask for the 'h' or 'c' generation";;
94 esac
95 chmod -w $1
96
97 exit 0
98
99 ############ Put tokens here ############
100 ## shell
101 ## sendmail