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 October  1, 2006 at 12:59:13 PM PDT
 * 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"          "delta\0"
    "gamma\0"         "help\0"          "omega\0";

char const * const greek_ap[6] = {
    greek + 14, greek + 20, greek + 25, greek + 31, greek + 37, greek + 42 };
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *  The hash code was generated by "gperf(1GNU)" from the following:
 *
 *  %{
 *  #include <stdio.h>
 *  typedef struct index t_index;
 *  %}
 *  struct index { char* name; int idx; };
 *  %%
 *  alpha, 1
 *  beta, 2
 *  delta, 3
 *  gamma, 4
 *  help, 5
 *  omega, 6
 *  %%
 */

#include <stdio.h>
typedef struct index t_index;
struct index { char* name; int idx; };
#define TOTAL_KEYWORDS 6
#define MIN_WORD_LENGTH 4
#define MAX_WORD_LENGTH 5
#define MIN_HASH_VALUE 4
#define MAX_HASH_VALUE 15
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static unsigned int
hash (str, len)
     register const char *str;
     register unsigned int len;
{
  static unsigned char asso_values[] =
    {
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16,  0,  5, 16,
       2,  0, 16,  5,  0, 16, 16, 16,  0,  0,
      16,  5,  0, 16, 16, 16,  0, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
      16, 16, 16, 16, 16, 16
    };
  register int hval = len;
  switch (hval)
    {
      default:
        hval += asso_values[(unsigned char)str[4]];
      case 4:
        hval += asso_values[(unsigned char)str[3]];
      case 3:
        hval += asso_values[(unsigned char)str[2]];
      case 2:
        hval += asso_values[(unsigned char)str[1]];
      case 1:
        hval += asso_values[(unsigned char)str[0]];
        break;
    }
  return hval;
}
#ifdef __GNUC__
__inline
#endif
struct index *
in_word_set (str, len)
     register const char *str;
     register unsigned int len;
{
  static struct index wordlist[] =
    {
      {"help", 5},
      {"alpha", 1},
      {"delta", 3},
      {"beta", 2},
      {"gamma", 4},
      {"omega", 6}
    };
  static short lookup[] =
    {
      -1, -1, -1, -1,  0,  1, -1,  2, -1,  3,  4, -1, -1, -1,
      -1,  5
    };
  if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
    {
      register int key = hash (str, len);
      if (key <= MAX_HASH_VALUE && key >= 0)
        {
          register int index = lookup[key];
          if (index >= 0)
            {
              register const char *s = wordlist[index].name;
              if (*str == *s && !strcmp (str + 1, s + 1))
                return &wordlist[index];
            }
        }
    }
  return 0;
}
/*
 *  END of gperf code
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

greek_enum_t
greek_enum(char const * name, char const ** next)
{
    size_t nmlen = 0;
    int    hi_ix = 5;
    int    lo_ix = 0;
    int    av_ix = 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 there were no name characters found, bail out now.
     * Check for commands triggerd by a single non-alpha character:
     */
    if (nmlen == 0) {
        switch (*name) {
        case '?':  /* help command alias */
             av_ix = GREEK_HELP - 1;
             name++;
             goto return_successfully;
        }
        return GREEK_INVALID;
    }

    /*
     *  First, let's try hashing the name.  If we have an exact match, we'll
     *  hash straight to it.  Don't bother if name shorter than shortest name.
     */
    if (nmlen >= 4) {
	t_index * pi = in_word_set(name_buf, nmlen);

	if (pi != NULL) {
	    av_ix = pi->idx - 1;
	    goto return_successfully;
	}
    }

    /*
     *  An exact match is not possible.  Check for partial match.
     */
    for (;;) {
        int cmp;
        char const * pz;

        av_ix = (hi_ix + lo_ix) / 2;
        pz    = greek_ap[av_ix];
        cmp   = strncmp(pz, name_buf, nmlen);

        if (cmp == 0) break; /* found a partial */

        if (cmp < 0)
             lo_ix = av_ix + 1;
        else hi_ix = av_ix - 1;

        if (lo_ix > hi_ix)
            return GREEK_INVALID;
    }

    /*
     *  See if there are any other partial matches.
     */
    if (av_ix > 0) {
	int cmp = strncmp(greek_ap[av_ix-1], name_buf, nmlen);
        if (cmp == 0)
            return GREEK_INVALID;
    }

    if (av_ix < 5) {
	int cmp = strncmp(greek_ap[av_ix+1], name_buf, nmlen);
	if (cmp == 0)
	    return GREEK_INVALID;
    }

 return_successfully:

    if (next != NULL) {
	name += nmlen;
	while ((*name == '\t') || (*name == ' '))   name++;
	*next = name;
    }
    return (greek_enum_t)(av_ix+1);
}

/*
 * Translate the command code into the name
 */
char const *
greek_name(greek_enum_t cmd)
{
    unsigned int ix = (unsigned int)cmd - 1;
    return (ix > 5) ? greek : greek_ap[ix];
}

typedef int (handle_greek_t)(char const * cmd, void * cookie);

extern handle_greek_t greek_inval_greek,
    greek_alpha, greek_beta,  greek_delta, greek_gamma, greek_help,
    greek_omega;

static handle_greek_t * const hdl_procs[7] = {
    greek_inval_greek,
    greek_alpha, greek_beta,  greek_delta, greek_gamma, greek_help,
    greek_omega };

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 */