diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-10-11 21:07:18 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-10-11 21:17:24 +0300 |
commit | 1df197e6035ea9826bfedee7d48812e318ba9c7a (patch) | |
tree | 76b8e9de41820755adf209854d06a84a8b5a1988 /contrib/libs/curl/src/tool_cb_prg.c | |
parent | f9c007ea1b59b960201def74990810b26ecdfd48 (diff) | |
download | ydb-1df197e6035ea9826bfedee7d48812e318ba9c7a.tar.gz |
Revert "Update contrib/libs/curl to 8.10.1" to fix
Revert "Update contrib/libs/curl to 8.10.1"
This reverts commit 428ef806a15515cdaa325530aa8cc6903fac5fb6, reversing
changes made to 40e46e6394df409d1545a3771c8a47a86ed55eac.
Revert "Fix formatting after rXXXXXX"
This reverts commit a73689311a92e195d14136c5a0049ef1e40b1f3e, reversing
changes made to 17980b8756d1f74d3dacddc7ca4945c30f35611c.
commit_hash:5c5194831e5455b61fbee61619066396626beab1
Diffstat (limited to 'contrib/libs/curl/src/tool_cb_prg.c')
-rw-r--r-- | contrib/libs/curl/src/tool_cb_prg.c | 109 |
1 files changed, 72 insertions, 37 deletions
diff --git a/contrib/libs/curl/src/tool_cb_prg.c b/contrib/libs/curl/src/tool_cb_prg.c index 5acd3fcc78..ef47b42da0 100644 --- a/contrib/libs/curl/src/tool_cb_prg.c +++ b/contrib/libs/curl/src/tool_cb_prg.c @@ -23,18 +23,28 @@ ***************************************************************************/ #include "tool_setup.h" +#ifdef HAVE_SYS_IOCTL_H +#include <sys/ioctl.h> +#endif + +#define ENABLE_CURLX_PRINTF +/* use our own printf() functions */ #include "curlx.h" #include "tool_cfgable.h" #include "tool_cb_prg.h" #include "tool_util.h" #include "tool_operate.h" -#include "terminal.h" #include "memdebug.h" /* keep this as LAST include */ -#define MAX_BARLENGTH 400 -#define MIN_BARLENGTH 20 +#define MAX_BARLENGTH 256 + +#ifdef HAVE_TERMIOS_H +# include <termios.h> +#elif defined(HAVE_TERMIO_H) +# include <termio.h> +#endif /* 200 values generated by this perl code: @@ -43,7 +53,7 @@ printf "%d, ", sin($i/200 * 2 * $pi) * 500000 + 500000; } */ -static const int sinus[] = { +static const unsigned int sinus[] = { 515704, 531394, 547052, 562664, 578214, 593687, 609068, 624341, 639491, 654504, 669364, 684057, 698568, 712883, 726989, 740870, 754513, 767906, 781034, 793885, 806445, 818704, 830647, 842265, 853545, 864476, 875047, @@ -76,19 +86,19 @@ static void fly(struct ProgressData *bar, bool moved) /* bar->width is range checked when assigned */ DEBUGASSERT(bar->width <= MAX_BARLENGTH); - buf[0] = '\r'; - memset(&buf[1], ' ', bar->width); + memset(buf, ' ', bar->width); + buf[bar->width] = '\r'; buf[bar->width + 1] = '\0'; - memcpy(&buf[bar->bar + 1], "-=O=-", 5); + memcpy(&buf[bar->bar], "-=O=-", 5); - pos = sinus[bar->tick%200] / (1000000 / check) + 1; + pos = sinus[bar->tick%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 5)%200] / (1000000 / check) + 1; + pos = sinus[(bar->tick + 5)%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 10)%200] / (1000000 / check) + 1; + pos = sinus[(bar->tick + 10)%200] / (1000000 / check); buf[pos] = '#'; - pos = sinus[(bar->tick + 15)%200] / (1000000 / check) + 1; + pos = sinus[(bar->tick + 15)%200] / (1000000 / check); buf[pos] = '#'; fputs(buf, bar->out); @@ -118,17 +128,6 @@ static void fly(struct ProgressData *bar, bool moved) # define CURL_OFF_T_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF) #endif -static void update_width(struct ProgressData *bar) -{ - int cols = get_terminal_columns(); - if(cols > MAX_BARLENGTH) - bar->width = MAX_BARLENGTH; - else if(cols > MIN_BARLENGTH) - bar->width = (int)cols; - else - bar->width = MIN_BARLENGTH; -} - int tool_progress_cb(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow) @@ -171,10 +170,10 @@ int tool_progress_cb(void *clientp, if(total) { /* we know the total data to get... */ if(bar->prev == point) - /* progress did not change since last invoke */ + /* progress didn't change since last invoke */ return 0; else if((tvdiff(now, bar->prevtime) < 100L) && point < total) - /* limit progress-bar updating to 10 Hz except when we are at 100% */ + /* limit progress-bar updating to 10 Hz except when we're at 100% */ return 0; } else { @@ -182,7 +181,6 @@ int tool_progress_cb(void *clientp, if(tvdiff(now, bar->prevtime) < 100L) /* limit progress-bar updating to 10 Hz */ return 0; - update_width(bar); fly(bar, point != bar->prev); } } @@ -190,14 +188,13 @@ int tool_progress_cb(void *clientp, /* simply count invokes */ bar->calls++; - update_width(bar); if((total > 0) && (point != bar->prev)) { char line[MAX_BARLENGTH + 1]; char format[40]; double frac; double percent; int barwidth; - size_t num; + int num; if(point > total) /* we have got more than the expected total! */ total = point; @@ -205,20 +202,13 @@ int tool_progress_cb(void *clientp, frac = (double)point / (double)total; percent = frac * 100.0; barwidth = bar->width - 7; - num = (size_t) (((double)barwidth) * frac); + num = (int) (((double)barwidth) * frac); if(num > MAX_BARLENGTH) num = MAX_BARLENGTH; memset(line, '#', num); line[num] = '\0'; msnprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth); -#ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wformat-nonliteral" -#endif fprintf(bar->out, format, line, percent); -#ifdef __clang__ -#pragma clang diagnostic pop -#endif } fflush(bar->out); bar->prev = point; @@ -235,14 +225,59 @@ int tool_progress_cb(void *clientp, void progressbarinit(struct ProgressData *bar, struct OperationConfig *config) { + char *colp; memset(bar, 0, sizeof(struct ProgressData)); /* pass the resume from value through to the progress function so it can - * display progress towards total file not just the part that is left. */ + * display progress towards total file not just the part that's left. */ if(config->use_resume) bar->initial_size = config->resume_from; - update_width(bar); + colp = curlx_getenv("COLUMNS"); + if(colp) { + char *endptr; + long num = strtol(colp, &endptr, 10); + if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 20) && + (num < 10000)) + bar->width = (int)num; + curl_free(colp); + } + + if(!bar->width) { + int cols = 0; + +#ifdef TIOCGSIZE + struct ttysize ts; + if(!ioctl(STDIN_FILENO, TIOCGSIZE, &ts)) + cols = ts.ts_cols; +#elif defined(TIOCGWINSZ) + struct winsize ts; + if(!ioctl(STDIN_FILENO, TIOCGWINSZ, &ts)) + cols = ts.ws_col; +#elif defined(_WIN32) + { + HANDLE stderr_hnd = GetStdHandle(STD_ERROR_HANDLE); + CONSOLE_SCREEN_BUFFER_INFO console_info; + + if((stderr_hnd != INVALID_HANDLE_VALUE) && + GetConsoleScreenBufferInfo(stderr_hnd, &console_info)) { + /* + * Do not use +1 to get the true screen-width since writing a + * character at the right edge will cause a line wrap. + */ + cols = (int) + (console_info.srWindow.Right - console_info.srWindow.Left); + } + } +#endif /* TIOCGSIZE */ + if(cols > 20) + bar->width = cols; + } + + if(!bar->width) + bar->width = 79; + else if(bar->width > MAX_BARLENGTH) + bar->width = MAX_BARLENGTH; bar->out = tool_stderr; bar->tick = 150; |