예제 #1
0
html_menu html_menu_new(void)
{
    html_menu m;
    cstring arr[4];

    if ((m = malloc(sizeof *m)) == NULL)
        return NULL;

    if ((m->items = list_new()) == NULL) {
        free(m);
        return NULL;
    }

    if (!cstring_multinew(arr, 4)) {
        list_free(m->items, free);
        free(m);
        return NULL;
    }

    m->text = arr[0];
    m->image = arr[1];
    m->hover_image = arr[2];
    m->link = arr[3];

    return m;
}
예제 #2
0
파일: cstring.c 프로젝트: timburks/highland
/*
 * 1. Count the number of words
 * 2. Allocate space for an array of cstrings. 
 * 3. Allocate each cstring.
 * 4. Copy each word
 */
size_t cstring_split(cstring** dest, const char* src, const char* delim)
{
	const char* s;
	size_t end, i, len, nelem;

	assert(dest != NULL);
	assert(src != NULL);
	assert(delim != NULL);

	/* Skip to first substring */
	len = strlen(src);
	s = src + strspn(src, delim);

	/* Only delimiters in src */
	if(s - src == (int)len) 
		return 0;

	/* Count elements */
	for(nelem = 0; *s != '\0'; nelem++) {
		s += strcspn(s, delim);
		s += strspn(s, delim);
	}

	/* allocate space */
	if( (*dest = mem_malloc(sizeof **dest * nelem)) == NULL)
		return 0;
	else if(cstring_multinew(*dest, nelem) == 0) {
		mem_free(*dest);
		return 0;
	}

	/* Now copy */
	s = src + strspn(src, delim); /* start of first substring */
	for(i = 0; *s != '\0'; i++) {
		end = strcspn(s, delim);
		if(!cstring_pcat((*dest)[i], s, s + end)) {
			cstring_multifree(*dest, nelem);
			return 0;
		}

		s += end;
		s += strspn(s, delim);
	}

	return nelem;
}
예제 #3
0
page_attribute attribute_new(void)
{
    page_attribute p;
    cstring arr[4];

    if ((p = calloc(1, sizeof *p)) == NULL)
        return NULL;

    if (!cstring_multinew(arr, sizeof arr / sizeof *arr)) {
        free(p);
        return NULL;
    }

    p->media_type = arr[0];
    p->language = arr[1];
    p->charset = arr[2];
    p->encoding = arr[3];

    return p;
}
예제 #4
0
파일: cookies.c 프로젝트: timburks/highland
cookie cookie_new(void)
{
	cookie p;
	cstring arr[5];

	if( (p = malloc(sizeof *p)) == NULL)
		;
	else if(!cstring_multinew(arr, 5)) {
		free(p);
		p = NULL;
	}
	else  {
		p->name = arr[0];
		p->value = arr[1];
		p->domain = arr[2];
		p->path = arr[3];
		p->comment = arr[4];
		p->max_age = MAX_AGE_NOT_SET;
		p->secure = 0;
		p->version = 1; /* default acc. to rfc2109 */
	}

	return p;
}