summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c44
1 files changed, 11 insertions, 33 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 0c1244017d..9e7e3948c8 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -40,9 +40,6 @@
40#include "ata_mmc.h" 40#include "ata_mmc.h"
41#endif 41#endif
42 42
43#define ONE_KILOBYTE 1024
44#define ONE_MEGABYTE (1024*1024)
45
46/* Format a large-range value for output, using the appropriate unit so that 43/* Format a large-range value for output, using the appropriate unit so that
47 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary" 44 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
48 * units) if possible, and 3 significant digits are shown. If a buffer is 45 * units) if possible, and 3 significant digits are shown. If a buffer is
@@ -66,28 +63,23 @@ char *output_dyn_value(char *buf, int buf_size, int value,
66 if (bin_scale) 63 if (bin_scale)
67 fraction = fraction * 1000 / 1024; 64 fraction = fraction * 1000 / 1024;
68 65
66 if (value >= 100 || !unit_no)
67 tbuf[0] = '\0';
68 else if (value >= 10)
69 snprintf(tbuf, sizeof(tbuf), "%01d", fraction / 100);
70 else
71 snprintf(tbuf, sizeof(tbuf), "%02d", fraction / 10);
72
69 if (buf) 73 if (buf)
70 { 74 {
71 if (value >= 100 || !unit_no) 75 if (strlen(tbuf))
72 snprintf(tbuf, sizeof(tbuf), "%d", value); 76 snprintf(buf, buf_size, "%d%s%s%s", value, str(LANG_POINT),
73 else if (value >= 10) 77 tbuf, P2STR(units[unit_no]));
74 snprintf(tbuf, sizeof(tbuf), "%d%s%01d", value, str(LANG_POINT),
75 fraction / 100);
76 else 78 else
77 snprintf(tbuf, sizeof(tbuf), "%d%s%02d", value, str(LANG_POINT), 79 snprintf(buf, buf_size, "%d%s", value, P2STR(units[unit_no]));
78 fraction / 10);
79
80 snprintf(buf, buf_size, "%s%s", tbuf, P2STR(units[unit_no]));
81 } 80 }
82 else 81 else
83 { 82 {
84 if (value >= 100 || !unit_no)
85 tbuf[0] = '\0';
86 else if (value >= 10)
87 snprintf(tbuf, sizeof(tbuf), "%01d", fraction / 100);
88 else
89 snprintf(tbuf, sizeof(tbuf), "%02d", fraction / 10);
90
91 /* strip trailing zeros from the fraction */ 83 /* strip trailing zeros from the fraction */
92 for (i = strlen(tbuf) - 1; (i >= 0) && (tbuf[i] == '0'); i--) 84 for (i = strlen(tbuf) - 1; (i >= 0) && (tbuf[i] == '0'); i--)
93 tbuf[i] = '\0'; 85 tbuf[i] = '\0';
@@ -139,20 +131,6 @@ int read_line(int fd, char* buffer, int buffer_size)
139 return errno ? -1 : num_read; 131 return errno ? -1 : num_read;
140} 132}
141 133
142#ifdef TEST_MAX5
143int main(int argc, char **argv)
144{
145 char buffer[32];
146 if(argc>1) {
147 printf("%d => %s\n",
148 atoi(argv[1]),
149 num2max5(atoi(argv[1]), buffer));
150 }
151 return 0;
152}
153
154#endif
155
156#ifdef HAVE_LCD_BITMAP 134#ifdef HAVE_LCD_BITMAP
157extern unsigned char lcd_framebuffer[LCD_HEIGHT/8][LCD_WIDTH]; 135extern unsigned char lcd_framebuffer[LCD_HEIGHT/8][LCD_WIDTH];
158static const unsigned char bmpheader[] = 136static const unsigned char bmpheader[] =