Ejemplo n.º 1
0
static unsigned char *string_getnextword(unsigned char *in, int size, int pos, int *newpos)
{
	int n;
	int at;
	int len;
	unsigned char *out;

	at = pos;

	// skip any space at the start
	while(at < size && char_isspace(in[at]))
		++at;

	// all space?  no word then
	if(at >= size)
		return 0;

	// skip until a space or end
	n = at;
	while(n < size && !char_isspace(in[n]))
		++n;
	len = n - at;

	// allocate length + zero byte
	out = (unsigned char *)jdns_alloc(len + 1);
	if(!out)
		return 0;
	memcpy(out, in + at, len);
	out[len] = 0;
	*newpos = at + len;
	return out;
}
Ejemplo n.º 2
0
static int i_sdup_conv(void *value, int n, void *inbuf)
{
  struct jelio_buf *jb = inbuf;
  char **sval = value;
  int c,count=0, wcount=0;
  size_t ulen, mlen;
  
  *sval = NULL;
  
  /* scan past whitespace */
  for(c = jelio_buffer_peekc(jb);char_isspace(c);c = jelio_buffer_peekc(jb))
    {
      jelio_buffer_getc(jb);
      wcount++;
    }
  
  while(1)
    {
      c = jelio_buffer_peekc(jb);
      if(c == -1 || char_isspace(c))
	break;
      count++;
      jelio_buffer_getc(jb);
      sbuprintv(sval, &ulen, &mlen, 1024*1024, "%%", o_c(c));
    }
  if(!count)
    {
      if(c == -1) return -1;
      return 0;
    }
  return count+wcount;
}
Ejemplo n.º 3
0
Archivo: i_xs.c Proyecto: jelaas/jelio
static int i_xs_conv(void *value, int n, void *inbuf)
{
  struct jelio_buf *jb = inbuf;
  unsigned char *sval = value;
  unsigned int c;
  int count=0;
  int scount=0;
  int flag = 0;
  
  /* scan past whitespace */
  for(c = jelio_buffer_peekc(jb);char_isspace(c);c = jelio_buffer_peekc(jb))
    {
      jelio_buffer_getc(jb);
      count++;
    }
  if(n < 1) return 0;
  
  while(1)
    {
      if(scount >= n)
	break;
      c = jelio_buffer_peekc(jb);
      if(c == -1 || char_isspace(c))
	break;
      if( (c < '0' || c > '9') && (c < 'a' || c > 'f'))
	break;
      count++;
      if(flag)
	{
	  if(c >= '0' && c <= '9')
	    *sval++ += (c - '0');
	  else
	    *sval++ += (c - 'a' + 10);
	  scount++;
	  flag = 0;
	}
      else
	{
	  if(c >= '0' && c <= '9')
	    *sval = (c - '0') << 4;
	  else
	    *sval = (c - 'a' + 10) << 4;
	  flag = 1;
	}
      jelio_buffer_getc(jb);
    }
  return count;
}
Ejemplo n.º 4
0
Archivo: i_uid.c Proyecto: jelaas/jelio
static int i_uid_conv(void *value, int n, void *inbuf)
{
  struct jelio_buf *jb = inbuf;
  uid_t *ival = value;
  int c,count=0, wcount=0;

  *ival = 0;

  /* scan past whitespace */
  for(c = jelio_buffer_peekc(jb);char_isspace(c);c = jelio_buffer_peekc(jb))
    {
      jelio_buffer_getc(jb);
      wcount++;
    }

  while(1)
    {
      c = jelio_buffer_peekc(jb);
      if(c < '0' || c > '9')
	break;
      count++;
      jelio_buffer_getc(jb);
      *ival *= 10;
      *ival += c -'0';
    }
  if(!count) return 0;
  return count+wcount;
}
Ejemplo n.º 5
0
Archivo: str.c Proyecto: hollow/lucid
int str_check(const char *str, int allowed)
{
	int i, n;

	if (!str)
		return 1;

	n = str_len(str);

	for (i = 0; i < n; i++) {
		if (allowed & CC_ALNUM  && char_isalnum (str[i])) continue;
		if (allowed & CC_ALPHA  && char_isalpha (str[i])) continue;
		if (allowed & CC_ASCII  && char_isascii (str[i])) continue;
		if (allowed & CC_BLANK  && char_isblank (str[i])) continue;
		if (allowed & CC_CNTRL  && char_iscntrl (str[i])) continue;
		if (allowed & CC_DIGIT  && char_isdigit (str[i])) continue;
		if (allowed & CC_GRAPH  && char_isgraph (str[i])) continue;
		if (allowed & CC_LOWER  && char_islower (str[i])) continue;
		if (allowed & CC_PRINT  && char_isprint (str[i])) continue;
		if (allowed & CC_PUNCT  && char_ispunct (str[i])) continue;
		if (allowed & CC_SPACE  && char_isspace (str[i])) continue;
		if (allowed & CC_UPPER  && char_isupper (str[i])) continue;
		if (allowed & CC_XDIGIT && char_isxdigit(str[i])) continue;

		return 0;
	}

	return 1;
}
Ejemplo n.º 6
0
Archivo: str.c Proyecto: hollow/lucid
int str_toumax(const char *str, unsigned long long int *val, int base, int n)
{
	unsigned long long int v = 0;
	const char *p = str;
	int d, minus = 0;
	char c;

	while (n && char_isspace((unsigned char) *p)) {
		p++;
		n--;
	}

	/* Single optional + or - */
	if (n) {
		c = *p;

		if (c == '-' || c == '+') {
			minus = (c == '-');
			p++;
			n--;
		}
	}

	if (base == 0) {
		if (n >= 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
			n -= 2;
			p += 2;
			base = 16;
		}

		else if (n >= 1 && p[0] == '0') {
			n--;
			p++;
			base = 8;
		}

		else {
			base = 10;
		}
	}

	else if (base == 16) {
		if (n >= 2 && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
			n -= 2;
			p += 2;
		}
	}

	while (n && (d = char_todigit(*p)) >= 0 && d < base) {
		v = v * base + d;
		n--;
		p++;
	}

	if (p - str > 0)
		*val = minus ? -v : v;

	return p - str;
}
Ejemplo n.º 7
0
Archivo: i_d.c Proyecto: jelaas/jelio
static int i_d_conv(void *value, int n, void *inbuf)
{
  struct jelio_buf *jb = inbuf;
  int *ival = value;
  int c,count=0, wcount=0;
  int mult = 1;

  if(ival) *ival = 0;

  /* scan past whitespace */
  for(c = jelio_buffer_peekc(jb);char_isspace(c);c = jelio_buffer_peekc(jb))
    {
      jelio_buffer_getc(jb);
      wcount++;
    }

  c = jelio_buffer_peekc(jb);
  if(c == '-')
    {
      mult = -1;
      jelio_buffer_getc(jb);
      wcount++;
    }
  else
    {
      if(c == '+')
	{
	  jelio_buffer_getc(jb);
	  wcount++;
	}
    }
  
  while(1)
    {
      c = jelio_buffer_peekc(jb);
      if(c < '0' || c > '9')
	break;
      count++;
      jelio_buffer_getc(jb);
      if(ival)
	{
	  *ival *= 10;
	  *ival += c -'0';
	}
    }
  if(ival) *ival *= mult;
  if(!count)
    {
      if(c == -1) return -1;
      return 0;
    }
  return count+wcount;
}
Ejemplo n.º 8
0
static int
str_8bit_isspace (const char *text)
{
    return char_isspace (text[0]);
}