~ubuntu-branches/ubuntu/raring/findutils/raring

« back to all changes in this revision

Viewing changes to gnulib/lib/human.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2005-07-04 11:37:37 UTC
  • mto: (11.1.1 lenny) (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050704113737-oxfumqxsqgfz5gay
Tags: upstream-4.2.22
ImportĀ upstreamĀ versionĀ 4.2.22

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* human.h -- print human readable file size
 
2
 
 
3
   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
 
4
   Free Software Foundation, Inc.
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2, or (at your option)
 
9
   any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software Foundation,
 
18
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
19
 
 
20
/* Written by Paul Eggert and Larry McVoy.  */
 
21
 
1
22
#ifndef HUMAN_H_
2
23
# define HUMAN_H_ 1
3
24
 
5
26
#  include <config.h>
6
27
# endif
7
28
 
8
 
# if HAVE_INTTYPES_H
9
 
#  include <inttypes.h>
10
 
# else
11
 
#  if HAVE_STDINT_H
12
 
#   include <stdint.h>
13
 
#  endif
 
29
# include <limits.h>
 
30
# include <stdbool.h>
 
31
 
 
32
# if HAVE_STDINT_H
 
33
#  include <stdint.h>
 
34
# endif
 
35
# if HAVE_UNISTD_H
 
36
#  include <unistd.h>
14
37
# endif
15
38
 
16
39
/* A conservative bound on the maximum length of a human-readable string.
17
 
   The output can be the product of the largest uintmax_t and the largest int,
18
 
   so add their sizes before converting to a bound on digits.  */
19
 
# define LONGEST_HUMAN_READABLE ((sizeof (uintmax_t) + sizeof (int)) \
20
 
                                 * CHAR_BIT / 3)
21
 
 
22
 
# ifndef PARAMS
23
 
#  if defined PROTOTYPES || (defined __STDC__ && __STDC__)
24
 
#   define PARAMS(Args) Args
25
 
#  else
26
 
#   define PARAMS(Args) ()
27
 
#  endif
28
 
# endif
29
 
 
30
 
enum human_inexact_style
 
40
   The output can be the square of the largest uintmax_t, so double
 
41
   its size before converting to a bound.
 
42
   log10 (2.0) < 146/485.  Add 1 for integer division truncation.
 
43
   Also, the output can have a thousands separator between every digit,
 
44
   so multiply by MB_LEN_MAX + 1 and then subtract MB_LEN_MAX.
 
45
   Append 1 for a space before the suffix.
 
46
   Finally, append 3, the maximum length of a suffix.  */
 
47
# define LONGEST_HUMAN_READABLE \
 
48
  ((2 * sizeof (uintmax_t) * CHAR_BIT * 146 / 485 + 1) * (MB_LEN_MAX + 1) \
 
49
   - MB_LEN_MAX + 1 + 3)
 
50
 
 
51
/* Options for human_readable.  */
 
52
enum
31
53
{
32
 
  human_floor = -1,
33
 
  human_round_to_even = 0,
34
 
  human_ceiling = 1
 
54
  /* Unless otherwise specified these options may be ORed together.  */
 
55
 
 
56
  /* The following three options are mutually exclusive.  */
 
57
  /* Round to plus infinity (default).  */
 
58
  human_ceiling = 0,
 
59
  /* Round to nearest, ties to even.  */
 
60
  human_round_to_nearest = 1,
 
61
  /* Round to minus infinity.  */
 
62
  human_floor = 2,
 
63
 
 
64
  /* Group digits together, e.g. `1,000,000'.  This uses the
 
65
     locale-defined grouping; the traditional C locale does not group,
 
66
     so this has effect only if some other locale is in use.  */
 
67
  human_group_digits = 4,
 
68
 
 
69
  /* When autoscaling, suppress ".0" at end.  */
 
70
  human_suppress_point_zero = 8,
 
71
 
 
72
  /* Scale output and use SI-style units, ignoring the output block size.  */
 
73
  human_autoscale = 16,
 
74
 
 
75
  /* Prefer base 1024 to base 1000.  */
 
76
  human_base_1024 = 32,
 
77
 
 
78
  /* Prepend " " before unit symbol.  */
 
79
  human_space_before_unit = 64,
 
80
 
 
81
  /* Append SI prefix, e.g. "k" or "M".  */
 
82
  human_SI = 128,
 
83
 
 
84
  /* Append "B" (if base 1000) or "iB" (if base 1024) to SI prefix.  */
 
85
  human_B = 256
35
86
};
36
87
 
37
 
char *human_readable PARAMS ((uintmax_t, char *, int, int));
38
 
char *human_readable_inexact PARAMS ((uintmax_t, char *, int, int,
39
 
                                      enum human_inexact_style));
 
88
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
40
89
 
41
 
void human_block_size PARAMS ((char const *, int, int *));
 
90
int human_options (char const *, bool, uintmax_t *);
42
91
 
43
92
#endif /* HUMAN_H_ */