bug-grep
[Top][All Lists]
Advanced

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

[PATCH 4/4] grep: be quiet about GREP_COLORS syntax


From: Paul Eggert
Subject: [PATCH 4/4] grep: be quiet about GREP_COLORS syntax
Date: Fri, 20 Jan 2012 23:08:30 -0800
User-agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0

* src/main.c (struct color_cap): fct now returns void,
since there's no longer need to use what it returns.
(color_cap_mt_fct, color_cap_rv_fct, color_cap_ne_fct): Return void.
(parse_grep_colors): Do not output diagnostics and then exit with
status 0.  Instead, ignore errors in GREP_COLORS.  This is more
consistent with programs that (e.g.) ignore errors in termcap entries,
and it's more internally-consistent as some GREP_COLORS errors
were ignored but not others.
---
 src/main.c |   46 +++++++++-------------------------------------
 1 files changed, 9 insertions(+), 37 deletions(-)

diff --git a/src/main.c b/src/main.c
index 84564e0..76e414b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -242,34 +242,28 @@ struct color_cap
   {
     const char *name;
     const char **var;
-    const char *(*fct) (void);
+    void (*fct) (void);
   };
 
-static const char *
+static void
 color_cap_mt_fct (void)
 {
   /* Our caller just set selected_match_color.  */
   context_match_color = selected_match_color;
-
-  return NULL;
 }
 
-static const char *
+static void
 color_cap_rv_fct (void)
 {
   /* By this point, it was 1 (or already -1).  */
   color_option = -1;  /* That's still != 0.  */
-
-  return NULL;
 }
 
-static const char *
+static void
 color_cap_ne_fct (void)
 {
   sgr_start = "\33[%sm";
   sgr_end   = "\33[m";
-
-  return NULL;
 }
 
 /* For GREP_COLORS.  */
@@ -1773,28 +1767,10 @@ parse_grep_colors (void)
           if (STREQ (cap->name, name))
             break;
         /* If name unknown, go on for forward compatibility.  */
-        if (cap->name)
-          {
-            if (cap->var)
-              {
-                if (val)
-                  *(cap->var) = val;
-                else
-                  error (0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity "
-                                 "needs a value (\"=...\"); skipped"), p, 
name);
-              }
-            else if (val)
-              error (0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity "
-                             "is boolean and cannot take a value (\"=%s\");"
-                             " skipped"), p, name, val);
-          }
+        if (cap->var && val)
+          *(cap->var) = val;
         if (cap->fct)
-          {
-            const char *err_str = cap->fct ();
-            if (err_str)
-              error (0, 0, _("in GREP_COLORS=\"%s\", the \"%s\" capacity %s"),
-                     p, name, err_str);
-          }
+          cap->fct ();
         if (c == '\0')
           return;
         name = q;
@@ -1803,7 +1779,7 @@ parse_grep_colors (void)
     else if (*q == '=')
       {
         if (q == name || val)
-          goto ill_formed;
+          return;
         *q++ = '\0'; /* Terminate name.  */
         val = q; /* Can be the empty string.  */
       }
@@ -1812,11 +1788,7 @@ parse_grep_colors (void)
     else if (*q == ';' || (*q >= '0' && *q <= '9'))
       q++; /* Accumulate val.  Protect the terminal from being sent crap.  */
     else
-      goto ill_formed;
-
- ill_formed:
-  error (0, 0, _("stopped processing of ill-formed GREP_COLORS=\"%s\" "
-                 "at remaining substring \"%s\""), p, q);
+      return;
 }
 
 int
-- 
1.7.6.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]