Example #1
0
/**
 * Search first the dynamic and then the static table for a matching keyword
 *
 * @param word    Pointer to the text -- NOT zero terminated
 * @param len     The length of the text
 * @return        CT_WORD (no match) or the keyword token
 */
c_token_t find_keyword_type(const char *word, int len)
{
   string            ss(word, len);
   chunk_tag_t       key;
   const chunk_tag_t *p_ret;

   if (len <= 0)
   {
      return(CT_NONE);
   }

   /* check the dynamic word list first */
   dkwmap::iterator it = dkwm.find(ss);
   if (it != dkwm.end())
   {
      return((*it).second);
   }

   key.tag = ss.c_str();

   /* check the static word list */
   p_ret = (const chunk_tag_t *)bsearch(&key, keywords, ARRAY_SIZE(keywords),
                                        sizeof(keywords[0]), kw_compare);
   if (p_ret != NULL)
   {
      p_ret = kw_static_match(p_ret);
   }
   return((p_ret != NULL) ? p_ret->type : CT_WORD);
}
Example #2
0
/**
 * Adds a keyword to the list of dynamic keywords
 *
 * @param tag        The tag (string) must be zero terminated
 * @param type       The type, usually CT_TYPE
 */
void add_keyword(const char *tag, c_token_t type)
{
   string ss = tag;

   /* See if the keyword has already been added */
   dkwmap::iterator it = dkwm.find(ss);
   if (it != dkwm.end())
   {
      LOG_FMT(LDYNKW, "%s: changed '%s' to %d\n", __func__, tag, type);
      (*it).second = type;
      return;
   }

   /* Insert the keyword */
   dkwm.insert(dkwmap::value_type(ss, type));
   LOG_FMT(LDYNKW, "%s: added '%s' as %d\n", __func__, tag, type);
}