[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 18/22] tools/utils: spread xlu_cfg_printf() over libxlu_cfg.c



There are far more printf()s inside libxlu_cfg.c, so these had been left
alone briefly.  Now attack all of these.

Signed-off-by: Elliott Mitchell <ehem+xen@xxxxxxx>
---
Note, several messages change mildly.  The message in parse() didn't
previously include the filename.
---
 tools/libs/util/libxlu_cfg.c | 78 ++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 43 deletions(-)

diff --git a/tools/libs/util/libxlu_cfg.c b/tools/libs/util/libxlu_cfg.c
index 7fec7fe7be..91e056bb33 100644
--- a/tools/libs/util/libxlu_cfg.c
+++ b/tools/libs/util/libxlu_cfg.c
@@ -78,8 +78,7 @@ static int ctx_prep(CfgParseContext *ctx, XLU_Config *cfg) {
 
     e= xlu__cfg_yylex_init_extra(ctx, &ctx->scanner);
     if (e) {
-        fprintf(cfg->report,"%s: unable to create scanner: %s\n",
-                cfg->config_source, strerror(e));
+        xlu_cfg_printf(cfg, " unable to create scanner: %s\n", strerror(e));
         return e;
     }
     return 0;
@@ -99,11 +98,12 @@ static void parse(CfgParseContext *ctx) {
     if (r) assert(ctx->err);
 
     if (ctx->err && ctx->likely_python) {
-        fputs(
- "warning: Config file looks like it contains Python code.\n"
- "warning:  Arbitrary Python is no longer supported.\n"
- "warning:  See https://wiki.xen.org/wiki/PythonInXlConfig\n";,
-              ctx->cfg->report);
+        xlu_cfg_printf(ctx->cfg,
+ " warning: Config file looks like it contains Python code.\n");
+        xlu_cfg_printf(ctx->cfg,
+ " warning:  Arbitrary Python is no longer supported.\n");
+        xlu_cfg_printf(ctx->cfg,
+ " warning:  See https://wiki.xen.org/wiki/PythonInXlConfig\n";);
     }
 }
 
@@ -144,8 +144,7 @@ int xlu_cfg_readdata(XLU_Config *cfg, const char *data, int 
length) {
 
     buf = xlu__cfg_yy_scan_bytes(data, length, ctx.scanner);
     if (!buf) {
-        fprintf(cfg->report,"%s: unable to allocate scanner buffer\n",
-                cfg->config_source);
+        xlu_cfg_printf(cfg, " unable to allocate scanner buffer\n");
         ctx.err= ENOMEM;
         goto xe;
     }
@@ -236,10 +235,10 @@ static int find_atom(const XLU_Config *cfg, const char *n,
 
     if (set->value->type!=XLU_STRING) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: parameter `%s' is"
+            xlu_cfg_printf(cfg,
+                    "%d: warning: parameter `%s' is"
                     " a list but should be a single value\n",
-                    cfg->config_source, set->lineno, n);
+                    set->lineno, n);
         return EINVAL;
     }
     *set_r= set;
@@ -257,10 +256,8 @@ int xlu_cfg_value_get_string(const XLU_Config *cfg, 
XLU_ConfigValue *value,
 {
     if (value->type != XLU_STRING) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d:%d: warning: value is not a string\n",
-                    cfg->config_source, value->loc.first_line,
-                    value->loc.first_column);
+            xlu_cfg_printf(cfg, "%d:%d: warning: value is not a string\n",
+                    value->loc.first_line, value->loc.first_column);
         *value_r = NULL;
         return EINVAL;
     }
@@ -274,10 +271,8 @@ int xlu_cfg_value_get_list(const XLU_Config *cfg, 
XLU_ConfigValue *value,
 {
     if (value->type != XLU_LIST) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d:%d: warning: value is not a list\n",
-                    cfg->config_source, value->loc.first_line,
-                    value->loc.first_column);
+            xlu_cfg_printf(cfg, "%d:%d: warning: value is not a list\n",
+                    value->loc.first_line, value->loc.first_column);
         *value_r = NULL;
         return EINVAL;
     }
