| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp $ */ | | 1 | /* $NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1997-2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Luke Mewburn. | | 8 | * by Luke Mewburn. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | __RCSID("$NetBSD: progressbar.c,v 1.22 2012/06/27 22:07:36 riastradh Exp $"); | | 34 | __RCSID("$NetBSD: progressbar.c,v 1.23 2019/06/22 23:40:33 christos Exp $"); |
35 | #endif /* not lint */ | | 35 | #endif /* not lint */ |
36 | | | 36 | |
37 | /* | | 37 | /* |
38 | * FTP User Program -- Misc support routines | | 38 | * FTP User Program -- Misc support routines |
39 | */ | | 39 | */ |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/types.h> | | 41 | #include <sys/types.h> |
42 | #include <sys/time.h> | | 42 | #include <sys/time.h> |
43 | | | 43 | |
44 | #include <err.h> | | 44 | #include <err.h> |
45 | #include <errno.h> | | 45 | #include <errno.h> |
46 | #include <signal.h> | | 46 | #include <signal.h> |
47 | #include <stdio.h> | | 47 | #include <stdio.h> |
| @@ -77,41 +77,43 @@ static void updateprogressmeter(int); | | | @@ -77,41 +77,43 @@ static void updateprogressmeter(int); |
77 | */ | | 77 | */ |
78 | static void | | 78 | static void |
79 | updateprogressmeter(int dummy) | | 79 | updateprogressmeter(int dummy) |
80 | { | | 80 | { |
81 | int oerrno = errno; | | 81 | int oerrno = errno; |
82 | | | 82 | |
83 | progressmeter(0); | | 83 | progressmeter(0); |
84 | errno = oerrno; | | 84 | errno = oerrno; |
85 | } | | 85 | } |
86 | | | 86 | |
87 | /* | | 87 | /* |
88 | * List of order of magnitude suffixes, per IEC 60027-2. | | 88 | * List of order of magnitude suffixes, per IEC 60027-2. |
89 | */ | | 89 | */ |
| | | 90 | #if !defined(NO_PROGRESS) || !defined(STANDALONE_PROGRESS) |
90 | static const char * const suffixes[] = { | | 91 | static const char * const suffixes[] = { |
91 | "", /* 2^0 (byte) */ | | 92 | "", /* 2^0 (byte) */ |
92 | "KiB", /* 2^10 Kibibyte */ | | 93 | "KiB", /* 2^10 Kibibyte */ |
93 | "MiB", /* 2^20 Mebibyte */ | | 94 | "MiB", /* 2^20 Mebibyte */ |
94 | "GiB", /* 2^30 Gibibyte */ | | 95 | "GiB", /* 2^30 Gibibyte */ |
95 | "TiB", /* 2^40 Tebibyte */ | | 96 | "TiB", /* 2^40 Tebibyte */ |
96 | "PiB", /* 2^50 Pebibyte */ | | 97 | "PiB", /* 2^50 Pebibyte */ |
97 | "EiB", /* 2^60 Exbibyte */ | | 98 | "EiB", /* 2^60 Exbibyte */ |
98 | #if 0 | | 99 | #if 0 |
99 | /* The following are not necessary for signed 64-bit off_t */ | | 100 | /* The following are not necessary for signed 64-bit off_t */ |
100 | "ZiB", /* 2^70 Zebibyte */ | | 101 | "ZiB", /* 2^70 Zebibyte */ |
101 | "YiB", /* 2^80 Yobibyte */ | | 102 | "YiB", /* 2^80 Yobibyte */ |
102 | #endif | | 103 | #endif |
103 | }; | | 104 | }; |
104 | #define NSUFFIXES (int)(sizeof(suffixes) / sizeof(suffixes[0])) | | 105 | #define NSUFFIXES (int)(sizeof(suffixes) / sizeof(suffixes[0])) |
| | | 106 | #endif |
105 | | | 107 | |
106 | /* | | 108 | /* |
107 | * Display a transfer progress bar if progress is non-zero. | | 109 | * Display a transfer progress bar if progress is non-zero. |
108 | * SIGALRM is hijacked for use by this function. | | 110 | * SIGALRM is hijacked for use by this function. |
109 | * - Before the transfer, set filesize to size of file (or -1 if unknown), | | 111 | * - Before the transfer, set filesize to size of file (or -1 if unknown), |
110 | * and call with flag = -1. This starts the once per second timer, | | 112 | * and call with flag = -1. This starts the once per second timer, |
111 | * and a call to updateprogressmeter() upon SIGALRM. | | 113 | * and a call to updateprogressmeter() upon SIGALRM. |
112 | * - During the transfer, updateprogressmeter will call progressmeter | | 114 | * - During the transfer, updateprogressmeter will call progressmeter |
113 | * with flag = 0 | | 115 | * with flag = 0 |
114 | * - After the transfer, call with flag = 1 | | 116 | * - After the transfer, call with flag = 1 |
115 | */ | | 117 | */ |
116 | static struct timeval start; | | 118 | static struct timeval start; |
117 | static struct timeval lastupdate; | | 119 | static struct timeval lastupdate; |
| @@ -129,28 +131,30 @@ progressmeter(int flag) | | | @@ -129,28 +131,30 @@ progressmeter(int flag) |
129 | off_t abbrevsize, bytespersec; | | 131 | off_t abbrevsize, bytespersec; |
130 | double elapsed; | | 132 | double elapsed; |
131 | int ratio, i, remaining, barlength; | | 133 | int ratio, i, remaining, barlength; |
132 | | | 134 | |
133 | /* | | 135 | /* |
134 | * Work variables for progress bar. | | 136 | * Work variables for progress bar. |
135 | * | | 137 | * |
136 | * XXX: if the format of the progress bar changes | | 138 | * XXX: if the format of the progress bar changes |
137 | * (especially the number of characters in the | | 139 | * (especially the number of characters in the |
138 | * `static' portion of it), be sure to update | | 140 | * `static' portion of it), be sure to update |
139 | * these appropriately. | | 141 | * these appropriately. |
140 | */ | | 142 | */ |
141 | #endif | | 143 | #endif |
| | | 144 | #if !defined(NO_PROGRESS) || !defined(STANDALONE_PROGRESS) |
142 | size_t len; | | 145 | size_t len; |
143 | char buf[256]; /* workspace for progress bar */ | | 146 | char buf[256]; /* workspace for progress bar */ |
| | | 147 | #endif |
144 | #ifndef NO_PROGRESS | | 148 | #ifndef NO_PROGRESS |
145 | #define BAROVERHEAD 45 /* non `*' portion of progress bar */ | | 149 | #define BAROVERHEAD 45 /* non `*' portion of progress bar */ |
146 | /* | | 150 | /* |
147 | * stars should contain at least | | 151 | * stars should contain at least |
148 | * sizeof(buf) - BAROVERHEAD entries | | 152 | * sizeof(buf) - BAROVERHEAD entries |
149 | */ | | 153 | */ |
150 | static const char stars[] = | | 154 | static const char stars[] = |
151 | "*****************************************************************************" | | 155 | "*****************************************************************************" |
152 | "*****************************************************************************" | | 156 | "*****************************************************************************" |
153 | "*****************************************************************************"; | | 157 | "*****************************************************************************"; |
154 | | | 158 | |
155 | #endif | | 159 | #endif |
156 | | | 160 | |