예제 #1
0
/**
 * Parse a version string and check for invalid syntax.
 *
 * Distinguish between lax (warnings) and strict (error) parsing.
 *
 * @param rversion The parsed version.
 * @param string The version string to parse.
 * @param err The warning or error message if any.
 *
 * @retval  0 On success.
 * @retval -1 On failure, and err is set accordingly.
 */
int
parseversion(struct versionrevision *rversion, const char *string,
             struct dpkg_error *err)
{
  char *hyphen, *colon, *eepochcolon;
  const char *end, *ptr;
  unsigned long epoch;

  if (!*string)
    return dpkg_put_error(err, _("version string is empty"));

  /* Trim leading and trailing space. */
  while (*string && isblank(*string))
    string++;
  /* String now points to the first non-whitespace char. */
  end = string;
  /* Find either the end of the string, or a whitespace char. */
  while (*end && !isblank(*end))
    end++;
  /* Check for extra chars after trailing space. */
  ptr = end;
  while (*ptr && isblank(*ptr))
    ptr++;
  if (*ptr)
    return dpkg_put_error(err, _("version string has embedded spaces"));

  colon= strchr(string,':');
  if (colon) {
    epoch= strtoul(string,&eepochcolon,10);
    if (colon != eepochcolon)
      return dpkg_put_error(err, _("epoch in version is not number"));
    if (!*++colon)
      return dpkg_put_error(err, _("nothing after colon in version number"));
    string= colon;
    rversion->epoch= epoch;
  } else {
    rversion->epoch= 0;
  }
  rversion->version= nfstrnsave(string,end-string);
  hyphen= strrchr(rversion->version,'-');
  if (hyphen)
    *hyphen++ = '\0';
  rversion->revision= hyphen ? hyphen : "";

  /* XXX: Would be faster to use something like cisversion and cisrevision. */
  ptr = rversion->version;
  if (*ptr && !cisdigit(*ptr++))
    return dpkg_put_warn(err, _("version number does not start with digit"));
  for (; *ptr; ptr++) {
    if (!cisdigit(*ptr) && !cisalpha(*ptr) && strchr(".-+~:", *ptr) == NULL)
      return dpkg_put_warn(err, _("invalid character in version number"));
  }
  for (ptr = rversion->revision; *ptr; ptr++) {
    if (!cisdigit(*ptr) && !cisalpha(*ptr) && strchr(".+~", *ptr) == NULL)
      return dpkg_put_warn(err, _("invalid character in revision number"));
  }

  return 0;
}
예제 #2
0
파일: parsehelp.c 프로젝트: Minipig/dpkg
/**
 * Check for invalid syntax in version structure.
 *
 * The rest of the syntax has been already checked in parseversion_lax(). So
 * we only do the stricter checks here.
 *
 * @param rversion The version to verify.
 *
 * @return An error string, or NULL if eveyrthing was ok.
 */
static const char *
version_strict_check(struct versionrevision *rversion)
{
  const char *ptr;

  /* XXX: Would be faster to use something like cisversion and cisrevision. */
  ptr = rversion->version;
  if (*ptr && !cisdigit(*ptr++))
    return _("version number does not start with digit");
  for (; *ptr; ptr++) {
    if (!cisdigit(*ptr) && !cisalpha(*ptr) && strchr(".-+~:", *ptr) == NULL)
      return _("invalid character in version number");
  }
  for (ptr = rversion->revision; *ptr; ptr++) {
    if (!cisdigit(*ptr) && !cisalpha(*ptr) && strchr(".+~", *ptr) == NULL)
      return _("invalid character in revision number");
  }

  return NULL;
}
예제 #3
0
파일: version.c 프로젝트: nisc-code/dpkg
/**
 * Give a weight to the character to order in the version comparison.
 *
 * @param c An ASCII character.
 */
static int
order(int c)
{
	if (cisdigit(c))
		return 0;
	else if (cisalpha(c))
		return c;
	else if (c == '~')
		return -1;
	else if (c)
		return c + 256;
	else
		return 0;
}
예제 #4
0
파일: string.c 프로젝트: smcv/dpkg
/**
 * Quote shell metacharacters in a string.
 *
 * This function allows passing strings to commands without splitting the
 * arguments, like in system(3)
 *
 * @param src The source string to escape.
 *
 * @return The new allocated string (never NULL).
 */
char *
str_quote_meta(const char *src)
{
	char *new_dst, *dst;

	new_dst = dst = m_malloc(strlen(src) * 2);

	while (*src) {
		if (!cisdigit(*src) && !cisalpha(*src))
			*dst++ = '\\';

		*dst++ = *src++;
	}

	*dst = '\0';

	return new_dst;
}
예제 #5
0
void main()
{
    char x;
    printf("Enter any character: ");
    scanf("%c", &x);

    if(cisalpha(x))
    {
        if(cisupper(x))
            printf("Uppercase Alphabet");
        else
            printf("Lowercase Alphabet");
    }

    else if(cisdigit(x))
        printf("Number");

    else
        printf("Special symbol");

}