[PATCH] Further job parsing fixes
[fio.git] / fio-ini.c
index 549be0ec5791ff5b6021848c1cd6249dd13ac4ae..2941a670f6a78603774b77b26d8782bc6a7378b2 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -35,7 +35,7 @@
 #define DEF_USE_THREAD (0)
 #define DEF_FILE_SIZE  (1024 * 1024 * 1024UL)
 
-static char fio_version_string[] = "fio 1.0";
+static char fio_version_string[] = "fio 1.1";
 
 static int repeatable = DEF_RAND_REPEAT;
 static char *ini_file;
@@ -336,7 +336,7 @@ static int str_cnv(char *p, unsigned long long *val)
        char *str;
        int len;
 
-       str = strstr(p, "=");
+       str = strchr(p, '=');
        if (!str)
                return 1;
 
@@ -384,7 +384,7 @@ static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
        if (!s)
                return 1;
 
-       s = strstr(s, "=");
+       s = strchr(s, '=');
        if (!s)
                return 1;
 
@@ -400,7 +400,7 @@ static int check_strstore(char *p, char *name, char *dest)
        if (!s)
                return 1;
 
-       s = strstr(p, "=");
+       s = strchr(p, '=');
        if (!s)
                return 1;
 
@@ -414,47 +414,75 @@ static int check_strstore(char *p, char *name, char *dest)
        return 0;
 }
 
-static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
+static int __check_range(char *str, unsigned long *val)
 {
-       char str[128];
-       char s1, s2;
+       char suffix;
 
-       sprintf(str, "%s=%%lu%%c-%%lu%%c", name);
-       if (sscanf(p, str, s, &s1, e, &s2) == 4) {
-               *s *= get_mult(s1);
-               *e *= get_mult(s2);
+       if (sscanf(str, "%lu%c", val, &suffix) == 2) {
+               *val *= get_mult(suffix);
                return 0;
        }
 
-       sprintf(str, "%s = %%lu%%c-%%lu%%c", name);
-       if (sscanf(p, str, s, &s1, e, &s2) == 4) {
-               *s *= get_mult(s1);
-               *e *= get_mult(s2);
+       if (sscanf(str, "%lu", val) == 1)
                return 0;
-       }
 
-       sprintf(str, "%s=%%lu-%%lu", name);
-       if (sscanf(p, str, s, e) == 2)
-               return 0;
+       return 1;
+}
+
+static int check_range(char *p, char *name, unsigned long *s, unsigned long *e)
+{
+       char option[128];
+       char *str, *p1, *p2;
+
+       strcpy(option, p);
+       p = option;
+
+       str = strstr(p, name);
+       if (!str)
+               return 1;
+
+       p += strlen(name);
+
+       str = strchr(p, '=');
+       if (!str)
+               return 1;
+
+       /*
+        * 'p' now holds whatever is after the '=' sign
+        */
+       p1 = str + 1;
 
-       sprintf(str, "%s = %%lu-%%lu", name);
-       if (sscanf(p, str, s, e) == 2)
+       /*
+        * terminate p1 at the '-' sign
+        */
+       p = strchr(p1, '-');
+       if (!p)
+               return 1;
+
+       p2 = p + 1;
+       *p = '\0';
+
+       if (!__check_range(p1, s) && !__check_range(p2, e))
                return 0;
 
        return 1;
-
 }
 
 static int check_int(char *p, char *name, unsigned int *val)
 {
-       char str[128];
+       char *str;
 
-       sprintf(str, "%s=%%d", name);
-       if (sscanf(p, str, val) == 1)
-               return 0;
+       str = strstr(p, name);
+       if (!str)
+               return 1;
+
+       str = strchr(p, '=');
+       if (!str)
+               return 1;
+
+       str++;
 
-       sprintf(str, "%s = %%d", name);
-       if (sscanf(p, str, val) == 1)
+       if (sscanf(str, "%u", val) == 1)
                return 0;
 
        return 1;