| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: strpct.3,v 1.2 2011/08/28 17:21:28 wiz Exp $ | | 1 | .\" $NetBSD: strpct.3,v 1.3 2011/09/01 23:13:16 fair Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2011 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2011 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This file was contributed to The NetBSD Foundation by Christos Zoulas. | | 6 | .\" This file was contributed to The NetBSD Foundation by Christos Zoulas. |
7 | .\" | | 7 | .\" |
8 | .\" Redistribution and use in source and binary forms, with or without | | 8 | .\" Redistribution and use in source and binary forms, with or without |
9 | .\" modification, are permitted provided that the following conditions | | 9 | .\" modification, are permitted provided that the following conditions |
10 | .\" are met: | | 10 | .\" are met: |
11 | .\" 1. Redistributions of source code must retain the above copyright | | 11 | .\" 1. Redistributions of source code must retain the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer. | | 12 | .\" notice, this list of conditions and the following disclaimer. |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| @@ -16,68 +16,73 @@ | | | @@ -16,68 +16,73 @@ |
16 | .\" | | 16 | .\" |
17 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 17 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
18 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 18 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
19 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 19 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
20 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 20 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
21 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 21 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
22 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 22 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
23 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 23 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
24 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 24 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
25 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 25 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
26 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 26 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | .\" POSSIBILITY OF SUCH DAMAGE. | | 27 | .\" POSSIBILITY OF SUCH DAMAGE. |
28 | .\" | | 28 | .\" |
29 | .Dd August 28, 2011 | | 29 | .Dd September 1, 2011 |
30 | .Dt STRPCT 3 | | 30 | .Dt STRPCT 3 |
31 | .Os | | 31 | .Os |
32 | .Sh NAME | | 32 | .Sh NAME |
33 | .Nm strpct | | 33 | .Nm strpct |
34 | .Nd decimal percent formatter | | 34 | .Nd decimal percent formatter |
35 | .Sh LIBRARY | | 35 | .Sh LIBRARY |
36 | .Lb libutil | | 36 | .Lb libutil |
37 | .Sh SYNOPSIS | | 37 | .Sh SYNOPSIS |
38 | .In util.h | | 38 | .In util.h |
39 | .Ft char * | | 39 | .Ft char * |
40 | .Fn strpct "char *buf" "size_t bufsiz" "uintmax_t numerator" "uintmax_t denominator" "size_t precision" | | 40 | .Fn strpct "char *buf" "size_t bufsiz" "uintmax_t numerator" "uintmax_t denominator" "size_t precision" |
41 | .Sh DESCRIPTION | | 41 | .Sh DESCRIPTION |
42 | The | | 42 | The |
43 | .Fn strpct | | 43 | .Fn strpct |
44 | function formats the fraction represented by | | 44 | function formats the fraction represented by |
45 | .Fa numerator | | 45 | .Fa numerator |
46 | and | | 46 | and |
47 | .Fa denominator | | 47 | .Fa denominator |
48 | into a percentage representation with given number of digits of | | 48 | into a percentage representation with given number of digits of |
49 | .Fa precision . | | 49 | .Fa precision |
| | | 50 | without using floating point arithmetic. |
50 | .Sh RETURN VALUES | | 51 | .Sh RETURN VALUES |
51 | .Fn strpct | | 52 | .Fn strpct |
52 | always returns a pointer to a NUL-terminated formatted string which | | 53 | always returns a pointer to a NUL-terminated formatted string which |
53 | is placed in | | 54 | is placed in |
54 | .Fa buf | | 55 | .Fa buf |
55 | and is up to | | 56 | and is up to |
56 | .Fa buflen | | 57 | .Fa buflen |
57 | characters. | | 58 | characters. |
58 | If there was an overflow, the formatted string will reflect that precision | | 59 | If there was an overflow, the formatted string will reflect that precision |
59 | loss. | | 60 | loss. |
60 | .Sh EXAMPLES | | 61 | .Sh EXAMPLES |
61 | .Bd -literal -offset indent | | 62 | .Bd -literal -offset indent |
62 | strpct(buf, buflen, 1, 16, 3); | | 63 | strpct(buf, buflen, 1, 16, 3); |
63 | \(rA "6.250" | | 64 | \(rA "6.250" |
64 | strpct(buf, buflen, 1, 2, 0); | | 65 | strpct(buf, buflen, 1, 2, 0); |
65 | \(rA "50" | | 66 | \(rA "50" |
66 | .Ed | | 67 | .Ed |
67 | .Sh HISTORY | | 68 | .Sh HISTORY |
68 | .Fn strpct | | 69 | .Fn strpct |
69 | was originally implemented in | | 70 | was originally implemented in |
70 | .Xr csh 1 . | | 71 | .Xr csh 1 |
| | | 72 | for |
| | | 73 | .Nx 1.3 . |
71 | It printed into a static buffer, was not locale aware, handled | | 74 | It printed into a static buffer, was not locale aware, handled |
72 | .Ft unsigned long | | 75 | .Ft unsigned long |
73 | numbers, and printed a | | 76 | numbers, and printed a |
74 | .Dq % | | 77 | .Dq % |
75 | at the end of the number. | | 78 | at the end of the number. |
76 | Other programs such as | | 79 | Other programs such as |
77 | .Xr df 1 | | 80 | .Xr df 1 |
78 | and | | 81 | and |
79 | .Xr time 1 | | 82 | .Xr time 1 |
80 | started using it. | | 83 | started using it. |
81 | .Fn strpct | | 84 | .Fn strpct |
82 | appeared in | | 85 | appeared separately in libutil for |
83 | .Nx 6.0 . | | 86 | .Nx 6.0 . |
| | | 87 | .Sh AUTHORS |
| | | 88 | .An Erik E. Fair Aq fair@netbsd.org |