simplifications
[apps/madmutt.git] / rctokens.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_tokens() {
35     while read tok; do
36         echo "$tok, RCTK_`echo $tok | tr 'a-z-' 'A-Z_'`"
37     done
38 }
39
40 do_c() {
41     cat <<EOF | gperf --ignore-case -m16 -l -t -C -F",0" -Nrc_which_token_aux
42 %{
43 `do_hdr`
44
45 #include <lib-lib/lib-lib.h>
46 #include "rctoken.h"
47
48 static const struct tok *
49 rc_which_token_aux(const char *str, unsigned int len);
50
51 %}
52 struct tok { const char *name; int val; };
53 %%
54 `do_tokens`
55 %%
56
57 static int rc_which_token(const char *s, ssize_t len)
58 {
59     if (len < 0)
60         len = m_strlen(s);
61
62     if (len) {
63         const struct tok *res = rc_which_token_aux(s, len);
64         return res ? res->val : -1;
65     } else {
66         return -1;
67     }
68 }
69 EOF
70 }
71
72 trap "rm -f $1" 1 2 3 15
73 grep '^### ' < $0 | cut -d' ' -f2 | do_c
74
75 exit 0
76
77 #****************************************************************************#
78 #                          muttrc tokens list                                #
79 #****************************************************************************#
80 ### account-hook
81 ### alias
82 ### alternates
83 ### alternative_order
84 ### append-hook
85 ### attachments
86 ### auto_view
87 ### bind
88 ### charset-hook
89 ### close-hook
90 ### color
91 ### exec
92 ### fcc-hook
93 ### fcc-save-hook
94 ### folder-hook
95 ### hdr_order
96 ### open-hook
97 ### unalternates
98 ### unattachments
99 ### uncolor
100 ### iconv-hook
101 ### crypt-hook
102 ### ignore
103 ### lists
104 ### macro
105 ### mailboxes
106 ### mbox-hook
107 ### message-hook
108 ### mime_lookup
109 ### mono
110 ### my_hdr
111 ### nospam
112 ### pgp-hook
113 ### push
114 ### reply-hook
115 ### reset
116 ### save-hook
117 ### score
118 ### send2-hook
119 ### send-hook
120 ### set
121 ### source
122 ### spam
123 ### subscribe
124 ### toggle
125 ### unalias
126 ### unalternative_order
127 ### unauto_view
128 ### unhdr_order
129 ### unhook
130 ### unignore
131 ### unlists
132 ### unmailboxes
133 ### unmime_lookup
134 ### unmono
135 ### unmy_hdr
136 ### unscore
137 ### unset
138 ### unsubscribe