@@ -325,10 +320,10 @@ int xlu_cfg_get_bounded_long(const XLU_Config *cfg, const 
char *n,
     e= find_atom(cfg,n,&set,dont_warn);  if (e) return e;
     if (set->op == XLU_OP_ADDITION) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: can't use += with numbers"
+            xlu_cfg_printf(cfg,
+                    "%d: warning: can't use += with numbers"
                     " for parameter `%s'\n",
-                    cfg->config_source, set->lineno, n);
+                    set->lineno, n);
         return EINVAL;
     }
     errno= 0; l= strtol(set->value->u.string, &ep, 0);
@@ -337,31 +332,31 @@ int xlu_cfg_get_bounded_long(const XLU_Config *cfg, const 
char *n,
         e= errno;
         assert(e==EINVAL || e==ERANGE);
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: parameter `%s' could not be parsed"
+            xlu_cfg_printf(cfg,
+                    "%d: warning: parameter `%s' could not be parsed"
                     " as a number: %s\n",
-                    cfg->config_source, set->lineno, n, strerror(e));
+                    set->lineno, n, strerror(e));
         return e;
     }
     if (*ep || ep==set->value->u.string) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: parameter `%s' is not a valid number\n",
-                    cfg->config_source, set->lineno, n);
+            xlu_cfg_printf(cfg,
+                    "%d: warning: parameter `%s' is not a valid number\n",
+                    set->lineno, n);
         return EINVAL;
     }
     if (l < min) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: value `%ld' is smaller than minimum bound 
'%ld'\n",
-                    cfg->config_source, set->lineno, l, min);
+            xlu_cfg_printf(cfg,
+                    "%d: warning: value `%ld' is smaller than minimum bound 
'%ld'\n",
+                    set->lineno, l, min);
         return EINVAL;
     }
     if (l > max) {
         if (!dont_warn)
-            fprintf(cfg->report,
-                    "%s:%d: warning: value `%ld' is greater than maximum bound 
'%ld'\n",
-                    cfg->config_source, set->lineno, l, max);
+            xlu_cfg_printf(cfg,
+                    "%d: warning: value `%ld' is greater than maximum bound 
'%ld'\n",
+                    set->lineno, l, max);
         return EINVAL;
     }
 
@@ -393,10 +388,10 @@ int xlu_cfg_get_list(const XLU_Config *cfg, const char *n,
     set= find(cfg,n);  if (!set) return ESRCH;
     if (set->value->type!=XLU_LIST) {
         if (!dont_warn) {
-            fprintf(cfg->report,
-                    "%s:%d: warning: parameter `%s' is a single value"
+            xlu_cfg_printf(cfg,
+                    "%d: warning: parameter `%s' is a single value"
                     " but should be a list\n",
-                    cfg->config_source, set->lineno, n);
+                    set->lineno, n);
         }
         return EINVAL;
     }
@@ -743,11 +738,8 @@ void xlu__cfg_yyerror(XLU__CFG_YYLTYPE *loc, 
CfgParseContext *ctx,
         len--;
     }
 
-    fprintf(ctx->cfg->report,
-            "%s:%d: config parsing error near %s%.*s%s%s: %s\n",
-            ctx->cfg->config_source, lineno,
-            len?"`":"", len, text, len?"'":"", newline,
-            msg);
+    xlu_cfg_printf(ctx->cfg, "%d: config parsing error near %s%.*s%s%s: %s\n",
+            lineno, len?"`":"", len, text, len?"'":"", newline, msg);
     if (!ctx->err) ctx->err= EINVAL;
 }
 
-- 
(\___(\___(\______          --=> 8-) EHM <=--          ______/)___/)___/)
 \BS (    |       ehem+sigmsg@xxxxxxx      PGP 87145445       |    )   /
  \_CS\   |  _____  -O #include <stddisclaimer.h> O-   _____  |   /  _/
8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445






 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.