aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/numconvert.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/numconvert.c b/src/numconvert.c
index d7680b4..174dae5 100644
--- a/src/numconvert.c
+++ b/src/numconvert.c
@@ -132,6 +132,7 @@ int main(int argc, char * argv[])
132{ 132{
133 int c; 133 int c;
134 int base; 134 int base;
135 int optbase;
135 int opt_index; 136 int opt_index;
136 char buff[9]; 137 char buff[9];
137 int32_t opt; 138 int32_t opt;
@@ -169,7 +170,6 @@ int main(int argc, char * argv[])
169 170
170 case 'a': 171 case 'a':
171 base = -1; 172 base = -1;
172 //opt |= (MY_OPT_BIN|MY_OPT_DEC|MY_OPT_HEX|MY_OPT_OCT|);
173 break; 173 break;
174 174
175 case 'B': 175 case 'B':
@@ -252,26 +252,36 @@ int main(int argc, char * argv[])
252 for(x = optind; x < argc; x++) 252 for(x = optind; x < argc; x++)
253 { 253 {
254 len = 0; 254 len = 0;
255 if (!(base)) 255 optbase = base;
256 if (!(optbase))
256 { 257 {
257 base = 10; 258 optbase = 10;
258 if (!(strncmp("00", argv[x], (size_t)2))) 259 if (!(strncmp("00", argv[x], (size_t)2)))
259 base = 2; 260 optbase = 2;
260 else if (!(strncmp("0x", argv[x], (size_t)2))) 261 else if (!(strncmp("0x", argv[x], (size_t)2)))
261 base = 16; 262 optbase = 16;
262 else if (!(strncmp("0", argv[x], (size_t)1))) 263 else if (!(strncmp("0", argv[x], (size_t)1)))
263 base = 8; 264 optbase = 8;
264 else 265 else
265 for(y = 0; ((uint32_t)y) < strlen(argv[x]); y++) 266 {
266 if ( ((argv[x][y] >= 'a') && (argv[x][y] <= 'z')) || 267 optbase = 10;
267 ((argv[x][y] >= 'A') && (argv[x][y] <= 'Z')) ) 268 for(y = 0; ( ((uint32_t)y) < strlen(argv[x]) && (optbase > 0) ); y++)
268 base = 16; 269 {
270 c = argv[x][y];
271 if ((c >= 'a') && (c <= 'z'))
272 optbase = 16;
273 else if ((c >= 'A') && (c <= 'Z'))
274 optbase = 16;
275 else if ((c < '0') || (c > '9'))
276 optbase = 16;
277 };
278 };
269 }; 279 };
270 max = sizeof(intmax_t); 280 max = sizeof(intmax_t);
271 if (base == -1) 281 if (optbase == -1)
272 num = argv[x][0]; 282 num = argv[x][0];
273 else 283 else
274 num = strtoumax(argv[x], NULL, base); 284 num = strtoumax(argv[x], NULL, optbase);
275 if (opt & MY_OPT_LIMIT) 285 if (opt & MY_OPT_LIMIT)
276 { 286 {
277 max = 1; 287 max = 1;