diff options
author | Aurélio A. Heckert <aurium@colivre.coop.br> | 2018-06-18 18:09:17 -0300 |
---|---|---|
committer | Aurélio A. Heckert <aurium@colivre.coop.br> | 2018-06-18 18:09:17 -0300 |
commit | 0f413e6a23beec60b206f070f0f38f0dbddd8fb4 (patch) | |
tree | 3ac704359fce97f3bec473803ca4b9cbee15cf8b /src | |
parent | Update Chinese (China) translation (diff) | |
download | zenity-0f413e6a23beec60b206f070f0f38f0dbddd8fb4.tar.gz zenity-0f413e6a23beec60b206f070f0f38f0dbddd8fb4.tar.bz2 zenity-0f413e6a23beec60b206f070f0f38f0dbddd8fb4.zip |
Makes progress to consider the decimal from percent update
Implements stof alternative to atof, to ignore locale settings.
This also helps the time remaining calculation for long tasks.
Diffstat (limited to 'src')
-rw-r--r-- | src/progress.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/progress.c b/src/progress.c index 1a5a68fd..00bb8aaa 100644 --- a/src/progress.c +++ b/src/progress.c @@ -105,6 +105,27 @@ zenity_progress_update_time_remaining (ZenityProgressData *progress_data) { } } +static float +stof(const char* s) { + float rez = 0, fact = 1; + if (*s == '-') { + s++; + fact = -1; + } + for (int point_seen = 0; *s; s++) { + if (*s == '.' || *s == ',') { + point_seen = 1; + continue; + } + int d = *s - '0'; + if (d >= 0 && d <= 9) { + if (point_seen) fact /= 10.0f; + rez = rez * 10.0f + (float)d; + } + } + return rez * fact; +} + static gboolean zenity_progress_handle_stdin ( GIOChannel *channel, GIOCondition condition, gpointer data) { @@ -190,7 +211,7 @@ zenity_progress_handle_stdin ( continue; /* Now try to convert the thing to a number */ - percentage = CLAMP (atoi (string->str), 0, 100); + percentage = CLAMP (stof (string->str), 0, 100); gtk_progress_bar_set_fraction ( GTK_PROGRESS_BAR (progress_bar), percentage / 100.0); |