8 std::map<std::string, std::string> config;
10 void read_config(const char *filename)
12 FILE *fp = fopen(filename, "r");
14 throw std::runtime_error("Couldn't open theme file.");
18 if (fgets(buf, 1024, fp) == NULL) {
22 char *ptr = strchr(buf, '\n');
26 ptr = strchr(buf, '\r');
30 ptr = strchr(buf, '#');
34 int len = strlen(buf);
35 while (len > 0 && (buf[len - 1] == ' ' || buf[len - 1] == '\t')) {
43 char key[1024], value[1024];
44 if (sscanf(buf, "%[^=] = %[^=]", key, value) != 2) {
45 fprintf(stderr, "Warning: Ignoring malformed line '%s'.\n", buf);
56 read_config("theme.config");
58 read_config("theme.config.local");
64 std::string get_theme_config(const std::string &key, const std::string subkey)
66 if (config.count(key + "." + subkey)) {
67 return config[key + "." + subkey];
70 std::string modkey = key;
71 while (modkey.find_last_of(".") != std::string::npos) {
72 modkey.resize(modkey.find_last_of("."));
73 if (config.count(modkey + "." + subkey)) {
74 return config[modkey + "." + subkey];
78 return config["default." + subkey];
81 void fill_background(unsigned char *buf, unsigned width, unsigned height)
83 int bg_r = atoi(get_theme_config("background", "red").c_str());
84 int bg_g = atoi(get_theme_config("background", "green").c_str());
85 int bg_b = atoi(get_theme_config("background", "blue").c_str());
87 unsigned char *ptr = buf;
88 for (unsigned i = 0; i < width * height; ++i) {