diff --git a/lib/libdpv/dialogrc.c b/lib/libdpv/dialogrc.c index eb4a53621084..e199d415c539 100644 --- a/lib/libdpv/dialogrc.c +++ b/lib/libdpv/dialogrc.c @@ -1,359 +1,360 @@ /*- - * Copyright (c) 2013-2014 Devin Teske + * Copyright (c) 2013-2015 Devin Teske * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include "dialogrc.h" #define STR_BUFSIZE 255 /* dialog(1) `.dialogrc' characteristics */ uint8_t use_colors = 1; uint8_t use_shadow = 1; 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} }; /* * 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; char *val; size_t len; char attrbuf[4]; if (option == NULL) { warnx("%s:%d:%s: Missing callback parameter", __FILE__, __LINE__, __func__); return (-1); /* Abort processing */ } /* Allocate memory for the data if not already done */ if (option->value.str == NULL) { if ((option->value.str = malloc(STR_BUFSIZE)) == NULL) return (-1); } /* * If the first character is left-parenthesis, the format is * `(background,foreground,highlight)' otherwise, we should take it * as a reference to another color. */ if (*cp != '(') { /* Copy the [current] value from the referenced color */ val = dialogrc_config_option(cp)->value.str; if (val != NULL) snprintf(option->value.str, STR_BUFSIZE, "%s", val); return (0); } else cp++; strtolower(cp); /* Initialize the attrbuf (fg,bg,hi,NUL) */ attrbuf[0] = '0'; attrbuf[1] = '0'; attrbuf[2] = 'B'; /* \ZB = disable; \Zb = enable (see dialog(1)) */ attrbuf[3] = '\0'; /* Interpret the foreground color */ if (strncmp(cp, "red,", 4) == 0) attrbuf[0] = '1'; else if (strncmp(cp, "green,", 6) == 0) attrbuf[0] = '2'; else if (strncmp(cp, "yellow,", 7) == 0) attrbuf[0] = '3'; else if (strncmp(cp, "blue,", 5) == 0) attrbuf[0] = '4'; else if (strncmp(cp, "magenta,", 8) == 0) attrbuf[0] = '5'; else if (strncmp(cp, "cyan,", 5) == 0) attrbuf[0] = '6'; else if (strncmp(cp, "white,", 6) == 0) attrbuf[0] = '7'; else if (strncmp(cp, "black,", 6) == 0) attrbuf[0] = '8'; /* Advance to the background color */ cp = strchr(cp, ','); if (cp == NULL) goto write_attrbuf; else cp++; /* Interpret the background color */ if (strncmp(cp, "red,", 4) == 0) attrbuf[1] = '1'; else if (strncmp(cp, "green,", 6) == 0) attrbuf[1] = '2'; else if (strncmp(cp, "yellow,", 7) == 0) attrbuf[1] = '3'; else if (strncmp(cp, "blue,", 5) == 0) attrbuf[1] = '4'; else if (strncmp(cp, "magenta,", 8) == 0) attrbuf[1] = '5'; else if (strncmp(cp, "cyan,", 5) == 0) attrbuf[1] = '6'; else if (strncmp(cp, "white,", 6) == 0) attrbuf[1] = '7'; else if (strncmp(cp, "black,", 6) == 0) attrbuf[1] = '8'; /* Advance to the highlight */ cp = strchr(cp, ','); if (cp == NULL) goto write_attrbuf; else cp++; /* Trim trailing parenthesis */ len = strlen(cp); if (cp[len - 1] == ')') cp[len - 1] = '\0'; /* Interpret the highlight (initialized to off above) */ if (strcmp(cp, "on") == 0 || strncmp(cp, "on,", 3) == 0) attrbuf[2] = 'b'; /* \Zb = enable bold (see dialog(1)) */ write_attrbuf: sprintf(option->value.str, "%s", attrbuf); return (0); } /* * 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) { if (option == NULL) { warnx("%s:%d:%s: Missing callback parameter", __FILE__, __LINE__, __func__); return (-1); /* Abort processing */ } /* Assume ON, check for OFF (case-insensitive) */ option->value.boolean = 1; strtolower(value); if (strcmp(value, "off") == 0) option->value.boolean = 0; return (0); } /* * 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) { if (option == NULL) { warnx("%s:%d:%s: Missing callback parameter", __FILE__, __LINE__, __func__); return (-1); /* Abort processing */ } /* Convert the string to a 32-bit signed integer */ option->value.num = (int32_t)strtol(value, (char **)NULL, 10); return (0); } /* * 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; if (option == NULL) { warnx("%s:%d:%s: Missing callback parameter", __FILE__, __LINE__, __func__); return (-1); /* Abort processing */ } /* Allocate memory for the data if not already done */ if (option->value.str == NULL) { if ((option->value.str = malloc(STR_BUFSIZE)) == NULL) return (-1); } /* Trim leading quote */ if (*value == '"') value++; /* Write the data into the buffer */ snprintf(option->value.str, STR_BUFSIZE, "%s", value); /* Trim trailing quote */ len = strlen(option->value.str); if (option->value.str[len - 1] == '"') option->value.str[len - 1] = '\0'; return (0); } /* * Parse (in order of preference) $DIALOGRC or `$HOME/.dialogrc'. Returns zero * on success, -1 on failure (and errno should be consulted). */ int parse_dialogrc(void) { char *cp; int res; size_t len; char path[PATH_MAX]; /* Allow $DIALOGRC to override `$HOME/.dialogrc' default */ if ((cp = getenv(ENV_DIALOGRC)) != NULL && *cp != '\0') snprintf(path, PATH_MAX, "%s", cp); else if ((cp = getenv(ENV_HOME)) != NULL) { /* Copy $HOME into buffer and append trailing `/' if missing */ snprintf(path, PATH_MAX, "%s", cp); len = strlen(path); cp = path + len; if (len > 0 && len < (PATH_MAX - 1) && *(cp - 1) != '/') { *cp++ = '/'; *cp = '\0'; len++; } /* If we still have room, shove in the name of rc file */ if (len < (PATH_MAX - 1)) snprintf(cp, PATH_MAX - len, "%s", DIALOGRC); } else { /* Like dialog(1), don't process a file if $HOME is unset */ errno = ENOENT; return (-1); } /* 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; use_colors = dialogrc_config_option("use_colors")->value.boolean; snprintf(gauge_color, STR_BUFSIZE, "%s", dialogrc_config_option("gauge_color")->value.str); return (res); } /* * 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)); } /* * Free allocated items initialized by setattr() (via parse_config() callback * matrix [dialogrc_config] used in parse_dialogrc() above). */ void dialogrc_free(void) { char *value; uint32_t n; for (n = 0; dialogrc_config[n].directive != NULL; n++) { if (dialogrc_config[n].action != &setattr) continue; value = dialogrc_config[n].value.str; if (value != NULL && value != gauge_color) { free(dialogrc_config[n].value.str); dialogrc_config[n].value.str = NULL; } } } diff --git a/lib/libdpv/dialogrc.h b/lib/libdpv/dialogrc.h index 7d1723584d51..a2eb1fbc24aa 100644 --- a/lib/libdpv/dialogrc.h +++ b/lib/libdpv/dialogrc.h @@ -1,56 +1,56 @@ /*- - * Copyright (c) 2013-2014 Devin Teske + * Copyright (c) 2013-2015 Devin Teske * 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 _DIALOGRC_H_ #define _DIALOGRC_H_ #include #include /* dialog(3) dlg_color_table[] attributes */ #define GAUGE_ATTR 33 /* entry used for gauge_color */ /* dialog(1) characteristics */ #define DIALOGRC ".dialogrc" #define ENV_DIALOGRC "DIALOGRC" #define ENV_HOME "HOME" /* dialog(1) `.dialogrc' characteristics */ extern uint8_t use_colors; extern uint8_t use_shadow; extern char gauge_color[]; 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_ */ diff --git a/lib/libfigpar/figpar.3 b/lib/libfigpar/figpar.3 index 8fd49d37c43e..60ab2b50eb85 100644 --- a/lib/libfigpar/figpar.3 +++ b/lib/libfigpar/figpar.3 @@ -1,251 +1,251 @@ .\" Copyright (c) 2013-2015 Devin Teske .\" 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$ .\" -.Dd Oct 22, 2015 +.Dd Nov 2, 2015 .Dt FIGPAR 3 .Os .Sh NAME .Nm figpar , .Nm parse_config , .Nm get_config_option .Nd configuration file parsing library .Sh LIBRARY .Lb libfigpar .Sh SYNOPSIS .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 .Fo replaceall .Fa "char *source, const char *find, const char *replace" .Fc .Ft unsigned int .Fo strcount .Fa "const char *source, const char *find" .Fc .Ft void .Fo strexpand .Fa "char *source" .Fc .Ft void .Fo strexpandnl .Fa "char *source" .Fc .Ft void .Fo strtolower .Fa "char *source" .Fc .Sh DESCRIPTION The .Nm library provides a light-weight, portable framework for parsing configuration files. The library uses .Xr open 2 , .Xr read 2 , and .Xr lseek 2 within the file pointed to by .Fa path to find directives and values which are then made available to the application. .Pp Due to the fact that configuration files may have basic syntax differences, the library does not attempt to impose any structure on the data but instead provides raw data to a set of callback functions. These callback functions can in-turn initiate abort through their return value, allowing custom syntax validation during parsing. .Pp 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 */ 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) */ }; .Ed .Pp The .Fa processing_options argument to .Fn parse_config 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 .Pp The .Fa options 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 function is invoked .Pq with the same arguments . .Pp If either .Fa action or .Fa unknown return non-zero, .Fn parse_config aborts reading the file and returns the error value to its caller. .Pp .Fn get_config_option traverses the options-array and returns the option that matches via .Xr strcmp 3 , 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 .Fa unknown function based on .Xr queue 3 that populates a singly-linked list of your own struct containing the .Fa directive and .Fa value . .Pp In addition, the following miscellaneous string manipulation routines are provided by .In string_m.h : .Bl -tag -width strexpandnl() .It Fn replaceall Replace all occurrences of .Fa find in .Fa source with .Fa replace . .It Fn strcount Count the number of occurrences of one string that appear in the .Fa source string. Return value is the total count. An example use would be if you need to know how large a block of memory needs to be for a .Fn replaceall series. .It Fn strexpand Expand escape sequences in a buffer pointed to by .Fa source . .It Fn strexpandnl Expand only the escaped newlines in a buffer pointed to by .Fa source . .It Fn strtolower Convert a string to lower case. .El .Sh SEE ALSO .Xr queue 3 .Sh HISTORY The .Nm library first appeared in .Fx 10.2 . .Sh AUTHORS .An Devin Teske Aq dteske@FreeBSD.org .Sh BUGS This is the first implementation of the library, and the interface may be subject to refinement. diff --git a/lib/libfigpar/figpar.c b/lib/libfigpar/figpar.c index a97fc85e9097..0a727ff6f041 100644 --- a/lib/libfigpar/figpar.c +++ b/lib/libfigpar/figpar.c @@ -1,469 +1,474 @@ /*- - * Copyright (c) 2002-2014 Devin Teske + * Copyright (c) 2002-2015 Devin Teske * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #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++) if (strcmp(options[n].directive, directive) == 0) 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); } /* * Parse the configuration file at `path' and execute the `action' call-back * functions for any directives defined by the array of config options (first * argument). * * For unknown directives that are encountered, you can optionally pass a * call-back function for the third argument to be called for unknowns. * * 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; uint8_t case_sensitive; uint8_t comment = 0; uint8_t end; uint8_t found; uint8_t have_equals = 0; uint8_t quote; uint8_t require_equals; uint8_t strict_equals; char p[2]; char *directive; char *t; char *value; int error; int fd; ssize_t r = 1; uint32_t dsize; uint32_t line = 1; uint32_t n; uint32_t vsize; uint32_t x; off_t charpos; off_t curpos; char rpath[PATH_MAX]; /* Sanity check: if no options and no unknown function, return */ if (options == NULL && unknown == NULL) 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; vsize = dsize = 0; /* Resolve the file path */ if (realpath(path, rpath) == 0) return (-1); /* Open the file */ if ((fd = open(rpath, O_RDONLY)) < 0) return (-1); /* Read the file until EOF */ while (r != 0) { r = read(fd, p, 1); /* skip to the beginning of a directive */ while (r != 0 && (isspace(*p) || *p == '#' || comment || (bsemicolon && *p == ';'))) { if (*p == '#') comment = 1; else if (*p == '\n') { comment = 0; line++; } r = read(fd, p, 1); } /* Test for EOF; if EOF then no directive was found */ if (r == 0) { close(fd); return (0); } /* Get the current offset */ curpos = lseek(fd, 0, SEEK_CUR) - 1; if (curpos == -1) { close(fd); return (-1); } /* Find the length of the directive */ for (n = 0; r != 0; n++) { if (isspace(*p)) break; if (bequals && *p == '=') { have_equals = 1; break; } if (bsemicolon && *p == ';') break; r = read(fd, p, 1); } /* Test for EOF, if EOF then no directive was found */ if (n == 0 && r == 0) { close(fd); return (0); } /* Go back to the beginning of the directive */ error = (int)lseek(fd, curpos, SEEK_SET); if (error == (curpos - 1)) { close(fd); return (-1); } /* Allocate and read the directive into memory */ if (n > dsize) { if ((directive = realloc(directive, n + 1)) == NULL) { close(fd); return (-1); } dsize = n; } r = read(fd, directive, n); /* Advance beyond the equals sign if appropriate/desired */ if (bequals && *p == '=') { if (lseek(fd, 1, SEEK_CUR) != -1) r = read(fd, p, 1); if (strict_equals && isspace(*p)) *p = '\n'; } /* Terminate the string */ directive[n] = '\0'; /* Convert directive to lower case before comparison */ if (!case_sensitive) strtolower(directive); /* Move to what may be the start of the value */ if (!(bsemicolon && *p == ';') && !(strict_equals && *p == '=')) { while (r != 0 && isspace(*p) && *p != '\n') r = read(fd, p, 1); } /* An equals sign may have stopped us, should we eat it? */ if (r != 0 && bequals && *p == '=' && !strict_equals) { have_equals = 1; r = read(fd, p, 1); while (r != 0 && isspace(*p) && *p != '\n') r = read(fd, p, 1); } /* If no value, allocate a dummy value and jump to action */ if (r == 0 || *p == '\n' || *p == '#' || (bsemicolon && *p == ';')) { /* Initialize the value if not already done */ if (value == NULL && (value = malloc(1)) == NULL) { close(fd); return (-1); } value[0] = '\0'; goto call_function; } /* Get the current offset */ curpos = lseek(fd, 0, SEEK_CUR) - 1; if (curpos == -1) { close(fd); return (-1); } /* Find the end of the value */ quote = 0; end = 0; while (r != 0 && end == 0) { /* Advance to the next character if we know we can */ if (*p != '\"' && *p != '#' && *p != '\n' && (!bsemicolon || *p != ';')) { r = read(fd, p, 1); continue; } /* * If we get this far, we've hit an end-key */ /* Get the current offset */ charpos = lseek(fd, 0, SEEK_CUR) - 1; if (charpos == -1) { close(fd); return (-1); } /* * Go back so we can read the character before the key * to check if the character is escaped (which means we * should continue). */ error = (int)lseek(fd, -2, SEEK_CUR); if (error == -3) { close(fd); return (-1); } r = read(fd, p, 1); /* * Count how many backslashes there are (an odd number * means the key is escaped, even means otherwise). */ for (n = 1; *p == '\\'; n++) { /* Move back another offset to read */ error = (int)lseek(fd, -2, SEEK_CUR); if (error == -3) { close(fd); return (-1); } r = read(fd, p, 1); } /* Move offset back to the key and read it */ error = (int)lseek(fd, charpos, SEEK_SET); if (error == (charpos - 1)) { close(fd); return (-1); } r = read(fd, p, 1); /* * If an even number of backslashes was counted meaning * key is not escaped, we should evaluate what to do. */ if ((n & 1) == 1) { switch (*p) { case '\"': /* * Flag current sequence of characters * to follow as being quoted (hashes * are not considered comments). */ quote = !quote; break; case '#': /* * If we aren't in a quoted series, we * just hit an inline comment and have * found the end of the value. */ if (!quote) end = 1; break; case '\n': /* * Newline characters must always be * escaped, whether inside a quoted * series or not, otherwise they * terminate the value. */ end = 1; case ';': if (!quote && bsemicolon) end = 1; break; } } else if (*p == '\n') /* Escaped newline character. increment */ line++; /* Advance to the next character */ r = read(fd, p, 1); } /* Get the current offset */ charpos = lseek(fd, 0, SEEK_CUR) - 1; if (charpos == -1) { close(fd); return (-1); } /* Get the length of the value */ n = (uint32_t)(charpos - curpos); if (r != 0) /* more to read, but don't read ending key */ n--; /* Move offset back to the beginning of the value */ error = (int)lseek(fd, curpos, SEEK_SET); if (error == (curpos - 1)) { close(fd); return (-1); } /* Allocate and read the value into memory */ if (n > vsize) { if ((value = realloc(value, n + 1)) == NULL) { close(fd); return (-1); } vsize = n; } r = read(fd, value, n); /* Terminate the string */ value[n] = '\0'; /* Cut trailing whitespace off by termination */ t = value + n; while (isspace(*--t)) *t = '\0'; /* Escape the escaped quotes (replaceall is in string_m.c) */ x = strcount(value, "\\\""); /* in string_m.c */ if (x != 0 && (n + x) > vsize) { if ((value = realloc(value, n + x + 1)) == NULL) { close(fd); return (-1); } vsize = n + x; } if (replaceall(value, "\\\"", "\\\\\"") < 0) { /* Replace operation failed for some unknown reason */ close(fd); return (-1); } /* Remove all new line characters */ if (replaceall(value, "\\\n", "") < 0) { /* Replace operation failed for some unknown reason */ close(fd); return (-1); } /* Resolve escape sequences */ strexpand(value); /* in string_m.c */ call_function: /* Abort if we're seeking only assignments */ if (require_equals && !have_equals) return (-1); found = have_equals = 0; /* reset */ /* If there are no options defined, call unknown and loop */ if (options == NULL && unknown != NULL) { error = unknown(NULL, line, directive, value); if (error != 0) { close(fd); return (error); } continue; } /* Loop through the array looking for a match for the value */ for (n = 0; options[n].directive != NULL; n++) { error = fnmatch(options[n].directive, directive, FNM_NOESCAPE); if (error == 0) { found = 1; /* Call function for array index item */ if (options[n].action != NULL) { error = options[n].action( &options[n], line, directive, value); if (error != 0) { close(fd); return (error); } } } else if (error != FNM_NOMATCH) { /* An error has occurred */ close(fd); return (-1); } } if (!found && unknown != NULL) { /* * No match was found for the value we read from the * file; call function designated for unknown values. */ error = unknown(NULL, line, directive, value); if (error != 0) { close(fd); return (error); } } } close(fd); return (0); } diff --git a/lib/libfigpar/figpar.h b/lib/libfigpar/figpar.h index 16f825a88502..f2dc45b288ae 100644 --- a/lib/libfigpar/figpar.h +++ b/lib/libfigpar/figpar.h @@ -1,99 +1,99 @@ /*- - * Copyright (c) 2002-2014 Devin Teske + * Copyright (c) 2002-2015 Devin Teske * 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 /* * 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 */ 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) */ -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 #endif /* _FIGPAR_H_ */ diff --git a/sys/sys/param.h b/sys/sys/param.h index 059c23453ee2..a9910aa83a7e 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -1,363 +1,363 @@ /*- * Copyright (c) 1982, 1986, 1989, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. * All or some portions of this file are derived from material licensed * to the University of California by American Telephone and Telegraph * Co. or Unix System Laboratories, Inc. and are reproduced herein with * the permission of UNIX System Laboratories, Inc. * * 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. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. * * @(#)param.h 8.3 (Berkeley) 4/4/95 * $FreeBSD$ */ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ #include #define BSD 199506 /* System version (year & month). */ #define BSD4_3 1 #define BSD4_4 1 /* * __FreeBSD_version numbers are documented in the Porter's Handbook. * If you bump the version for any reason, you should update the documentation * there. * Currently this lives here in the doc/ repository: * * head/en_US.ISO8859-1/books/porters-handbook/versions/chapter.xml * * scheme is: Rxx * 'R' is in the range 0 to 4 if this is a release branch or * x.0-CURRENT before RELENG_*_0 is created, otherwise 'R' is * 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, * which by definition is always true on FreeBSD. This macro is also defined * on other systems that use the kernel of FreeBSD, such as GNU/kFreeBSD. * * It is tempting to use this macro in userland code when we want to enable * kernel-specific routines, and in fact it's fine to do this in code that * is part of FreeBSD itself. However, be aware that as presence of this * macro is still not widespread (e.g. older FreeBSD versions, 3rd party * compilers, etc), it is STRONGLY DISCOURAGED to check for this macro in * external applications without also checking for __FreeBSD__ as an * alternative. */ #undef __FreeBSD_kernel__ #define __FreeBSD_kernel__ #ifdef _KERNEL #define P_OSREL_SIGWAIT 700000 #define P_OSREL_SIGSEGV 700004 #define P_OSREL_MAP_ANON 800104 #define P_OSREL_MAP_FSTRICT 1100036 #define P_OSREL_SHUTDOWN_ENOTCONN 1100077 #define P_OSREL_MAJOR(x) ((x) / 100000) #endif #ifndef LOCORE #include #endif /* * Machine-independent constants (some used in following include files). * Redefined constants are from POSIX 1003.1 limits file. * * MAXCOMLEN should be >= sizeof(ac_comm) (see ) */ #include #define MAXCOMLEN 19 /* max command name remembered */ #define MAXINTERP PATH_MAX /* max interpreter file name length */ #define MAXLOGNAME 33 /* max login name length (incl. NUL) */ #define MAXUPRC CHILD_MAX /* max simultaneous processes */ #define NCARGS ARG_MAX /* max bytes for an exec function */ #define NGROUPS (NGROUPS_MAX+1) /* max number groups */ #define NOFILE OPEN_MAX /* max open files per process */ #define NOGROUP 65535 /* marker for empty group set member */ #define MAXHOSTNAMELEN 256 /* max hostname size */ #define SPECNAMELEN 63 /* max length of devicename */ /* More types and definitions used throughout the kernel. */ #ifdef _KERNEL #include #include #ifndef LOCORE #include #include #endif #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE 1 #endif #endif #ifndef _KERNEL /* Signals. */ #include #endif /* Machine type dependent parameters. */ #include #ifndef _KERNEL #include #endif #ifndef DEV_BSHIFT #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */ #endif #define DEV_BSIZE (1<>PAGE_SHIFT) #endif /* * btodb() is messy and perhaps slow because `bytes' may be an off_t. We * want to shift an unsigned type to avoid sign extension and we don't * want to widen `bytes' unnecessarily. Assume that the result fits in * a daddr_t. */ #ifndef btodb #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \ (sizeof (bytes) > sizeof(long) \ ? (daddr_t)((unsigned long long)(bytes) >> DEV_BSHIFT) \ : (daddr_t)((unsigned long)(bytes) >> DEV_BSHIFT)) #endif #ifndef dbtob #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \ ((off_t)(db) << DEV_BSHIFT) #endif #define PRIMASK 0x0ff #define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ #define PDROP 0x200 /* OR'd with pri to stop re-entry of interlock mutex */ #define NZERO 0 /* default "nice" */ #define NBBY 8 /* number of bits in a byte */ #define NBPW sizeof(int) /* number of bytes per word (integer) */ #define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ #define NODEV (dev_t)(-1) /* non-existent device */ /* * File system parameters and macros. * * MAXBSIZE - Filesystems are made out of blocks of at most MAXBSIZE bytes * per block. MAXBSIZE may be made larger without effecting * any existing filesystems as long as it does not exceed MAXPHYS, * and may be made smaller at the risk of not being able to use * filesystems which require a block size exceeding MAXBSIZE. * * MAXBCACHEBUF - Maximum size of a buffer in the buffer cache. This must * be >= MAXBSIZE and can be set differently for different * architectures by defining it in . * Making this larger allows NFS to do larger reads/writes. * * BKVASIZE - Nominal buffer space per buffer, in bytes. BKVASIZE is the * minimum KVM memory reservation the kernel is willing to make. * Filesystems can of course request smaller chunks. Actual * backing memory uses a chunk size of a page (PAGE_SIZE). * The default value here can be overridden on a per-architecture * basis by defining it in . This should * probably be done to increase its value, when MAXBCACHEBUF is * defined as a larger value in . * * If you make BKVASIZE too small you risk seriously fragmenting * the buffer KVM map which may slow things down a bit. If you * make it too big the kernel will not be able to optimally use * the KVM memory reserved for the buffer cache and will wind * up with too-few buffers. * * The default is 16384, roughly 2x the block size used by a * normal UFS filesystem. */ #define MAXBSIZE 65536 /* must be power of 2 */ #ifndef MAXBCACHEBUF #define MAXBCACHEBUF MAXBSIZE /* must be a power of 2 >= MAXBSIZE */ #endif #ifndef BKVASIZE #define BKVASIZE 16384 /* must be power of 2 */ #endif #define BKVAMASK (BKVASIZE-1) /* * MAXPATHLEN defines the longest permissible path length after expanding * symbolic links. It is used to allocate a temporary buffer from the buffer * pool in which to do the name expansion, hence should be a power of two, * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the * maximum number of symbolic links that may be expanded in a path name. * It should be set high enough to allow all legitimate uses, but halt * infinite loops reasonably quickly. */ #define MAXPATHLEN PATH_MAX #define MAXSYMLINKS 32 /* Bit map related macros. */ #define setbit(a,i) (((unsigned char *)(a))[(i)/NBBY] |= 1<<((i)%NBBY)) #define clrbit(a,i) (((unsigned char *)(a))[(i)/NBBY] &= ~(1<<((i)%NBBY))) #define isset(a,i) \ (((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) #define isclr(a,i) \ ((((const unsigned char *)(a))[(i)/NBBY] & (1<<((i)%NBBY))) == 0) /* Macros for counting and rounding. */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) #endif #define nitems(x) (sizeof((x)) / sizeof((x)[0])) #define rounddown(x, y) (((x)/(y))*(y)) #define rounddown2(x, y) ((x)&(~((y)-1))) /* if y is power of two */ #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */ #define powerof2(x) ((((x)-1)&(x))==0) /* Macros for min/max. */ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) #ifdef _KERNEL /* * Basic byte order function prototypes for non-inline functions. */ #ifndef LOCORE #ifndef _BYTEORDER_PROTOTYPED #define _BYTEORDER_PROTOTYPED __BEGIN_DECLS __uint32_t htonl(__uint32_t); __uint16_t htons(__uint16_t); __uint32_t ntohl(__uint32_t); __uint16_t ntohs(__uint16_t); __END_DECLS #endif #endif #ifndef lint #ifndef _BYTEORDER_FUNC_DEFINED #define _BYTEORDER_FUNC_DEFINED #define htonl(x) __htonl(x) #define htons(x) __htons(x) #define ntohl(x) __ntohl(x) #define ntohs(x) __ntohs(x) #endif /* !_BYTEORDER_FUNC_DEFINED */ #endif /* lint */ #endif /* _KERNEL */ /* * Scale factor for scaled integers used to count %cpu time and load avgs. * * The number of CPU `tick's that map to a unique `%age' can be expressed * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that * can be calculated (assuming 32 bits) can be closely approximated using * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). * * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. */ #define FSHIFT 11 /* bits to right of fixed binary point */ #define FSCALE (1<> (PAGE_SHIFT - DEV_BSHIFT)) #define ctodb(db) /* calculates pages to devblks */ \ ((db) << (PAGE_SHIFT - DEV_BSHIFT)) /* * Old spelling of __containerof(). */ #define member2struct(s, m, x) \ ((struct s *)(void *)((char *)(x) - offsetof(struct s, m))) /* * Access a variable length array that has been declared as a fixed * length array. */ #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) #endif /* _SYS_PARAM_H_ */