Make figpar(3) types/macros [more] unique (s/fp_/figpar_/gi)
This commit is contained in:
parent
232e189a56
commit
9d9cc24662
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2013-2014 Devin Teske <dteske@FreeBSD.org>
|
||||
* Copyright (c) 2013-2015 Devin Teske <dteske@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -49,58 +49,58 @@ char gauge_color[STR_BUFSIZE] = "47b"; /* (BLUE,WHITE,ON) */
|
||||
char separator[STR_BUFSIZE] = "";
|
||||
|
||||
/* Function prototypes */
|
||||
static int setattr(struct fp_config *, uint32_t, char *, char *);
|
||||
static int setbool(struct fp_config *, uint32_t, char *, char *);
|
||||
static int setnum(struct fp_config *, uint32_t, char *, char *);
|
||||
static int setstr(struct fp_config *, uint32_t, char *, char *);
|
||||
static int setattr(struct figpar_config *, uint32_t, char *, char *);
|
||||
static int setbool(struct figpar_config *, uint32_t, char *, char *);
|
||||
static int setnum(struct figpar_config *, uint32_t, char *, char *);
|
||||
static int setstr(struct figpar_config *, uint32_t, char *, char *);
|
||||
|
||||
/*
|
||||
* Anatomy of DIALOGRC (~/.dialogrc by default)
|
||||
* NOTE: Must appear after private function prototypes (above)
|
||||
* NB: Brace-initialization of union requires cast to *first* member of union
|
||||
*/
|
||||
static struct fp_config dialogrc_config[] = {
|
||||
/* TYPE Directive DEFAULT HANDLER */
|
||||
{FP_TYPE_INT, "aspect", {(void *)0}, &setnum},
|
||||
{FP_TYPE_STR, "separate_widget", {separator}, &setstr},
|
||||
{FP_TYPE_INT, "tab_len", {(void *)0}, &setnum},
|
||||
{FP_TYPE_BOOL, "visit_items", {(void *)0}, &setbool},
|
||||
{FP_TYPE_BOOL, "use_shadow", {(void *)1}, &setbool},
|
||||
{FP_TYPE_BOOL, "use_colors", {(void *)1}, &setbool},
|
||||
{FP_TYPE_STR, "screen_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "shadow_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "dialog_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "title_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "border_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_active_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_inactive_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_key_active_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_key_inactive_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_label_active_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "button_label_inactive_color",{NULL}, &setattr},
|
||||
{FP_TYPE_STR, "inputbox_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "inputbox_border_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "searchbox_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "searchbox_title_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "searchbox_border_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "position_indicator_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "menubox_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "menubox_border_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "item_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "item_selected_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "tag_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "tag_selected_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "tag_key_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "tag_key_selected_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "check_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "check_selected_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "uarrow_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "darrow_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "itemhelp_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "form_active_text_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "form_text_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "form_item_readonly_color", {NULL}, &setattr},
|
||||
{FP_TYPE_STR, "gauge_color", {gauge_color}, &setattr},
|
||||
static struct figpar_config dialogrc_config[] = {
|
||||
/* TYPE DIRECTIVE DEFAULT HANDLER */
|
||||
{FIGPAR_TYPE_INT, "aspect", {(void *)0}, &setnum},
|
||||
{FIGPAR_TYPE_STR, "separate_widget", {separator}, &setstr},
|
||||
{FIGPAR_TYPE_INT, "tab_len", {(void *)0}, &setnum},
|
||||
{FIGPAR_TYPE_BOOL, "visit_items", {(void *)0}, &setbool},
|
||||
{FIGPAR_TYPE_BOOL, "use_shadow", {(void *)1}, &setbool},
|
||||
{FIGPAR_TYPE_BOOL, "use_colors", {(void *)1}, &setbool},
|
||||
{FIGPAR_TYPE_STR, "screen_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "shadow_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "dialog_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "title_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "border_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_active_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_inactive_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_key_active_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_key_inactive_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_label_active_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "button_label_inactive_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "inputbox_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "inputbox_border_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "searchbox_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "searchbox_title_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "searchbox_border_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "position_indicator_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "menubox_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "menubox_border_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "item_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "item_selected_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "tag_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "tag_selected_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "tag_key_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "tag_key_selected_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "check_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "check_selected_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "uarrow_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "darrow_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "itemhelp_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "form_active_text_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "form_text_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "form_item_readonly_color", {NULL}, &setattr},
|
||||
{FIGPAR_TYPE_STR, "gauge_color", {gauge_color}, &setattr},
|
||||
{0, NULL, {0}, NULL}
|
||||
};
|
||||
|
||||
@ -108,7 +108,7 @@ static struct fp_config dialogrc_config[] = {
|
||||
* figpar call-back for interpreting value as .dialogrc `Attribute'
|
||||
*/
|
||||
static int
|
||||
setattr(struct fp_config *option, uint32_t line __unused,
|
||||
setattr(struct figpar_config *option, uint32_t line __unused,
|
||||
char *directive __unused, char *value)
|
||||
{
|
||||
char *cp = value;
|
||||
@ -204,7 +204,7 @@ setattr(struct fp_config *option, uint32_t line __unused,
|
||||
* figpar call-back for interpreting value as .dialogrc `Boolean'
|
||||
*/
|
||||
static int
|
||||
setbool(struct fp_config *option, uint32_t line __unused,
|
||||
setbool(struct figpar_config *option, uint32_t line __unused,
|
||||
char *directive __unused, char *value)
|
||||
{
|
||||
|
||||
@ -227,7 +227,7 @@ setbool(struct fp_config *option, uint32_t line __unused,
|
||||
* figpar call-back for interpreting value as .dialogrc `Number'
|
||||
*/
|
||||
static int
|
||||
setnum(struct fp_config *option, uint32_t line __unused,
|
||||
setnum(struct figpar_config *option, uint32_t line __unused,
|
||||
char *directive __unused, char *value)
|
||||
{
|
||||
|
||||
@ -247,7 +247,7 @@ setnum(struct fp_config *option, uint32_t line __unused,
|
||||
* figpar call-back for interpreting value as .dialogrc `String'
|
||||
*/
|
||||
static int
|
||||
setstr(struct fp_config *option, uint32_t line __unused,
|
||||
setstr(struct figpar_config *option, uint32_t line __unused,
|
||||
char *directive __unused, char *value)
|
||||
{
|
||||
size_t len;
|
||||
@ -315,7 +315,8 @@ parse_dialogrc(void)
|
||||
}
|
||||
|
||||
/* Process file (either $DIALOGRC if set, or `$HOME/.dialogrc') */
|
||||
res = parse_config(dialogrc_config, path, NULL, FP_BREAK_ON_EQUALS);
|
||||
res = parse_config(dialogrc_config,
|
||||
path, NULL, FIGPAR_BREAK_ON_EQUALS);
|
||||
|
||||
/* Set some globals based on what we parsed */
|
||||
use_shadow = dialogrc_config_option("use_shadow")->value.boolean;
|
||||
@ -328,10 +329,10 @@ parse_dialogrc(void)
|
||||
|
||||
/*
|
||||
* Return a pointer to the `.dialogrc' config option specific to `directive' or
|
||||
* static fp_dummy_config (full of NULLs) if none found (see
|
||||
* static figpar_dummy_config (full of NULLs) if none found (see
|
||||
* get_config_option(3); part of figpar(3)).
|
||||
*/
|
||||
struct fp_config *
|
||||
struct figpar_config *
|
||||
dialogrc_config_option(const char *directive)
|
||||
{
|
||||
return (get_config_option(dialogrc_config, directive));
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2013-2014 Devin Teske <dteske@FreeBSD.org>
|
||||
* Copyright (c) 2013-2015 Devin Teske <dteske@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -50,7 +50,7 @@ extern char separator[];
|
||||
__BEGIN_DECLS
|
||||
void dialogrc_free(void);
|
||||
int parse_dialogrc(void);
|
||||
struct fp_config *dialogrc_config_option(const char *_directive);
|
||||
struct figpar_config *dialogrc_config_option(const char *_directive);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_DIALOGRC_H_ */
|
||||
|
@ -24,7 +24,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd Oct 22, 2015
|
||||
.Dd Nov 2, 2015
|
||||
.Dt FIGPAR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -38,13 +38,13 @@
|
||||
.In figpar.h
|
||||
.Ft int
|
||||
.Fo parse_config
|
||||
.Fa "struct fp_config options[], const char *path"
|
||||
.Fa "int \*[lp]*unknown\*[rp]\*[lp]struct fp_config *option, uint32_t line"
|
||||
.Fa "struct figpar_config options[], const char *path"
|
||||
.Fa "int \*[lp]*unknown\*[rp]\*[lp]struct figpar_config *option, uint32_t line"
|
||||
.Fa "char *directive, char *value\*[rp], uint8_t processing_options"
|
||||
.Fc
|
||||
.Ft "struct fp_config *"
|
||||
.Ft "struct figpar_config *"
|
||||
.Fo get_config_option
|
||||
.Fa "struct fp_config options[], const char *directive"
|
||||
.Fa "struct figpar_config options[], const char *directive"
|
||||
.Fc
|
||||
.In string_m.h
|
||||
.Ft int
|
||||
@ -91,32 +91,32 @@ Configuration directives, types, and callback functions are provided through
|
||||
data structures defined in
|
||||
.In figpar.h :
|
||||
.Bd -literal -offset indent
|
||||
struct fp_config {
|
||||
enum fp_cfgtype type; /* value type */
|
||||
const char *directive; /* keyword */
|
||||
union fp_cfgvalue value; /* value */
|
||||
struct figpar_config {
|
||||
enum figpar_cfgtype type; /* value type */
|
||||
const char *directive; /* keyword */
|
||||
union figpar_cfgvalue value; /* value */
|
||||
|
||||
/* Pointer to function used when directive is found */
|
||||
int (*action)(struct fp_config *option, uint32_t line,
|
||||
int (*action)(struct figpar_config *option, uint32_t line,
|
||||
char *directive, char *value);
|
||||
};
|
||||
|
||||
enum fp_cfgtype {
|
||||
FP_TYPE_NONE = 0x0000, /* for directives with no value */
|
||||
FP_TYPE_BOOL = 0x0001, /* boolean */
|
||||
FP_TYPE_INT = 0x0002, /* signed 32 bit integer */
|
||||
FP_TYPE_UINT = 0x0004, /* unsigned 32 bit integer */
|
||||
FP_TYPE_STR = 0x0008, /* string pointer */
|
||||
FP_TYPE_STRARRAY = 0x0010, /* string array pointer */
|
||||
FP_TYPE_DATA1 = 0x0020, /* void data type-1 (whatever) */
|
||||
FP_TYPE_DATA2 = 0x0040, /* void data type-2 (whatever) */
|
||||
FP_TYPE_DATA3 = 0x0080, /* void data type-3 (whatever) */
|
||||
FP_TYPE_RESERVED1 = 0x0100, /* reserved data type-1 (future) */
|
||||
FP_TYPE_RESERVED2 = 0x0200, /* reserved data type-2 (future) */
|
||||
FP_TYPE_RESERVED3 = 0x0400, /* reserved data type-3 (future) */
|
||||
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 */
|
||||
};
|
||||
|
||||
union fp_cfgvalue {
|
||||
union figpar_cfgvalue {
|
||||
void *data; /* Pointer to NUL-terminated string */
|
||||
char *str; /* Pointer to NUL-terminated string */
|
||||
char **strarray; /* Pointer to an array of strings */
|
||||
@ -133,26 +133,26 @@ argument to
|
||||
is a mask of bit fields which indicate various
|
||||
processing options.
|
||||
The possible flags are as follows:
|
||||
.Bl -tag -width FP_BREAK_ON_SEMICOLON
|
||||
.It Dv FP_BREAK_ON_EQUALS
|
||||
.Bl -tag -width FIGPAR_BREAK_ON_SEMICOLON
|
||||
.It Dv FIGPAR_BREAK_ON_EQUALS
|
||||
An equals sign
|
||||
.Pq Ql Li =
|
||||
is normally considered part of the directive.
|
||||
This flag enables terminating the directive at the equals sign.
|
||||
Also makes equals sign optional and transient.
|
||||
.It Dv FP_BREAK_ON_SEMICOLON
|
||||
.It Dv FIGPAR_BREAK_ON_SEMICOLON
|
||||
A semicolon
|
||||
.Pq Ql Li \;
|
||||
is normally considered part of the value.
|
||||
This flag enables terminating the value at the semicolon.
|
||||
Also allows multiple statements on a single line separated by semicolon.
|
||||
.It Dv FP_CASE_SENSITIVE
|
||||
.It Dv FIGPAR_CASE_SENSITIVE
|
||||
Normally directives are matched case insensitively using
|
||||
.Xr fnmatch 3 .
|
||||
This flag enables directive matching to be case sensitive.
|
||||
.It Dv FP_REQUIRE_EQUALS
|
||||
.It Dv FIGPAR_REQUIRE_EQUALS
|
||||
If a directive is not followed by an equals, processing is aborted.
|
||||
.It Dv FP_STRICT_EQUALS
|
||||
.It Dv FIGPAR_STRICT_EQUALS
|
||||
Equals must be part of the directive to be considered a delimiter between
|
||||
directive and value.
|
||||
.El
|
||||
@ -163,14 +163,14 @@ struct array pointer can be NULL and every directive will invoke the
|
||||
.Fn unknown
|
||||
function argument.
|
||||
.Pp
|
||||
The directive for each fp_config item in the
|
||||
The directive for each figpar_config item in the
|
||||
.Fn parse_config
|
||||
options argument is matched against each parsed directive using
|
||||
.Xr fnmatch 3
|
||||
until a match is found.
|
||||
If a match is found, the
|
||||
.Fn action
|
||||
function for that fp_config directive is invoked with the line number,
|
||||
function for that figpar_config directive is invoked with the line number,
|
||||
directive, and value.
|
||||
Otherwise if no match, the
|
||||
.Fn unknown
|
||||
@ -192,11 +192,11 @@ or if no match a pointer to a static dummy struct is returned
|
||||
.Pq whose values are all zero or NULL .
|
||||
.Pp
|
||||
The use of
|
||||
.Fa "struct fp_config"
|
||||
.Fa "struct figpar_config"
|
||||
is entirely optional as-is the use of
|
||||
.Fa "enum fp_cfgtype"
|
||||
.Fa "enum figpar_cfgtype"
|
||||
or
|
||||
.Fa "union fp_cfgvalue" .
|
||||
.Fa "union figpar_cfgvalue" .
|
||||
For example, you could choose to pass a NULL pointer to
|
||||
.Fn parse_config
|
||||
for the first argument and then provide a simple
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2002-2014 Devin Teske <dteske@FreeBSD.org>
|
||||
* Copyright (c) 2002-2015 Devin Teske <dteske@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -40,24 +40,25 @@ __FBSDID("$FreeBSD$");
|
||||
#include "figpar.h"
|
||||
#include "string_m.h"
|
||||
|
||||
struct fp_config fp_dummy_config = {0, NULL, {0}, NULL};
|
||||
struct figpar_config figpar_dummy_config = {0, NULL, {0}, NULL};
|
||||
|
||||
/*
|
||||
* Search for config option (struct fp_config) in the array of config options,
|
||||
* returning the struct whose directive matches the given parameter. If no
|
||||
* match is found, a pointer to the static dummy array (above) is returned.
|
||||
* Search for config option (struct figpar_config) in the array of config
|
||||
* options, returning the struct whose directive matches the given parameter.
|
||||
* If no match is found, a pointer to the static dummy array (above) is
|
||||
* returned.
|
||||
*
|
||||
* This is to eliminate dependency on the index position of an item in the
|
||||
* array, since the index position is more apt to be changed as code grows.
|
||||
*/
|
||||
struct fp_config *
|
||||
get_config_option(struct fp_config options[], const char *directive)
|
||||
struct figpar_config *
|
||||
get_config_option(struct figpar_config options[], const char *directive)
|
||||
{
|
||||
uint32_t n;
|
||||
|
||||
/* Check arguments */
|
||||
if (options == NULL || directive == NULL)
|
||||
return (&fp_dummy_config);
|
||||
return (&figpar_dummy_config);
|
||||
|
||||
/* Loop through the array, return the index of the first match */
|
||||
for (n = 0; options[n].directive != NULL; n++)
|
||||
@ -65,12 +66,12 @@ get_config_option(struct fp_config options[], const char *directive)
|
||||
return (&(options[n]));
|
||||
|
||||
/* Re-initialize the dummy variable in case it was written to */
|
||||
fp_dummy_config.directive = NULL;
|
||||
fp_dummy_config.type = 0;
|
||||
fp_dummy_config.action = NULL;
|
||||
fp_dummy_config.value.u_num = 0;
|
||||
figpar_dummy_config.directive = NULL;
|
||||
figpar_dummy_config.type = 0;
|
||||
figpar_dummy_config.action = NULL;
|
||||
figpar_dummy_config.value.u_num = 0;
|
||||
|
||||
return (&fp_dummy_config);
|
||||
return (&figpar_dummy_config);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -84,9 +85,9 @@ get_config_option(struct fp_config options[], const char *directive)
|
||||
* Returns zero on success; otherwise returns -1 and errno should be consulted.
|
||||
*/
|
||||
int
|
||||
parse_config(struct fp_config options[], const char *path,
|
||||
int (*unknown)(struct fp_config *option, uint32_t line, char *directive,
|
||||
char *value), uint16_t processing_options)
|
||||
parse_config(struct figpar_config options[], const char *path,
|
||||
int (*unknown)(struct figpar_config *option, uint32_t line,
|
||||
char *directive, char *value), uint16_t processing_options)
|
||||
{
|
||||
uint8_t bequals;
|
||||
uint8_t bsemicolon;
|
||||
@ -119,11 +120,15 @@ parse_config(struct fp_config options[], const char *path,
|
||||
return (-1);
|
||||
|
||||
/* Processing options */
|
||||
bequals = (processing_options & FP_BREAK_ON_EQUALS) == 0 ? 0 : 1;
|
||||
bsemicolon = (processing_options & FP_BREAK_ON_SEMICOLON) == 0 ? 0 : 1;
|
||||
case_sensitive = (processing_options & FP_CASE_SENSITIVE) == 0 ? 0 : 1;
|
||||
require_equals = (processing_options & FP_REQUIRE_EQUALS) == 0 ? 0 : 1;
|
||||
strict_equals = (processing_options & FP_STRICT_EQUALS) == 0 ? 0 : 1;
|
||||
bequals = (processing_options & FIGPAR_BREAK_ON_EQUALS) == 0 ? 0 : 1;
|
||||
bsemicolon =
|
||||
(processing_options & FIGPAR_BREAK_ON_SEMICOLON) == 0 ? 0 : 1;
|
||||
case_sensitive =
|
||||
(processing_options & FIGPAR_CASE_SENSITIVE) == 0 ? 0 : 1;
|
||||
require_equals =
|
||||
(processing_options & FIGPAR_REQUIRE_EQUALS) == 0 ? 0 : 1;
|
||||
strict_equals =
|
||||
(processing_options & FIGPAR_STRICT_EQUALS) == 0 ? 0 : 1;
|
||||
|
||||
/* Initialize strings */
|
||||
directive = value = 0;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2002-2014 Devin Teske <dteske@FreeBSD.org>
|
||||
* Copyright (c) 2002-2015 Devin Teske <dteske@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -34,7 +34,7 @@
|
||||
/*
|
||||
* Union for storing various types of data in a single common container.
|
||||
*/
|
||||
union fp_cfgvalue {
|
||||
union figpar_cfgvalue {
|
||||
void *data; /* Pointer to NUL-terminated string */
|
||||
char *str; /* Pointer to NUL-terminated string */
|
||||
char **strarray; /* Pointer to an array of strings */
|
||||
@ -46,53 +46,53 @@ union fp_cfgvalue {
|
||||
/*
|
||||
* Option types (based on above cfgvalue union)
|
||||
*/
|
||||
enum fp_cfgtype {
|
||||
FP_TYPE_NONE = 0x0000, /* for directives with no value */
|
||||
FP_TYPE_BOOL = 0x0001, /* boolean */
|
||||
FP_TYPE_INT = 0x0002, /* signed 32 bit integer */
|
||||
FP_TYPE_UINT = 0x0004, /* unsigned 32 bit integer */
|
||||
FP_TYPE_STR = 0x0008, /* string pointer */
|
||||
FP_TYPE_STRARRAY = 0x0010, /* string array pointer */
|
||||
FP_TYPE_DATA1 = 0x0020, /* void data type-1 (whatever) */
|
||||
FP_TYPE_DATA2 = 0x0040, /* void data type-2 (whatever) */
|
||||
FP_TYPE_DATA3 = 0x0080, /* void data type-3 (whatever) */
|
||||
FP_TYPE_RESERVED1 = 0x0100, /* reserved data type-1 (future) */
|
||||
FP_TYPE_RESERVED2 = 0x0200, /* reserved data type-2 (future) */
|
||||
FP_TYPE_RESERVED3 = 0x0400, /* reserved data type-3 (future) */
|
||||
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 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Options to parse_config() for processing_options bitmask
|
||||
*/
|
||||
#define FP_BREAK_ON_EQUALS 0x0001 /* stop reading directive at `=' */
|
||||
#define FP_BREAK_ON_SEMICOLON 0x0002 /* `;' starts a new line */
|
||||
#define FP_CASE_SENSITIVE 0x0004 /* directives are case sensitive */
|
||||
#define FP_REQUIRE_EQUALS 0x0008 /* assignment directives only */
|
||||
#define FP_STRICT_EQUALS 0x0010 /* `=' must be part of directive */
|
||||
#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 */
|
||||
|
||||
/*
|
||||
* Anatomy of a config file option
|
||||
*/
|
||||
struct fp_config {
|
||||
enum fp_cfgtype type; /* Option value type */
|
||||
struct figpar_config {
|
||||
enum figpar_cfgtype type; /* Option value type */
|
||||
const char *directive; /* config file keyword */
|
||||
union fp_cfgvalue value; /* NB: set by action */
|
||||
union figpar_cfgvalue value; /* NB: set by action */
|
||||
|
||||
/*
|
||||
* Function pointer; action to be taken when the directive is found
|
||||
*/
|
||||
int (*action)(struct fp_config *option, uint32_t line, char *directive,
|
||||
char *value);
|
||||
int (*action)(struct figpar_config *option, uint32_t line,
|
||||
char *directive, char *value);
|
||||
};
|
||||
extern struct fp_config fp_dummy_config;
|
||||
extern struct figpar_config figpar_dummy_config;
|
||||
|
||||
__BEGIN_DECLS
|
||||
int parse_config(struct fp_config _options[],
|
||||
int parse_config(struct figpar_config _options[],
|
||||
const char *_path,
|
||||
int (*_unknown)(struct fp_config *_option,
|
||||
int (*_unknown)(struct figpar_config *_option,
|
||||
uint32_t _line, char *_directive, char *_value),
|
||||
uint16_t _processing_options);
|
||||
struct fp_config *get_config_option(struct fp_config _options[],
|
||||
struct figpar_config *get_config_option(struct figpar_config _options[],
|
||||
const char *_directive);
|
||||
__END_DECLS
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
* in the range 5 to 9.
|
||||
*/
|
||||
#undef __FreeBSD_version
|
||||
#define __FreeBSD_version 1100085 /* Master, propagated to newvers */
|
||||
#define __FreeBSD_version 1100086 /* Master, propagated to newvers */
|
||||
|
||||
/*
|
||||
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
|
||||
|
Loading…
Reference in New Issue
Block a user