8 std::map<std::string, std::string> config;
12 FILE *fp = fopen("theme.config", "rb");
14 throw std::runtime_error("Couldn't open theme.config.");
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);
49 config.insert(std::make_pair(key, value));
54 std::string get_theme_config(const std::string &key, const std::string subkey)
56 if (config.count(key + "." + subkey)) {
57 return config[key + "." + subkey];
60 std::string modkey = key;
61 while (modkey.find_last_of(".") != std::string::npos) {
62 modkey.resize(modkey.find_last_of("."));
63 if (config.count(modkey + "." + subkey)) {
64 return config[modkey + "." + subkey];
68 return config["default." + subkey];
71 void fill_background(unsigned char *buf, unsigned width, unsigned height)
73 int bg_r = atoi(get_theme_config("background", "red").c_str());
74 int bg_g = atoi(get_theme_config("background", "green").c_str());
75 int bg_b = atoi(get_theme_config("background", "blue").c_str());
77 unsigned char *ptr = buf;
78 for (unsigned i = 0; i < width * height; ++i) {