On 23/07/07 19:37 +0200, Peter Stuge wrote:
> File global larsize is yucky and hurts reuse.

Updated patch removing global larsize is attached.  

Now, not to be a jerk, but if there are no more comments, can I get some
ACKs, so I can get this code in? :-)

Jordan

-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.
[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 <[EMAIL PROTECTED]>
Index: LinuxBIOSv3/util/lar/lar.c
===================================================================
--- LinuxBIOSv3.orig/util/lar/lar.c	2007-07-25 09:31:53.000000000 -0600
+++ LinuxBIOSv3/util/lar/lar.c	2007-07-25 09:32:45.000000000 -0600
@@ -37,7 +37,6 @@
 #define COPYRIGHT "Copyright (C) 2006-2007 coresystems GmbH"
 
 static int isverbose = 0;
-static long larsize = 0;
 static char *bootblock = NULL;
 enum compalgo algo = none;
 
@@ -46,7 +45,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 +60,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 1024 or\n");
+	printf("                \ta 'm' suffix to multiple the size by 1024*1024.\n");
 	printf("  -b [bootblock]\tSpecify the bootblock blob\n");
 	printf("  -C [lzma|nrv2b]\tSpecify the compression method to use\n\n");
 
@@ -73,14 +74,32 @@
 
 }
 
-int verbose(void)
+/* 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 unsigned int parse_larsize(char *str)
 {
-	return isverbose;
+	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);
+		}
+	}
+
+	return size;
 }
 
-long get_larsize(void)
+int verbose(void)
 {
-	return larsize;
+	return isverbose;
 }
 
 char *get_bootblock(void)
@@ -88,9 +107,9 @@
 	return bootblock;
 }
 
-int create_lar(const char *archivename, struct file *files)
+int create_lar(const char *archivename, struct file *files, int size)
 {
-	struct lar *lar = lar_new_archive(archivename, larsize);
+	struct lar *lar = lar_new_archive(archivename, size);
 
 	if (lar == NULL) {
 		fprintf(stderr, "Unable to create %s as a LAR archive.\n",
@@ -171,6 +190,7 @@
 {
 	int opt;
 	int option_index = 0;
+	unsigned int larsize = 0;
 
 	int larmode = NONE;
 
@@ -219,7 +239,7 @@
 			larmode = EXTRACT;
 			break;
 		case 's':
-			larsize = strtol(optarg, (char **)NULL, 10);
+			larsize = parse_larsize(optarg);
 			break;
 		case 'b':
 			bootblock = strdup(optarg);
@@ -316,7 +336,7 @@
 		extract_lar(archivename, get_files());
 		break;
 	case CREATE:
-		create_lar(archivename, get_files());
+		create_lar(archivename, get_files(), larsize);
 		break;
 	case LIST:
 		list_lar(archivename, get_files());
-- 
linuxbios mailing list
[email protected]
http://www.linuxbios.org/mailman/listinfo/linuxbios

Reply via email to