示例#1
0
Style *
new_style(const char *name, LList *spec)
{
	Style *style;
	Iterator *it;
	StrBuf *prebuf;
	StrBuf *postbuf;

	style = xmalloc(sizeof(Style));
	style->name = xstrdup(name);
	prebuf = strbuf_new();
	postbuf = strbuf_new();

	for (it = llist_iterator(spec); iterator_has_next(it); ) {
		StyleInfo *info = iterator_next(it);
		if (info->type == STYLEINFO_PRE) {
			strbuf_append(prebuf, info->value);
		} else if (info->type == STYLEINFO_POST) {
			strbuf_prepend(postbuf, info->value);
		} else if (info->type == STYLEINFO_STYLE) {
			const Style *add_style = info->value;
			strbuf_append(prebuf, add_style->pre_string);
			strbuf_prepend(postbuf, add_style->post_string);
		}
	}

	style->pre_string = strbuf_free_to_string(prebuf);
	style->post_string = strbuf_free_to_string(postbuf);
	style->refs = 1;

	return style;
}
示例#2
0
static unsigned char *
rle_decode(unsigned char *data, int datalen, int width, int *decoded_size)
{
	StrBuf *buf, *retbuf;
	unsigned char *ret, *tmp;
	int extra, x;

	buf = strbuf_new ();
	retbuf = strbuf_new ();

	extra = 4 - (width % 4);
	if (extra == 4) extra = 0;

	for (x = 0; x < datalen; x++) {
		if (data[x] == 0) {
			x++;
			tmp = (unsigned char *) strrepeat ("", 1, (int) data[x]);
			strbuf_append (buf, tmp, data[x]);
			free (tmp);
		} else
			strbuf_append (buf, &(data[x]), 1);
	}

	for (x = 0; x < buf->len; x += width) {
		if (extra > 0) {
			tmp = (unsigned char *) strrepeat ("", 1, extra);
			strbuf_prepend (retbuf, tmp, extra);
			free (tmp);
		}
		strbuf_prepend (retbuf, buf->str + x, width);
	}

	ret = retbuf->str;
	if (decoded_size) *decoded_size = retbuf->len;
	strbuf_free (retbuf, 0);
	strbuf_free (buf, 1);
	return ret;
}