summaryrefslogtreecommitdiff
path: root/src/factor.c
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-02-10 12:47:23 +0000
committerPádraig Brady <P@draigBrady.com>2013-02-10 20:30:53 +0000
commit3309e880fb2b5d4316809c5ceef4f5b2b8d34a38 (patch)
tree7f55499b883b230b4a8d550e2d340befe2d82e4e /src/factor.c
parent71ab11eac1de965e90abf050bf1bbe22eb4ac7b9 (diff)
downloadcoreutils-3309e880fb2b5d4316809c5ceef4f5b2b8d34a38.tar.xz
maint: consolidate developer debug messages
Both factor and numfmt recently introduced debug messages for developers, enabled by --verbose and ---devdebug respectively. There were a few issues though: 1. They used different mechanisms to enable these messages. 2. factor used --verbose which might be needed for something else 3. They used different methods to output the messages, and numfmt used error() which added an unwanted newline 4. numfmt marked all these messages for translation and factor marked a couple. We really don't need these translated. So we fix the above issues here while renaming the enabling option for both commands to ---debug (still undocumented). * src/factor.c (verbose): Rename to dev_debug and change from int to bool as it's just a toggle flag. (long_options): Rename --verbose to ---debug. * src/system.h (devmsg): A new inline function to output a message if enabled by a global dev_debug variable in the compilation unit. * src/numfmt.c: Use devmsg() rather than error(). Also remove the translation tags from these messages. Also change debug flag to bool from int. * tests/misc/numfmt.pl: Adjust for the ---devdebug to ---debug change. * cfg.mk (sc_marked_devdiagnostics): Add a syntax check to ensure translations are not added to devmsg calls. Reported by Göran Uddeborg in http://bugs.gnu.org/13665
Diffstat (limited to 'src/factor.c')
-rw-r--r--src/factor.c37
1 files changed, 13 insertions, 24 deletions
diff --git a/src/factor.c b/src/factor.c
index 95451a58d..df3d7a0a9 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -216,12 +216,12 @@ static enum alg_type alg;
enum
{
- VERBOSE_OPTION = CHAR_MAX + 1
+ DEV_DEBUG_OPTION = CHAR_MAX + 1
};
static struct option const long_options[] =
{
- {"verbose", no_argument, NULL, VERBOSE_OPTION},
+ {"-debug", no_argument, NULL, DEV_DEBUG_OPTION},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
@@ -685,8 +685,9 @@ static const struct primes_dtab primes_dtab[] = {
the integers used to generate primes.h. */
verify (W <= WIDE_UINT_BITS);
-/* This flag is honored only in the GMP code. */
-static int verbose = 0;
+/* debugging for developers. Enables devmsg().
+ This flag is used only in the GMP code. */
+bool dev_debug = false;
/* Prove primality or run probabilistic tests. */
static bool flag_prove_primality = true;
@@ -703,18 +704,6 @@ static bool flag_prove_primality = true;
#endif
static void
-debug (char const *fmt, ...)
-{
- if (verbose)
- {
- va_list ap;
- va_start (ap, fmt);
- vfprintf (stderr, fmt, ap);
- va_end (ap);
- }
-}
-
-static void
factor_insert_refind (struct factors *factors, uintmax_t p, unsigned int i,
unsigned int off)
{
@@ -844,7 +833,7 @@ mp_factor_using_division (mpz_t t, struct mp_factors *factors)
mpz_t q;
unsigned long int p;
- debug ("[trial division] ");
+ devmsg ("[trial division] ");
mpz_init (q);
@@ -1665,7 +1654,7 @@ mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,
mpz_t x, z, y, P;
mpz_t t, t2;
- debug ("[pollard-rho (%lu)] ", a);
+ devmsg ("[pollard-rho (%lu)] ", a);
mpz_inits (t, t2, NULL);
mpz_init_set_si (y, 2);
@@ -1728,7 +1717,7 @@ mp_factor_using_pollard_rho (mpz_t n, unsigned long int a,
if (!mp_prime_p (t))
{
- debug ("[composite factor--restarting pollard-rho] ");
+ devmsg ("[composite factor--restarting pollard-rho] ");
mp_factor_using_pollard_rho (t, a + 1, factors);
}
else
@@ -2247,7 +2236,7 @@ mp_factor (mpz_t t, struct mp_factors *factors)
if (mpz_cmp_ui (t, 1) != 0)
{
- debug ("[is number prime?] ");
+ devmsg ("[is number prime?] ");
if (mp_prime_p (t))
mp_factor_insert (factors, t);
else
@@ -2400,7 +2389,7 @@ print_factors (const char *input)
case LONGINT_OK:
if (((t1 << 1) >> 1) == t1)
{
- debug ("[%s]", _("using single-precision arithmetic"));
+ devmsg ("[using single-precision arithmetic] ");
print_factors_single (t1, t0);
return true;
}
@@ -2416,7 +2405,7 @@ print_factors (const char *input)
}
#if HAVE_GMP
- debug ("[%s]", _("using arbitrary-precision arithmetic"));
+ devmsg ("[using arbitrary-precision arithmetic] ");
mpz_t t;
struct mp_factors factors;
@@ -2502,8 +2491,8 @@ main (int argc, char **argv)
{
switch (c)
{
- case VERBOSE_OPTION:
- verbose = 1;
+ case DEV_DEBUG_OPTION:
+ dev_debug = true;
break;
case 's':