2014-11-04 23:46:01 +00:00
|
|
|
/*-
|
2015-11-02 20:03:59 +00:00
|
|
|
* Copyright (c) 2002-2015 Devin Teske <dteske@FreeBSD.org>
|
2014-11-04 23:46:01 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _FIGPAR_H_
|
|
|
|
#define _FIGPAR_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Union for storing various types of data in a single common container.
|
|
|
|
*/
|
2015-11-02 20:03:59 +00:00
|
|
|
union figpar_cfgvalue {
|
2014-11-04 23:46:01 +00:00
|
|
|
void *data; /* Pointer to NUL-terminated string */
|
|
|
|
char *str; /* Pointer to NUL-terminated string */
|
|
|
|
char **strarray; /* Pointer to an array of strings */
|
|
|
|
int32_t num; /* Signed 32-bit integer value */
|
|
|
|
uint32_t u_num; /* Unsigned 32-bit integer value */
|
|
|
|
uint32_t boolean:1; /* Boolean integer value (0 or 1) */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Option types (based on above cfgvalue union)
|
|
|
|
*/
|
2015-11-02 20:03:59 +00:00
|
|
|
enum figpar_cfgtype {
|
|
|
|
FIGPAR_TYPE_NONE = 0x0000, /* directives with no value */
|
|
|
|
FIGPAR_TYPE_BOOL = 0x0001, /* boolean */
|
|
|
|
FIGPAR_TYPE_INT = 0x0002, /* signed 32 bit integer */
|
|
|
|
FIGPAR_TYPE_UINT = 0x0004, /* unsigned 32 bit integer */
|
|
|
|
FIGPAR_TYPE_STR = 0x0008, /* string pointer */
|
|
|
|
FIGPAR_TYPE_STRARRAY = 0x0010, /* string array pointer */
|
|
|
|
FIGPAR_TYPE_DATA1 = 0x0020, /* void data type-1 (open) */
|
|
|
|
FIGPAR_TYPE_DATA2 = 0x0040, /* void data type-2 (open) */
|
|
|
|
FIGPAR_TYPE_DATA3 = 0x0080, /* void data type-3 (open) */
|
|
|
|
FIGPAR_TYPE_RESERVED1 = 0x0100, /* reserved data type-1 */
|
|
|
|
FIGPAR_TYPE_RESERVED2 = 0x0200, /* reserved data type-2 */
|
|
|
|
FIGPAR_TYPE_RESERVED3 = 0x0400, /* reserved data type-3 */
|
2014-11-04 23:46:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Options to parse_config() for processing_options bitmask
|
|
|
|
*/
|
2015-11-02 20:03:59 +00:00
|
|
|
#define FIGPAR_BREAK_ON_EQUALS 0x0001 /* stop reading directive at `=' */
|
|
|
|
#define FIGPAR_BREAK_ON_SEMICOLON 0x0002 /* `;' starts a new line */
|
|
|
|
#define FIGPAR_CASE_SENSITIVE 0x0004 /* directives are case sensitive */
|
|
|
|
#define FIGPAR_REQUIRE_EQUALS 0x0008 /* assignment directives only */
|
|
|
|
#define FIGPAR_STRICT_EQUALS 0x0010 /* `=' must be part of directive */
|
2014-11-04 23:46:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Anatomy of a config file option
|
|
|
|
*/
|
2015-11-02 20:03:59 +00:00
|
|
|
struct figpar_config {
|
|
|
|
enum figpar_cfgtype type; /* Option value type */
|
2014-11-04 23:46:01 +00:00
|
|
|
const char *directive; /* config file keyword */
|
2015-11-02 20:03:59 +00:00
|
|
|
union figpar_cfgvalue value; /* NB: set by action */
|
2014-11-04 23:46:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function pointer; action to be taken when the directive is found
|
|
|
|
*/
|
2015-11-02 20:03:59 +00:00
|
|
|
int (*action)(struct figpar_config *option, uint32_t line,
|
|
|
|
char *directive, char *value);
|
2014-11-04 23:46:01 +00:00
|
|
|
};
|
2015-11-02 20:03:59 +00:00
|
|
|
extern struct figpar_config figpar_dummy_config;
|
2014-11-04 23:46:01 +00:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
2015-11-02 20:03:59 +00:00
|
|
|
int parse_config(struct figpar_config _options[],
|
2014-11-04 23:46:01 +00:00
|
|
|
const char *_path,
|
2015-11-02 20:03:59 +00:00
|
|
|
int (*_unknown)(struct figpar_config *_option,
|
2014-11-04 23:46:01 +00:00
|
|
|
uint32_t _line, char *_directive, char *_value),
|
|
|
|
uint16_t _processing_options);
|
2015-11-02 20:03:59 +00:00
|
|
|
struct figpar_config *get_config_option(struct figpar_config _options[],
|
2014-11-04 23:46:01 +00:00
|
|
|
const char *_directive);
|
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* _FIGPAR_H_ */
|