summaryrefslogtreecommitdiff
path: root/apps/plugins/otp.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2017-09-18 06:00:05 -0400
committerMichael Sevakis <jethead71@rockbox.org>2017-11-21 05:01:14 -0500
commitaced667f48c29a160aa4e5c0a8df037092b28189 (patch)
tree66e48e4a27daaf36f01d7ff1ed6876a7de38b0c0 /apps/plugins/otp.c
parent5c9688961ef9166cec5225db50d5f73691d8292d (diff)
downloadrockbox-aced667f48c29a160aa4e5c0a8df037092b28189.tar.gz
rockbox-aced667f48c29a160aa4e5c0a8df037092b28189.zip
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
Diffstat (limited to 'apps/plugins/otp.c')
-rw-r--r--apps/plugins/otp.c22
1 files changed, 10 insertions, 12 deletions
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)
516 516
517static void show_code(int acct) 517static void show_code(int acct)
518{ 518{
519 /* rockbox's printf doesn't support a variable field width afaik */
520 char format_buf[64];
521 if(!accounts[acct].is_totp) 519 if(!accounts[acct].is_totp)
522 { 520 {
523 rb->snprintf(format_buf, sizeof(format_buf), "%%0%dd", accounts[acct].digits); 521 rb->splashf(0, "%0*d", accounts[acct].digits,
524 rb->splashf(0, format_buf, HOTP(accounts[acct].secret, 522 HOTP(accounts[acct].secret,
525 accounts[acct].sec_len, 523 accounts[acct].sec_len,
526 accounts[acct].hotp_counter, 524 accounts[acct].hotp_counter,
527 accounts[acct].digits)); 525 accounts[acct].digits));
528 ++accounts[acct].hotp_counter; 526 ++accounts[acct].hotp_counter;
529 } 527 }
530#if CONFIG_RTC 528#if CONFIG_RTC
531 else 529 else
532 { 530 {
533 rb->snprintf(format_buf, sizeof(format_buf), "%%0%dd (%%ld second(s) left)", accounts[acct].digits); 531 rb->splashf(0, "%0*d (%ld seconds(s) left)", accounts[acct].digits,
534 rb->splashf(0, format_buf, TOTP(accounts[acct].secret, 532 TOTP(accounts[acct].secret,
535 accounts[acct].sec_len, 533 accounts[acct].sec_len,
536 accounts[acct].totp_period, 534 accounts[acct].totp_period,
537 accounts[acct].digits), 535 accounts[acct].digits),
538 accounts[acct].totp_period - get_utc() % accounts[acct].totp_period); 536 accounts[acct].totp_period - get_utc() % accounts[acct].totp_period);
539 } 537 }
540#else 538#else