Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/human.h @ 6275:fd0ccce602e4
Sync from coreutils.
* .cppi-disable: Add regcomp.c, regex_internal.c, regex_internal.h,
stat-time.h.
* argmatch.h: Include verify.h
(ARGMATCH_VERIFY): Use verify rather than rolling our own.
(ARGMATCH_ASSERT): Remove; unused.
* canonicalize.c: Assume STDC_HEADERS.
* exclude.c: Include "strcase.h".
* regex_internal.h [!defined _LIBC]: Likewise.
* getusershell.c: Include stdio--.h rather than stdio.h
and stdio-safer.h.
(getusershell): Call fopen, not fopen_safer.
* save-cwd.c: Include fcntl--.h rather than fcntl.h.
Do not include unistd-safer.h.
(save_cwd): Don't call fd_safer; no longer needed
now that we include fcntl--.h.
* modules/argmatch (Depends-on): Add verify.
* modules/getloadavg (Depends-on): Depend on fcntl-safer, not
unistd-safer.
* modules/save-cwd (Depends-on): Likewise.
* backupfile.m4, calloc.m4, chown.m4, cloexec.m4, dup2.m4:
* fileblocks.m4, free.m4, ftruncate.m4, getcwd.m4, getpagesize.m4:
* getugroups.m4, group-member.m4, idcache.m4, link-follow.m4:
* mkstemp.m4, mktime.m4, mountlist.m4, nanosleep.m4, pathmax.m4:
* physmem.m4, posixver.m4, putenv.m4, safe-read.m4, same.m4:
* save-cwd.m4, stdio-safer.m4, unistd-safer.m4, unlinkdir.m4:
* userspec.m4, xgetcwd.m4, xreadlink.m4:
Don't bother checking for string.h, stdlib.h, unistd.h.
* fts.m4 (gl_FUNC_FTS_CORE): Don't require
AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK; that's now the lstat
module's job.
* jm-macros.m4 (gl_MACROS): Likewise.
* prereq.m4 (gl_PREREQ): Add gl_FUNC_LSTAT.
* backupfile.c: Use ARGMATCH_VERIFY, just in case.
* posixtm.c (posixtime) [lint]: Initialize *all* of tm0, not just
the .tm_year member, since otherwise gcc-4.0 would now warn about
tm_zone, tm_gmtoff, tm_isdst, tm_yday, tm_wday.
* quotearg.c (quotearg_n_options): Change code to be suboptimal, in
order to avoid an unsuppressible warning from gcc on 64-bit systems.
* lstat.m4 (gl_FUNC_LSTAT):
Use AC_LIBSOURCES to require lstat.c and lstat.h.
Remove obsolete comment.
* xreadlink.m4: Use AC_LIBSOURCES and AC_LIBOBJ.
* xstrtod.m4: Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 23 Sep 2005 04:15:13 +0000 |
parents | 96c32553b4c6 |
children | 19c2e5121b2f |
rev | line source |
---|---|
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
1 /* human.h -- print human readable file size |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
2 |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 |
5159 | 4 Free Software Foundation, Inc. |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
5 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
9 any later version. |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
10 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
11 This program is distributed in the hope that it will be useful, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
14 GNU General Public License for more details. |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
15 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
17 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5691
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
19 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
20 /* Written by Paul Eggert and Larry McVoy. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
21 |
1137
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
22 #ifndef HUMAN_H_ |
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
23 # define HUMAN_H_ 1 |
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
24 |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
25 # include <limits.h> |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
26 # include <stdbool.h> |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
27 |
5159 | 28 # if HAVE_STDINT_H |
29 # include <stdint.h> | |
30 # endif | |
6275 | 31 # include <unistd.h> |
1813
9e16d9bc8891
<inttypes.h>: Include it here instead.
Jim Meyering <jim@meyering.net>
parents:
1392
diff
changeset
|
32 |
1137
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
33 /* A conservative bound on the maximum length of a human-readable string. |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
34 The output can be the square of the largest uintmax_t, so double |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
35 its size before converting to a bound. |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
36 log10 (2.0) < 146/485. Add 1 for integer division truncation. |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
37 Also, the output can have a thousands separator between every digit, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
38 so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX. |
5458 | 39 Append 1 for a space before the suffix. |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
40 Finally, append 3, the maximum length of a suffix. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
41 # define LONGEST_HUMAN_READABLE \ |
5691
ec62790f0938
Factor int-properties macros into a single file, except for
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
42 ((2 * sizeof (uintmax_t) * CHAR_BIT * 146 / 485 + 1) * (MB_LEN_MAX + 1) \ |
5458 | 43 - MB_LEN_MAX + 1 + 3) |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
44 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
45 /* Options for human_readable. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
46 enum |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
47 { |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
48 /* Unless otherwise specified these options may be ORed together. */ |
1137
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
49 |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
50 /* The following three options are mutually exclusive. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
51 /* Round to plus infinity (default). */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
52 human_ceiling = 0, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
53 /* Round to nearest, ties to even. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
54 human_round_to_nearest = 1, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
55 /* Round to minus infinity. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
56 human_floor = 2, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
57 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
58 /* Group digits together, e.g. `1,000,000'. This uses the |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
59 locale-defined grouping; the traditional C locale does not group, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
60 so this has effect only if some other locale is in use. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
61 human_group_digits = 4, |
1137
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
62 |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
63 /* When autoscaling, suppress ".0" at end. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
64 human_suppress_point_zero = 8, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
65 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
66 /* Scale output and use SI-style units, ignoring the output block size. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
67 human_autoscale = 16, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
68 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
69 /* Prefer base 1024 to base 1000. */ |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
70 human_base_1024 = 32, |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
71 |
5458 | 72 /* Prepend " " before unit symbol. */ |
73 human_space_before_unit = 64, | |
74 | |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
75 /* Append SI prefix, e.g. "k" or "M". */ |
5458 | 76 human_SI = 128, |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
77 |
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
78 /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix. */ |
5458 | 79 human_B = 256 |
1864
734d9b0f9fce
(enum human_inexact_style): New enum.
Jim Meyering <jim@meyering.net>
parents:
1813
diff
changeset
|
80 }; |
734d9b0f9fce
(enum human_inexact_style): New enum.
Jim Meyering <jim@meyering.net>
parents:
1813
diff
changeset
|
81 |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
82 char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t); |
1392
849f05797f68
(human_readable): Coalesce last two args into one, for convenience.
Jim Meyering <jim@meyering.net>
parents:
1170
diff
changeset
|
83 |
4351
d0d257fdad20
Merge human.c changes from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4132
diff
changeset
|
84 int human_options (char const *, bool, uintmax_t *); |
1137
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
85 |
2c9059ccc457
New file. The interface is inspired
Jim Meyering <jim@meyering.net>
parents:
diff
changeset
|
86 #endif /* HUMAN_H_ */ |