1
1
/* seq - print sequence of numbers to standard output.
2
Copyright (C) 1994-2012 Free Software Foundation, Inc.
2
Copyright (C) 1994-2013 Free Software Foundation, Inc.
4
4
This program is free software: you can redistribute it and/or modify
5
5
it under the terms of the GNU General Public License as published by
72
72
"), program_name, program_name, program_name);
74
74
Print numbers from FIRST to LAST, in steps of INCREMENT.\n\
77
emit_mandatory_arg_note ();
76
80
-f, --format=FORMAT use printf style floating-point FORMAT\n\
77
81
-s, --separator=STRING use STRING to separate numbers (default: \\n)\n\
78
82
-w, --equal-width equalize width by padding with leading zeroes\n\
167
171
long exponent = strtol (e + 1, NULL, 10);
168
172
ret.precision += exponent < 0 ? -exponent : 0;
173
/* Don't account for e.... in the width since this is not output. */
174
ret.width -= strlen (arg) - (e - arg);
175
/* Adjust the width as per the exponent. */
180
if (e == decimal_point + 1) /* undo #. -> # above */
185
exponent = -exponent;
187
ret.width += exponent;
317
336
last_width--; /* don't include space for '.' */
318
337
if (last.precision == 0 && prec)
319
338
last_width++; /* include space for '.' */
339
if (first.precision == 0 && prec)
340
first_width++; /* include space for '.' */
320
341
size_t width = MAX (first_width, last_width);
321
342
if (width <= INT_MAX)
404
425
bool ok = cmp (p, p_len, q, q_len) <= 0;
407
/* Buffer at least this many output lines per fwrite call.
428
/* Buffer at least this many numbers per fwrite call.
408
429
This gives a speed-up of more than 2x over the unbuffered code
409
430
when printing the first 10^9 integers. */
411
432
char *buf = xmalloc (N * (n + 1));
412
433
char const *buf_end = buf + N * (n + 1);
437
/* Write first number to buffer. */
438
z = mempcpy (z, p, p_len);
440
/* Append separator then number. */
416
441
while (cmp (p, p_len, q, q_len) < 0)
418
444
incr (&p, &p_len);
419
445
z = mempcpy (z, p, p_len);
421
if (buf_end - n - 1 < z)
446
/* If no place for another separator + number then
447
output buffer so far, and reset to start of buffer. */
448
if (buf_end - (n + 1) < z)
423
450
fwrite (buf, z - buf, 1, stdout);
428
/* Write any remaining, buffered output. */
430
fwrite (buf, z - buf, 1, stdout);
455
/* Write any remaining buffered output, and the terminator. */
457
fwrite (buf, z - buf, 1, stdout);
432
459
IF_LINT (free (buf));
538
565
then use the much more efficient integer-only code. */
539
566
if (all_digits_p (argv[optind])
540
567
&& (n_args == 1 || all_digits_p (argv[optind + 1]))
541
&& (n_args < 3 || STREQ ("1", argv[optind + 2]))
568
&& (n_args < 3 || (STREQ ("1", argv[optind + 1])
569
&& all_digits_p (argv[optind + 2])))
542
570
&& !equal_width && !format_str && strlen (separator) == 1)
544
572
char const *s1 = n_args == 1 ? "1" : argv[optind];
545
char const *s2 = n_args == 1 ? argv[optind] : argv[optind + 1];
573
char const *s2 = argv[optind + (n_args - 1)];
546
574
if (seq_fast (s1, s2))
547
575
exit (EXIT_SUCCESS);