Esempio n. 1
0
int	match(char *str, char *match)
{
  int	i;
  int	j;
  int	m_res;

  i = 0;
  j = 0;
  while (str[i] != '\0' && match[j] != '\0')
  {
    avance_match(match, &j);
    m_res = char_match(str[i], match[j]);
    if (m_res == -1)
      return (0);
    if (m_res == 0)
      ++j;
    else if (m_res == 1)
      if (match[j + 1] == '\0')
        return (1);
      else if (char_match(str[i], match[j + 1]) == 0)
        j += 2;
    ++i;
  }
  avance_match(match, &j);
  if (str[i] == '\0' && match[j] == '*' && match[j + 1] == '\0')
    return (1);
  return (match[j] == '\0' ? 1 : 0);
}
Esempio n. 2
0
int	id_count_word_charset(char* str, char* charset)
{
	int     i;
	int     count_word;

	i = 0;
	count_word = 0;
	while (str[i] != 0)
	{
	        if (char_match(str[i], charset) == 1)
	                count_word = count_word + 1;
	        i = i + 1;
	}
	return count_word;
}
Esempio n. 3
0
// a version of strtok(), recognises identifiers, integers, and single-char symbols
// NB: very unsafe; not re-entrant. Use with caution!
char *get_token (char *pLine)
{
  static char *pNext;
  static char saved;
  char *pToken = NULL;

  if (pLine)
    {
      pNext = pLine;
    }
  else if (pNext)
    {
      *pNext = saved;
    }

  if (!pNext)
    return NULL;

  // skip white space
  while (*pNext && char_match (*pNext, " \t\n") )
    {
      pNext ++;
    }

  if (*pNext == 0)
    // reached end of string
    return NULL;
  else
    {
      // find next token
      pToken = pNext;

      if (isalpha (*pNext))
        {
          // identifier is alpha (alpha|digit|"_")*
          while (*pNext && ( isalpha(*pNext) || isdigit(*pNext) || (*pNext == '_' ) ) )
            {
              pNext ++;
            }
        }
      else if (isdigit (*pNext) || char_match (*pNext, "+-"))
        {
          // number is [+|-] (digit)+ [. digit+]
          pNext ++;
          while (*pNext && isdigit (*pNext) )
            {
              pNext ++;
            }
          if (*pNext && *pNext == '.')
            {
              pNext ++;
              while (*pNext && isdigit (*pNext) )
                {
                  pNext ++;
                }
            }
        }
      else
        {
          // anything else is presumed to be single char token, e.g. "="
          pNext ++;
        }

      saved = *pNext;
      *pNext = 0;
      return pToken;
    }
}