mirror of
				https://github.com/labwc/labwc.git
				synced 2025-11-03 09:01:51 -05:00 
			
		
		
		
	Improve log messages for reading config+theme
This commit is contained in:
		
							parent
							
								
									35015e57c6
								
							
						
					
					
						commit
						4a89fbfb22
					
				
					 4 changed files with 26 additions and 18 deletions
				
			
		| 
						 | 
					@ -103,8 +103,7 @@ char *find_dir(struct ctx *ctx)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	/* no directory was found */
 | 
						/* no directory was found */
 | 
				
			||||||
	ctx->buf[0] = '.';
 | 
						ctx->buf[0] = '\0';
 | 
				
			||||||
	ctx->buf[1] = '\0';
 | 
					 | 
				
			||||||
	return ctx->buf;
 | 
						return ctx->buf;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -23,7 +23,7 @@ void warn(const char *err, ...)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	va_list params;
 | 
						va_list params;
 | 
				
			||||||
	fprintf(stderr, LABWC_COLOR_RED);
 | 
						fprintf(stderr, LABWC_COLOR_RED);
 | 
				
			||||||
	fprintf(stderr, "[labwc] warning: ");
 | 
						fprintf(stderr, "[labwc] ");
 | 
				
			||||||
	va_start(params, err);
 | 
						va_start(params, err);
 | 
				
			||||||
	vfprintf(stderr, err, params);
 | 
						vfprintf(stderr, err, params);
 | 
				
			||||||
	va_end(params);
 | 
						va_end(params);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -260,11 +260,10 @@ static void post_processing(void)
 | 
				
			||||||
	set_title_height();
 | 
						set_title_height();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void rcxml_path(char *buf, size_t len, const char *filename)
 | 
					static void rcxml_path(char *buf, size_t len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (filename)
 | 
						if (!strlen(config_dir()))
 | 
				
			||||||
		snprintf(buf, len, "%s", filename);
 | 
							return;
 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
	snprintf(buf, len, "%s/rc.xml", config_dir());
 | 
						snprintf(buf, len, "%s/rc.xml", config_dir());
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -274,7 +273,7 @@ void rcxml_read(const char *filename)
 | 
				
			||||||
	char *line = NULL;
 | 
						char *line = NULL;
 | 
				
			||||||
	size_t len = 0;
 | 
						size_t len = 0;
 | 
				
			||||||
	struct buf b;
 | 
						struct buf b;
 | 
				
			||||||
	char rcxml[4096];
 | 
						char rcxml[4096] = { 0 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rcxml_init();
 | 
						rcxml_init();
 | 
				
			||||||
	wl_list_init(&rc.keybinds);
 | 
						wl_list_init(&rc.keybinds);
 | 
				
			||||||
| 
						 | 
					@ -283,13 +282,20 @@ void rcxml_read(const char *filename)
 | 
				
			||||||
	 * Reading file into buffer before parsing makes it easier to write
 | 
						 * Reading file into buffer before parsing makes it easier to write
 | 
				
			||||||
	 * unit tests.
 | 
						 * unit tests.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	rcxml_path(rcxml, sizeof(rcxml), filename);
 | 
						if (filename)
 | 
				
			||||||
	info("reading config file (%s)", rcxml);
 | 
							snprintf(rcxml, sizeof(rcxml), "%s", filename);
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							rcxml_path(rcxml, sizeof(rcxml));
 | 
				
			||||||
 | 
						if (rcxml[0] == '\0') {
 | 
				
			||||||
 | 
							warn("cannot find rc.xml config file");
 | 
				
			||||||
 | 
							goto no_config;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	stream = fopen(rcxml, "r");
 | 
						stream = fopen(rcxml, "r");
 | 
				
			||||||
	if (!stream) {
 | 
						if (!stream) {
 | 
				
			||||||
		warn("cannot read (%s)", rcxml);
 | 
							warn("cannot read (%s)", rcxml);
 | 
				
			||||||
		goto out;
 | 
							goto no_config;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						info("reading config file (%s)", rcxml);
 | 
				
			||||||
	buf_init(&b);
 | 
						buf_init(&b);
 | 
				
			||||||
	while (getline(&line, &len, stream) != -1) {
 | 
						while (getline(&line, &len, stream) != -1) {
 | 
				
			||||||
		char *p = strrchr(line, '\n');
 | 
							char *p = strrchr(line, '\n');
 | 
				
			||||||
| 
						 | 
					@ -301,7 +307,7 @@ void rcxml_read(const char *filename)
 | 
				
			||||||
	fclose(stream);
 | 
						fclose(stream);
 | 
				
			||||||
	rcxml_parse_xml(&b);
 | 
						rcxml_parse_xml(&b);
 | 
				
			||||||
	free(b.buf);
 | 
						free(b.buf);
 | 
				
			||||||
out:
 | 
					no_config:
 | 
				
			||||||
	post_processing();
 | 
						post_processing();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -118,19 +118,22 @@ void theme_builtin(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void theme_read(const char *theme_name)
 | 
					void theme_read(const char *theme_name)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE *stream;
 | 
						FILE *stream = NULL;
 | 
				
			||||||
	char *line = NULL;
 | 
						char *line = NULL;
 | 
				
			||||||
	size_t len = 0;
 | 
						size_t len = 0;
 | 
				
			||||||
	char themerc[4096];
 | 
						char themerc[4096];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name));
 | 
						if (strlen(theme_dir(theme_name))) {
 | 
				
			||||||
	info("reading themerc (%s)", themerc);
 | 
							snprintf(themerc, sizeof(themerc), "%s/themerc",
 | 
				
			||||||
 | 
								 theme_dir(theme_name));
 | 
				
			||||||
		stream = fopen(themerc, "r");
 | 
							stream = fopen(themerc, "r");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (!stream) {
 | 
						if (!stream) {
 | 
				
			||||||
		warn("cannot read (%s) - load built-in theme", themerc);
 | 
							warn("cannot find theme (%s), using built-in", theme_name);
 | 
				
			||||||
		theme_builtin();
 | 
							theme_builtin();
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						info("reading themerc (%s)", themerc);
 | 
				
			||||||
	while (getline(&line, &len, stream) != -1) {
 | 
						while (getline(&line, &len, stream) != -1) {
 | 
				
			||||||
		char *p = strrchr(line, '\n');
 | 
							char *p = strrchr(line, '\n');
 | 
				
			||||||
		if (p)
 | 
							if (p)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue