Example #1
0
static t_buff	get_line(const int fd, char **line, t_buff b)
{
	unsigned int	line_pos;
	char			*l;

	line_pos = 0;
	if (fd != b.buf_fd || b.buf_pos >= BUFF_SIZE || b.eof < 0)
		b = read_buffer(fd, b);
	while (b.buff[b.buf_pos] != '\n' && b.buf_pos < b.eof && b.eof > -1)
	{
		if (((line_pos + 1) % L_LEN == 0) || line_pos == 0)
			l = re_malloc(l, line_pos);
		l[line_pos] = b.buff[b.buf_pos];
		line_pos++;
		b.buf_pos++;
		if (b.buf_pos >= BUFF_SIZE)
			b = read_buffer(fd, b);
	}
	if ((b.eof < BUFF_SIZE && b.eof != -1) && (b.eof <= b.buf_pos))
		b.eof = -2;
	b.buf_pos++;
	if (line_pos == 0)
		*line = 0;
	else
		*line = l;
	return (b);
}
Example #2
0
CHAR_TYPE* re_ansi_to_unicode(const char* s)
{
    size_t sz;
    CHAR_TYPE* data;
    
    sz = mbstowcs(NULL, s, 0);
    if(sz == (size_t)-1)
        return NULL;
    
    data = re_malloc((sz + 1) * sizeof(CHAR_TYPE));
    if(!data)
        return NULL;
    mbstowcs(data, s, sz + 1);

    return data;
}
Example #3
0
char* re_unicode_to_ansi(const CHAR_TYPE* s)
{
    size_t sz;
    char* data;

    sz = wcstombs(NULL, s, 0);
    if(sz == (size_t)-1)
        return NULL;

    data = re_malloc((sz + 1) * sizeof(char));
    if(!data)
        return NULL;
    wcstombs(data, s, sz + 1);
    
    return data;
}
Example #4
0
/*
 - reg_sub_w - perform substitutions
 */
int re_sub_w(const regexp* rp, const CHAR_TYPE* s, const CHAR_TYPE* source, CHAR_TYPE** dest)
{
    /* note: there can only be 10 expressions (\0 to \9) */
    regmatch matches[10];
    int error;

    if(dest)
        *dest = NULL;
	if (rp == NULL || source == NULL || s == NULL || dest == NULL) {
		re_report("NULL parameter to regsub");
		return REGEXP_BADARG;
	}
	if ((UCHAR_TYPE)*(rp->program) != MAGIC) {
		re_report("damaged regexp");
		return REGEXP_BADARG;
	}
    /* figure out how much room is needed */
    if((error = re_subcount_w(rp, s, source, matches)) < 1)
        return error;

    /* allocate memory */
    *dest = (CHAR_TYPE*)re_malloc(error * sizeof(CHAR_TYPE));
    if(!*dest)
    {
        re_report("out of memory allocating substitute destination");
        return REGEXP_ESPACE;
    }
    
    /* do actual substitution */
    if((error = re_dosub_w(s, source, matches, *dest)) < 0)
    {
        re_cfree(*dest);
        *dest = NULL;
        return error;
    }
    /* done */
    return error;
}
Example #5
0
  size_t new_st_size;

  /* if name is found, return its position: */
  St_ptr_type tmp = st_lookup(name);
  if (tmp != ST_NULL) return tmp;

D( printf("st entry: %d\n",st_pos); )

  /* allocate new memory if necessary: */
  if(st_pos == st_size)
  { 
    /* increase the size of st: */
    new_st_size = st_size + ST_SIZE_ADD;
    /* reallocate memory with self-made realloc-function: */
    st = re_malloc(st, 
		   (size_t) (st_size * sizeof (St_type)),
		   (size_t) (new_st_size * sizeof (St_type)));

    /* store the new st size for the next re_malloc:*/
    st_size = new_st_size;

D( printf("st_insert: re_malloc newsize = %d\n", st_size); st_out();)
  }

  /* insert name in the ST name field: */
  st[st_pos].name = malloc(strlen(name) + 1);
  if (st == NULL) err_prt(ERR_MEM);

  strcpy(st[st_pos].name, name);

  /* preset the other ST fields: */