From a6fef8e8fb3b3a6da805ccef08fb8e90b850318a Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 20 Dec 2018 17:35:45 +0000 Subject: [PATCH] Convert printf_* from config.c and config_libconfig.c Signed-off-by: Yuxuan Shui --- src/config.c | 42 ++++++++++++++++---------------- src/config_libconfig.c | 55 ++++++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/config.c b/src/config.c index 681c63d..5bc6b75 100644 --- a/src/config.c +++ b/src/config.c @@ -22,13 +22,13 @@ parse_long(const char *s, long *dest) { const char *endptr = NULL; long val = strtol(s, (char **) &endptr, 0); if (!endptr || endptr == s) { - printf_errf("(\"%s\"): Invalid number.", s); + log_error("Invalid number: %s", s); return false; } while (isspace(*endptr)) ++endptr; if (*endptr) { - printf_errf("(\"%s\"): Trailing characters.", s); + log_error("Trailing characters: %s", s); return false; } *dest = val; @@ -43,7 +43,7 @@ parse_matrix_readnum(const char *src, double *dest) { char *pc = NULL; double val = strtod(src, &pc); if (!pc || pc == src) { - printf_errf("(\"%s\"): No number found.", src); + log_error("No number found: %s", src); return src; } @@ -78,16 +78,16 @@ parse_matrix(session_t *ps, const char *src, const char **endptr) { // Validate matrix width and height if (wid <= 0 || hei <= 0) { - printf_errf("(): Invalid matrix width/height."); + log_error("Invalid matrix width/height."); goto err1; } if (!(wid % 2 && hei % 2)) { - printf_errf("(): Width/height not odd."); + log_error("Width/height not odd."); goto err1; } if (wid > 16 || hei > 16) - printf_errf("(): Matrix width/height too large, may slow down" - "rendering, and/or consume lots of memory"); + log_warn("Matrix width/height too large, may slow down" + "rendering, and/or consume lots of memory"); // Allocate memory auto matrix = ccalloc(wid * hei + 2, xcb_render_fixed_t); @@ -110,14 +110,14 @@ parse_matrix(session_t *ps, const char *src, const char **endptr) { matrix[2 + i] = DOUBLE_TO_XFIXED(val); } if (BKEND_XRENDER == ps->o.backend && hasneg) - printf_errf("(): A convolution kernel with negative values " - "may not work properly under X Render backend."); + log_warn("A convolution kernel with negative values may not work properly under X " + "Render backend."); } // Detect trailing characters for ( ;*pc && ';' != *pc; ++pc) if (!isspace(*pc) && ',' != *pc) { - printf_errf("(): Trailing characters in matrix string."); + log_error("Trailing characters in matrix string."); goto err2; } @@ -133,7 +133,7 @@ parse_matrix(session_t *ps, const char *src, const char **endptr) { if (endptr) *endptr = pc; else if (*pc) { - printf_errf("(): Only one matrix expected."); + log_error("Only one matrix expected."); goto err2; } @@ -197,13 +197,13 @@ parse_conv_kern_lst(session_t *ps, const char *src, xcb_render_fixed_t **dest, i } if (i > 1) { - printf_errf("(): You are seeing this message because your are using multipass\n" - "blur. Please report an issue to us so we know multipass blur is actually been used.\n" - "Otherwise it might be removed in future releases"); + log_warn("You are seeing this message because your are using multipassblur. Please " + "report an issue to us so we know multipass blur is actually been used. " + "Otherwise it might be removed in future releases"); } if (*pc) { - printf_errf("(): Too many blur kernels!"); + log_error("Too many blur kernels!"); return false; } @@ -239,7 +239,7 @@ parse_geometry(session_t *ps, const char *src, region_t *dest) { if (src != endptr) { geom.wid = val; if (geom.wid < 0) { - printf_errf("(\"%s\"): Invalid width.", src); + log_error("Invalid width: %s", src); return false; } src = endptr; @@ -255,7 +255,7 @@ parse_geometry(session_t *ps, const char *src, region_t *dest) { if (src != endptr) { geom.hei = val; if (geom.hei < 0) { - printf_errf("(\"%s\"): Invalid height.", src); + log_error("Invalid height: %s", src); return false; } src = endptr; @@ -288,7 +288,7 @@ parse_geometry(session_t *ps, const char *src, region_t *dest) { } if (*src) { - printf_errf("(\"%s\"): Trailing characters.", src); + log_error("Trailing characters: %s", src); return false; } @@ -305,11 +305,11 @@ bool parse_rule_opacity(session_t *ps, const char *src) { char *endptr = NULL; long val = strtol(src, &endptr, 0); if (!endptr || endptr == src) { - printf_errf("(\"%s\"): No opacity specified?", src); + log_error("No opacity specified: %s", src); return false; } if (val > 100 || val < 0) { - printf_errf("(\"%s\"): Opacity %ld invalid.", src, val); + log_error("Opacity %ld invalid: %s", val, src); return false; } @@ -317,7 +317,7 @@ bool parse_rule_opacity(session_t *ps, const char *src) { while (*endptr && isspace(*endptr)) ++endptr; if (':' != *endptr) { - printf_errf("(\"%s\"): Opacity terminator not found.", src); + log_error("Opacity terminator not found: %s", src); return false; } ++endptr; diff --git a/src/config_libconfig.c b/src/config_libconfig.c index d4fa5a2..1804a8f 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -140,10 +140,11 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, f = open_config_file(ps->o.config_file, &path); if (!f) { if (ps->o.config_file) { - printf_errfq(1, "(): Failed to read configuration file \"%s\".", - ps->o.config_file); free(ps->o.config_file); ps->o.config_file = NULL; + + log_fatal("Failed to read configuration file \"%s\".", ps->o.config_file); + abort(); } return; } @@ -166,8 +167,8 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, fclose(f); f = NULL; if (read_result == CONFIG_FALSE) { - printf("Error when reading configuration file \"%s\", line %d: %s\n", - path, config_error_line(&cfg), config_error_text(&cfg)); + log_error("Error when reading configuration file \"%s\", line %d: %s", + path, config_error_line(&cfg), config_error_text(&cfg)); config_destroy(&cfg); free(path); return; @@ -213,22 +214,22 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, *shadow_enable = ival; // -C (no_dock_shadow) if (config_lookup_bool(&cfg, "no-dock-shadow", &ival)) { - printf_errf("(): option `no-dock-shadow` is deprecated, and will be removed.\n" - " Please use the wintype option `shadow` of `dock` instead."); + log_warn("Option `no-dock-shadow` is deprecated, and will be removed." + " Please use the wintype option `shadow` of `dock` instead."); ps->o.wintype_option[WINTYPE_DOCK].shadow = false; winopt_mask[WINTYPE_DOCK].shadow = true; } // -G (no_dnd_shadow) if (config_lookup_bool(&cfg, "no-dnd-shadow", &ival)) { - printf_errf("(): option `no-dnd-shadow` is deprecated, and will be removed.\n" - " Please use the wintype option `shadow` of `dnd` instead."); + log_warn("Option `no-dnd-shadow` is deprecated, and will be removed." + " Please use the wintype option `shadow` of `dnd` instead."); ps->o.wintype_option[WINTYPE_DND].shadow = false; winopt_mask[WINTYPE_DND].shadow = true; }; // -m (menu_opacity) if (config_lookup_float(&cfg, "menu-opacity", &dval)) { - printf_errf("(): option `menu-opacity` is deprecated, and will be removed.\n" - "Please use the wintype option `opacity` of `popup_menu` and `dropdown_menu` instead."); + log_warn("Option `menu-opacity` is deprecated, and will be removed.Please use the " + "wintype option `opacity` of `popup_menu` and `dropdown_menu` instead."); ps->o.wintype_option[WINTYPE_DROPDOWN_MENU].opacity = dval; ps->o.wintype_option[WINTYPE_POPUP_MENU].opacity = dval; winopt_mask[WINTYPE_DROPDOWN_MENU].opacity = true; @@ -276,11 +277,15 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, // --refresh-rate config_lookup_int(&cfg, "refresh-rate", &ps->o.refresh_rate); // --vsync - if (config_lookup_string(&cfg, "vsync", &sval) && !parse_vsync(ps, sval)) + if (config_lookup_string(&cfg, "vsync", &sval) && !parse_vsync(ps, sval)) { + log_fatal("Cannot parse vsync"); exit(1); + } // --backend - if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) + if (config_lookup_string(&cfg, "backend", &sval) && !parse_backend(ps, sval)) { + log_fatal("Cannot parse backend"); exit(1); + } // --log-level if (config_lookup_string(&cfg, "log-level", &sval)) { auto level = string_to_log_level(sval); @@ -332,8 +337,10 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, &ps->o.blur_background_fixed); // --blur-kern if (config_lookup_string(&cfg, "blur-kern", &sval) - && !parse_conv_kern_lst(ps, sval, ps->o.blur_kerns, MAX_BLUR_PASS)) + && !parse_conv_kern_lst(ps, sval, ps->o.blur_kerns, MAX_BLUR_PASS)) { + log_fatal("Cannot parse \"blur-kern\""); exit(1); + } // --resize-damage config_lookup_int(&cfg, "resize-damage", &ps->o.resize_damage); // --glx-no-stencil @@ -341,9 +348,11 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, // --glx-no-rebind-pixmap lcfg_lookup_bool(&cfg, "glx-no-rebind-pixmap", &ps->o.glx_no_rebind_pixmap); // --glx-swap-method - if (config_lookup_string(&cfg, "glx-swap-method", &sval) - && !parse_glx_swap_method(ps, sval)) + if (config_lookup_string(&cfg, "glx-swap-method", &sval) && + !parse_glx_swap_method(ps, sval)) { + log_fatal("Cannot parse \"glx-swap-method\""); exit(1); + } // --glx-use-gpushader4 lcfg_lookup_bool(&cfg, "glx-use-gpushader4", &ps->o.glx_use_gpushader4); // --xrender-sync @@ -352,22 +361,22 @@ void parse_config_libconfig(session_t *ps, bool *shadow_enable, lcfg_lookup_bool(&cfg, "xrender-sync-fence", &ps->o.xrender_sync_fence); if (lcfg_lookup_bool(&cfg, "clear-shadow", &bval)) - printf_errf("(): \"clear-shadow\" is removed as an option, and is always" - " enabled now. Consider removing it from your config file"); + log_warn("\"clear-shadow\" is removed as an option, and is always" + " enabled now. Consider removing it from your config file"); if (lcfg_lookup_bool(&cfg, "paint-on-overlay", &bval)) - printf_errf("(): \"paint-on-overlay\" has been removed as an option, and " - "is enabled whenever possible"); + log_warn("\"paint-on-overlay\" has been removed as an option, and " + "is enabled whenever possible"); if (config_lookup_float(&cfg, "alpha-step", &dval)) - printf_errf("(): \"alpha-step\" has been removed, compton now tries to make use" - " of all alpha values"); + log_warn("\"alpha-step\" has been removed, compton now tries to make use" + " of all alpha values"); const char *deprecation_message = "has been removed. If you encounter problems " "without this feature, please feel free to open a bug report"; if (lcfg_lookup_bool(&cfg, "glx-use-copysubbuffermesa", &bval) && bval) - printf_errf("(): \"glx-use-copysubbuffermesa\" %s", deprecation_message); + log_warn("\"glx-use-copysubbuffermesa\" %s", deprecation_message); if (lcfg_lookup_bool(&cfg, "glx-copy-from-front", &bval) && bval) - printf_errf("(): \"glx-copy-from-front\" %s", deprecation_message); + log_warn("\"glx-copy-from-front\" %s", deprecation_message); // Wintype settings