Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add FreeBSD's strfmon(3). From Rui Paulo. No bump this time....



details:   https://anonhg.NetBSD.org/src/rev/5eb9e10da710
branches:  trunk
changeset: 579981:5eb9e10da710
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Apr 03 20:09:29 2005 +0000

description:
Add FreeBSD's strfmon(3). From Rui Paulo. No bump this time. Take advantage
of the getpwent_r bump.

diffstat:

 include/Makefile             |    3 +-
 include/monetary.h           |   51 +++
 lib/libc/stdlib/Makefile.inc |    8 +-
 lib/libc/stdlib/strfmon.3    |  169 +++++++++++
 lib/libc/stdlib/strfmon.c    |  616 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 843 insertions(+), 4 deletions(-)

diffs (truncated from 894 to 300 lines):

diff -r e3a85a004680 -r 5eb9e10da710 include/Makefile
--- a/include/Makefile  Sun Apr 03 20:01:53 2005 +0000
+++ b/include/Makefile  Sun Apr 03 20:09:29 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.119 2004/12/14 00:23:20 nathanw Exp $
+#      $NetBSD: Makefile,v 1.120 2005/04/03 20:09:29 christos Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/4/94
 
 # Doing a make includes builds /usr/include
@@ -14,6 +14,7 @@
        limits.h link.h link_aout.h link_elf.h locale.h \
        login_cap.h lwp.h malloc.h math.h md2.h \
        memory.h mntopts.h mpool.h \
+       monetary.h \
        ndbm.h netconfig.h netdb.h netgroup.h nlist.h nl_types.h \
        nsswitch.h paths.h pwd.h randomid.h ranlib.h re_comp.h regex.h regexp.h \
        resolv.h res_update.h rmd160.h rmt.h sa.h sched.h search.h semaphore.h setjmp.h \
diff -r e3a85a004680 -r 5eb9e10da710 include/monetary.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/include/monetary.h        Sun Apr 03 20:09:29 2005 +0000
@@ -0,0 +1,51 @@
+/*     $NetBSD: monetary.h,v 1.1 2005/04/03 20:09:29 christos Exp $    */
+
+/*-
+ * Copyright (c) 2001 Alexey Zelkin <phantom%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/include/monetary.h,v 1.7 2002/09/20 08:22:48 mike Exp $
+ */
+
+#ifndef _MONETARY_H_
+#define        _MONETARY_H_
+
+#include <sys/cdefs.h>
+#include <machine/ansi.h>
+
+#ifdef _BSD_SIZE_T_
+typedef        _BSD_SIZE_T_    size_t;
+#undef _BSD_SIZE_T_
+#endif
+
+#ifdef _BSD_SSIZE_T_
+typedef        _BSD_SSIZE_T_   ssize_t;
+#undef _BSD_SSIZE_T_
+#endif
+
+__BEGIN_DECLS
+ssize_t        strfmon(char * __restrict, size_t, const char * __restrict, ...);
+__END_DECLS
+
+#endif /* !_MONETARY_H_ */
diff -r e3a85a004680 -r 5eb9e10da710 lib/libc/stdlib/Makefile.inc
--- a/lib/libc/stdlib/Makefile.inc      Sun Apr 03 20:01:53 2005 +0000
+++ b/lib/libc/stdlib/Makefile.inc      Sun Apr 03 20:09:29 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.57 2004/08/05 00:17:02 yamt Exp $
+#      $NetBSD: Makefile.inc,v 1.58 2005/04/03 20:09:29 christos Exp $
 #      from: @(#)Makefile.inc  8.3 (Berkeley) 2/4/95
 
 # stdlib sources
@@ -15,7 +15,8 @@
        strsuftoll.c strtod.c \
        strtoimax.c strtol.c strtoll.c strtoq.c strtoul.c strtoull.c \
        strtoumax.c strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c \
-       __unsetenv13.c unsetenv.c
+       __unsetenv13.c unsetenv.c \
+       strfmon.c
 
 # machine-dependent stdlib sources
 # m-d Makefile.inc must include sources for:
@@ -28,7 +29,8 @@
        grantpt.3 hcreate.3 labs.3 ldiv.3 llabs.3 lldiv.3 malloc.3 memory.3 \
        posix_openpt.3 ptsname.3 qabs.3 \
        qdiv.3 qsort.3 radixsort.3 rand48.3 rand.3 random.3 \
-       strsuftoll.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 unlockpt.3
+       strsuftoll.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3 unlockpt.3 \
+       strfmon.3
 
 MLINKS+=a64l.3 l64a.3
 MLINKS+=a64l.3 l64a_r.3
