diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2018-10-20 22:42:55 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2018-10-25 21:26:37 +0200 |
commit | c24670586a316dd5a431b25f0687aec0275a876f (patch) | |
tree | 7afc3876beabf44430034f95c60f9a717ac33989 | |
parent | 3f710b0af49a68fd00f3ea7460bad1e4cf982613 (diff) | |
download | ccache-c24670586a316dd5a431b25f0687aec0275a876f.tar.gz |
Refactor conf item lookup code
- Extracted parse/format/verify functions into a separate confitems.c
file.
- The *_lookup.c files are now compilation units of their own instead of
being included inside conf.c. This feels cleaner, and also relieves
cppcheck from having to check dirty, autogenerated code.
-rw-r--r-- | Makefile.in | 5 | ||||
-rw-r--r-- | dev.mk.in | 6 | ||||
-rw-r--r-- | src/conf.c | 301 | ||||
-rw-r--r-- | src/confitems.c | 284 | ||||
-rw-r--r-- | src/confitems.gperf | 15 | ||||
-rw-r--r-- | src/confitems.h | 49 | ||||
-rw-r--r-- | src/confitems_lookup.c | 126 | ||||
-rw-r--r-- | src/envtoconfitems.gperf | 3 | ||||
-rw-r--r-- | src/envtoconfitems.h | 14 | ||||
-rw-r--r-- | src/envtoconfitems_lookup.c | 94 |
10 files changed, 487 insertions, 410 deletions
diff --git a/Makefile.in b/Makefile.in index ee280b45..9e90755d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,6 +35,7 @@ non_3pp_sources = \ src/cleanup.c \ src/compopt.c \ src/conf.c \ + src/confitems.c \ src/counters.c \ src/execute.c \ src/exitfn.c \ @@ -51,6 +52,8 @@ generated_sources = \ src/version.c 3pp_sources = \ @getopt_long_c@ \ + src/confitems_lookup.c \ + src/envtoconfitems_lookup.c \ src/hashtable.c \ src/hashtable_itr.c \ src/murmurhashneutral2.c \ @@ -120,8 +123,6 @@ install: ccache$(EXEEXT) @disable_man@ccache.1 clean: rm -rf $(files_to_clean) -conf.c: confitems_lookup.c envtoconfitems_lookup.c - src/snprintf.o: CFLAGS += @no_implicit_fallthrough_warning@ $(zlib_objs): CPPFLAGS += -include config.h $(zlib_objs): CFLAGS += @no_implicit_fallthrough_warning@ @@ -38,7 +38,9 @@ headers = \ src/ccache.h \ src/compopt.h \ src/conf.h \ + src/confitems.h \ src/counters.h \ + src/envtoconfitems.h \ src/getopt_long.h \ src/hash.h \ src/hashtable.h \ @@ -110,8 +112,8 @@ src/version.o: src/version.c %_lookup.c: %.gperf $(if $(quiet),@echo " GPERF $@") - $(Q)$(GPERF) $< | awk '/#ifdef __GNUC__/ { ++i; if (i == 2) { print "static"; }} {print}' >$@ - $(Q)echo "static const size_t $$(echo $(notdir $*) | tr a-z A-Z)_TOTAL_KEYWORDS = $$(sed -nr 's/.*TOTAL_KEYWORDS = ([0-9]+).*/\1/p' $@);" >>$@ + $(Q)$(GPERF) $< >$@ + $(Q)echo "size_t $$(echo '$(notdir $*)_count(void)') { return $$(sed -nr 's/.*TOTAL_KEYWORDS = (.+),.*/\1/p' $@); }" >>$@ .PHONY: dist dist: $(dist_archives) @@ -15,301 +15,10 @@ // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "conf.h" +#include "confitems.h" +#include "envtoconfitems.h" #include "ccache.h" -typedef bool (*conf_item_parser)(const char *str, void *result, char **errmsg); -typedef bool (*conf_item_verifier)(void *value, char **errmsg); -typedef char *(*conf_item_formatter)(void *value); - -struct conf_item { - const char *name; - size_t number; - conf_item_parser parser; - size_t offset; - conf_item_verifier verifier; - conf_item_formatter formatter; -}; - -struct env_to_conf_item { - const char *env_name; - const char *conf_name; -}; - -static bool -parse_bool(const char *str, void *result, char **errmsg) -{ - bool *value = (bool *)result; - - if (str_eq(str, "true")) { - *value = true; - return true; - } else if (str_eq(str, "false")) { - *value = false; - return true; - } else { - *errmsg = format("not a boolean value: \"%s\"", str); - return false; - } -} - -static const char * -bool_to_string(bool value) -{ - return value ? "true" : "false"; -} - -static char * -format_bool(void *value) -{ - bool *b = (bool *)value; - return x_strdup(bool_to_string(*b)); -} - -static bool -parse_env_string(const char *str, void *result, char **errmsg) -{ - char **value = (char **)result; - free(*value); - *value = subst_env_in_string(str, errmsg); - return *value != NULL; -} - -static char * -format_string(void *value) -{ - char **str = (char **)value; - return x_strdup(*str); -} - -static char * -format_env_string(void *value) -{ - return format_string(value); -} - -static bool -parse_float(const char *str, void *result, char **errmsg) -{ - float *value = (float *)result; - errno = 0; - char *endptr; - float x = strtof(str, &endptr); - if (errno == 0 && *str != '\0' && *endptr == '\0') { - *value = x; - return true; - } else { - *errmsg = format("invalid floating point: \"%s\"", str); - return false; - } -} - -static char * -format_float(void *value) -{ - float *x = (float *)value; - return format("%.1f", *x); -} - -static bool -parse_size(const char *str, void *result, char **errmsg) -{ - uint64_t *value = (uint64_t *)result; - uint64_t size; - if (parse_size_with_suffix(str, &size)) { - *value = size; - return true; - } else { - *errmsg = format("invalid size: \"%s\"", str); - return false; - } -} - -static char * -format_size(void *value) -{ - uint64_t *size = (uint64_t *)value; - return format_parsable_size_with_suffix(*size); -} - -static bool -parse_sloppiness(const char *str, void *result, char **errmsg) -{ - unsigned *value = (unsigned *)result; - if (!str) { - return *value; - } - - char *p = x_strdup(str); - char *q = p; - char *word; - char *saveptr = NULL; - while ((word = strtok_r(q, ", ", &saveptr))) { - if (str_eq(word, "file_macro")) { - *value |= SLOPPY_FILE_MACRO; - } else if (str_eq(word, "file_stat_matches")) { - *value |= SLOPPY_FILE_STAT_MATCHES; - } else if (str_eq(word, "file_stat_matches_ctime")) { - *value |= SLOPPY_FILE_STAT_MATCHES_CTIME; - } else if (str_eq(word, "include_file_ctime")) { - *value |= SLOPPY_INCLUDE_FILE_CTIME; - } else if (str_eq(word, "include_file_mtime")) { - *value |= SLOPPY_INCLUDE_FILE_MTIME; - } else if (str_eq(word, "no_system_headers")) { - *value |= SLOPPY_NO_SYSTEM_HEADERS; - } else if (str_eq(word, "pch_defines")) { - *value |= SLOPPY_PCH_DEFINES; - } else if (str_eq(word, "time_macros")) { - *value |= SLOPPY_TIME_MACROS; - } else { - *errmsg = format("unknown sloppiness: \"%s\"", word); - free(p); - return false; - } - q = NULL; - } - free(p); - return true; -} - -static char * -format_sloppiness(void *value) -{ - unsigned *sloppiness = (unsigned *)value; - char *s = x_strdup(""); - if (*sloppiness & SLOPPY_FILE_MACRO) { - reformat(&s, "%sfile_macro, ", s); - } - if (*sloppiness & SLOPPY_INCLUDE_FILE_MTIME) { - reformat(&s, "%sinclude_file_mtime, ", s); - } - if (*sloppiness & SLOPPY_INCLUDE_FILE_CTIME) { - reformat(&s, "%sinclude_file_ctime, ", s); - } - if (*sloppiness & SLOPPY_TIME_MACROS) { - reformat(&s, "%stime_macros, ", s); - } - if (*sloppiness & SLOPPY_PCH_DEFINES) { - reformat(&s, "%spch_defines, ", s); - } - if (*sloppiness & SLOPPY_FILE_STAT_MATCHES) { - reformat(&s, "%sfile_stat_matches, ", s); - } - if (*sloppiness & SLOPPY_FILE_STAT_MATCHES_CTIME) { - reformat(&s, "%sfile_stat_matches_ctime, ", s); - } - if (*sloppiness & SLOPPY_NO_SYSTEM_HEADERS) { - reformat(&s, "%sno_system_headers, ", s); - } - if (*sloppiness) { - // Strip last ", ". - s[strlen(s) - 2] = '\0'; - } - return s; -} - -static bool -parse_string(const char *str, void *result, char **errmsg) -{ - (void)errmsg; - - char **value = (char **)result; - free(*value); - *value = x_strdup(str); - return true; -} - -static bool -parse_umask(const char *str, void *result, char **errmsg) -{ - unsigned *value = (unsigned *)result; - if (str_eq(str, "")) { - *value = UINT_MAX; - return true; - } - - errno = 0; - char *endptr; - *value = strtoul(str, &endptr, 8); - if (errno == 0 && *str != '\0' && *endptr == '\0') { - return true; - } else { - *errmsg = format("not an octal integer: \"%s\"", str); - return false; - } -} - -static char * -format_umask(void *value) -{ - unsigned *umask = (unsigned *)value; - if (*umask == UINT_MAX) { - return x_strdup(""); - } else { - return format("%03o", *umask); - } -} - -static bool -parse_unsigned(const char *str, void *result, char **errmsg) -{ - unsigned *value = (unsigned *)result; - errno = 0; - char *endptr; - long x = strtol(str, &endptr, 10); - if (errno == 0 && x >= 0 && *str != '\0' && *endptr == '\0') { - *value = x; - return true; - } else { - *errmsg = format("invalid unsigned integer: \"%s\"", str); - return false; - } -} - -static char * -format_unsigned(void *value) -{ - unsigned *i = (unsigned *)value; - return format("%u", *i); -} - -static bool -verify_absolute_path(void *value, char **errmsg) -{ - char **path = (char **)value; - assert(*path); - if (str_eq(*path, "")) { - // The empty string means "disable" in this case. - return true; - } else if (is_absolute_path(*path)) { - return true; - } else { - *errmsg = format("not an absolute path: \"%s\"", *path); - return false; - } -} - -static bool -verify_dir_levels(void *value, char **errmsg) -{ - unsigned *levels = (unsigned *)value; - assert(levels); - if (*levels >= 1 && *levels <= 8) { - return true; - } else { - *errmsg = format("cache directory levels must be between 1 and 8"); - return false; - } -} - -#define ITEM(name, type) \ - parse_ ## type, offsetof(struct conf, name), NULL, format_ ## type -#define ITEM_V(name, type, verification) \ - parse_ ## type, offsetof(struct conf, name), \ - verify_ ## verification, format_ ## type - -#include "confitems_lookup.c" -#include "envtoconfitems_lookup.c" - static const struct conf_item * find_conf(const char *name) { @@ -333,7 +42,7 @@ handle_conf_setting(struct conf *conf, const char *key, const char *value, return false; } - if (from_env_variable && item->parser == parse_bool) { + if (from_env_variable && item->parser == confitem_parse_bool) { // Special rule for boolean settings from the environment: "0", "false", // "disable" and "no" (case insensitive) are invalid, and all other values // mean true. @@ -446,8 +155,8 @@ conf_create(void) conf->temporary_dir = x_strdup(""); conf->umask = UINT_MAX; // Default: don't set umask. conf->unify = false; - conf->item_origins = x_malloc(CONFITEMS_TOTAL_KEYWORDS * sizeof(char *)); - for (size_t i = 0; i < CONFITEMS_TOTAL_KEYWORDS; ++i) { + conf->item_origins = x_malloc(confitems_count() * sizeof(char *)); + for (size_t i = 0; i < confitems_count(); ++i) { conf->item_origins[i] = "default"; } return conf; diff --git a/src/confitems.c b/src/confitems.c new file mode 100644 index 00000000..de6c8e1a --- /dev/null +++ b/src/confitems.c @@ -0,0 +1,284 @@ +// Copyright (C) 2018 Joel Rosdahl +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#include "confitems.h" +#include "ccache.h" + +static char * +format_string(void *value) +{ + char **str = (char **)value; + return x_strdup(*str); +} + +bool +confitem_parse_bool(const char *str, void *result, char **errmsg) +{ + bool *value = (bool *)result; + + if (str_eq(str, "true")) { + *value = true; + return true; + } else if (str_eq(str, "false")) { + *value = false; + return true; + } else { + *errmsg = format("not a boolean value: \"%s\"", str); + return false; + } +} + +char * +confitem_format_bool(void *value) +{ + bool *b = (bool *)value; + return x_strdup(*b ? "true" : "false"); +} + +bool +confitem_parse_env_string(const char *str, void *result, char **errmsg) +{ + char **value = (char **)result; + free(*value); + *value = subst_env_in_string(str, errmsg); + return *value != NULL; +} + +char * +confitem_format_env_string(void *value) +{ + return format_string(value); +} + +bool +confitem_parse_float(const char *str, void *result, char **errmsg) +{ + float *value = (float *)result; + errno = 0; + char *endptr; + float x = strtof(str, &endptr); + if (errno == 0 && *str != '\0' && *endptr == '\0') { + *value = x; + return true; + } else { + *errmsg = format("invalid floating point: \"%s\"", str); + return false; + } +} + +char * +confitem_format_float(void *value) +{ + float *x = (float *)value; + return format("%.1f", *x); +} + +bool +confitem_parse_size(const char *str, void *result, char **errmsg) +{ + uint64_t *value = (uint64_t *)result; + uint64_t size; + if (parse_size_with_suffix(str, &size)) { + *value = size; + return true; + } else { + *errmsg = format("invalid size: \"%s\"", str); + return false; + } +} + +char * +confitem_format_size(void *value) +{ + uint64_t *size = (uint64_t *)value; + return format_parsable_size_with_suffix(*size); +} + +bool +confitem_parse_sloppiness(const char *str, void *result, char **errmsg) +{ + unsigned *value = (unsigned *)result; + if (!str) { + return *value; + } + + char *p = x_strdup(str); + char *q = p; + char *word; + char *saveptr = NULL; + while ((word = strtok_r(q, ", ", &saveptr))) { + if (str_eq(word, "file_macro")) { + *value |= SLOPPY_FILE_MACRO; + } else if (str_eq(word, "file_stat_matches")) { + *value |= SLOPPY_FILE_STAT_MATCHES; + } else if (str_eq(word, "file_stat_matches_ctime")) { + *value |= SLOPPY_FILE_STAT_MATCHES_CTIME; + } else if (str_eq(word, "include_file_ctime")) { + *value |= SLOPPY_INCLUDE_FILE_CTIME; + } else if (str_eq(word, "include_file_mtime")) { + *value |= SLOPPY_INCLUDE_FILE_MTIME; + } else if (str_eq(word, "no_system_headers")) { + *value |= SLOPPY_NO_SYSTEM_HEADERS; + } else if (str_eq(word, "pch_defines")) { + *value |= SLOPPY_PCH_DEFINES; + } else if (str_eq(word, "time_macros")) { + *value |= SLOPPY_TIME_MACROS; + } else { + *errmsg = format("unknown sloppiness: \"%s\"", word); + free(p); + return false; + } + q = NULL; + } + free(p); + return true; +} + +char * +confitem_format_sloppiness(void *value) +{ + unsigned *sloppiness = (unsigned *)value; + char *s = x_strdup(""); + if (*sloppiness & SLOPPY_FILE_MACRO) { + reformat(&s, "%sfile_macro, ", s); + } + if (*sloppiness & SLOPPY_INCLUDE_FILE_MTIME) { + reformat(&s, "%sinclude_file_mtime, ", s); + } + if (*sloppiness & SLOPPY_INCLUDE_FILE_CTIME) { + reformat(&s, "%sinclude_file_ctime, ", s); + } + if (*sloppiness & SLOPPY_TIME_MACROS) { + reformat(&s, "%stime_macros, ", s); + } + if (*sloppiness & SLOPPY_PCH_DEFINES) { + reformat(&s, "%spch_defines, ", s); + } + if (*sloppiness & SLOPPY_FILE_STAT_MATCHES) { + reformat(&s, "%sfile_stat_matches, ", s); + } + if (*sloppiness & SLOPPY_FILE_STAT_MATCHES_CTIME) { + reformat(&s, "%sfile_stat_matches_ctime, ", s); + } + if (*sloppiness & SLOPPY_NO_SYSTEM_HEADERS) { + reformat(&s, "%sno_system_headers, ", s); + } + if (*sloppiness) { + // Strip last ", ". + s[strlen(s) - 2] = '\0'; + } + return s; +} + +bool +confitem_parse_string(const char *str, void *result, char **errmsg) +{ + (void)errmsg; + + char **value = (char **)result; + free(*value); + *value = x_strdup(str); + return true; +} + +char * +confitem_format_string(void *value) +{ + return format_string(value); +} + +bool +confitem_parse_umask(const char *str, void *result, char **errmsg) +{ + unsigned *value = (unsigned *)result; + if (str_eq(str, "")) { + *value = UINT_MAX; + return true; + } + + errno = 0; + char *endptr; + *value = strtoul(str, &endptr, 8); + if (errno == 0 && *str != '\0' && *endptr == '\0') { + return true; + } else { + *errmsg = format("not an octal integer: \"%s\"", str); + return false; + } +} + +char * +confitem_format_umask(void *value) +{ + unsigned *umask = (unsigned *)value; + if (*umask == UINT_MAX) { + return x_strdup(""); + } else { + return format("%03o", *umask); + } +} + +bool +confitem_parse_unsigned(const char *str, void *result, char **errmsg) +{ + unsigned *value = (unsigned *)result; + errno = 0; + char *endptr; + long x = strtol(str, &endptr, 10); + if (errno == 0 && x >= 0 && *str != '\0' && *endptr == '\0') { + *value = x; + return true; + } else { + *errmsg = format("invalid unsigned integer: \"%s\"", str); + return false; + } +} + +char * +confitem_format_unsigned(void *value) +{ + unsigned *i = (unsigned *)value; + return format("%u", *i); +} + +bool +confitem_verify_absolute_path(void *value, char **errmsg) +{ + char **path = (char **)value; + assert(*path); + if (str_eq(*path, "")) { + // The empty string means "disable" in this case. + return true; + } else if (is_absolute_path(*path)) { + return true; + } else { + *errmsg = format("not an absolute path: \"%s\"", *path); + return false; + } +} + +bool +confitem_verify_dir_levels(void *value, char **errmsg) +{ + unsigned *levels = (unsigned *)value; + assert(levels); + if (*levels >= 1 && *levels <= 8) { + return true; + } else { + *errmsg = format("cache directory levels must be between 1 and 8"); + return false; + } +} diff --git a/src/confitems.gperf b/src/confitems.gperf index f3954b55..af9f82da 100644 --- a/src/confitems.gperf +++ b/src/confitems.gperf @@ -4,7 +4,20 @@ %readonly-tables %define hash-function-name confitems_hash %define lookup-function-name confitems_get -%define initializer-suffix ,0,NULL,0,NULL,NULL +%define initializer-suffix ,0,0,NULL,NULL,NULL +%{ +#include "confitems.h" +#include "conf.h" + +#undef bool +#define ITEM_ENTRY(name, type, verify_fn) \ + offsetof(struct conf, name), confitem_parse_ ## type, \ + confitem_format_ ## type, verify_fn +#define ITEM(name, type) \ + ITEM_ENTRY(name, type, NULL) +#define ITEM_V(name, type, verification) \ + ITEM_ENTRY(name, type, confitem_verify_ ## verification) +%} struct conf_item; %% base_dir, 0, ITEM_V(base_dir, env_string, absolute_path) diff --git a/src/confitems.h b/src/confitems.h new file mode 100644 index 00000000..e811b579 --- /dev/null +++ b/src/confitems.h @@ -0,0 +1,49 @@ +#ifndef CONFITEMS_H +#define CONFITEMS_H + +#include "system.h" + +typedef bool (*conf_item_parser)(const char *str, void *result, char **errmsg); +typedef bool (*conf_item_verifier)(void *value, char **errmsg); +typedef char *(*conf_item_formatter)(void *value); + +struct conf_item { + const char *name; + size_t number; + size_t offset; + conf_item_parser parser; + conf_item_formatter formatter; + conf_item_verifier verifier; +}; + +bool confitem_parse_bool(const char *str, void *result, char **errmsg); +char *confitem_format_bool(void *value); + +bool confitem_parse_env_string(const char *str, void *result, char **errmsg); +char *confitem_format_env_string(void *value); + +bool confitem_parse_float(const char *str, void *result, char **errmsg); +char *confitem_format_float(void *value); + +bool confitem_parse_size(const char *str, void *result, char **errmsg); +char *confitem_format_size(void *value); + +bool confitem_parse_sloppiness(const char *str, void *result, char **errmsg); +char *confitem_format_sloppiness(void *value); + +bool confitem_parse_string(const char *str, void *result, char **errmsg); +char *confitem_format_string(void *value); + +bool confitem_parse_umask(const char *str, void *result, char **errmsg); +char *confitem_format_umask(void *value); + +bool confitem_parse_unsigned(const char *str, void *result, char **errmsg); +char *confitem_format_unsigned(void *value); + +bool confitem_verify_absolute_path(void *value, char **errmsg); +bool confitem_verify_dir_levels(void *value, char **errmsg); + +const struct conf_item *confitems_get(const char *str, size_t len); +size_t confitems_count(void); + +#endif diff --git a/src/confitems_lookup.c b/src/confitems_lookup.c index b8f68699..0e2c4fa3 100644 --- a/src/confitems_lookup.c +++ b/src/confitems_lookup.c @@ -1,4 +1,4 @@ -/* ANSI-C code produced by gperf version 3.0.4 */ +/* ANSI-C code produced by gperf version 3.1 */ /* Command-line: gperf src/confitems.gperf */ /* Computed positions: -k'1-2' */ @@ -26,10 +26,23 @@ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) /* The character set is not based on ISO-646. */ -#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>." +#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>." #endif #line 8 "src/confitems.gperf" + +#include "confitems.h" +#include "conf.h" + +#undef bool +#define ITEM_ENTRY(name, type, verify_fn) \ + offsetof(struct conf, name), confitem_parse_ ## type, \ + confitem_format_ ## type, verify_fn +#define ITEM(name, type) \ + ITEM_ENTRY(name, type, NULL) +#define ITEM_V(name, type, verification) \ + ITEM_ENTRY(name, type, confitem_verify_ ## verification) +#line 21 "src/confitems.gperf" struct conf_item; /* maximum key range = 48, duplicates = 0 */ @@ -41,7 +54,7 @@ inline #endif #endif static unsigned int -confitems_hash (register const char *str, register unsigned int len) +confitems_hash (register const char *str, register size_t len) { static const unsigned char asso_values[] = { @@ -75,15 +88,8 @@ confitems_hash (register const char *str, register unsigned int len) return len + asso_values[(unsigned char)str[1]] + asso_values[(unsigned char)str[0]]; } -static -#ifdef __GNUC__ -__inline -#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ -__attribute__ ((__gnu_inline__)) -#endif -#endif const struct conf_item * -confitems_get (register const char *str, register unsigned int len) +confitems_get (register const char *str, register size_t len) { enum { @@ -96,92 +102,92 @@ confitems_get (register const char *str, register unsigned int len) static const struct conf_item wordlist[] = { - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, -#line 30 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, +#line 43 "src/confitems.gperf" {"path", 20, ITEM(path, env_string)}, - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, - {"",0,NULL,0,NULL,NULL}, -#line 13 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, + {"",0,0,NULL,NULL,NULL}, +#line 26 "src/confitems.gperf" {"compiler", 3, ITEM(compiler, string)}, -#line 11 "src/confitems.gperf" +#line 24 "src/confitems.gperf" {"cache_dir", 1, ITEM(cache_dir, env_string)}, - {"",0,NULL,0,NULL,NULL}, -#line 15 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 28 "src/confitems.gperf" {"compression", 5, ITEM(compression, bool)}, - {"",0,NULL,0,NULL,NULL}, -#line 17 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 30 "src/confitems.gperf" {"cpp_extension", 7, ITEM(cpp_extension, string)}, -#line 14 "src/confitems.gperf" +#line 27 "src/confitems.gperf" {"compiler_check", 4, ITEM(compiler_check, string)}, -#line 18 "src/confitems.gperf" +#line 31 "src/confitems.gperf" {"debug", 8, ITEM(debug, bool)}, -#line 12 "src/confitems.gperf" +#line 25 "src/confitems.gperf" {"cache_dir_levels", 2, ITEM_V(cache_dir_levels, unsigned, dir_levels)}, -#line 16 "src/confitems.gperf" +#line 29 "src/confitems.gperf" {"compression_level", 6, ITEM(compression_level, unsigned)}, -#line 27 "src/confitems.gperf" +#line 40 "src/confitems.gperf" {"log_file", 17, ITEM(log_file, env_string)}, -#line 32 "src/confitems.gperf" +#line 45 "src/confitems.gperf" {"prefix_command", 22, ITEM(prefix_command, env_string)}, -#line 39 "src/confitems.gperf" +#line 52 "src/confitems.gperf" {"stats", 29, ITEM(stats, bool)}, -#line 31 "src/confitems.gperf" +#line 44 "src/confitems.gperf" {"pch_external_checksum", 21, ITEM(pch_external_checksum, bool)}, -#line 36 "src/confitems.gperf" +#line 49 "src/confitems.gperf" {"recache", 26, ITEM(recache, bool)}, -#line 33 "src/confitems.gperf" +#line 46 "src/confitems.gperf" {"prefix_command_cpp", 23, ITEM(prefix_command_cpp, env_string)}, -#line 34 "src/confitems.gperf" +#line 47 "src/confitems.gperf" {"read_only", 24, ITEM(read_only, bool)}, -#line 38 "src/confitems.gperf" +#line 51 "src/confitems.gperf" {"sloppiness", 28, ITEM(sloppiness, sloppiness)}, - {"",0,NULL,0,NULL,NULL}, -#line 25 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 38 "src/confitems.gperf" {"keep_comments_cpp", 15, ITEM(keep_comments_cpp, bool)}, -#line 29 "src/confitems.gperf" +#line 42 "src/confitems.gperf" {"max_size", 19, ITEM(max_size, size)}, -#line 28 "src/confitems.gperf" +#line 41 "src/confitems.gperf" {"max_files", 18, ITEM(max_files, unsigned)}, -#line 42 "src/confitems.gperf" +#line 55 "src/confitems.gperf" {"unify", 32, ITEM(unify, bool)}, -#line 35 "src/confitems.gperf" +#line 48 "src/confitems.gperf" {"read_only_direct", 25, ITEM(read_only_direct, bool)}, -#line 20 "src/confitems.gperf" +#line 33 "src/confitems.gperf" {"disable", 10, ITEM(disable, bool)}, -#line 40 "src/confitems.gperf" +#line 53 "src/confitems.gperf" {"temporary_dir", 30, ITEM(temporary_dir, env_string)}, -#line 37 "src/confitems.gperf" +#line 50 "src/confitems.gperf" {"run_second_cpp", 27, ITEM(run_second_cpp, bool)}, - {"",0,NULL,0,NULL,NULL}, -#line 19 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 32 "src/confitems.gperf" {"direct_mode", 9, ITEM(direct_mode, bool)}, - {"",0,NULL,0,NULL,NULL}, -#line 23 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 36 "src/confitems.gperf" {"hash_dir", 13, ITEM(hash_dir, bool)}, -#line 22 "src/confitems.gperf" +#line 35 "src/confitems.gperf" {"hard_link", 12, ITEM(hard_link, bool)}, -#line 41 "src/confitems.gperf" +#line 54 "src/confitems.gperf" {"umask", 31, ITEM(umask, umask)}, - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, -#line 10 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, +#line 23 "src/confitems.gperf" {"base_dir", 0, ITEM_V(base_dir, env_string, absolute_path)}, -#line 21 "src/confitems.gperf" +#line 34 "src/confitems.gperf" {"extra_files_to_hash", 11, ITEM(extra_files_to_hash, env_string)}, - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, - {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL}, -#line 26 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, + {"",0,0,NULL,NULL,NULL}, {"",0,0,NULL,NULL,NULL}, +#line 39 "src/confitems.gperf" {"limit_multiple", 16, ITEM(limit_multiple, float)}, - {"",0,NULL,0,NULL,NULL}, -#line 24 "src/confitems.gperf" + {"",0,0,NULL,NULL,NULL}, +#line 37 "src/confitems.gperf" {"ignore_headers_in_manifest", 14, ITEM(ignore_headers_in_manifest, env_string)} }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { - register int key = confitems_hash (str, len); + register unsigned int key = confitems_hash (str, len); - if (key <= MAX_HASH_VALUE && key >= 0) + if (key <= MAX_HASH_VALUE) { register const char *s = wordlist[key].name; @@ -191,4 +197,4 @@ confitems_get (register const char *str, register unsigned int len) } return 0; } -static const size_t CONFITEMS_TOTAL_KEYWORDS = 33; +size_t confitems_count(void) { return 33; } diff --git a/src/envtoconfitems.gperf b/src/envtoconfitems.gperf index 4d255190..ffd354b2 100644 --- a/src/envtoconfitems.gperf +++ b/src/envtoconfitems.gperf @@ -6,6 +6,9 @@ %define lookup-function-name envtoconfitems_get %define slot-name env_name %define initializer-suffix ,"" +%{ +#include "envtoconfitems.h" +%} struct env_to_conf_item; %% BASEDIR, "base_dir" diff --git a/src/envtoconfitems.h b/src/envtoconfitems.h new file mode 100644 index 00000000..baeee5c4 --- /dev/null +++ b/src/envtoconfitems.h @@ -0,0 +1,14 @@ +#ifndef ENVTOCONFITEMS_H +#define ENVTOCONFITEMS_H + +#include "system.h" + +struct env_to_conf_item { + const char *env_name; + const char *conf_name; +}; + +const struct env_to_conf_item *envtoconfitems_get(const char *str, size_t len); +size_t envtoconfitems_count(void); + +#endif diff --git a/src/envtoconfitems_lookup.c b/src/envtoconfitems_lookup.c index b5afa695..30432af4 100644 --- a/src/envtoconfitems_lookup.c +++ b/src/envtoconfitems_lookup.c @@ -1,4 +1,4 @@ -/* ANSI-C code produced by gperf version 3.0.4 */ +/* ANSI-C code produced by gperf version 3.1 */ /* Command-line: gperf src/envtoconfitems.gperf */ /* Computed positions: -k'4-5' */ @@ -26,10 +26,13 @@ && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) /* The character set is not based on ISO-646. */ -#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>." +#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>." #endif #line 9 "src/envtoconfitems.gperf" + +#include "envtoconfitems.h" +#line 12 "src/envtoconfitems.gperf" struct env_to_conf_item; /* maximum key range = 52, duplicates = 0 */ @@ -41,7 +44,7 @@ inline #endif #endif static unsigned int -envtoconfitems_hash (register const char *str, register unsigned int len) +envtoconfitems_hash (register const char *str, register size_t len) { static const unsigned char asso_values[] = { @@ -72,7 +75,7 @@ envtoconfitems_hash (register const char *str, register unsigned int len) 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54, 54 }; - register int hval = len; + register unsigned int hval = len; switch (hval) { @@ -89,15 +92,8 @@ envtoconfitems_hash (register const char *str, register unsigned int len) return hval; } -static -#ifdef __GNUC__ -__inline -#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ -__attribute__ ((__gnu_inline__)) -#endif -#endif const struct env_to_conf_item * -envtoconfitems_get (register const char *str, register unsigned int len) +envtoconfitems_get (register const char *str, register size_t len) { enum { @@ -111,93 +107,93 @@ envtoconfitems_get (register const char *str, register unsigned int len) static const struct env_to_conf_item wordlist[] = { {"",""}, {"",""}, -#line 12 "src/envtoconfitems.gperf" +#line 15 "src/envtoconfitems.gperf" {"CC", "compiler"}, -#line 19 "src/envtoconfitems.gperf" +#line 22 "src/envtoconfitems.gperf" {"DIR", "cache_dir"}, -#line 17 "src/envtoconfitems.gperf" - {"CPP2", "run_second_cpp"}, #line 20 "src/envtoconfitems.gperf" + {"CPP2", "run_second_cpp"}, +#line 23 "src/envtoconfitems.gperf" {"DEBUG", "debug"}, {"",""}, -#line 42 "src/envtoconfitems.gperf" +#line 45 "src/envtoconfitems.gperf" {"TEMPDIR", "temporary_dir"}, -#line 13 "src/envtoconfitems.gperf" +#line 16 "src/envtoconfitems.gperf" {"COMPILER", "compiler"}, -#line 33 "src/envtoconfitems.gperf" +#line 36 "src/envtoconfitems.gperf" {"PATH", "path"}, -#line 40 "src/envtoconfitems.gperf" +#line 43 "src/envtoconfitems.gperf" {"SLOPPINESS", "sloppiness"}, {"",""}, -#line 26 "src/envtoconfitems.gperf" +#line 29 "src/envtoconfitems.gperf" {"HASHDIR", "hash_dir"}, -#line 14 "src/envtoconfitems.gperf" +#line 17 "src/envtoconfitems.gperf" {"COMPILERCHECK", "compiler_check"}, -#line 28 "src/envtoconfitems.gperf" +#line 31 "src/envtoconfitems.gperf" {"LIMIT_MULTIPLE", "limit_multiple"}, -#line 44 "src/envtoconfitems.gperf" +#line 47 "src/envtoconfitems.gperf" {"UNIFY", "unify"}, -#line 35 "src/envtoconfitems.gperf" +#line 38 "src/envtoconfitems.gperf" {"PREFIX", "prefix_command"}, -#line 29 "src/envtoconfitems.gperf" +#line 32 "src/envtoconfitems.gperf" {"LOGFILE", "log_file"}, -#line 30 "src/envtoconfitems.gperf" +#line 33 "src/envtoconfitems.gperf" {"MAXFILES", "max_files"}, {"",""}, -#line 36 "src/envtoconfitems.gperf" +#line 39 "src/envtoconfitems.gperf" {"PREFIX_CPP", "prefix_command_cpp"}, -#line 21 "src/envtoconfitems.gperf" +#line 24 "src/envtoconfitems.gperf" {"DIRECT", "direct_mode"}, -#line 11 "src/envtoconfitems.gperf" +#line 14 "src/envtoconfitems.gperf" {"BASEDIR", "base_dir"}, -#line 15 "src/envtoconfitems.gperf" +#line 18 "src/envtoconfitems.gperf" {"COMPRESS", "compression"}, -#line 23 "src/envtoconfitems.gperf" +#line 26 "src/envtoconfitems.gperf" {"EXTENSION", "cpp_extension"}, -#line 41 "src/envtoconfitems.gperf" +#line 44 "src/envtoconfitems.gperf" {"STATS", "stats"}, {"",""}, -#line 31 "src/envtoconfitems.gperf" +#line 34 "src/envtoconfitems.gperf" {"MAXSIZE", "max_size"}, -#line 16 "src/envtoconfitems.gperf" +#line 19 "src/envtoconfitems.gperf" {"COMPRESSLEVEL", "compression_level"}, {"",""}, -#line 34 "src/envtoconfitems.gperf" +#line 37 "src/envtoconfitems.gperf" {"PCH_EXTSUM", "pch_external_checksum"}, {"",""}, -#line 39 "src/envtoconfitems.gperf" +#line 42 "src/envtoconfitems.gperf" {"RECACHE", "recache"}, -#line 37 "src/envtoconfitems.gperf" +#line 40 "src/envtoconfitems.gperf" {"READONLY", "read_only"}, {"",""}, -#line 43 "src/envtoconfitems.gperf" +#line 46 "src/envtoconfitems.gperf" {"UMASK", "umask"}, {"",""}, -#line 32 "src/envtoconfitems.gperf" +#line 35 "src/envtoconfitems.gperf" {"NLEVELS", "cache_dir_levels"}, -#line 18 "src/envtoconfitems.gperf" +#line 21 "src/envtoconfitems.gperf" {"COMMENTS", "keep_comments_cpp"}, {"",""}, -#line 38 "src/envtoconfitems.gperf" +#line 41 "src/envtoconfitems.gperf" {"READONLY_DIRECT", "read_only_direct"}, {"",""}, -#line 22 "src/envtoconfitems.gperf" - {"DISABLE", "disable"}, #line 25 "src/envtoconfitems.gperf" + {"DISABLE", "disable"}, +#line 28 "src/envtoconfitems.gperf" {"HARDLINK", "hard_link"}, {"",""}, {"",""}, {"",""}, {"",""}, {"",""}, {"",""}, -#line 24 "src/envtoconfitems.gperf" +#line 27 "src/envtoconfitems.gperf" {"EXTRAFILES", "extra_files_to_hash"}, {"",""}, {"",""}, -#line 27 "src/envtoconfitems.gperf" +#line 30 "src/envtoconfitems.gperf" {"IGNOREHEADERS", "ignore_headers_in_manifest"} }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { - register int key = envtoconfitems_hash (str, len); + register unsigned int key = envtoconfitems_hash (str, len); - if (key <= MAX_HASH_VALUE && key >= 0) + if (key <= MAX_HASH_VALUE) { register const char *s = wordlist[key].env_name; @@ -207,4 +203,4 @@ envtoconfitems_get (register const char *str, register unsigned int len) } return 0; } -static const size_t ENVTOCONFITEMS_TOTAL_KEYWORDS = 34; +size_t envtoconfitems_count(void) { return 34; } |