int main(void)
{
  char s1[] = "Hello";
  char s2[] = "HellomynameisJo";

  printf("%d\n", strings_compare(s1, s2));
  printf("%d\n", strings_compare(s2, s1));
  printf("%d\n", strings_compare(s1, s1));
  return (0);
}
int main(void)
{
  char s1[] = "Hello";
  char s2[] = "Horld!";

  printf("%d\n", strings_compare(s1, s2));
  printf("strcmp: %d\n", strcmp(s1, s2));
  printf("%d\n", strings_compare(s2, s1));
  printf("strcmp: %d\n", strcmp(s2, s1));
  printf("%d\n", strings_compare(s1, s1));
  printf("strcmp: %d\n", strcmp(s1, s1));
  return (0);
}
/*
 * Function that returns a malloc'd string containing
 * the env value.
 * CHECKED: functions, length, width, brackets TODO comments...
 */
char *get_env(char *check, char **env)
{
	int i = 0;
	char **env_var;
	char *ret;
	char *ptr;
	while (env[i] != NULL) {
		env_var = string_split(env[i], '=');
		if (strings_compare(env_var[0], check) == 0) {
			/* found variable */
			ptr = env[i];
			while (*ptr != '=') {
			ptr++;
		}
		ptr++;
		ret = malloc(sizeof(char) * (str_len(ptr)+1));
		string_copy(ret, ptr);
		free_command(env_var);
		return ret;
	}
	free_command(env_var);
	i++;
	}
	return 0;
}
Example #4
0
/*
 * Executes the given command's function. If successful,
 * returns 1 (true), otherwise, returns 0 (false).
 */
static int execute_command(const char *cmd)//bool
{
	unsigned int i = 0;
	const char *name = allowable_commands[i].name;
	while (!strings_compare(name, "END_OF_TABLE"))
	{
		name = allowable_commands[i].name;
		if (strings_compare(cmd, name))
		{
			function_pointer p = allowable_commands[i].execute;
			(*p)();
			return 1;//true - found the function and executed it
		}
		else
		{
			i++;
		}
	}

	return 0;//false - never found the function
}
Example #5
0
static int pattern_compare (const void *arg1, const void *arg2, void *arg3)
{
  const FcPattern *p1 = *(FcPattern * const *)arg1;
  const FcPattern *p2 = *(FcPattern * const *)arg2;
  const char **el = (const char **)arg3;
  FcChar8 *string1, *string2;
  int int1, int2;
  FcBool bool1, bool2;
  FcLangSet *langset1, *langset2;
  double double1, double2;
  int ret = 0;

  while (*el)
  {
    /* string */
    if (!strcmp(*el, FC_FAMILY) || !strcmp(*el, FC_STYLE) || !strcmp(*el, FC_FONTFORMAT))
    {
      if (FcPatternGetString (p1, *el, 0, &string1) == FcResultMatch &&
	  FcPatternGetString (p2, *el, 0, &string2) == FcResultMatch) 
        ret = strings_compare((char *)string1, (char *)string2);
    }
    /* integer */
    else if (!strcmp(*el, FC_WEIGHT) || !strcmp(*el, FC_WIDTH) ||
	     !strcmp(*el, FC_SLANT) || !strcmp(*el, FC_SPACING))
    {
      if (FcPatternGetInteger(p1, *el, 0, &int1) == FcResultMatch && 
	  FcPatternGetInteger(p2, *el, 0, &int2) == FcResultMatch)
	ret = int2 - int1;
    }
    /* bool */
    else if (!strcmp(*el, FC_SCALABLE) || !strcmp(*el, FC_DECORATIVE))
    {
      if (FcPatternGetBool(p1, *el, 0, &bool1) == FcResultMatch &&
	  FcPatternGetBool(p1, *el, 0, &bool2) == FcResultMatch)
       ret = bool2 - bool1;
    }
    /* double */
    else if (!strcmp(*el, FC_PIXEL_SIZE))
    {
      if (FcPatternGetDouble(p1, *el, 0, &double1) == FcResultMatch &&
	  FcPatternGetDouble(p2, *el, 0, &double2) == FcResultMatch)
	ret = fabs(double1 - SIZE_MEAN) - fabs(double2 - SIZE_MEAN);
    }
    /* lang set */
    else if (!strcmp(*el, FC_LANG))
    {
      /* to choose size of bitmap font which supports widest range of langs */
      /* maybe charset would be better? */
      if (FcPatternGetLangSet(p1, *el, 0, &langset1) == FcResultMatch &&
	  FcPatternGetLangSet(p2, *el, 0, &langset2) == FcResultMatch)
      {
        ret = 0;
	if (FcLangSetContains(langset1, langset2))
	  ret = -1;
	if (FcLangSetContains(langset2, langset1))
        {
          if (ret == -1)
            ret = 0; /* langset1 <= langset2 & langset1 >= langset2 */
          else
    	    ret = 1;
        }
      }
    }

    if (ret)
      break;

    el++;
  }

  return ret;
}