progressmeter.c (124287) | progressmeter.c (126274) |
---|---|
1/* 2 * Copyright (c) 2003 Nils Nordman. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include "includes.h" | 1/* 2 * Copyright (c) 2003 Nils Nordman. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include "includes.h" |
26RCSID("$OpenBSD: progressmeter.c,v 1.15 2003/08/31 12:14:22 markus Exp $"); | 26RCSID("$OpenBSD: progressmeter.c,v 1.19 2004/02/05 15:33:33 markus Exp $"); |
27 28#include "progressmeter.h" 29#include "atomicio.h" 30#include "misc.h" 31 32#define DEFAULT_WINSIZE 80 33#define MAX_WINSIZE 512 34#define PADDING 1 /* padding between the progress indicators */ --- 40 unchanged lines hidden (view full) --- 75 bytes *= 100; 76 for (i = 0; bytes >= 100*1000 && unit[i] != 'T'; i++) 77 bytes = (bytes + 512) / 1024; 78 if (i == 0) { 79 i++; 80 bytes = (bytes + 512) / 1024; 81 } 82 snprintf(buf, size, "%3lld.%1lld%c%s", | 27 28#include "progressmeter.h" 29#include "atomicio.h" 30#include "misc.h" 31 32#define DEFAULT_WINSIZE 80 33#define MAX_WINSIZE 512 34#define PADDING 1 /* padding between the progress indicators */ --- 40 unchanged lines hidden (view full) --- 75 bytes *= 100; 76 for (i = 0; bytes >= 100*1000 && unit[i] != 'T'; i++) 77 bytes = (bytes + 512) / 1024; 78 if (i == 0) { 79 i++; 80 bytes = (bytes + 512) / 1024; 81 } 82 snprintf(buf, size, "%3lld.%1lld%c%s", |
83 (int64_t) bytes / 100, | 83 (int64_t) (bytes + 5) / 100, |
84 (int64_t) (bytes + 5) / 10 % 10, 85 unit[i], 86 i ? "B" : " "); 87} 88 89static void 90format_size(char *buf, int size, off_t bytes) 91{ --- 10 unchanged lines hidden (view full) --- 102void 103refresh_progress_meter(void) 104{ 105 char buf[MAX_WINSIZE + 1]; 106 time_t now; 107 off_t transferred; 108 double elapsed; 109 int percent; | 84 (int64_t) (bytes + 5) / 10 % 10, 85 unit[i], 86 i ? "B" : " "); 87} 88 89static void 90format_size(char *buf, int size, off_t bytes) 91{ --- 10 unchanged lines hidden (view full) --- 102void 103refresh_progress_meter(void) 104{ 105 char buf[MAX_WINSIZE + 1]; 106 time_t now; 107 off_t transferred; 108 double elapsed; 109 int percent; |
110 int bytes_left; | 110 off_t bytes_left; |
111 int cur_speed; 112 int hours, minutes, seconds; 113 int i, len; 114 int file_len; 115 116 transferred = *counter - cur_pos; 117 cur_pos = *counter; 118 now = time(NULL); 119 bytes_left = end_pos - cur_pos; 120 121 if (bytes_left > 0) 122 elapsed = now - last_update; | 111 int cur_speed; 112 int hours, minutes, seconds; 113 int i, len; 114 int file_len; 115 116 transferred = *counter - cur_pos; 117 cur_pos = *counter; 118 now = time(NULL); 119 bytes_left = end_pos - cur_pos; 120 121 if (bytes_left > 0) 122 elapsed = now - last_update; |
123 else | 123 else { |
124 elapsed = now - start; | 124 elapsed = now - start; |
125 /* Calculate true total speed when done */ 126 transferred = end_pos; 127 bytes_per_second = 0; 128 } |
|
125 126 /* calculate speed */ 127 if (elapsed != 0) 128 cur_speed = (transferred / elapsed); 129 else | 129 130 /* calculate speed */ 131 if (elapsed != 0) 132 cur_speed = (transferred / elapsed); 133 else |
130 cur_speed = 0; | 134 cur_speed = transferred; |
131 132#define AGE_FACTOR 0.9 133 if (bytes_per_second != 0) { 134 bytes_per_second = (bytes_per_second * AGE_FACTOR) + 135 (cur_speed * (1.0 - AGE_FACTOR)); 136 } else 137 bytes_per_second = cur_speed; 138 --- 127 unchanged lines hidden --- | 135 136#define AGE_FACTOR 0.9 137 if (bytes_per_second != 0) { 138 bytes_per_second = (bytes_per_second * AGE_FACTOR) + 139 (cur_speed * (1.0 - AGE_FACTOR)); 140 } else 141 bytes_per_second = cur_speed; 142 --- 127 unchanged lines hidden --- |