Blame lens.c

Packit 0021fb
/*
Packit 0021fb
 * This file is part of ltrace.
Packit 0021fb
 * Copyright (C) 2011 Petr Machata, Red Hat Inc.
Packit 0021fb
 *
Packit 0021fb
 * This program is free software; you can redistribute it and/or
Packit 0021fb
 * modify it under the terms of the GNU General Public License as
Packit 0021fb
 * published by the Free Software Foundation; either version 2 of the
Packit 0021fb
 * License, or (at your option) any later version.
Packit 0021fb
 *
Packit 0021fb
 * This program is distributed in the hope that it will be useful, but
Packit 0021fb
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0021fb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0021fb
 * General Public License for more details.
Packit 0021fb
 *
Packit 0021fb
 * You should have received a copy of the GNU General Public License
Packit 0021fb
 * along with this program; if not, write to the Free Software
Packit 0021fb
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit 0021fb
 * 02110-1301 USA
Packit 0021fb
 */
Packit 0021fb
Packit 0021fb
#include <assert.h>
Packit 0021fb
Packit 0021fb
#include "lens.h"
Packit 0021fb
#include "lens_default.h"
Packit 0021fb
#include "type.h"
Packit 0021fb
#include "value.h"
Packit 0021fb
Packit 0021fb
int
Packit 0021fb
format_argument(FILE *stream, struct value *value,
Packit 0021fb
		struct value_dict *arguments)
Packit 0021fb
{
Packit 0021fb
	/* Find the closest enclosing parental value whose type has a
Packit 0021fb
	 * lens assigned.  */
Packit 0021fb
	struct value *parent;
Packit 0021fb
	for (parent = value; (parent != NULL && parent->type != NULL
Packit 0021fb
			      && parent->type->lens == NULL);
Packit 0021fb
	     parent = parent->parent)
Packit 0021fb
		;
Packit 0021fb
Packit 0021fb
	struct lens *lens = &default_lens;
Packit 0021fb
	if (parent != NULL && parent->type != NULL
Packit 0021fb
	    && parent->type->lens != NULL)
Packit 0021fb
		lens = parent->type->lens;
Packit 0021fb
Packit 0021fb
	return lens_format(lens, stream, value, arguments);
Packit 0021fb
}
Packit 0021fb
Packit 0021fb
int
Packit 0021fb
lens_format(struct lens *lens, FILE *stream, struct value *value,
Packit 0021fb
	    struct value_dict *arguments)
Packit 0021fb
{
Packit 0021fb
	assert(lens->format_cb != NULL);
Packit 0021fb
	return lens->format_cb(lens, stream, value, arguments);
Packit 0021fb
}
Packit 0021fb
Packit 0021fb
void
Packit 0021fb
lens_destroy(struct lens *lens)
Packit 0021fb
{
Packit 0021fb
	if (lens != NULL
Packit 0021fb
	    && lens->destroy_cb != NULL)
Packit 0021fb
		lens->destroy_cb(lens);
Packit 0021fb
}