Annotation of embedaddon/strongswan/src/libstrongswan/utils/printf_hook/printf_hook.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2009 Tobias Brunner
                      3:  * Copyright (C) 2006-2008 Martin Willi
                      4:  * HSR Hochschule fuer Technik Rapperswil
                      5:  *
                      6:  * This program is free software; you can redistribute it and/or modify it
                      7:  * under the terms of the GNU General Public License as published by the
                      8:  * Free Software Foundation; either version 2 of the License, or (at your
                      9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     10:  *
                     11:  * This program is distributed in the hope that it will be useful, but
                     12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     14:  * for more details.
                     15:  */
                     16: 
                     17: /**
                     18:  * @defgroup printf_hook printf_hook
                     19:  * @{ @ingroup utils
                     20:  */
                     21: 
                     22: #ifndef PRINTF_HOOK_H_
                     23: #define PRINTF_HOOK_H_
                     24: 
                     25: #include <stdlib.h>
                     26: 
                     27: typedef struct printf_hook_t printf_hook_t;
                     28: typedef struct printf_hook_spec_t printf_hook_spec_t;
                     29: typedef struct printf_hook_data_t printf_hook_data_t;
                     30: typedef enum printf_hook_argtype_t printf_hook_argtype_t;
                     31: 
                     32: #if defined(USE_VSTR)
                     33: # include "printf_hook_vstr.h"
                     34: #elif defined(USE_BUILTIN_PRINTF)
                     35: # include "printf_hook_builtin.h"
                     36: #endif
                     37: 
                     38: /**
                     39:  * Argument types to pass to printf hook.
                     40:  */
                     41: enum printf_hook_argtype_t {
                     42:        PRINTF_HOOK_ARGTYPE_END,
                     43:        PRINTF_HOOK_ARGTYPE_INT,
                     44:        PRINTF_HOOK_ARGTYPE_POINTER,
                     45: };
                     46: 
                     47: /**
                     48:  * Callback function type for printf hooks.
                     49:  *
                     50:  * @param data         hook data, to pass to print_in_hook()
                     51:  * @param spec         format specifier
                     52:  * @param args         arguments array
                     53:  * @return                     number of characters written
                     54:  */
                     55: typedef int (*printf_hook_function_t)(printf_hook_data_t *data,
                     56:                                                                          printf_hook_spec_t *spec,
                     57:                                                                          const void *const *args);
                     58: 
                     59: /**
                     60:  * Properties of the format specifier
                     61:  */
                     62: struct printf_hook_spec_t {
                     63: 
                     64:        /**
                     65:         * TRUE if a '#' was used in the format specifier
                     66:         */
                     67:        int hash;
                     68: 
                     69:        /**
                     70:         * TRUE if a '-' was used in the format specifier
                     71:         */
                     72:        int minus;
                     73: 
                     74:        /**
                     75:         * TRUE if a '+' was used in the format specifier
                     76:         */
                     77:        int plus;
                     78: 
                     79:        /**
                     80:         * The width as given in the format specifier.
                     81:         */
                     82:        int width;
                     83: };
                     84: 
                     85: /**
                     86:  * Printf handler management.
                     87:  */
                     88: struct printf_hook_t {
                     89: 
                     90:        /**
                     91:         * Register a printf handler.
                     92:         *
                     93:         * @param spec          printf hook format character
                     94:         * @param hook          hook function
                     95:         * @param ...           list of PRINTF_HOOK_ARGTYPE_*, MUST end with PRINTF_HOOK_ARGTYPE_END
                     96:         */
                     97:        void (*add_handler)(printf_hook_t *this, char spec,
                     98:                                                printf_hook_function_t hook, ...);
                     99: 
                    100:        /**
                    101:         * Destroy a printf_hook instance.
                    102:         */
                    103:        void (*destroy)(printf_hook_t *this);
                    104: };
                    105: 
                    106: /**
                    107:  * Create a printf_hook instance.
                    108:  */
                    109: printf_hook_t *printf_hook_create();
                    110: 
                    111: /**
                    112:  * Print with format string within a printf hook.
                    113:  *
                    114:  * @param data         hook data, as passed to printf hook
                    115:  * @param fmt          printf format string
                    116:  * @param ...          arguments to format string
                    117:  * @return                     number of characters written
                    118:  */
                    119: size_t print_in_hook(printf_hook_data_t *data, char *fmt, ...);
                    120: 
                    121: #endif /** PRINTF_HOOK_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>