Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/games/factor - for readability when the exponent < 10 don't ...
details: https://anonhg.NetBSD.org/src/rev/7e00dadba1c3
branches: trunk
changeset: 940240:7e00dadba1c3
user: christos <christos%NetBSD.org@localhost>
date: Wed Oct 07 19:48:29 2020 +0000
description:
- for readability when the exponent < 10 don't prefix it with 0x (from kre)
- fix usage
- merge printing code.
diffstat:
games/factor/factor.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diffs (74 lines):
diff -r 9eb7544e2d7f -r 7e00dadba1c3 games/factor/factor.c
--- a/games/factor/factor.c Wed Oct 07 19:06:50 2020 +0000
+++ b/games/factor/factor.c Wed Oct 07 19:48:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $ */
+/* $NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -41,7 +41,7 @@
__SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: factor.c,v 1.34 2020/10/05 21:11:47 christos Exp $");
+__RCSID("$NetBSD: factor.c,v 1.35 2020/10/07 19:48:29 christos Exp $");
#endif
#ifdef __FBSDID
__FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 356666 2020-01-12 20:25:11Z gad $");
@@ -177,6 +177,18 @@
exit(0);
}
+static void
+pr_exp(int i, int xflag)
+{
+ printf(xflag && i > 9 ? "^0x%x" : "^%d", i);
+}
+
+static void
+pr_uint64(uint64_t i, int xflag)
+{
+ printf(xflag ? " 0x%" PRIx64 : " %" PRIu64, i);
+}
+
/*
* pr_fact - print the factors of a number
*
@@ -246,15 +258,14 @@
do {
i++;
if (!hflag)
- printf(xflag ? " 0x%" PRIx64 : " %" PRIu64,
- *fact);
+ pr_uint64(*fact, xflag);
BN_div_word(val, (BN_ULONG)*fact);
} while (BN_mod_word(val, (BN_ULONG)*fact) == 0);
if (hflag) {
- printf(xflag ? " 0x%" PRIx64 : " %" PRIu64, *fact);
+ pr_uint64(*fact, xflag);
if (i > 1)
- printf(xflag ? "^0x%x" : "^%d", i);
+ pr_exp(i, xflag);
}
/* Let the user know we're doing something. */
@@ -288,7 +299,7 @@
BN_print_dec_fp(stdout, val);
}
if (ex > 1)
- printf(xflag ? "^0x%x" : "^%d", ex);
+ pr_exp(ex, xflag);
if (val != NULL) {
BN_copy(sval, val);
@@ -302,7 +313,7 @@
static void
usage(void)
{
- fprintf(stderr, "usage: factor [-h] [value ...]\n");
+ fprintf(stderr, "Usage: %s [-hx] [value ...]\n", getprogname());
exit(1);
}
Home |
Main Index |
Thread Index |
Old Index