[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] inttostr: add a new function, inttostr
From: |
Jim Meyering |
Subject: |
Re: [PATCH] inttostr: add a new function, inttostr |
Date: |
Thu, 10 Jun 2010 00:22:59 +0200 |
Bruno Haible wrote:
...
> This is not complete. You also need to tell Automake to compile the inttostr.c
> file, either through a
> lib_SOURCES += inttostr.c
> line in the module description, or in m4/inttostr.m4.
Thanks.
I'll add tests, too.
> Since we have seen (last time a week ago) how limited AC_LIBOBJ is in general,
> I would suggest to convert the 4 AC_LIBOBJ invocations to a lib_SOURCES
> augmentation, like this:
>
...
> --- modules/inttostr.orig Wed Jun 9 23:23:20 2010
> +++ modules/inttostr Wed Jun 9 23:23:09 2010
> @@ -19,6 +19,7 @@
> gl_INTTOSTR
>
> Makefile.am:
> +lib_SOURCES += imaxtostr.c offtostr.c umaxtostr.c uinttostr.c
Yes, I prefer this, too.
I'll push something like the following (adding all 5) once I've tested.
>From a6a22ebe641e64b9034f95b6300311a9f5749d91 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 9 Jun 2010 18:22:25 +0200
Subject: [PATCH] inttostr: add a new function, inttostr
The namesake function was not available. The existence of the
template file, inttostr.c makes its addition nontrivial.
* lib/anytostr.c: Rename from inttostr.c.
* lib/inttostr.c: New file.
* modules/inttostr (Files): Add anytostr.c.
(Makefile.am): Set lib_SOURCES instead of ...
* m4/inttostr.m4: Remove uses of AC_LIBOBJ.
* lib/imaxtostr.c: Update use.
* lib/offtostr.c: Likewise.
* lib/uinttostr.c: Likewise.
* lib/umaxtostr.c: Likewise.
---
ChangeLog | 15 ++++++++++++++
lib/anytostr.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/imaxtostr.c | 2 +-
lib/inttostr.c | 57 ++---------------------------------------------------
lib/offtostr.c | 2 +-
lib/uinttostr.c | 2 +-
lib/umaxtostr.c | 2 +-
m4/inttostr.m4 | 7 +-----
modules/inttostr | 7 ++++++
9 files changed, 84 insertions(+), 64 deletions(-)
create mode 100644 lib/anytostr.c
diff --git a/ChangeLog b/ChangeLog
index edb9122..e4ea93d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-06-09 Jim Meyering <address@hidden>
+
+ inttostr: add a new function, inttostr
+ The namesake function was not available. The existence of the
+ template file, inttostr.c makes its addition nontrivial.
+ * lib/anytostr.c: Rename from inttostr.c.
+ * lib/inttostr.c: New file.
+ * modules/inttostr (Files): Add anytostr.c.
+ (Makefile.am): Set lib_SOURCES instead of ...
+ * m4/inttostr.m4: Remove uses of AC_LIBOBJ.
+ * lib/imaxtostr.c: Update use.
+ * lib/offtostr.c: Likewise.
+ * lib/uinttostr.c: Likewise.
+ * lib/umaxtostr.c: Likewise.
+
2010-06-08 Peter Simons <address@hidden>
maint.mk: make the news-check rule more configurable
diff --git a/lib/anytostr.c b/lib/anytostr.c
new file mode 100644
index 0000000..07e5966
--- /dev/null
+++ b/lib/anytostr.c
@@ -0,0 +1,54 @@
+/* anytostr.c -- convert integers to printable strings
+
+ Copyright (C) 2001, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Paul Eggert */
+
+#include <config.h>
+
+#include "inttostr.h"
+#include "verify.h"
+
+/* Convert I to a printable string in BUF, which must be at least
+ INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
+ printable string, which need not start at BUF. */
+
+char *
+inttostr (inttype i, char *buf)
+{
+ verify (TYPE_SIGNED (inttype) == inttype_is_signed);
+ char *p = buf + INT_STRLEN_BOUND (inttype);
+ *p = 0;
+
+#if inttype_is_signed
+ if (i < 0)
+ {
+ do
+ *--p = '0' - i % 10;
+ while ((i /= 10) != 0);
+
+ *--p = '-';
+ }
+ else
+#endif
+ {
+ do
+ *--p = '0' + i % 10;
+ while ((i /= 10) != 0);
+ }
+
+ return p;
+}
diff --git a/lib/imaxtostr.c b/lib/imaxtostr.c
index 34ef96c..33f361c 100644
--- a/lib/imaxtostr.c
+++ b/lib/imaxtostr.c
@@ -1,4 +1,4 @@
#define inttostr imaxtostr
#define inttype intmax_t
#define inttype_is_signed 1
-#include "inttostr.c"
+#include "anytostr.c"
diff --git a/lib/inttostr.c b/lib/inttostr.c
index 7a4a47f..bb403e5 100644
--- a/lib/inttostr.c
+++ b/lib/inttostr.c
@@ -1,54 +1,3 @@
-/* inttostr.c -- convert integers to printable strings
-
- Copyright (C) 2001, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-/* Written by Paul Eggert */
-
-#include <config.h>
-
-#include "inttostr.h"
-#include "verify.h"
-
-/* Convert I to a printable string in BUF, which must be at least
- INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the
- printable string, which need not start at BUF. */
-
-char *
-inttostr (inttype i, char *buf)
-{
- verify (TYPE_SIGNED (inttype) == inttype_is_signed);
- char *p = buf + INT_STRLEN_BOUND (inttype);
- *p = 0;
-
-#if inttype_is_signed
- if (i < 0)
- {
- do
- *--p = '0' - i % 10;
- while ((i /= 10) != 0);
-
- *--p = '-';
- }
- else
-#endif
- {
- do
- *--p = '0' + i % 10;
- while ((i /= 10) != 0);
- }
-
- return p;
-}
+#define inttype int
+#define inttype_is_signed 1
+#include "anytostr.c"
diff --git a/lib/offtostr.c b/lib/offtostr.c
index 3a60c6e..c5143dc 100644
--- a/lib/offtostr.c
+++ b/lib/offtostr.c
@@ -1,4 +1,4 @@
#define inttostr offtostr
#define inttype off_t
#define inttype_is_signed 1
-#include "inttostr.c"
+#include "anytostr.c"
diff --git a/lib/uinttostr.c b/lib/uinttostr.c
index 1662985..0ec328a 100644
--- a/lib/uinttostr.c
+++ b/lib/uinttostr.c
@@ -1,4 +1,4 @@
#define inttostr uinttostr
#define inttype unsigned int
#define inttype_is_signed 0
-#include "inttostr.c"
+#include "anytostr.c"
diff --git a/lib/umaxtostr.c b/lib/umaxtostr.c
index 914f388..19908f3 100644
--- a/lib/umaxtostr.c
+++ b/lib/umaxtostr.c
@@ -1,4 +1,4 @@
#define inttostr umaxtostr
#define inttype uintmax_t
#define inttype_is_signed 0
-#include "inttostr.c"
+#include "anytostr.c"
diff --git a/m4/inttostr.m4 b/m4/inttostr.m4
index 3e17ed5..ff64ddb 100644
--- a/m4/inttostr.m4
+++ b/m4/inttostr.m4
@@ -1,4 +1,4 @@
-#serial 7
+#serial 8
dnl Copyright (C) 2004, 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -6,11 +6,6 @@ dnl with or without modifications, as long as this notice is
preserved.
AC_DEFUN([gl_INTTOSTR],
[
- AC_LIBOBJ([imaxtostr])
- AC_LIBOBJ([offtostr])
- AC_LIBOBJ([umaxtostr])
- AC_LIBOBJ([uinttostr])
-
gl_PREREQ_INTTOSTR
gl_PREREQ_IMAXTOSTR
gl_PREREQ_OFFTOSTR
diff --git a/modules/inttostr b/modules/inttostr
index 2c2b76e..495ef25 100644
--- a/modules/inttostr
+++ b/modules/inttostr
@@ -2,6 +2,7 @@ Description:
Convert integers to printable strings.
Files:
+lib/anytostr.c
lib/imaxtostr.c
lib/inttostr.c
lib/inttostr.h
@@ -19,6 +20,12 @@ configure.ac:
gl_INTTOSTR
Makefile.am:
+lib_SOURCES += \
+ imaxtostr.c \
+ inttostr.c \
+ offtostr.c \
+ uinttostr.c \
+ umaxtostr.c
Include:
"inttostr.h"
--
1.7.1.501.g23b46