diff options
author | Jim Meyering <jim@meyering.net> | 1999-04-21 03:18:23 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-04-21 03:18:23 +0000 |
commit | cf6eaeb03b16e0369b88a694efc459c69f7e66af (patch) | |
tree | 6c7adfc122507822415df3cc2a8e4734f8d7a509 | |
parent | 42ccae28c6d571d52ce1abeaa3b00cfbc8e3436f (diff) | |
download | coreutils-cf6eaeb03b16e0369b88a694efc459c69f7e66af.tar.xz |
<xstrtol.h>: Include this, not xstrtoul.h.
<human.h>: Include.
Use uintmax_t in place of unsigned long.
Use human_readable to convert to strings for printing.
-rw-r--r-- | src/factor.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/factor.c b/src/factor.c index 5fa5f736a..1ea7cecfc 100644 --- a/src/factor.c +++ b/src/factor.c @@ -28,8 +28,9 @@ #include "system.h" #include "long-options.h" #include "error.h" -#include "xstrtoul.h" +#include "human.h" #include "readtokens.h" +#include "xstrtol.h" /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "factor" @@ -76,9 +77,9 @@ Print factors of each NUMBER; read standard input with no arguments.\n\ /* FIXME: comment */ static int -factor (long unsigned int n0, int max_n_factors, long unsigned int *factors) +factor (uintmax_t n0, int max_n_factors, uintmax_t *factors) { - register unsigned long n = n0, d, q; + register uintmax_t n = n0, d, q; int n_factors = 0; if (n < 1) @@ -128,20 +129,21 @@ factor (long unsigned int n0, int max_n_factors, long unsigned int *factors) static int print_factors (const char *s) { - unsigned long int factors[MAX_N_FACTORS]; - unsigned long n; + uintmax_t factors[MAX_N_FACTORS]; + uintmax_t n; int n_factors; int i; + char buf[LONGEST_HUMAN_READABLE + 1]; - if (xstrtoul (s, NULL, 10, &n, "") != LONGINT_OK) + if (xstrtoumax (s, NULL, 10, &n, "") != LONGINT_OK) { error (0, 0, _("`%s' is not a valid positive integer"), s); return 1; } n_factors = factor (n, MAX_N_FACTORS, factors); - printf ("%lu:", n); + printf ("%s:", human_readable (n, buf, 1, 1)); for (i = 0; i < n_factors; i++) - printf (" %lu", factors[i]); + printf (" %s", human_readable (factors[i], buf, 1, 1)); putchar ('\n'); return 0; } |