[Pdbg] [PATCH] progress: No more progress

Joel Stanley joel at jms.id.au
Tue Aug 14 14:08:06 AEST 2018


This adds an option to suppress progress:

 -S, --shutup
         Shut up those annoying progress bars

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 src/main.c     | 10 +++++++++-
 src/progress.c | 16 ++++++++++++++++
 src/progress.h |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index b446b5b6ff9b..73b307183105 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@
 #include "htm.h"
 #include "options.h"
 #include "optcmd.h"
+#include "progress.h"
 
 #define PR_ERROR(x, args...) \
 	pdbg_log(PDBG_ERROR, x, ##args)
@@ -162,6 +163,8 @@ static void print_usage(char *pname)
 	printf("\t\tand defaults to 0x50 for I2C\n");
 	printf("\t-D, --debug=<debug level>\n");
 	printf("\t\t0:error (default) 1:warning 2:notice 3:info 4:debug\n");
+	printf("\t-S, --shutup\n");
+	printf("\t\tShut up those annoying progress bars\n");
 	printf("\t-V, --version\n");
 	printf("\t-h, --help\n");
 	printf("\n");
@@ -328,6 +331,7 @@ static bool parse_options(int argc, char *argv[])
 		{"cpu",			required_argument,	NULL,	'l'},
 #endif
 		{"debug",		required_argument,	NULL,	'D'},
+		{"shutup",		no_argument,		NULL,	'S'},
 		{"version",		no_argument,		NULL,	'V'},
 		{NULL,			0,			NULL,     0}
 	};
@@ -339,7 +343,7 @@ static bool parse_options(int argc, char *argv[])
 	memset(l_list, 0, sizeof(l_list));
 
 	do {
-		c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:V" PPC_OPTS,
+		c = getopt_long(argc, argv, "+ab:c:d:hp:s:t:D:SV" PPC_OPTS,
 				long_opts, NULL);
 		if (c == -1)
 			break;
@@ -425,6 +429,10 @@ static bool parse_options(int argc, char *argv[])
 				fprintf(stderr, "Invalid slave address '%s'\n", optarg);
 			break;
 
+		case 'S':
+			progress_shutup();
+			break;
+
 		case 'D':
 			pdbg_set_loglevel(atoi(optarg));
 			break;
diff --git a/src/progress.c b/src/progress.c
index 648596db7565..4baee12a3a59 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <time.h>
 #include <assert.h>
+#include <stdbool.h>
 
 #include "progress.h"
 
@@ -27,6 +28,7 @@ static uint64_t progress_pcent;
 static uint64_t progress_n_upd;
 static time_t progress_prevsec;
 static struct timespec progress_start;
+static bool shutup;
 
 #define PROGRESS_CHARS	50
 
@@ -36,6 +38,9 @@ static void progress_bar(unsigned int percent)
 
 	assert(percent <= 100);
 
+	if (shutup)
+		return;
+
 	progress = (percent * PROGRESS_CHARS) / 101;
 
 	fprintf(stderr, "\r[");
@@ -47,6 +52,11 @@ static void progress_bar(unsigned int percent)
 	fflush(stderr);
 }
 
+void progress_shutup(void)
+{
+	shutup = true;
+}
+
 void progress_init(void)
 {
 	progress_pcent = 0;
@@ -64,6 +74,9 @@ void progress_tick(uint64_t cur, uint64_t end)
 	unsigned int pcent;
 	double sec;
 
+	if (shutup)
+		return;
+
 	pcent = (unsigned int)((cur * 100) / end);
 	if (progress_pcent == pcent && cur < progress_n_upd &&
 	    cur < end)
@@ -100,5 +113,8 @@ void progress_tick(uint64_t cur, uint64_t end)
 
 void progress_end(void)
 {
+	if (shutup)
+		return;
+
 	fprintf(stderr, "\n");
 }
diff --git a/src/progress.h b/src/progress.h
index 48c93b2c8789..a3714c8de17e 100644
--- a/src/progress.h
+++ b/src/progress.h
@@ -20,5 +20,6 @@
 void progress_init(void);
 void progress_tick(uint64_t cur, uint64_t end);
 void progress_end(void);
+void progress_shutup(void);
 
 #endif /* __PROGRESS_H */
-- 
2.17.1



More information about the Pdbg mailing list