Hello!

I still research code from 'coreutils' and find place where put some benefits. I offer replace block for setting quoting style(watching environment variable QUOTING_STYLE) with function as comment 'FIXME: put this in a function.' in src/ls.c. I don't sure about function name and required prototype, but my vision I introduce in patch. I successfully test this block throw tests in tests/ls/*.sh and 'make syntax-check'.


--
with best regards
Yurij Goncharuk

>From 2c9bea2d0026bc41351033f8f19024c6f87334b8 Mon Sep 17 00:00:00 2001
From: Yurij Goncharuk <[email protected]>
Date: Thu, 21 Aug 2014 22:40:22 +0400
Subject: [PATCH] ls: Add check_env_quoting() function

src/ls.c (check_env_quoting): Replace block for check
environment variable QUOTING_STYLE and correspond set
quoting style(if no '--quoting-style' command-line argument)
with function check_env_quoting(), suggest FIXME comment.
---
 src/ls.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/ls.c b/src/ls.c
index cd5996e..d93567d 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -284,6 +284,10 @@ static void queue_directory (char const *name, char const *realname,
 static void sort_files (void);
 static void parse_ls_color (void);
 
+/* Set quoting style if command-line argument '--quoting-style'
+   is not set and setted environment variable QUOTING_STYLE */
+static void check_env_quoting (char const *q_style);
+
 /* Initial size of hash table.
    Most hierarchies are likely to be shallower than this.  */
 #define INITIAL_TABLE_SIZE 30
@@ -1577,20 +1581,7 @@ decode_switches (int argc, char **argv)
   hide_patterns = NULL;
   print_scontext = false;
 
-  /* FIXME: put this in a function.  */
-  {
-    char const *q_style = getenv ("QUOTING_STYLE");
-    if (q_style)
-      {
-        int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
-        if (0 <= i)
-          set_quoting_style (NULL, quoting_style_vals[i]);
-        else
-          error (0, 0,
-         _("ignoring invalid value of environment variable QUOTING_STYLE: %s"),
-                 quotearg (q_style));
-      }
-  }
+  check_env_quoting (getenv ("QUOTING_STYLE"));
 
   line_length = 80;
   {
@@ -2493,6 +2484,21 @@ parse_ls_color (void)
     color_symlink_as_referent = true;
 }
 
+static void
+check_env_quoting (char const *q_style)
+{
+  if (q_style)
+    {
+      int i = ARGMATCH (q_style, quoting_style_args, quoting_style_vals);
+      if (0 <= i)
+        set_quoting_style (NULL, quoting_style_vals[i]);
+      else
+        error (0, 0,
+       _("ignoring invalid value of environment variable QUOTING_STYLE: %s"),
+               quotearg (q_style));
+    }
+}
+
 /* Set the exit status to report a failure.  If SERIOUS, it is a
    serious failure; otherwise, it is merely a minor problem.  */
 
-- 
1.8.4.5

Reply via email to