diff options
Diffstat (limited to 'scp.c')
-rw-r--r-- | scp.c | 65 |
1 files changed, 35 insertions, 30 deletions
@@ -75,7 +75,7 @@ | |||
75 | */ | 75 | */ |
76 | 76 | ||
77 | #include "includes.h" | 77 | #include "includes.h" |
78 | RCSID("$OpenBSD: scp.c,v 1.95 2002/12/05 11:08:35 markus Exp $"); | 78 | RCSID("$OpenBSD: scp.c,v 1.96 2002/12/13 15:20:52 markus Exp $"); |
79 | 79 | ||
80 | #include "xmalloc.h" | 80 | #include "xmalloc.h" |
81 | #include "atomicio.h" | 81 | #include "atomicio.h" |
@@ -1119,13 +1119,19 @@ foregroundproc(void) | |||
1119 | void | 1119 | void |
1120 | progressmeter(int flag) | 1120 | progressmeter(int flag) |
1121 | { | 1121 | { |
1122 | static const char spaces[] = " " | ||
1123 | " " | ||
1124 | " " | ||
1125 | " " | ||
1126 | " " | ||
1127 | " "; | ||
1122 | static const char prefixes[] = " KMGTP"; | 1128 | static const char prefixes[] = " KMGTP"; |
1123 | static struct timeval lastupdate; | 1129 | static struct timeval lastupdate; |
1124 | static off_t lastsize; | 1130 | static off_t lastsize; |
1125 | struct timeval now, td, wait; | 1131 | struct timeval now, td, wait; |
1126 | off_t cursize, abbrevsize; | 1132 | off_t cursize, abbrevsize, bytespersec; |
1127 | double elapsed; | 1133 | double elapsed; |
1128 | int ratio, barlength, i, remaining; | 1134 | int ratio, remaining, i, ai, bi, nspaces; |
1129 | char buf[512]; | 1135 | char buf[512]; |
1130 | 1136 | ||
1131 | if (flag == -1) { | 1137 | if (flag == -1) { |
@@ -1145,45 +1151,44 @@ progressmeter(int flag) | |||
1145 | } else | 1151 | } else |
1146 | ratio = 100; | 1152 | ratio = 100; |
1147 | 1153 | ||
1148 | snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio); | ||
1149 | |||
1150 | barlength = getttywidth() - 51; | ||
1151 | if (barlength > 0) { | ||
1152 | i = barlength * ratio / 100; | ||
1153 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | ||
1154 | "|%.*s%*s|", i, | ||
1155 | "*******************************************************" | ||
1156 | "*******************************************************" | ||
1157 | "*******************************************************" | ||
1158 | "*******************************************************" | ||
1159 | "*******************************************************" | ||
1160 | "*******************************************************" | ||
1161 | "*******************************************************", | ||
1162 | barlength - i, ""); | ||
1163 | } | ||
1164 | i = 0; | ||
1165 | abbrevsize = cursize; | 1154 | abbrevsize = cursize; |
1166 | while (abbrevsize >= 100000 && i < sizeof(prefixes)) { | 1155 | for (ai = 0; abbrevsize >= 10000 && ai < sizeof(prefixes); ai++) |
1167 | i++; | ||
1168 | abbrevsize >>= 10; | 1156 | abbrevsize >>= 10; |
1169 | } | ||
1170 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5lu %c%c ", | ||
1171 | (unsigned long) abbrevsize, prefixes[i], | ||
1172 | prefixes[i] == ' ' ? ' ' : 'B'); | ||
1173 | 1157 | ||
1174 | timersub(&now, &lastupdate, &wait); | 1158 | timersub(&now, &lastupdate, &wait); |
1175 | if (cursize > lastsize) { | 1159 | if (cursize > lastsize) { |
1176 | lastupdate = now; | 1160 | lastupdate = now; |
1177 | lastsize = cursize; | 1161 | lastsize = cursize; |
1178 | if (wait.tv_sec >= STALLTIME) { | ||
1179 | start.tv_sec += wait.tv_sec; | ||
1180 | start.tv_usec += wait.tv_usec; | ||
1181 | } | ||
1182 | wait.tv_sec = 0; | 1162 | wait.tv_sec = 0; |
1183 | } | 1163 | } |
1184 | timersub(&now, &start, &td); | 1164 | timersub(&now, &start, &td); |
1185 | elapsed = td.tv_sec + (td.tv_usec / 1000000.0); | 1165 | elapsed = td.tv_sec + (td.tv_usec / 1000000.0); |
1186 | 1166 | ||
1167 | bytespersec = 0; | ||
1168 | if (statbytes > 0) { | ||
1169 | bytespersec = statbytes; | ||
1170 | if (elapsed > 0.0) | ||
1171 | bytespersec /= elapsed; | ||
1172 | } | ||
1173 | for (bi = 1; bytespersec >= 1024000 && bi < sizeof(prefixes); bi++) | ||
1174 | bytespersec >>= 10; | ||
1175 | |||
1176 | nspaces = MIN(getttywidth() - 79, sizeof(spaces) - 1); | ||
1177 | |||
1178 | snprintf(buf, sizeof(buf), | ||
1179 | "\r%-45.45s%.*s%3d%% %4lld%c%c %3lld.%01d%cB/s", | ||
1180 | curfile, | ||
1181 | nspaces, | ||
1182 | spaces, | ||
1183 | ratio, | ||
1184 | (long long)abbrevsize, | ||
1185 | prefixes[ai], | ||
1186 | ai == 0 ? ' ' : 'B', | ||
1187 | (long long)(bytespersec / 1024), | ||
1188 | (int)((bytespersec % 1024) * 10 / 1024), | ||
1189 | prefixes[bi] | ||
1190 | ); | ||
1191 | |||
1187 | if (flag != 1 && | 1192 | if (flag != 1 && |
1188 | (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) { | 1193 | (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes)) { |
1189 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), | 1194 | snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), |