EXIT AUTOCRAP \o/
[apps/madmutt.git] / lib-lua / lua-token.gperf
diff --git a/lib-lua/lua-token.gperf b/lib-lua/lua-token.gperf
new file mode 100644 (file)
index 0000000..73c6594
--- /dev/null
@@ -0,0 +1,172 @@
+#! /bin/sh -e
+
+die() {
+    echo "$@" 1>&2
+    exit 2
+}
+
+do_hdr() {
+    cat <<EOF
+/*
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or (at
+ *  your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful, but
+ *  WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  Copyright © 2007 Pierre Habouzit
+ */
+
+/*****     THIS FILE IS AUTOGENERATED DO NOT MODIFY DIRECTLY !    *****/
+
+EOF
+}
+
+do_h() {
+    do_hdr
+    cat <<EOF
+#ifndef MUTT_LIB_LUA_LUA_TOKEN_H
+#define MUTT_LIB_LUA_LUA_TOKEN_H
+
+typedef enum mlua_token {
+    LTK_UNKNOWN = -1,
+`grep_self "$0" | tr 'a-z-/' 'A-Z__' | sed -e 's/.*/    LTK_&,/'`
+    LTK_count,
+} mlua_token;
+
+extern const char *__mlua_token[LTK_count];
+
+__attribute__((pure))
+mlua_token mlua_which_token(const char *s, ssize_t len);
+#endif /* MUTT_LIB_LUA_LUA_TOKEN_H */
+EOF
+}
+
+do_tokens() {
+    while read tok; do
+        echo "$tok, LTK_`echo $tok | tr 'a-z-' 'A-Z_'`"
+    done
+}
+
+do_c() {
+    cat <<EOF | gperf -m16 -l -t -C -F",0" -Nmlua_which_token_aux
+%{
+`do_hdr`
+
+#include <lib-lib/lib-lib.h>
+#include "lua-token.h"
+
+static const struct tok *
+mlua_which_token_aux(const char *str, unsigned int len);
+
+%}
+struct tok { const char *name; int val; };
+%%
+`grep_self "$0" | do_tokens`
+%%
+
+const char *__mlua_token[LTK_count] = {
+`grep_self "$0" | sed -e 's/.*/    "&",/'`
+};
+
+mlua_token mlua_which_token(const char *s, ssize_t len)
+{
+    if (len < 0)
+        len = m_strlen(s);
+
+    if (len) {
+        const struct tok *res = mlua_which_token_aux(s, len);
+        return res ? res->val : LTK_UNKNOWN;
+    } else {
+        return LTK_UNKNOWN;
+    }
+}
+EOF
+}
+
+grep_self() {
+    grep '^## ' "$1" | cut -d' ' -f2
+}
+
+trap "rm -f $1" 1 2 3 15
+
+rm -f $1
+case "$1" in
+    *.h) do_h > $1;;
+    *.c) do_c > $1;;
+    *)  die "you must ask for the 'h' or 'c' generation";;
+esac
+chmod -w $1
+
+exit 0
+
+############ Put tokens here ############
+## alias_file
+## alias_format
+## ask-no
+## ask-yes
+## assumed_charset
+## autoencrypt
+## autopgp
+## autosign
+## autosmime
+## beep
+## beep_new
+## bindir
+## ca_certificates_file
+## cert_file
+## charset
+## docdir
+## dotlock
+## dsn_notify
+## dsn_return
+## editor
+## envelope_from_address
+## file_charset
+## force_tls
+## from
+## gecos_mask
+## hcache_backend
+## homedir
+## hostname
+## mailcap_path
+## mailcap_sanitize
+## mail_check
+## min_dh_prime_bits
+## no
+## operating_system
+## pgp_entry_format
+## quit
+## record
+## replyencrypt
+## replysign
+## replysignencrypted
+## send_charset
+## sendmail
+## sendmail_wait
+## shell
+## shorthost
+## signature
+## smime_is_default
+## spam_separator
+## starttls
+## sysconfdir
+## tmpdir
+## use_8bitmime
+## use_domain
+## use_envelope_from
+## username
+## use_sslv3
+## use_tlsv1
+## verify_sig
+## version
+## yes