Home | History | Annotate | Download | only in ltrace
      1 /*
      2  * This file is part of ltrace.
      3  * Copyright (C) 2011 Petr Machata, Red Hat Inc.
      4  *
      5  * This program is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU General Public License as
      7  * published by the Free Software Foundation; either version 2 of the
      8  * License, or (at your option) any later version.
      9  *
     10  * This program is distributed in the hope that it will be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU General Public License
     16  * along with this program; if not, write to the Free Software
     17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
     18  * 02110-1301 USA
     19  */
     20 
     21 #include <assert.h>
     22 
     23 #include "lens.h"
     24 #include "lens_default.h"
     25 #include "type.h"
     26 #include "value.h"
     27 
     28 int
     29 format_argument(FILE *stream, struct value *value,
     30 		struct value_dict *arguments)
     31 {
     32 	/* Find the closest enclosing parental value whose type has a
     33 	 * lens assigned.  */
     34 	struct value *parent;
     35 	for (parent = value; (parent != NULL && parent->type != NULL
     36 			      && parent->type->lens == NULL);
     37 	     parent = parent->parent)
     38 		;
     39 
     40 	struct lens *lens = &default_lens;
     41 	if (parent != NULL && parent->type != NULL
     42 	    && parent->type->lens != NULL)
     43 		lens = parent->type->lens;
     44 
     45 	return lens_format(lens, stream, value, arguments);
     46 }
     47 
     48 int
     49 lens_format(struct lens *lens, FILE *stream, struct value *value,
     50 	    struct value_dict *arguments)
     51 {
     52 	assert(lens->format_cb != NULL);
     53 	return lens->format_cb(lens, stream, value, arguments);
     54 }
     55 
     56 void
     57 lens_destroy(struct lens *lens)
     58 {
     59 	if (lens != NULL
     60 	    && lens->destroy_cb != NULL)
     61 		lens->destroy_cb(lens);
     62 }
     63