[PATCH] Add full command line parameter support

You may now give full job options on the command line. Makes it easier
to script fio or for one-off runs, as you don't have to write a job file
and run that.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/parse.c b/parse.c
index 197a46e..48703b6 100644
--- a/parse.c
+++ b/parse.c
@@ -48,9 +48,8 @@
 /*
  * convert string into decimal value, noting any size suffix
  */
-static int str_to_decimal(char *p, unsigned long long *val, int kilo)
+static int str_to_decimal(const char *str, unsigned long long *val, int kilo)
 {
-	char *str = p;
 	int len;
 
 	len = strlen(str);
@@ -66,12 +65,12 @@
 	return 0;
 }
 
-static int check_str_bytes(char *p, unsigned long long *val)
+static int check_str_bytes(const char *p, unsigned long long *val)
 {
 	return str_to_decimal(p, val, 1);
 }
 
-static int check_str_time(char *p, unsigned long long *val)
+static int check_str_time(const char *p, unsigned long long *val)
 {
 	return str_to_decimal(p, val, 0);
 }
@@ -109,7 +108,7 @@
 	return 1;
 }
 
-static int check_int(char *p, unsigned int *val)
+static int check_int(const char *p, unsigned int *val)
 {
 	if (sscanf(p, "%u", val) == 1)
 		return 0;
@@ -132,16 +131,14 @@
 	return NULL;
 }
 
-static int handle_option(struct fio_option *o, char *ptr, void *data)
+static int handle_option(struct fio_option *o, const char *ptr, void *data)
 {
 	unsigned int il, *ilp;
 	unsigned long long ull, *ullp;
 	unsigned long ul1, ul2, *ulp1, *ulp2;
-	char *tmpbuf, **cp;
+	char **cp;
 	int ret = 0, is_time = 0;
 
-	tmpbuf = malloc(4096);
-
 	switch (o->type) {
 	case FIO_OPT_STR: {
 		fio_opt_str_fn *fn = o->cb;
@@ -239,13 +236,26 @@
 		ret = 1;
 	}
 
-	free(tmpbuf);
 	return ret;
 }
 
+int parse_cmd_option(const char *opt, const char *val,
+		     struct fio_option *options, void *data)
+{
+	struct fio_option *o;
+
+	o = find_option(options, opt);
+	if (!o) {
+		fprintf(stderr, "Bad option %s\n", opt);
+		return 1;
+	}
+
+	return handle_option(o, val, data);
+}
+
 int parse_option(const char *opt, struct fio_option *options, void *data)
 {
-	struct fio_option *o = find_option(options, opt);
+	struct fio_option *o;
 	char *pre, *post;
 	char tmp[64];