summaryrefslogtreecommitdiff
path: root/src/seq.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-09-05 06:54:59 +0000
committerJim Meyering <jim@meyering.net>2003-09-05 06:54:59 +0000
commit1ba2d9615e3cb7334a20498881bf2ef744338fd1 (patch)
tree0fb5b378adcbe059e5c1a50ac6a787c0e46dff7d /src/seq.c
parent9746b175d7fd795c0f814cfcfcc7e21c3a719c0e (diff)
downloadcoreutils-1ba2d9615e3cb7334a20498881bf2ef744338fd1.tar.xz
(step): Default to 1.
(print_numbers): Allow the output to be empty. (main): The default step is 1, even if LAST < FIRST; as per documentation.
Diffstat (limited to 'src/seq.c')
-rw-r--r--src/seq.c68
1 files changed, 12 insertions, 56 deletions
diff --git a/src/seq.c b/src/seq.c
index 6e640a4a7..d7a306887 100644
--- a/src/seq.c
+++ b/src/seq.c
@@ -55,7 +55,7 @@ static char *decimal_point = ".";
static double first;
/* The increment. */
-static double step;
+static double step = 1.0;
/* The last number. */
static double last;
@@ -178,55 +178,20 @@ valid_format (const char *fmt)
static int
print_numbers (const char *fmt)
{
- if (first > last)
- {
- int i;
-
- if (step >= 0)
- {
- error (0, 0,
- _("when the starting value is larger than the limit,\n\
-the increment must be negative"));
- usage (EXIT_FAILURE);
- }
-
- printf (fmt, first);
- for (i = 1; /* empty */; i++)
- {
- double x = first + i * step;
+ int i;
- if (x < last)
- break;
-
- fputs (separator, stdout);
- printf (fmt, x);
- }
- }
- else
+ for (i = 0; /* empty */; i++)
{
- int i;
-
- if (step <= 0)
- {
- error (0, 0,
- _("when the starting value is smaller than the limit,\n\
-the increment must be positive"));
- usage (EXIT_FAILURE);
- }
-
- printf (fmt, first);
- for (i = 1; /* empty */; i++)
- {
- double x = first + i * step;
-
- if (x > last)
- break;
-
- fputs (separator, stdout);
- printf (fmt, x);
- }
+ double x = first + i * step;
+ if (step < 0 ? x < last : last < x)
+ break;
+ if (i)
+ fputs (separator, stdout);
+ printf (fmt, x);
}
- fputs (terminator, stdout);
+
+ if (i)
+ fputs (terminator, stdout);
return 0;
}
@@ -333,7 +298,6 @@ main (int argc, char **argv)
{
int errs;
int optc;
- int step_is_set;
/* The printf(3) format used for output. */
char *format_str = NULL;
@@ -349,7 +313,6 @@ main (int argc, char **argv)
equal_width = 0;
separator = "\n";
first = 1.0;
- step_is_set = 0;
/* Figure out the locale's idea of a decimal point. */
#if HAVE_LOCALECONV
@@ -434,9 +397,7 @@ main (int argc, char **argv)
if (optind < argc)
{
step = last;
- step_is_set = 1;
last = scan_double_arg (argv[optind++]);
-
}
}
@@ -447,11 +408,6 @@ format string may not be specified when printing equal width strings"));
usage (EXIT_FAILURE);
}
- if (!step_is_set)
- {
- step = first <= last ? 1.0 : -1.0;
- }
-
if (format_str == NULL)
{
if (equal_width)