Generated from the greek.def file:
/* -*- buffer-read-only: t -*- vi: set ro:
*
* DO NOT EDIT THIS FILE (greek.c)
*
* It has been AutoGen-ed Sunday February 18, 2007 at 12:18:38 PM PST
* From the definitions /home/bkorb/ag/addon/dispatch/greek.def
* and the template file dispatch.tpl
*/
#include <ctype.h>
#include <string.h>
#include "greek.h"
static int fumble;
static char const greek[48] =
"** INVALID **\0" "alpha\0" "beta\0" "gamma\0"
"delta\0" "omega\0" "help\0";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* The hash code was generated by "gperf(1GNU)" from the following:
*
* %{
* #include <stdio.h>
* %}
* struct greek_index { char const * name; int const idx; };
* %%
* alpha, 1
* beta, 2
* gamma, 3
* delta, 4
* omega, 5
* help, 6
* %%
*/
struct greek_index { char const * name; int const idx; };
/* maximum key range = 9, duplicates = 0 */
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
greek_hash (register const char *str, register unsigned int len)
{
static const unsigned char asso_values[] =
{
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 7, 5, 13,
2, 13, 13, 5, 0, 13, 13, 13, 13, 13,
13, 0, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
13, 13, 13, 13, 13, 13
};
return len + asso_values[(unsigned char)str[0]];
}
#ifdef __GNUC__
__inline
#endif
static const struct greek_index *
greek_find (register const char *str, register unsigned int len)
{
enum
{
TOTAL_KEYWORDS = 6,
MIN_WORD_LENGTH = 4,
MAX_WORD_LENGTH = 5,
MIN_HASH_VALUE = 4,
MAX_HASH_VALUE = 12
};
static const struct greek_index wordlist[] =
{
{(char*)0}, {(char*)0}, {(char*)0}, {(char*)0},
{"help", 6},
{"omega", 5},
{(char*)0},
{"delta", 4},
{(char*)0},
{"beta", 2},
{"gamma", 3},
{(char*)0},
{"alpha", 1}
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = greek_hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register const char *s = wordlist[key].name;
if (s && *str == *s && !strcmp (str + 1, s + 1))
return &wordlist[key];
}
}
return 0;
}
/*
* END of gperf code
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
greek_enum_t
greek_enum(char const * name, char const ** next)
{
size_t nmlen = 0;
char name_buf[6];
/*
* Skip leading white space and figure out how many name characters
* there are. It cannot be longer than the longest name in our table.
*/
while (isspace(*name)) name++;
if (isalpha(*name)) {
char const * ps = name;
char * pd = name_buf;
for (;;) {
char ch = *(ps++);
if (isupper(ch))
*(pd++) = _tolower(ch);
else if (isalnum(ch))
*(pd++) = ch;
else switch (ch) {
case '-':
case '_': *(pd++) = '_'; break;
default: goto name_scan_done;
}
if (++nmlen > 5)
return GREEK_INVALID;
} name_scan_done:;
*pd = '\0';
}
if (nmlen == 0) {
greek_enum_t res = GREEK_INVALID;
/*
* If there were no name characters found, then
* check for commands triggerd by a single non-alpha character:
*/
switch (*name) {
case '?': /* help command alias */
res = GREEK_HELP;
name++;
break;
}
return (res);
}
if (nmlen >= 4) do {
struct greek_index const * pi = greek_find(name_buf, nmlen);
if (pi == NULL)
break;
if (next != NULL) {
name += nmlen;
while (isspace(*name)) name++;
*next = name;
}
return (greek_enum_t)pi->idx;
} while (0);
/*
* An exact match is not possible. Check for partial match.
*/
{
/*
* indexes of names in greek in alphabetical order.
*/
static int const alpha_ix[6] = {
14, 20, 31, 25, 43, 37
};
/*
* Map the alphabetized index into the enum value
*/
static int const enum_val[6] = {
GREEK_ALPHA, GREEK_BETA, GREEK_DELTA, GREEK_GAMMA, GREEK_HELP,
GREEK_OMEGA };
return (greek_enum_t)partial_name_match(
name_buf, greek, alpha_ix, enum_val, 5);
}
}
/*
* Translate the command code into the name
*/
char const *
greek_name(greek_enum_t cmd)
{
/*
* Table of name offsets indexed by the enum value
*/
static unsigned int const enum_idx[6] = {
14, 20, 25, 31, 37, 43 };
unsigned int ix = (unsigned int)cmd - 1;
if (ix > 5)
ix = 0;
else
ix = enum_idx[ix];
return greek + ix;
}
typedef int (handle_greek_t)(char const * cmd, void * cookie);
extern handle_greek_t greek_inval_greek,
greek_alpha, greek_beta, greek_gamma, greek_delta, greek_omega,
greek_help;
static handle_greek_t * const hdl_procs[7] = {
greek_inval_greek,
greek_alpha, greek_beta, greek_gamma, greek_delta, greek_omega,
greek_help };
int
dispatch_greek(char const * cmd, void * cookie)
{
greek_enum_t id = greek_enum(cmd, &cmd);
handle_greek_t * hdl = hdl_procs[id];
return (*hdl)(cmd, cookie);
}
/* end of greek.c */