* %End-Header%
*/
+#include "config.h"
#include "e2p.h"
#include <stdlib.h>
switch (*p) { /* Using fall-through logic */
case 'T': case 't':
num <<= 10;
+ /* fallthrough */
case 'G': case 'g':
num <<= 10;
+ /* fallthrough */
case 'M': case 'm':
num <<= 10;
+ /* fallthrough */
case 'K': case 'k':
- num >>= log_block_size;
+ if (log_block_size < 0)
+ num <<= 10;
+ else
+ num >>= log_block_size;
break;
case 's':
- num >>= (1+log_block_size);
+ if (log_block_size < 0)
+ num <<= 9;
+ else
+ num >>= (1+log_block_size);
break;
case '\0':
break;
unsigned long num;
int log_block_size = 0;
- if (argc != 2) {
- fprintf(stderr, "Usage: %s arg\n", argv[0]);
+ if (argc != 2 && argc != 3) {
+ fprintf(stderr, "Usage: %s arg [log_block_size]\n", argv[0]);
exit(1);
}
+ if (argc == 3) {
+ char *p;
+
+ log_block_size = strtol(argv[2], &p, 0);
+ if (*p) {
+ fprintf(stderr, "Bad log_block_size: %s\n", argv[2]);
+ exit(1);
+ }
+ }
+
num = parse_num_blocks(argv[1], log_block_size);
printf("Parsed number: %lu\n", num);