Last one. :) This one doesn't follow with any of the previous patches, but its fun. This allows a modifier suffix on the end of the -s [size] option to make it more human friendly. So now instead of -s 32768, you can use -s 32k instead. Both 'k' (size * 1024) and 'm' (size * 1024 * 1024) are supported.
Jordan
[PATCH][LAR] Allow human friendly suffixes for the size option
Enable 'k' and 'm' suffixes to modify the size in a human friendly way - s 32k is much easier on the brain then -s 32768.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com Index: LinuxBIOSv3/util/lar/lar.c =================================================================== --- LinuxBIOSv3.orig/util/lar/lar.c 2007-07-11 11:51:57.000000000 -0600 +++ LinuxBIOSv3/util/lar/lar.c 2007-07-11 11:52:01.000000000 -0600 @@ -46,7 +46,7 @@ printf("\nLAR - the LinuxBIOS Archiver " VERSION "\n" COPYRIGHT "\n\n" "Usage: %s [-cxal] archive.lar [[[file1] file2] ...]\n\n", name); printf("Examples:\n"); - printf(" lar -c -s 32768 -b bootblock myrom.lar foo nocompress:bar\n"); + printf(" lar -c -s 32k -b bootblock myrom.lar foo nocompress:bar\n"); printf(" lar -a myrom.lar foo blob:baz\n"); printf(" lar -l myrom.lar\n\n");
@@ -61,7 +61,9 @@ printf(" * Pathname is the name to use in the LAR header.\n\n");
printf("Create options:\n"); - printf(" -s [size]\tSpecify the size of the archive (in bytes)\n"); + printf(" -s [size] \tSpecify the size of the archive.\n"); + printf(" \tUse a 'k' suffix to multiply the size by 1K or\n"); + printf(" \ta 'm' suffix to multiple the size by 1M.\n"); printf(" -b [bootblock]\tSpecify the bootblock blob\n"); printf(" -C [lzma|nrv2b]\tSpecify the compression method to use\n\n");
@@ -73,6 +75,29 @@
}
+/* Add a human touch to the LAR size by allowing suffixes: + XX[KkMm] where k = XX * 1024 and m or M = xx * 1024 * 1024 +*/ + +static void parse_larsize(char *str) +{ + char *p = NULL; + unsigned int size = strtoul(str, &p, 0); + + if (p != NULL) { + if (*p == 'k' || *p == 'K') + size *= 1024; + else if (*p == 'm' || *p == 'M') + size *= (1024 * 1024); + else { + fprintf(stderr, "Unknown LAR size suffix %c\n", *p); + exit(1); + } + } + + larsize = size; +} + int verbose(void) { return isverbose; @@ -219,7 +244,7 @@ larmode = EXTRACT; break; case 's': - larsize = strtol(optarg, (char **)NULL, 10); + parse_larsize(optarg); break; case 'b': bootblock = strdup(optarg);
Acked-by: Ronald G. Minnich rminnich@gmail.com
On 7/11/07, Jordan Crouse jordan.crouse@amd.com wrote:
Last one. :) This one doesn't follow with any of the previous patches, but its fun. This allows a modifier suffix on the end of the -s [size] option to make it more human friendly. So now instead of -s 32768, you can use -s 32k instead. Both 'k' (size * 1024) and 'm' (size * 1024 * 1024) are supported.
Jordan
[PATCH][LAR] Allow human friendly suffixes for the size option
Enable 'k' and 'm' suffixes to modify the size in a human friendly way - s 32k is much easier on the brain then -s 32768.
Signed-off-by: Jordan Crouse jordan.crouse@amd.com Index: LinuxBIOSv3/util/lar/lar.c =================================================================== --- LinuxBIOSv3.orig/util/lar/lar.c 2007-07-11 11:51:57.000000000 -0600 +++ LinuxBIOSv3/util/lar/lar.c 2007-07-11 11:52:01.000000000 -0600 @@ -46,7 +46,7 @@ printf("\nLAR - the LinuxBIOS Archiver " VERSION "\n" COPYRIGHT "\n\n" "Usage: %s [-cxal] archive.lar [[[file1] file2] ...]\n\n", name); printf("Examples:\n");
printf(" lar -c -s 32768 -b bootblock myrom.lar foo nocompress:bar\n");
printf(" lar -c -s 32k -b bootblock myrom.lar foo nocompress:bar\n"); printf(" lar -a myrom.lar foo blob:baz\n"); printf(" lar -l myrom.lar\n\n");
@@ -61,7 +61,9 @@ printf(" * Pathname is the name to use in the LAR header.\n\n");
printf("Create options:\n");
printf(" -s [size]\tSpecify the size of the archive (in bytes)\n");
printf(" -s [size] \tSpecify the size of the archive.\n");
printf(" \tUse a 'k' suffix to multiply the size by 1K or\n");
printf(" \ta 'm' suffix to multiple the size by 1M.\n"); printf(" -b [bootblock]\tSpecify the bootblock blob\n"); printf(" -C [lzma|nrv2b]\tSpecify the compression method to use\n\n");
@@ -73,6 +75,29 @@
}
+/* Add a human touch to the LAR size by allowing suffixes:
- XX[KkMm] where k = XX * 1024 and m or M = xx * 1024 * 1024
+*/
+static void parse_larsize(char *str) +{
- char *p = NULL;
- unsigned int size = strtoul(str, &p, 0);
- if (p != NULL) {
- if (*p == 'k' || *p == 'K')
size *= 1024;
- else if (*p == 'm' || *p == 'M')
size *= (1024 * 1024);
- else {
fprintf(stderr, "Unknown LAR size suffix %c\n", *p);
exit(1);
- }
- }
- larsize = size;
+}
int verbose(void) { return isverbose; @@ -219,7 +244,7 @@ larmode = EXTRACT; break; case 's':
larsize = strtol(optarg, (char **)NULL, 10);
parse_larsize(optarg); break; case 'b': bootblock = strdup(optarg);
-- linuxbios mailing list linuxbios@linuxbios.org http://www.linuxbios.org/mailman/listinfo/linuxbios
On Wed, Jul 11, 2007 at 11:27:53AM -0700, ron minnich wrote:
Acked-by: Ronald G. Minnich rminnich@gmail.com
Yep,
Acked-by: Uwe Hermann uwe@hermann-uwe.de
But some small issues:
+/* Add a human touch to the LAR size by allowing suffixes:
- XX[KkMm] where k = XX * 1024 and m or M = xx * 1024 * 1024
+*/
/* Add a human touch to the LAR size by allowing suffixes: * XX[KkMm] where k = XX * 1024 and m or M = xx * 1024 * 1024 */
+static void parse_larsize(char *str)
static void parse_larsize(const char *str)
+{
- char *p = NULL;
- unsigned int size = strtoul(str, &p, 0);
- if (p != NULL) {
- if (*p == 'k' || *p == 'K')
size *= 1024;
- else if (*p == 'm' || *p == 'M')
size *= (1024 * 1024);
- else {
fprintf(stderr, "Unknown LAR size suffix %c\n", *p);
exit(1);
- }
- }
- larsize = size;
+}
Please fix the coding style (TABs instead of spaces, for example).
Uwe.
Great idea.
On Wed, Jul 11, 2007 at 12:26:16PM -0600, Jordan Crouse wrote:
- printf(" \tUse a 'k' suffix to multiply the size by 1K or\n");
- printf(" \ta 'm' suffix to multiple the size by 1M.\n");
I would prefer 1024 rather than 1K and 1048576 or 1024*1024 rather than 1M.
+static void parse_larsize(char *str)
static u32 ..
- larsize = size;
.. and return size ?
May it's useful somewhere else too? Ie. move to lib.c?
//Peter
On 12/07/07 01:19 +0200, Peter Stuge wrote:
Great idea.
On Wed, Jul 11, 2007 at 12:26:16PM -0600, Jordan Crouse wrote:
- printf(" \tUse a 'k' suffix to multiply the size by 1K or\n");
- printf(" \ta 'm' suffix to multiple the size by 1M.\n");
I would prefer 1024 rather than 1K and 1048576 or 1024*1024 rather than 1M.
Good idea. I think 'dd' does the same thing.
+static void parse_larsize(char *str)
static u32 ..
- larsize = size;
.. and return size ?
May it's useful somewhere else too? Ie. move to lib.c?
I don't know - this is the only place we do this sort of thing - in fact, its probably overkill to have a function - we could do it right in the switch statement if we wanted to.
Jordan
On Wed, Jul 11, 2007 at 05:41:21PM -0600, Jordan Crouse wrote:
I would prefer 1024 rather than 1K and 1048576 or 1024*1024 rather than 1M.
Good idea. I think 'dd' does the same thing.
--8<-- $ dd --help .. BLOCKS and BYTES may be followed by the following multiplicative suffixes: xM M, c 1, w 2, b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024, GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y. -->8--
I think we should just stay with [kK]=1024 and [mM]=1024*1024 though.
But the point was that lar should print the numbers rather than the suffixes in the help output.
+static void parse_larsize(char *str)
May it's useful somewhere else too? Ie. move to lib.c?
I don't know - this is the only place we do this sort of thing - in fact, its probably overkill to have a function - we could do it right in the switch statement if we wanted to.
Sounds good to me.
//Peter