4 * @brief General purpose definitions and macros.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 #include "definitions.h"
32 static char *enum_name(enum_name_t
*e
, long val
)
36 if (val
>= e
->first
&& val
<= e
->last
)
38 return e
->names
[val
- e
->first
];
41 while ((e
= e
->next
));
47 * output handler in printf() for enum names
49 static int print_enum(FILE *stream
, const struct printf_info
*info
,
50 const void *const *args
)
52 enum_name_t
*ed
= *((void**)(args
[0]));
53 long val
= *((size_t*)(args
[1]));
56 name
= enum_name(ed
, val
);
59 return fprintf(stream
, "(unknown enum value: %ld)", val
);
61 return fprintf(stream
, "%s", name
);
65 * arginfo handler in printf() for enum names
67 static int print_enum_arginfo(const struct printf_info
*info
, size_t n
, int *argtypes
)
72 argtypes
[0] = PA_POINTER
;
80 * register printf() handlers for enum names
82 static void __attribute__ ((constructor
))print_register()
84 register_printf_function(ENUM_PRINTF_SPEC
, print_enum
, print_enum_arginfo
);