]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add a confitem field for entry printing, and a printer for each type
authorGabriel Scherer <gabriel.scherer@gmail.com>
Sun, 10 Jun 2018 09:59:15 +0000 (11:59 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 14 Oct 2018 19:57:51 +0000 (21:57 +0200)
src/conf.c
src/confitems.gperf
src/confitems_lookup.c

index 5eaa38aaa72a8a2f32fbb92f62caee6592f32d9e..ca6f6aaeebf7ca643240dbeea9a2f166b080c5c7 100644 (file)
@@ -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"
index 7fd8ab960cf2242f43b3847aa085e9e57577db1d..f3954b55969e77aa9e6859893bbab7160edcf16e 100644 (file)
@@ -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)
index 39660efcbe0ec76d9d6924e64dc65927a69703b8..b8f6869936ea6b207c0da51360f2dea23708c626 100644 (file)
@@ -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)}
     };