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  Saturday May 24, 2008 at 10:51:22 AM PDT
 * From the definitions    /home/bkorb/ag/addon/dispatch/greek.def
 * and the template file   dispatch.tpl
 *
 *  Recognizer generation options:
 *
 *  external scope
 *  gperf generated
 *  partial name matches are matched, if the match is unique
 *  A dispatch routine is generated that will call handler routines
 */

#include "greek.h"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *  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__
#else
#ifdef __cplusplus
#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__
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#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
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static struct greek_index const greek_mapping_table[] = {
    { "alpha",     1 },
    { "beta",      2 },
    { "delta",     4 },
    { "gamma",     3 },
    { "help",      6 },
    { "omega",     5 } };

extern 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';
    }

    {
        struct greek_index const * xlat = greek_find(name_buf, nmlen);
        if (xlat != NULL) {
            if (next != NULL) {
                name += nmlen;
                while (isspace(*name))   name++;
                *next = name;
            }

            return (greek_enum_t)xlat->idx;
        }
    }

    /* check for partial match: */
    {
        int av;
        int hi = 6 - 1;
        int lo = 0;
        for (;;) {
            int cmp;
            av = (hi + lo) / 2;
            cmp = strncmp(greek_mapping_table[av].name, name_buf, nmlen);
            if (cmp == 0)
                break;
            if (cmp < 0)
                lo = av + 1;
            else
                hi = av - 1;
            if (hi < lo)
                return GREEK_INVALID;
        }

        if ((av > 0) &&
            (strncmp(greek_mapping_table[av-1].name, name_buf, nmlen) == 0))
            return GREEK_INVALID;

        if ((av < 5) &&
            (strncmp(greek_mapping_table[av+1].name, name_buf, nmlen) == 0))
            return GREEK_INVALID;

        if (next != NULL) {
            name += nmlen;
            while (isspace(*name))   name++;
            *next = name;
        }

        return (greek_enum_t)greek_mapping_table[av].idx;
    }
}

extern char const *
greek_name(greek_enum_t cmd)
{
    /*
     *  Table of Command Names
     */
    static char const * const names[7] = {
        "** INVALID **", "alpha",         "beta",          "gamma",
        "delta",         "omega",         "help" };

    if ((unsigned)cmd > 6)
        cmd = GREEK_INVALID;

    return names[cmd];
}


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

extern handle_greek_t do_inval_greek,
    do_alpha, do_beta,  do_gamma, do_delta, do_omega, do_help;

static handle_greek_t * const hdl_procs[7] = {
    do_inval_greek,
    do_alpha, do_beta,  do_gamma, do_delta, do_omega, do_help };

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