Exemplo n.º 1
0
static int
find_rule(char *word, int index, Rule *rules)
{
  Rule *rule;
  char *left, *match, *right, *output;
  int remainder;

  for (;;)			/* Search for the rule */
    {
      rule = rules++;
      match = (*rule)[1];

      if (match == 0)		/* bad symbol! */
	{
	  fprintf(stderr,
		  "Error: Can't find rule for: '%c' in \"%s\"\n", word[index], word);
	  return index+1;	/* Skip it! */
	}

      for (remainder = index; *match != '\0'; match++, remainder++)
	{
	  if (*match != word[remainder])
	    break;
	}

      if (*match != '\0')	/* found missmatch */
	continue;
      /*
	 printf("\nWord: \"%s\", Index:%4d, Trying: \"%s/%s/%s\" = \"%s\"\n",
	 word, index, (*rule)[0], (*rule)[1], (*rule)[2], (*rule)[3]);
	 */
      left = (*rule)[0];
      right = (*rule)[2];

      if (!leftmatch(left, &word[index-1]))
	continue;
      /*
	 printf("leftmatch(\"%s\",\"...%c\") succeded!\n", left, word[index-1]);
	 */
      if (!rightmatch(right, &word[remainder]))
	continue;
      /*
	 printf("rightmatch(\"%s\",\"%s\") succeded!\n", right, &word[remainder]);
	 */
      output = (*rule)[3];
      /*
	 printf("Success: ");
	 */
      dmk_outstring(output);
      return remainder;
    }
}
Exemplo n.º 2
0
static int find_rule(darray *arg, char *word, int index, Rule *rules)
{
	for (;;)                         /* Search for the rule */
	{
		Rule *rule;
		const char *left,
			*match,
			*right,
			*output;
		int remainder;
		rule = rules++;
		match = (*rule)[1];

		if (match == 0)
			/* bad symbol! */
		{
			fprintf(stderr, "Error: Can't find rule for: '%c' in \"%s\"\n",
				word[index], word);
			return index + 1;            /* Skip it! */
		}

		for (remainder = index; *match != '\0'; match++, remainder++)
		{
			if (*match != word[remainder])
				break;
		}

		if (*match != '\0')
			continue;                     /* found missmatch */

		left = (*rule)[0];

		right = (*rule)[2];

		if (!leftmatch(left, &word[index - 1]))
			continue;

		if (!rightmatch(right, &word[remainder]))
			continue;

		output = (*rule)[3];

		phone_cat(arg, output);

		return remainder;
	}
}
Exemplo n.º 3
0
Arquivo: text.c Projeto: EQ4/rsynth
static int
find_rule(void *arg, out_p out, unsigned char *word, int index, Rule *rules)
{        
 if (rule_debug)
  printf("Looking for %c in %c rules\n",word[index],*rules->match);
 for (;;)                         /* Search for the rule */
  {
   Rule *rule = rules++;
   unsigned char *match = (unsigned char *) rule->match;
   int remainder;
   if (match == 0) /* bad symbol! */
    {
     if (rule_debug)
      fprintf(stderr, "Error: Can't find rule for: '%c' in \"%s\"\n",
             word[index], word);
     return index + 1;            /* Skip it! */
    }
   for (remainder = index; *match != '\0'; match++, remainder++)
    {
     if (*match != word[remainder])
      break;
    }
   if (*match != '\0')
    {
     continue;                     /* found missmatch */
    }

   if (!leftmatch((unsigned char *) rule->left, &word[index - 1]))
    continue;

   if (!rightmatch((unsigned char *) rule->right, &word[remainder]))
    continue;

   if (rule_debug)
    printf("...%s|%s|%s...=> %s succeded!\n", rule->left, rule->match, rule->right, rule->output); 

   (*out) (arg, rule->output);
   return remainder;
  }
}