summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2011-07-26 22:10:17 +0200
committerJoel Rosdahl <joel@rosdahl.net>2011-07-29 17:15:52 +0200
commitff068ce709f70e6cff8439c861f6c55c0ba55a33 (patch)
treecdd9d33aadb75c7f6644ee7941a4ccbcb70fa9a6
parent165fa068c8ba496d5173feb0b98148564580d8aa (diff)
downloadccache-ff068ce709f70e6cff8439c861f6c55c0ba55a33.tar.gz
config: Add conf_print_items function
-rw-r--r--conf.c104
-rw-r--r--conf.h3
-rw-r--r--test/test_conf.c84
3 files changed, 191 insertions, 0 deletions
diff --git a/conf.c b/conf.c
index efbb55eb..5cd73928 100644
--- a/conf.c
+++ b/conf.c
@@ -615,3 +615,107 @@ conf_set_value_in_file(const char *path, const char *key, const char *value,
return true;
}
+
+bool conf_print_items(struct conf *conf,
+ void(*printer)(const char *s, void *context),
+ void *context)
+{
+ char *s = x_strdup("");
+ char *s2;
+
+ reformat(&s, "base_dir = %s", conf->base_dir);
+ printer(s, context);
+
+ reformat(&s, "cache_dir = %s", conf->cache_dir);
+ printer(s, context);
+
+ reformat(&s, "cache_dir_levels = %u", conf->cache_dir_levels);
+ printer(s, context);
+
+ reformat(&s, "compiler = %s", conf->compiler);
+ printer(s, context);
+
+ reformat(&s, "compiler_check = %s", conf->compiler_check);
+ printer(s, context);
+
+ reformat(&s, "compression = %s", conf->compression ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "cpp_extension = %s", conf->cpp_extension);
+ printer(s, context);
+
+ reformat(&s, "detect_shebang = %s", conf->detect_shebang ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "direct_mode = %s", conf->direct_mode ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "disable = %s", conf->disable ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "extra_files_to_hash = %s", conf->extra_files_to_hash);
+ printer(s, context);
+
+ reformat(&s, "hard_link = %s", conf->hard_link ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "hash_dir = %s", conf->hash_dir ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "log_file = %s", conf->log_file);
+ printer(s, context);
+
+ reformat(&s, "max_files = %u", conf->max_files);
+ printer(s, context);
+
+ s2 = format_parsable_size_with_suffix(conf->max_size);
+ reformat(&s, "max_size = %s", s2);
+ printer(s, context);
+ free(s2);
+
+ reformat(&s, "path = %s", conf->path);
+ printer(s, context);
+
+ reformat(&s, "prefix_command = %s", conf->prefix_command);
+ printer(s, context);
+
+ reformat(&s, "read_only = %s", conf->read_only ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "recache = %s", conf->recache ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "run_second_cpp = %s", conf->run_second_cpp ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "sloppiness = ");
+ if (conf->sloppiness & SLOPPY_FILE_MACRO) {
+ reformat(&s, "%sfile_macro, ", s);
+ }
+ if (conf->sloppiness & SLOPPY_INCLUDE_FILE_MTIME) {
+ reformat(&s, "%sinclude_file_mtime, ", s);
+ }
+ if (conf->sloppiness & SLOPPY_TIME_MACROS) {
+ reformat(&s, "%stime_macros, ", s);
+ }
+ if (conf->sloppiness) {
+ /* Strip last ", ". */
+ s[strlen(s) - 2] = '\0';
+ }
+ printer(s, context);
+
+ reformat(&s, "stats = %s", conf->stats ? "true" : "false");
+ printer(s, context);
+
+ reformat(&s, "temporary_dir = %s", conf->temporary_dir);
+ printer(s, context);
+
+ reformat(&s, "umask = %03o", conf->umask);
+ printer(s, context);
+
+ reformat(&s, "unify = %s", conf->unify ? "true" : "false");
+ printer(s, context);
+
+ free(s);
+ return true;
+}
diff --git a/conf.h b/conf.h
index 79c83144..d6fef70e 100644
--- a/conf.h
+++ b/conf.h
@@ -38,5 +38,8 @@ bool conf_read(struct conf *conf, const char *path, char **errmsg);
bool conf_update_from_environment(struct conf *conf, char **errmsg);
bool conf_set_value_in_file(const char *path, const char *key,
const char *value, char **errmsg);
+bool conf_print_items(struct conf *conf,
+ void(*printer)(const char *s, void *context),
+ void *context);
#endif
diff --git a/test/test_conf.c b/test/test_conf.c
index b7fa37cf..2ad6d80b 100644
--- a/test/test_conf.c
+++ b/test/test_conf.c
@@ -20,6 +20,26 @@
#include "test/framework.h"
#include "test/util.h"
+static char *received_conf_items[100];
+static size_t n_received_conf_items = 0;
+
+static void
+conf_item_receiver(const char *s, void *context)
+{
+ (void)context;
+ received_conf_items[n_received_conf_items] = x_strdup(s);
+ ++n_received_conf_items;
+}
+
+static void
+free_received_conf_items(void)
+{
+ while (n_received_conf_items > 0) {
+ --n_received_conf_items;
+ free(received_conf_items[n_received_conf_items]);
+ }
+}
+
TEST_SUITE(conf)
TEST(conf_item_table_should_be_sorted)
@@ -326,4 +346,68 @@ TEST(conf_set_existing_value)
CHECK_STR_EQ_FREE2("path = vanilla\nstats = chocolate\n", data);
}
+TEST(conf_print_items)
+{
+ struct conf conf = {
+ "bd",
+ "cd",
+ 7,
+ "c",
+ "cc",
+ true,
+ "ce",
+ true,
+ false,
+ true,
+ "efth",
+ true,
+ true,
+ "lf",
+ 4711,
+ 98.7 * 1000 * 1000,
+ "p",
+ "pc",
+ true,
+ true,
+ true,
+ SLOPPY_FILE_MACRO|SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_TIME_MACROS,
+ false,
+ "td",
+ 022,
+ true
+ };
+ size_t n = 0;
+
+ conf_print_items(&conf, conf_item_receiver, NULL);
+ CHECK_INT_EQ(26, n_received_conf_items);
+ CHECK_STR_EQ("base_dir = bd", received_conf_items[n++]);
+ CHECK_STR_EQ("cache_dir = cd", received_conf_items[n++]);
+ CHECK_STR_EQ("cache_dir_levels = 7", received_conf_items[n++]);
+ CHECK_STR_EQ("compiler = c", received_conf_items[n++]);
+ CHECK_STR_EQ("compiler_check = cc", received_conf_items[n++]);
+ CHECK_STR_EQ("compression = true", received_conf_items[n++]);
+ CHECK_STR_EQ("cpp_extension = ce", received_conf_items[n++]);
+ CHECK_STR_EQ("detect_shebang = true", received_conf_items[n++]);
+ CHECK_STR_EQ("direct_mode = false", received_conf_items[n++]);
+ CHECK_STR_EQ("disable = true", received_conf_items[n++]);
+ CHECK_STR_EQ("extra_files_to_hash = efth", received_conf_items[n++]);
+ CHECK_STR_EQ("hard_link = true", received_conf_items[n++]);
+ CHECK_STR_EQ("hash_dir = true", received_conf_items[n++]);
+ CHECK_STR_EQ("log_file = lf", received_conf_items[n++]);
+ CHECK_STR_EQ("max_files = 4711", received_conf_items[n++]);
+ CHECK_STR_EQ("max_size = 98.7M", received_conf_items[n++]);
+ CHECK_STR_EQ("path = p", received_conf_items[n++]);
+ CHECK_STR_EQ("prefix_command = pc", received_conf_items[n++]);
+ CHECK_STR_EQ("read_only = true", received_conf_items[n++]);
+ CHECK_STR_EQ("recache = true", received_conf_items[n++]);
+ CHECK_STR_EQ("run_second_cpp = true", received_conf_items[n++]);
+ CHECK_STR_EQ("sloppiness = file_macro, include_file_mtime, time_macros",
+ received_conf_items[n++]);
+ CHECK_STR_EQ("stats = false", received_conf_items[n++]);
+ CHECK_STR_EQ("temporary_dir = td", received_conf_items[n++]);
+ CHECK_STR_EQ("umask = 022", received_conf_items[n++]);
+ CHECK_STR_EQ("unify = true", received_conf_items[n++]);
+ free_received_conf_items();
+}
+
TEST_SUITE_END