From aced667f48c29a160aa4e5c0a8df037092b28189 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 18 Sep 2017 06:00:05 -0400 Subject: Undo hacks to meant to get around string formatting limitations The new vuprintf makes unnecessary workarounds due to formatting limitations. I checked grep output for whatever appeared to fit but it's possible I missed some instances because they weren't so obvious. Also, this means sound settings can dynamically work with any number of decimals rather than the current assumption of one or two. Add an ipow() function to help and take advantage of dynamic field width and precision. Consolidate string formatting of sound settings. Change-Id: I46caf534859dfd1916cd440cd25e5206b192fcd8 --- apps/plugins/otp.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'apps/plugins/otp.c') diff --git a/apps/plugins/otp.c b/apps/plugins/otp.c index 69cb8b7982..6dece4ad38 100644 --- a/apps/plugins/otp.c +++ b/apps/plugins/otp.c @@ -516,25 +516,23 @@ static void add_acct(void) static void show_code(int acct) { - /* rockbox's printf doesn't support a variable field width afaik */ - char format_buf[64]; if(!accounts[acct].is_totp) { - rb->snprintf(format_buf, sizeof(format_buf), "%%0%dd", accounts[acct].digits); - rb->splashf(0, format_buf, HOTP(accounts[acct].secret, - accounts[acct].sec_len, - accounts[acct].hotp_counter, - accounts[acct].digits)); + rb->splashf(0, "%0*d", accounts[acct].digits, + HOTP(accounts[acct].secret, + accounts[acct].sec_len, + accounts[acct].hotp_counter, + accounts[acct].digits)); ++accounts[acct].hotp_counter; } #if CONFIG_RTC else { - rb->snprintf(format_buf, sizeof(format_buf), "%%0%dd (%%ld second(s) left)", accounts[acct].digits); - rb->splashf(0, format_buf, TOTP(accounts[acct].secret, - accounts[acct].sec_len, - accounts[acct].totp_period, - accounts[acct].digits), + rb->splashf(0, "%0*d (%ld seconds(s) left)", accounts[acct].digits, + TOTP(accounts[acct].secret, + accounts[acct].sec_len, + accounts[acct].totp_period, + accounts[acct].digits), accounts[acct].totp_period - get_utc() % accounts[acct].totp_period); } #else -- cgit v1.2.3