bug-coreutils
[Top][All Lists]
Advanced

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

[PATCH] better diagnostics for seq


From: Steven Schubiger
Subject: [PATCH] better diagnostics for seq
Date: Mon, 18 Feb 2008 15:16:08 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Attached is a patch that enhances seq's diagnostics. If you agree
that this is the right way to go, I'll amend other files (ChangeLog,
etc.) as needed.

Steven Schubiger

diff --git a/src/seq.c b/src/seq.c
index 261a44b..4a6f96e 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -185,12 +185,38 @@ scan_arg (const char *arg)
 static char const *
 long_double_format (char const *fmt, struct layout *layout)
 {
+  const char *fmt_scan;
   size_t i;
+  size_t counted_directives = 0;
   size_t prefix_len = 0;
   size_t suffix_len = 0;
   size_t length_modifier_offset;
   bool has_L;

+  fmt_scan = (const char *) fmt;
+  while (*fmt_scan)
+    {
+      if (*fmt_scan == ' ')
+        fmt_scan++;
+      else
+        {
+          if (*fmt_scan == '%'
+              && (*(fmt_scan + 1) != '%'
+               && *(fmt_scan + 1) != ' '
+               && *(fmt_scan + 1) != '\0'))
+            {
+              counted_directives++;
+              fmt_scan += 2;
+            }
+          else
+            fmt_scan++;
+        }
+    }
+  if (counted_directives == 0)
+    error (EXIT_FAILURE, 0, _("no %% directive"));
+  else if (counted_directives > 1)
+    error (EXIT_FAILURE, 0, _("too many %% directives"));
+
   for (i = 0; ! (fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
     if (fmt[i])
       prefix_len++;
@@ -209,8 +235,8 @@ long_double_format (char const *fmt, struct layout *layout)
   length_modifier_offset = i;
   has_L = (fmt[i] == 'L');
   i += has_L;
-  if (! strchr ("efgaEFGA", fmt[i]))
-    return NULL;
+  if (! strchr ("efgaEFGA", fmt[i]))
+    error (EXIT_FAILURE, 0, _("invalid directive: `%c%c'"), fmt[i - 1], 
fmt[i]);

   for (i++; ! (fmt[i] == '%' && fmt[i + 1] != '%'); i += (fmt[i] == '%') + 1)
     if (fmt[i])




reply via email to

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