From: Martin Mares Date: Fri, 25 Jul 2014 11:04:27 +0000 (+0200) Subject: Extended types: Cleaned up unit name parsing X-Git-Tag: v6.1~3^2~43^2~4 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f5e05c4dfbfef5b7d4a30bdf8b5a079fa797664d;p=libucw.git Extended types: Cleaned up unit name parsing 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. --- diff --git a/ucw/xtypes.c b/ucw/xtypes.c index df6eb444..588b33ac 100644 --- a/ucw/xtypes.c +++ b/ucw/xtypes.c @@ -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; } diff --git a/ucw/xtypes.h b/ucw/xtypes.h index 0d801ad4..3bf96568 100644 --- a/ucw/xtypes.h +++ b/ucw/xtypes.h @@ -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