8dc5a8356e88b5a9f5ee28ab1feeb6c56295e68c
[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 = -1,
42 `tr 'a-z-/' 'A-Z__' | sed -e 's/.*/    LTK_&,/'`
43     LTK_count,
44 };
45
46 __attribute__((pure))
47 enum lua_token lua_which_token(const char *s, ssize_t len);
48 #endif /* MUTT_LIB_LUA_LUA_TOKEN_H */
49 EOF
50 }
51
52 do_tokens() {
53     while read tok; do
54         echo "$tok, LTK_`echo $tok | tr 'a-z-' 'A-Z_'`"
55     done
56 }
57
58 do_c() {
59     cat <<EOF | gperf -m16 -l -t -C -F",0" -Nlua_which_token_aux
60 %{
61 `do_hdr`
62
63 #include <lib-lib/lib-lib.h>
64 #include "lua-token.h"
65
66 static const struct tok *
67 lua_which_token_aux(const char *str, unsigned int len);
68
69 %}
70 struct tok { const char *name; int val; };
71 %%
72 `do_tokens`
73 %%
74
75 enum lua_token lua_which_token(const char *s, ssize_t len)
76 {
77     if (len < 0)
78         len = m_strlen(s);
79
80     if (len) {
81         const struct tok *res = lua_which_token_aux(s, len);
82         return res ? res->val : LTK_UNKNOWN;
83     } else {
84         return LTK_UNKNOWN;
85     }
86 }
87 EOF
88 }
89
90 grep_self() {
91     grep '^## ' "$1" | cut -d' ' -f2
92 }
93
94 trap "rm -f $1" 1 2 3 15
95
96 rm -f $1
97 case "$1" in
98     *.h) grep_self "$0" | do_h > $1;;
99     *.c) grep_self "$0" | do_c > $1;;
100     *)  die "you must ask for the 'h' or 'c' generation";;
101 esac
102 chmod -w $1
103
104 exit 0
105
106 ############ Put tokens here ############
107 ## dotlock
108 ## editor
109 ## quit
110 ## sendmail
111 ## shell
112 ## tmpdir