coreutils
[Top][All Lists]
Advanced

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

[coreutils][patch] seq: User specified terminator


From: William Plusnick
Subject: [coreutils][patch] seq: User specified terminator
Date: Wed, 27 Oct 2010 12:27:14 -0500

I added a way to specify the string printed after the last number in the seq command, as suggested by a comment. I am not sure how helpful this option is, because I personally don't use the seq command much. I also added documentation to both usage (and, in effect, the man page) and coreutils.texi. It was so small that I didn't see any need for a test. It went over the ten line limit, but is pretty trivial and the large majority is documentation, so I am unsure if I need to sign anything. I also forgot to add a NEWS entry, but I am not even sure this will get accepted, yet. :-)

Thanks, William

From 22a82960eb69f6a781a1d320381b48bb5c80ffd8 Mon Sep 17 00:00:00 2001
From: Patrick W. Plusnick II <address@hidden>
Date: Wed, 27 Oct 2010 12:08:37 -0500
Subject: [PATCH] seq: added an option to specify the terminator
 *src/seq.c: I added a new option called terminator (t) that prints a user specified string after the last number; the
     terminator string still defaults to a newline. I also added documentation in the usage function.
 *doc/coreutils.texi: added documentation for the change.

---
 doc/coreutils.texi |    6 +++++-
 src/seq.c          |   12 +++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 0b5a3d3..c9b5345 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -15612,7 +15612,11 @@ the default format is @samp{%g}.
 @itemx --separator=@var{string}
 @cindex separator for numbers in @command{seq}
 Separate numbers with @var{string}; default is a newline.
-The output always terminates with a newline.
+
+@item -t @var{string}
+@itemx --terminator=@var{string}
+@cindex terminator for the last number in @command{seq}
+Ouput @var{string} after the last number; default is a newline.
 
 @item -w
 @itemx --equal-width
diff --git a/src/seq.c b/src/seq.c
index c9bdf94..75c9e5c 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -46,14 +46,14 @@ static char const *separator;
 
 /* The string output after all numbers have been output.
    Usually "\n" or "\0".  */
-/* FIXME: make this an option.  */
-static char const terminator[] = "\n";
+static char const *terminator;
 
 static struct option const long_options[] =
 {
   { "equal-width", no_argument, NULL, 'w'},
   { "format", required_argument, NULL, 'f'},
   { "separator", required_argument, NULL, 's'},
+  { "terminator", required_argument, NULL, 't'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   { NULL, 0, NULL, 0}
@@ -77,6 +77,7 @@ Print numbers from FIRST to LAST, in steps of INCREMENT.\n\
 \n\
   -f, --format=FORMAT      use printf style floating-point FORMAT\n\
   -s, --separator=STRING   use STRING to separate numbers (default: \\n)\n\
+  -t, --terminator=STRING  output STRING after the last number (default: \\n)\n\
   -w, --equal-width        equalize width by padding with leading zeroes\n\
 "), stdout);
       fputs (HELP_OPTION_DESCRIPTION, stdout);
@@ -359,6 +360,7 @@ main (int argc, char **argv)
 
   equal_width = false;
   separator = "\n";
+  terminator = "\n";
 
   /* We have to handle negative numbers in the command line but this
      conflicts with the command line arguments.  So explicitly check first
@@ -372,7 +374,7 @@ main (int argc, char **argv)
           break;
         }
 
-      optc = getopt_long (argc, argv, "+f:s:w", long_options, NULL);
+      optc = getopt_long (argc, argv, "+f:s:t:w", long_options, NULL);
       if (optc == -1)
         break;
 
@@ -386,6 +388,10 @@ main (int argc, char **argv)
           separator = optarg;
           break;
 
+    case 't':
+      terminator = optarg;
+      break;
+
         case 'w':
           equal_width = true;
           break;
--
1.7.1



reply via email to

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