]> mj.ucw.cz Git - libucw.git/commitdiff
Extended types: Cleaned up unit name parsing
authorMartin Mares <mj@ucw.cz>
Fri, 25 Jul 2014 11:04:27 +0000 (13:04 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 25 Jul 2014 11:04:27 +0000 (13:04 +0200)
First of all, please show some respect and don't mess up coding
style of existing source files.

Second, when all parsing functions in xtypes.h use a common name
for the input string, just use it, too.

ucw/xtypes.c
ucw/xtypes.h

index df6eb444cfac884dbc21ea766f11ab006e5c8613..588b33ace1444bc434c7fff5eb0ec929bb3c8b69 100644 (file)
@@ -46,15 +46,10 @@ const char *xtype_format_fmt(struct xtype *xt, u32 fmt, struct mempool *pool)
   return "";
 }
 
-int xtype_unit_parser(const char *units_str, struct unit_definition *units_def)
+int xtype_unit_parser(const char *str, struct unit_definition *units)
 {
-  int i = 0;
-  while(units_def[i].unit != NULL) {
-    if(strcmp(units_str, units_def[i].unit) == 0) {
+  for (int i=0; units[i].unit; i++)
+    if (!strcmp(str, units[i].unit))
       return i;
-    }
-    i++;
-  }
-
   return -1;
 }
index 0d801ad41fb08806dced9d94afef56b56af619cb..3bf9656831f8c4a939c77716bfe0db2fec5ad0b3 100644 (file)
@@ -86,10 +86,10 @@ struct unit_definition {
 };
 
 /**
- * Parses a unit definition in units_str and returns index into units_def array. -1 if the units
- * were not contained in the array.
+ * Parse a name of a unit and return its index in the @units array or -1
+ * if is not present there.
  **/
-int xtype_unit_parser(const char *units_str, struct unit_definition *units_def);
+int xtype_unit_parser(const char *str, struct unit_definition *units);
 
 /**
  * This structure describes an xtype. Among other things, it points to callback