diff -r e3a85a004680 -r 5eb9e10da710 lib/libc/stdlib/strfmon.3
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdlib/strfmon.3 Sun Apr 03 20:09:29 2005 +0000
@@ -0,0 +1,169 @@
+.\"    $NetBSD: strfmon.3,v 1.1 2005/04/03 20:09:29 christos Exp $      
+.\"
+.\" Copyright (c) 2001 Jeroen Ruigrok van der Werven <asmodai%FreeBSD.org@localhost>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\"    From: FreeBSD: Id: strfmon.3,v 1.7 2003/01/06 06:21:25 tjr Exp
+.\"
+.Dd October 12, 2002
+.Dt STRFMON 3
+.Os
+.Sh NAME
+.Nm strfmon
+.Nd convert monetary value to string
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In monetary.h
+.Ft ssize_t
+.Fn strfmon "char * restrict s" "size_t maxsize" "const char * restrict format" "..."
+.Sh DESCRIPTION
+The
+.Fn strfmon
+function places characters into the array pointed to by
+.Fa s
+as controlled by the string pointed to by
+.Fa format .
+No more than
+.Fa maxsize
+bytes are placed into the array.
+.Pp
+The format string is composed of zero or more directives:
+ordinary characters (not
+.Cm % ) ,
+which are copied unchanged to the output stream; and conversion
+specifications, each of which results in fetching zero or more subsequent
+arguments.
+Each conversion specification is introduced by the
+.Cm %
+character.
+After the
+.Cm % ,
+the following appear in sequence:
+.Bl -bullet
+.It
+Zero or more of the following flags:
+.Bl -tag -width "XXX"
+.It Cm = Ns Ar f
+A
+.Sq Cm =
+character followed by another character
+.Ar f
+which is used as the numeric fill character.
+.It Cm ^
+Do not use grouping characters, regardless of the current locale default.
+.It Cm +
+Represent positive values by prefixing them with a positive sign,
+and negative values by prefixing them with a negative sign.
+This is the default.
+.It Cm \&(
+Enclose negative values in parentheses.
+.It Cm \&!
+Do not include a currency symbol in the output.
+.It Cm \-
+Left justify the result.
+Only valid when a field width is specified.
+.El
+.It
+An optional minimum field width as a decimal number.
+By default, there is no minimum width.
+.It
+A
+.Sq Cm #
+sign followed by a decimal number specifying the maximum
+expected number of digits after the radix character.
+.It
+A
+.Sq Cm \&.
+character followed by a decimal number specifying the number
+the number of digits after the radix character.
+.It
+One of the following conversion specifiers:
+.Bl -tag -width "XXX"
+.It Cm i
+The
+.Vt double
+argument is formatted as an international monetary amount.
+.It Cm n
+The
+.Vt double
+argument is formatted as a national monetary amount.
+.It Cm %
+A
+.Sq Li %
+character is written.
+.El
+.El
+.Sh RETURN VALUES
+If the total number of resulting bytes including the terminating
+.Dv NULL
+byte is not more than
+.Fa maxsize ,
+.Fn strfmon
+returns the number of bytes placed into the array pointed to by
+.Fa s ,
+not including the terminating
+.Dv NULL
+byte.
+Otherwise, \-1 is returned,
+the contents of the array are indeterminate,
+and
+.Va errno
+is set to indicate the error.
+.Sh ERRORS
+The
+.Fn strfmon
+function will fail if:
+.Bl -tag -width Er
+.It Bq Er E2BIG
+Conversion stopped due to lack of space in the buffer.
+.It Bq Er EINVAL
+The format string is invalid.
+.It Bq Er ENOMEM
+Not enough memory for temporary buffers.
+.El
+.Sh SEE ALSO
+.Xr localeconv 3
+.Sh STANDARDS
+The
+.Fn strfmon
+function
+conforms to
+.St -p1003.1-2001 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Fn strfmon
+function was implemented by
+.An Alexey Zelkin Aq phantom%FreeBSD.org@localhost .
+.Pp
+This manual page was written by
+.An Jeroen Ruigrok van der Werven Aq asmodai%FreeBSD.org@localhost
+based on the standards' text.
+.Sh BUGS
+The
+.Fn strfmon
+function does not correctly handle multibyte characters in the
+.Fa format
+argument.
diff -r e3a85a004680 -r 5eb9e10da710 lib/libc/stdlib/strfmon.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/stdlib/strfmon.c Sun Apr 03 20:09:29 2005 +0000
@@ -0,0 +1,616 @@
+/*     $NetBSD: strfmon.c,v 1.1 2005/04/03 20:09:29 christos Exp $     */
+
+/*-
+ * Copyright (c) 2001 Alexey Zelkin <phantom%FreeBSD.org@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)



Home | Main Index | Thread Index | Old Index