Esempio n. 1
0
/*
 * Convert a sexpr list into a C array of vals.  E.g.,
 *
 *     '(A B C)
 *
 * turns into a VT_ARRAY containing:
 *
 *     { A, B, C }
 */
struct val *sexpr_list_to_val_array(struct val *list)
{
	struct val **arr;
	ssize_t len;
	int ret;

	len = sexpr_length(val_getref(list));
	if (len < 0) {
		val_putref(list);
		return ERR_PTR(-EINVAL);
	}

	arr = mem_reallocarray(NULL, len, sizeof(struct val *));
	if (!arr) {
		val_putref(list);
		return ERR_PTR(-ENOMEM);
	}

	ret = sexpr_list_to_array(list, arr, len);
	if (ret != len) {
		free(arr);
		return ERR_PTR(-EINVAL);
	}

	return val_alloc_array(arr, len);
}
Esempio n. 2
0
int panel_alloc(struct panel **panelp, const char *label,
		unsigned yoffs, int width, int height)
{
	struct panel *panel;
	int err;

	if (!panelp || !width || !height)
		return EINVAL;

	panel = mem_zalloc(sizeof(*panel), destructor);
	if (!panel)
		return ENOMEM;

	err = str_dup(&panel->label, label);
	if (err)
		goto out;

	panel->size.w = width;
	panel->size.h = height;
	panel->yoffs = yoffs;
	panel->xoffs = TEXT_WIDTH;

	panel->size_text.w = TEXT_WIDTH;
	panel->size_text.h = height;

	panel->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
						    panel->size_text.w,
						    panel->size_text.h);
	panel->cr = cairo_create(panel->surface);
	if (!panel->surface || !panel->cr) {
		warning("vidinfo: cairo error\n");
		return ENOMEM;
	}

	cairo_select_font_face (panel->cr, "Hyperfont",
				CAIRO_FONT_SLANT_NORMAL,
				CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (panel->cr, height-2);

	panel->rrdc  = 0;
	panel->rrdsz = (width - TEXT_WIDTH) / 2;
	panel->rrdv  = mem_reallocarray(NULL, panel->rrdsz,
					sizeof(*panel->rrdv), NULL);
	if (!panel->rrdv) {
		err = ENOMEM;
		goto out;
	}

	tmr_start(&panel->tmr, 0, tmr_handler, panel);

	info("new panel '%s' (%u x %u) with RRD size %u\n",
	     label, width, height, panel->rrdsz);

 out:
	if (err)
		mem_deref(panel);
	else
		*panelp = panel;

	return err;
}