1274116Sdteske/*- 2290275Sdteske * Copyright (c) 2002-2015 Devin Teske <dteske@FreeBSD.org> 3274116Sdteske * All rights reserved. 4274116Sdteske * 5274116Sdteske * Redistribution and use in source and binary forms, with or without 6274116Sdteske * modification, are permitted provided that the following conditions 7274116Sdteske * are met: 8274116Sdteske * 1. Redistributions of source code must retain the above copyright 9274116Sdteske * notice, this list of conditions and the following disclaimer. 10274116Sdteske * 2. Redistributions in binary form must reproduce the above copyright 11274116Sdteske * notice, this list of conditions and the following disclaimer in the 12274116Sdteske * documentation and/or other materials provided with the distribution. 13274116Sdteske * 14274116Sdteske * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15274116Sdteske * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16274116Sdteske * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17274116Sdteske * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18274116Sdteske * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19274116Sdteske * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20274116Sdteske * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21274116Sdteske * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22274116Sdteske * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23274116Sdteske * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24274116Sdteske * SUCH DAMAGE. 25274116Sdteske * 26274116Sdteske * $FreeBSD: releng/11.0/lib/libfigpar/figpar.h 290275 2015-11-02 20:03:59Z dteske $ 27274116Sdteske */ 28274116Sdteske 29274116Sdteske#ifndef _FIGPAR_H_ 30274116Sdteske#define _FIGPAR_H_ 31274116Sdteske 32274116Sdteske#include <sys/types.h> 33274116Sdteske 34274116Sdteske/* 35274116Sdteske * Union for storing various types of data in a single common container. 36274116Sdteske */ 37290275Sdteskeunion figpar_cfgvalue { 38274116Sdteske void *data; /* Pointer to NUL-terminated string */ 39274116Sdteske char *str; /* Pointer to NUL-terminated string */ 40274116Sdteske char **strarray; /* Pointer to an array of strings */ 41274116Sdteske int32_t num; /* Signed 32-bit integer value */ 42274116Sdteske uint32_t u_num; /* Unsigned 32-bit integer value */ 43274116Sdteske uint32_t boolean:1; /* Boolean integer value (0 or 1) */ 44274116Sdteske}; 45274116Sdteske 46274116Sdteske/* 47274116Sdteske * Option types (based on above cfgvalue union) 48274116Sdteske */ 49290275Sdteskeenum figpar_cfgtype { 50290275Sdteske FIGPAR_TYPE_NONE = 0x0000, /* directives with no value */ 51290275Sdteske FIGPAR_TYPE_BOOL = 0x0001, /* boolean */ 52290275Sdteske FIGPAR_TYPE_INT = 0x0002, /* signed 32 bit integer */ 53290275Sdteske FIGPAR_TYPE_UINT = 0x0004, /* unsigned 32 bit integer */ 54290275Sdteske FIGPAR_TYPE_STR = 0x0008, /* string pointer */ 55290275Sdteske FIGPAR_TYPE_STRARRAY = 0x0010, /* string array pointer */ 56290275Sdteske FIGPAR_TYPE_DATA1 = 0x0020, /* void data type-1 (open) */ 57290275Sdteske FIGPAR_TYPE_DATA2 = 0x0040, /* void data type-2 (open) */ 58290275Sdteske FIGPAR_TYPE_DATA3 = 0x0080, /* void data type-3 (open) */ 59290275Sdteske FIGPAR_TYPE_RESERVED1 = 0x0100, /* reserved data type-1 */ 60290275Sdteske FIGPAR_TYPE_RESERVED2 = 0x0200, /* reserved data type-2 */ 61290275Sdteske FIGPAR_TYPE_RESERVED3 = 0x0400, /* reserved data type-3 */ 62274116Sdteske}; 63274116Sdteske 64274116Sdteske/* 65274116Sdteske * Options to parse_config() for processing_options bitmask 66274116Sdteske */ 67290275Sdteske#define FIGPAR_BREAK_ON_EQUALS 0x0001 /* stop reading directive at `=' */ 68290275Sdteske#define FIGPAR_BREAK_ON_SEMICOLON 0x0002 /* `;' starts a new line */ 69290275Sdteske#define FIGPAR_CASE_SENSITIVE 0x0004 /* directives are case sensitive */ 70290275Sdteske#define FIGPAR_REQUIRE_EQUALS 0x0008 /* assignment directives only */ 71290275Sdteske#define FIGPAR_STRICT_EQUALS 0x0010 /* `=' must be part of directive */ 72274116Sdteske 73274116Sdteske/* 74274116Sdteske * Anatomy of a config file option 75274116Sdteske */ 76290275Sdteskestruct figpar_config { 77290275Sdteske enum figpar_cfgtype type; /* Option value type */ 78274116Sdteske const char *directive; /* config file keyword */ 79290275Sdteske union figpar_cfgvalue value; /* NB: set by action */ 80274116Sdteske 81274116Sdteske /* 82274116Sdteske * Function pointer; action to be taken when the directive is found 83274116Sdteske */ 84290275Sdteske int (*action)(struct figpar_config *option, uint32_t line, 85290275Sdteske char *directive, char *value); 86274116Sdteske}; 87290275Sdteskeextern struct figpar_config figpar_dummy_config; 88274116Sdteske 89274116Sdteske__BEGIN_DECLS 90290275Sdteskeint parse_config(struct figpar_config _options[], 91274116Sdteske const char *_path, 92290275Sdteske int (*_unknown)(struct figpar_config *_option, 93274116Sdteske uint32_t _line, char *_directive, char *_value), 94274116Sdteske uint16_t _processing_options); 95290275Sdteskestruct figpar_config *get_config_option(struct figpar_config _options[], 96274116Sdteske const char *_directive); 97274116Sdteske__END_DECLS 98274116Sdteske 99274116Sdteske#endif /* _FIGPAR_H_ */ 100