summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2018-06-10 11:59:15 +0200
committerJoel Rosdahl <joel@rosdahl.net>2018-10-14 21:57:51 +0200
commit94c0b893e899c8621e31120e45f87b7c74e011f7 (patch)
treea9ae253ff408cd12b9872a484efd9eb26d30e895
parentde022dbf7573797f04ca48b2780adef122c1eda1 (diff)
downloadccache-94c0b893e899c8621e31120e45f87b7c74e011f7.tar.gz
Add a confitem field for entry printing, and a printer for each type
-rw-r--r--src/conf.c99
-rw-r--r--src/confitems.gperf2
-rw-r--r--src/confitems_lookup.c26
3 files changed, 109 insertions, 18 deletions
diff --git a/src/conf.c b/src/conf.c
index 5eaa38aa..ca6f6aae 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -19,6 +19,7 @@
typedef bool (*conf_item_parser)(const char *str, void *result, char **errmsg);
typedef bool (*conf_item_verifier)(void *value, char **errmsg);
+typedef const char *(*conf_item_formatter)(void *value);
struct conf_item {
const char *name;
@@ -26,6 +27,7 @@ struct conf_item {
conf_item_parser parser;
size_t offset;
conf_item_verifier verifier;
+ conf_item_formatter formatter;
};
struct env_to_conf_item {
@@ -50,6 +52,19 @@ parse_bool(const char *str, void *result, char **errmsg)
}
}
+static const char *
+bool_to_string(bool value)
+{
+ return value ? "true" : "false";
+}
+
+static const 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)
{
@@ -59,6 +74,19 @@ parse_env_string(const char *str, void *result, char **errmsg)
return *value != NULL;
}
+static const char *
+format_string(void *value)
+{
+ char **str = (char **)value;
+ return x_strdup(*str);
+}
+
+static const char *
+format_env_string(void *value)
+{
+ return format_string(value);
+}
+
static bool
parse_float(const char *str, void *result, char **errmsg)
{
@@ -75,6 +103,13 @@ parse_float(const char *str, void *result, char **errmsg)
}
}
+static const char *
+format_float(void *value)
+{
+ float *x = (float *)value;
+ return format("%.1f", *x);
+}
+
static bool
parse_size(const char *str, void *result, char **errmsg)
{
@@ -89,6 +124,13 @@ parse_size(const char *str, void *result, char **errmsg)
}
}
+static const 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)
{
@@ -129,6 +171,42 @@ parse_sloppiness(const char *str, void *result, char **errmsg)
return true;
}
+static const 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)
{
@@ -160,6 +238,17 @@ parse_umask(const char *str, void *result, char **errmsg)
}
}
+static const 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)
{
@@ -177,9 +266,10 @@ parse_unsigned(const char *str, void *result, char **errmsg)
}
static const char *
-bool_to_string(bool value)
+format_unsigned(void *value)
{
- return value ? "true" : "false";
+ unsigned *i = (unsigned *)value;
+ return format("%u", *i);
}
static bool
@@ -212,9 +302,10 @@ verify_dir_levels(void *value, char **errmsg)
}
#define ITEM(name, type) \
- parse_ ## type, offsetof(struct conf, name), NULL
+ parse_ ## type, offsetof(struct conf, name), NULL, format_ ## type
#define ITEM_V(name, type, verification) \
- parse_ ## type, offsetof(struct conf, name), verify_ ## verification
+ parse_ ## type, offsetof(struct conf, name), \
+ verify_ ## verification, format_ ## type
#include "confitems_lookup.c"
#include "envtoconfitems_lookup.c"
diff --git a/src/confitems.gperf b/src/confitems.gperf
index 7fd8ab96..f3954b55 100644
--- a/src/confitems.gperf
+++ b/src/confitems.gperf
@@ -4,7 +4,7 @@
%readonly-tables
%define hash-function-name confitems_hash
%define lookup-function-name confitems_get
-%define initializer-suffix ,0,NULL,0,NULL
+%define initializer-suffix ,0,NULL,0,NULL,NULL
struct conf_item;
%%
base_dir, 0, ITEM_V(base_dir, env_string, absolute_path)
diff --git a/src/confitems_lookup.c b/src/confitems_lookup.c
index 39660efc..b8f68699 100644
--- a/src/confitems_lookup.c
+++ b/src/confitems_lookup.c
@@ -96,20 +96,20 @@ confitems_get (register const char *str, register unsigned int len)
static const struct conf_item wordlist[] =
{
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
+ {"",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"
{"path", 20, ITEM(path, env_string)},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 13 "src/confitems.gperf"
{"compiler", 3, ITEM(compiler, string)},
#line 11 "src/confitems.gperf"
{"cache_dir", 1, ITEM(cache_dir, env_string)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 15 "src/confitems.gperf"
{"compression", 5, ITEM(compression, bool)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 17 "src/confitems.gperf"
{"cpp_extension", 7, ITEM(cpp_extension, string)},
#line 14 "src/confitems.gperf"
@@ -136,7 +136,7 @@ confitems_get (register const char *str, register unsigned int len)
{"read_only", 24, ITEM(read_only, bool)},
#line 38 "src/confitems.gperf"
{"sloppiness", 28, ITEM(sloppiness, sloppiness)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 25 "src/confitems.gperf"
{"keep_comments_cpp", 15, ITEM(keep_comments_cpp, bool)},
#line 29 "src/confitems.gperf"
@@ -153,26 +153,26 @@ confitems_get (register const char *str, register unsigned int len)
{"temporary_dir", 30, ITEM(temporary_dir, env_string)},
#line 37 "src/confitems.gperf"
{"run_second_cpp", 27, ITEM(run_second_cpp, bool)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 19 "src/confitems.gperf"
{"direct_mode", 9, ITEM(direct_mode, bool)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 23 "src/confitems.gperf"
{"hash_dir", 13, ITEM(hash_dir, bool)},
#line 22 "src/confitems.gperf"
{"hard_link", 12, ITEM(hard_link, bool)},
#line 41 "src/confitems.gperf"
{"umask", 31, ITEM(umask, umask)},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL}, {"",0,NULL,0,NULL,NULL},
#line 10 "src/confitems.gperf"
{"base_dir", 0, ITEM_V(base_dir, env_string, absolute_path)},
#line 21 "src/confitems.gperf"
{"extra_files_to_hash", 11, ITEM(extra_files_to_hash, env_string)},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
- {"",0,NULL,0,NULL}, {"",0,NULL,0,NULL},
+ {"",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"
{"limit_multiple", 16, ITEM(limit_multiple, float)},
- {"",0,NULL,0,NULL},
+ {"",0,NULL,0,NULL,NULL},
#line 24 "src/confitems.gperf"
{"ignore_headers_in_manifest", 14, ITEM(ignore_headers_in_manifest, env_string)}
};