Пример #1
0
void print_keywords(FILE *pfile)
{
   for (dkwmap::iterator it = dkwm.begin(); it != dkwm.end(); ++it)
   {
      c_token_t tt = (*it).second;
      if (tt == CT_TYPE)
      {
         fprintf(pfile, "type %*.s%s\n",
                 cpd.max_option_name_len - 4, " ", (*it).first.c_str());
      }
      else if (tt == CT_MACRO_OPEN)
      {
         fprintf(pfile, "macro-open %*.s%s\n",
                 cpd.max_option_name_len - 11, " ", (*it).first.c_str());
      }
      else if (tt == CT_MACRO_CLOSE)
      {
         fprintf(pfile, "macro-close %*.s%s\n",
                 cpd.max_option_name_len - 12, " ", (*it).first.c_str());
      }
      else if (tt == CT_MACRO_ELSE)
      {
         fprintf(pfile, "macro-else %*.s%s\n",
                 cpd.max_option_name_len - 11, " ", (*it).first.c_str());
      }
      else
      {
         const char *tn = get_token_name(tt);

         fprintf(pfile, "set %s %*.s%s\n", tn,
                 int(cpd.max_option_name_len - (4 + strlen(tn))), " ", (*it).first.c_str());
      }
   }
}
Пример #2
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);
}
Пример #3
0
void output_types(FILE *pfile)
{
   if (dkwm.size() > 0)
   {
      fprintf(pfile, "-== User Types ==-\n");
      for (dkwmap::iterator it = dkwm.begin(); it != dkwm.end(); ++it)
      {
         fprintf(pfile, "%s\n", (*it).first.c_str());
      }
   }
}
Пример #4
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);
}