Extensive cleanups and simplifications in dcc_glist()

The only user-visible change here is that the bar displayed for DCC_BAR_TYPE 1 is now shown
as empty for a zero-length file rather than full, matching the 0.0% complete that is shown
and the bar displayed in the DCC_BAR_TYPE 0 case.
This commit is contained in:
Kevin Easton
2016-10-26 23:44:48 +11:00
parent d8a53ab045
commit ed12420755
2 changed files with 69 additions and 66 deletions

View File

@@ -1,5 +1,8 @@
[Changes 1.2.2] [Changes 1.2.2]
* Set completion bar for /SET DCC_BAR_TYPE 1 to empty rather than full for
zero filesize files. (caf)
* Correctly align formatting of /DCC LIST line for /SET DCC_BAR_TYPE 1. (caf) * Correctly align formatting of /DCC LIST line for /SET DCC_BAR_TYPE 1. (caf)
* Act on channel mode lock as half-op. (caf) * Act on channel mode lock as half-op. (caf)

View File

@@ -2465,37 +2465,39 @@ int blocksize = get_int_var(DCC_BLOCK_SIZE_VAR);
doing_multi = 0; doing_multi = 0;
} }
static char *get_bar_percent(int percent) static const char *get_bar_percent(int percent)
{ {
#ifdef ONLY_STD_CHARS #ifdef ONLY_STD_CHARS
static char *_dcc_offer[12] = {"%K-.........%n", /* 0 */ static const char * const _dcc_offer[] = {
"%K-.........%n", /* 10 */ "%K-.........%n", /* 0 */
"%K-=........%n", /* 20 */ "%K-.........%n", /* 10 */
"%K-=*.......%n", /* 30 */ "%K-=........%n", /* 20 */
"%K-=*%1%K=%0%K......%n", /* 40 */ "%K-=*.......%n", /* 30 */
"%K-=*%1%K=-%0%K.....%n", /* 50 */ "%K-=*%1%K=%0%K......%n", /* 40 */
"%K-=*%1%K=-.%0%K....%n", /* 60 */ "%K-=*%1%K=-%0%K.....%n", /* 50 */
"%K-=*%1%K=-. %0%K...%n", /* 70 */ "%K-=*%1%K=-.%0%K....%n", /* 60 */
"%K-=*%1%K=-. %R.%0%K..%n", /* 80 */ "%K-=*%1%K=-. %0%K...%n", /* 70 */
"%K-=*%1%K=-. %R.-%0%K.%n", /* 90 */ "%K-=*%1%K=-. %R.%0%K..%n", /* 80 */
"%K-=*%1%K=-. %R.-=%n", /* 100 */ "%K-=*%1%K=-. %R.-%0%K.%n", /* 90 */
empty_string}; "%K-=*%1%K=-. %R.-=%n"}; /* 100 */
#else #else
static char *_dcc_offer[12] = {"%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 0 */ static const char * const _dcc_offer[] = {
"%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 10 */ "%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 0 */
"%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 20 */ "%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 10 */
"%K<><4B>۰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 30 */ "%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 20 */
"%K<><4B><EFBFBD>%1%K<>%0%K<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 40 */ "%K<><4B>۰<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 30 */
"%K<><4B><EFBFBD>%1%K<><EFBFBD>%0%K<><4B><EFBFBD><EFBFBD><EFBFBD>%n", /* 50 */ "%K<><4B><EFBFBD>%1%K<>%0%K<><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%n", /* 40 */
"%K<><4B><EFBFBD>%1%K<><4B><EFBFBD>%0%K<><4B><EFBFBD><EFBFBD>%n", /* 60 */ "%K<><4B><EFBFBD>%1%K<><4B>%0%K<><4B><EFBFBD><EFBFBD><EFBFBD>%n", /* 50 */
"%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%0%K<><4B><EFBFBD>%n", /* 70 */ "%K<><4B><EFBFBD>%1%K<><4B><EFBFBD>%0%K<><4B><EFBFBD><EFBFBD>%n", /* 60 */
"%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<EFBFBD>%0%K<><4B>%n", /* 80 */ "%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%0%K<><4B><EFBFBD>%n", /* 70 */
"%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<><EFBFBD>%0%K<>%n", /* 90 */ "%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<>%0%K<><EFBFBD>%n", /* 80 */
"%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<><52><EFBFBD>%n", /* 100 */ "%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<><52>%0%K<EFBFBD>%n", /* 90 */
empty_string}; "%K<><4B><EFBFBD>%1%K<><4B><EFBFBD><EFBFBD>%R<><52><EFBFBD>%n"}; /* 100 */
#endif #endif
if (percent <= 100) const int idx = percent / 10;
return _dcc_offer[percent];
if (idx >= 0 && idx < (sizeof _dcc_offer / sizeof _dcc_offer[0]))
return _dcc_offer[idx];
return empty_string; return empty_string;
} }
@@ -2504,8 +2506,8 @@ void dcc_glist(char *command, char *args)
{ {
#define DCC_FORMAT_STAT_PENDING "#$[3]0 $[6]1%Y$2%n $[11]3 $[25]4 $[7]5 $6-" #define DCC_FORMAT_STAT_PENDING "#$[3]0 $[6]1%Y$2%n $[11]3 $[25]4 $[7]5 $6-"
#define DCC_FORMAT_STAT_CHAT "#$[3]0 $[6]1%Y$2%n $[11]3 $4 $[-4]5 $[-4]6 $[-3]7 $[-3]8 $[7]9 $10" #define DCC_FORMAT_STAT_CHAT "#$[3]0 $[6]1%Y$2%n $[11]3 $4 $[-4]5 $[-4]6 $[-3]7 $[-3]8 $[7]9 $10"
#define DCC_FORMAT_STAT_BARTYPE_0 "#$[3]0 $[6]1%Y$2%n $[11]3 $4 $[7]5 $[11]6 $[7]7 $8-" #define DCC_FORMAT_STAT_BARTYPE_0 "#$[3]0 $[6]1%Y$2%n $[11]3 $4 $[7]5 $[7]6 $[7]7 $8-"
#define DCC_FORMAT_STAT_BARTYPE_1 "#$[3]0 $[6]1%Y$2%n $[11]3 $[7]5 $[22]6 $[7]7 $8-" #define DCC_FORMAT_STAT_BARTYPE_1 "#$[3]0 $[6]1%Y$2%n $[11]3 $[7]5 $[18]6 $[7]7 $8-"
int i; int i;
DCC_int *n = NULL; DCC_int *n = NULL;
SocketList *s; SocketList *s;
@@ -2514,8 +2516,6 @@ void dcc_glist(char *command, char *args)
char *status; char *status;
int count = 0; int count = 0;
DCC_List *c; DCC_List *c;
char kilobytes[20];
double barsize = 0.0;
char spec[BIG_BUFFER_SIZE]; char spec[BIG_BUFFER_SIZE];
char *filename, *p; char *filename, *p;
@@ -2582,8 +2582,10 @@ void dcc_glist(char *command, char *args)
char local_type[30]; char local_type[30];
time_t xtime; time_t xtime;
int seconds = 0, minutes = 0; int seconds = 0, minutes = 0;
int iperc = 0; char percent[20];
int size = 0; char eta[20];
char kilobytes[20];
if (!check_dcc_socket(i)) if (!check_dcc_socket(i))
continue; continue;
s = get_socket(i); s = get_socket(i);
@@ -2653,43 +2655,36 @@ void dcc_glist(char *command, char *args)
continue; continue;
} }
bytes = n->bytes_read + n->bytes_sent; bytes = n->bytes_read + n->bytes_sent;
sprintf(kilobytes, "%2.4g", bytes / 1024.0 / xtime);
type = s->flags & DCC_TYPES; type = s->flags & DCC_TYPES;
tdcc = s->flags & DCC_TDCC; tdcc = s->flags & DCC_TDCC;
status = s->flags & DCC_OFFER ? "Offer":s->flags & DCC_ACTIVE ? "Active": s->flags&DCC_WAIT?"Wait":"Unknown"; status = s->flags & DCC_OFFER ? "Offer":s->flags & DCC_ACTIVE ? "Active": s->flags&DCC_WAIT?"Wait":"Unknown";
if ((bytes >= 0) && (s->flags & DCC_ACTIVE))
if (bytes && (n->filesize - n->transfer_orders.byteoffset) >= bytes)
{ {
if (bytes && (n->filesize - n->transfer_orders.byteoffset) >= bytes) perc = 100.0 * (bytes + n->transfer_orders.byteoffset) / n->filesize;
{ if (perc > 100.0)
perc = (100.0 * ((double)bytes + n->transfer_orders.byteoffset) / (double)(n->filesize)); perc = 100.0;
if ( perc > 100.0) perc = 100.0; else if (perc < 0.0)
else if (perc < 0.0) perc = 0.0; perc = 0.0;
seconds = (int) (( (n->filesize - n->transfer_orders.byteoffset - bytes) / (bytes / xtime)) + 0.5);
minutes = seconds / 60;
seconds = seconds - (minutes * 60);
if (minutes > 999) {
minutes = 999;
seconds = 59;
}
if (seconds < 0) seconds = 0;
} else
seconds = minutes = perc = 0;
iperc = ((int)perc) / 10; seconds = (int) (((n->filesize - n->transfer_orders.byteoffset - bytes) / (bytes / xtime)) + 0.5);
barsize = ((double) (n->filesize)) / (double) BAR_LENGTH; minutes = seconds / 60;
seconds = seconds % 60;
if (minutes > 999) {
minutes = 999;
seconds = 59;
}
if (seconds < 0) seconds = 0;
} else
seconds = minutes = perc = 0;
size = (int) ((double) bytes / (double)barsize); strcpy(spec, convert_output_format(get_bar_percent(perc), NULL, NULL));
snprintf(percent, sizeof percent, "%4.1f%%", perc);
snprintf(eta, sizeof eta, "%02d:%02d", minutes, seconds);
snprintf(kilobytes, sizeof kilobytes, "%2.4g", bytes / 1024.0 / xtime);
if (n->filesize == 0)
size = BAR_LENGTH;
sprintf(spec, "%s %4.1f%s %02d:%02d", get_bar_percent(iperc), perc, "%%", minutes, seconds);
strcpy(spec, convert_output_format(spec, NULL, NULL));
}
if (do_hook(DCC_STATF_LIST, "%d %s %s %s %s %s %s", if (do_hook(DCC_STATF_LIST, "%d %s %s %s %s %s %s",
n->dccnum, local_type, s->server, status, n->dccnum, local_type, s->server, status,
kilobytes, strip_path(filename), kilobytes, strip_path(filename),
@@ -2701,9 +2696,9 @@ void dcc_glist(char *command, char *args)
else else
stat_format = DCC_FORMAT_STAT_BARTYPE_1; stat_format = DCC_FORMAT_STAT_BARTYPE_1;
put_it("%s", convert_output_format(stat_format, "%d %s %s %s %s %s %s", put_it("%s", convert_output_format(stat_format, "%d %s %s %s %s %s %s %s %s",
n->dccnum, local_type, n->encrypt ? "E":"<EFBFBD>", n->dccnum, local_type, n->encrypt ? "E":"<EFBFBD>",
s->server, spec, kilobytes, s->server, spec, percent, eta, kilobytes,
strip_path(filename))); strip_path(filename)));
} }
@@ -2712,9 +2707,14 @@ void dcc_glist(char *command, char *args)
{ {
char stats[80]; char stats[80];
char *stat_ptr, *spec_ptr; char *stat_ptr, *spec_ptr;
int size = 0;
if (!get_int_var(DCC_BAR_TYPE_VAR)) if (!get_int_var(DCC_BAR_TYPE_VAR))
continue; continue;
if (n->filesize > 0)
size = (int)(BAR_LENGTH * bytes / n->filesize);
snprintf(stats, sizeof stats, "%4.1f%% (%lu of %lu bytes)", snprintf(stats, sizeof stats, "%4.1f%% (%lu of %lu bytes)",
perc, (unsigned long)bytes, (unsigned long)n->filesize); perc, (unsigned long)bytes, (unsigned long)n->filesize);
snprintf(spec, sizeof spec, BOLD_TOG_STR "[" snprintf(spec, sizeof spec, BOLD_TOG_STR "["