summaryrefslogtreecommitdiff
path: root/src/progressbar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/progressbar.c')
-rw-r--r--src/progressbar.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/progressbar.c b/src/progressbar.c
new file mode 100644
index 0000000..f8a4121
--- /dev/null
+++ b/src/progressbar.c
@@ -0,0 +1,91 @@
+#include "progressbar.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+
+int create_progressbar( cssh_progressbar_t *progressbar, uint64_t min_value, uint64_t max_value, size_t size, const char *label_fmt, ... )
+{
+ progressbar->min_value = min_value;
+ progressbar->max_value = max_value;
+
+ va_list va;
+ va_start( va, label_fmt );
+
+ progressbar->label = (char *)malloc( size );
+ if( progressbar->label == NULL ) {
+ return -1;
+ }
+
+ (void)vsnprintf( progressbar->label, size, label_fmt, va );
+
+ va_end( va );
+
+ return 0;
+}
+
+void free_progressbar( cssh_progressbar_t *progressbar )
+{
+ free( progressbar->label );
+}
+
+void set_value_of_progressbar( cssh_progressbar_t *progressbar, uint64_t value )
+{
+ fprintf( stderr, "%s %"PRIu64"\n", progressbar->label, value );
+}
+
+int create_progressbar_pool( cssh_progressbar_pool_t *pool, size_t initial_size )
+{
+ pool->N = 0;
+ pool->capacity = initial_size;
+ pool->progressbar = (cssh_progressbar_t **)malloc( pool->capacity * sizeof( cssh_progressbar_t * ) );
+ if( pool->progressbar == NULL ) {
+ return -1;
+ }
+
+ return 0;
+}
+
+void free_progressbar_pool( cssh_progressbar_pool_t *pool )
+{
+ for( size_t i = 0; i < pool->N; i++ ) {
+ free_progressbar( pool->progressbar[i] );
+ }
+
+ free( pool->progressbar );
+}
+
+int append_progressbar_to_pool( cssh_progressbar_pool_t *pool, cssh_progressbar_t *progressbar )
+{
+ if( pool->N + 1 > pool->capacity ) {
+ return -1;
+ }
+
+ pool->progressbar[pool->N] = progressbar;
+ pool->N++;
+
+ return 0;
+}
+
+int remvove_progressbar_from_pool( cssh_progressbar_pool_t *pool, cssh_progressbar_t *progressbar )
+{
+ if( pool->N == 0 ) {
+ return -1;
+ }
+
+ for( size_t i = 0; i < pool->N; i++ ) {
+ if( pool->progressbar[i] ) {
+ if( i < pool->N - 1 ) {
+ memmove( &pool->progressbar[i], &pool->progressbar[i+1],
+ ( pool->N - i ) * sizeof( cssh_progressbar_t * ) );
+ }
+ pool->N--;
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+