mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 19:29:02 +00:00
progress meter: move file name to bb_progress_t. +20 bytes
We were doing expensive unicode conversion on every update Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e52e67cb51
commit
d55e139649
@ -1587,15 +1587,21 @@ typedef struct bb_progress_t {
|
|||||||
off_t lastsize;
|
off_t lastsize;
|
||||||
unsigned lastupdate_sec;
|
unsigned lastupdate_sec;
|
||||||
unsigned start_sec;
|
unsigned start_sec;
|
||||||
smallint inited;
|
const char *curfile;
|
||||||
} bb_progress_t;
|
} bb_progress_t;
|
||||||
|
|
||||||
void bb_progress_init(bb_progress_t *p) FAST_FUNC;
|
#define is_bb_progress_inited(p) ((p)->curfile != NULL)
|
||||||
void bb_progress_update(bb_progress_t *p, const char *curfile,
|
#define bb_progress_free(p) do { \
|
||||||
|
if (ENABLE_UNICODE_SUPPORT) free((char*)((p)->curfile)); \
|
||||||
|
(p)->curfile = NULL; \
|
||||||
|
} while (0)
|
||||||
|
void bb_progress_init(bb_progress_t *p, const char *curfile) FAST_FUNC;
|
||||||
|
void bb_progress_update(bb_progress_t *p,
|
||||||
uoff_t beg_range,
|
uoff_t beg_range,
|
||||||
uoff_t transferred,
|
uoff_t transferred,
|
||||||
uoff_t totalsize) FAST_FUNC;
|
uoff_t totalsize) FAST_FUNC;
|
||||||
|
|
||||||
|
|
||||||
extern const char *applet_name;
|
extern const char *applet_name;
|
||||||
|
|
||||||
/* Some older linkers don't perform string merging, we used to have common strings
|
/* Some older linkers don't perform string merging, we used to have common strings
|
||||||
|
@ -52,12 +52,17 @@ static unsigned int get_tty2_width(void)
|
|||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FAST_FUNC bb_progress_init(bb_progress_t *p)
|
void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
|
||||||
{
|
{
|
||||||
|
#if ENABLE_UNICODE_SUPPORT
|
||||||
|
init_unicode();
|
||||||
|
p->curfile = unicode_conv_to_printable_fixedwidth(/*NULL,*/ curfile, 20);
|
||||||
|
#else
|
||||||
|
p->curfile = curfile;
|
||||||
|
#endif
|
||||||
p->start_sec = monotonic_sec();
|
p->start_sec = monotonic_sec();
|
||||||
p->lastupdate_sec = p->start_sec;
|
p->lastupdate_sec = p->start_sec;
|
||||||
p->lastsize = 0;
|
p->lastsize = 0;
|
||||||
p->inited = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* File already had beg_size bytes.
|
/* File already had beg_size bytes.
|
||||||
@ -68,7 +73,6 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p)
|
|||||||
* If totalsize == 0, then it is unknown.
|
* If totalsize == 0, then it is unknown.
|
||||||
*/
|
*/
|
||||||
void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
||||||
const char *curfile,
|
|
||||||
uoff_t beg_size,
|
uoff_t beg_size,
|
||||||
uoff_t transferred,
|
uoff_t transferred,
|
||||||
uoff_t totalsize)
|
uoff_t totalsize)
|
||||||
@ -130,16 +134,10 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
|||||||
beg_and_transferred = beg_size + transferred;
|
beg_and_transferred = beg_size + transferred;
|
||||||
|
|
||||||
ratio = 100 * beg_and_transferred / totalsize;
|
ratio = 100 * beg_and_transferred / totalsize;
|
||||||
#if ENABLE_UNICODE_SUPPORT
|
if (ENABLE_UNICODE_SUPPORT)
|
||||||
init_unicode();
|
fprintf(stderr, "\r%s%4u%% ", p->curfile, ratio);
|
||||||
{
|
else
|
||||||
char *buf = unicode_conv_to_printable_fixedwidth(/*NULL,*/ curfile, 20);
|
fprintf(stderr, "\r%-20.20s%4u%% ", p->curfile, ratio);
|
||||||
fprintf(stderr, "\r%s%4u%% ", buf, ratio);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "\r%-20.20s%4u%% ", curfile, ratio);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
barlength = get_tty2_width() - 49;
|
barlength = get_tty2_width() - 49;
|
||||||
if (barlength > 0) {
|
if (barlength > 0) {
|
||||||
|
@ -107,19 +107,19 @@ struct BUG_G_too_big {
|
|||||||
#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
|
#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
|
||||||
static void tftp_progress_update(void)
|
static void tftp_progress_update(void)
|
||||||
{
|
{
|
||||||
bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size);
|
bb_progress_update(&G.pmt, 0, G.pos, G.size);
|
||||||
}
|
}
|
||||||
static void tftp_progress_init(void)
|
static void tftp_progress_init(void)
|
||||||
{
|
{
|
||||||
bb_progress_init(&G.pmt);
|
bb_progress_init(&G.pmt, G.file);
|
||||||
tftp_progress_update();
|
tftp_progress_update();
|
||||||
}
|
}
|
||||||
static void tftp_progress_done(void)
|
static void tftp_progress_done(void)
|
||||||
{
|
{
|
||||||
if (G.pmt.inited) {
|
if (is_bb_progress_inited(&G.pmt)) {
|
||||||
tftp_progress_update();
|
tftp_progress_update();
|
||||||
bb_putchar_stderr('\n');
|
bb_putchar_stderr('\n');
|
||||||
G.pmt.inited = 0;
|
bb_progress_free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -445,7 +445,7 @@ static int tftp_protocol(
|
|||||||
#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
|
#if ENABLE_FEATURE_TFTP_PROGRESS_BAR
|
||||||
if (ENABLE_TFTP && remote_file) /* tftp */
|
if (ENABLE_TFTP && remote_file) /* tftp */
|
||||||
G.pos = (block_nr - 1) * (uoff_t)blksize;
|
G.pos = (block_nr - 1) * (uoff_t)blksize;
|
||||||
if (G.pmt.inited)
|
if (is_bb_progress_inited(&G.pmt))
|
||||||
tftp_progress_update();
|
tftp_progress_update();
|
||||||
#endif
|
#endif
|
||||||
/* Was it final ACK? then exit */
|
/* Was it final ACK? then exit */
|
||||||
|
@ -81,9 +81,9 @@ static void progress_meter(int flag)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (flag == PROGRESS_START)
|
if (flag == PROGRESS_START)
|
||||||
bb_progress_init(&G.pmt);
|
bb_progress_init(&G.pmt, G.curfile);
|
||||||
|
|
||||||
bb_progress_update(&G.pmt, G.curfile, G.beg_range, G.transferred,
|
bb_progress_update(&G.pmt, G.beg_range, G.transferred,
|
||||||
G.chunked ? 0 : G.beg_range + G.transferred + G.content_len);
|
G.chunked ? 0 : G.beg_range + G.transferred + G.content_len);
|
||||||
|
|
||||||
if (flag == PROGRESS_END) {
|
if (flag == PROGRESS_END) {
|
||||||
|
Loading…
Reference in New Issue
Block a user