]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/table-types.c
tableprinter: size units are now static
[libucw.git] / ucw / table-types.c
index 1d3130b791206d09c006b9a7f27751cdfe3ce065..1894a9a6daddf673b929461bc69ee7b3eeac75a9 100644 (file)
@@ -16,7 +16,7 @@
 
 /** xt_size **/
 
-struct unit_definition xtype_units_size[] = {
+static struct unit_definition xtype_units_size[] = {
   [SIZE_UNIT_BYTE] = { "", 1LLU, 1 },
   [SIZE_UNIT_KILOBYTE] = { "KB", 1024LLU, 1 },
   [SIZE_UNIT_MEGABYTE] = { "MB", 1024LLU * 1024LLU, 1 },
@@ -49,7 +49,7 @@ static const char *xt_size_format(void *src, u32 fmt, struct mempool *pool)
   return mp_printf(pool, "%"PRIu64"%s", curr_val, xtype_units_size[out_units].unit);
 }
 
-static const char * xt_size_fmt_parse(const char *opt_str, u32 *dest, struct mempool *pool UNUSED)
+static const char *xt_size_fmt_parse(const char *opt_str, u32 *dest, struct mempool *pool)
 {
   if(opt_str == NULL) {
     return "NULL is not supported as a column argument.";
@@ -69,11 +69,11 @@ static const char * xt_size_fmt_parse(const char *opt_str, u32 *dest, struct mem
   return NULL;
 }
 
-static const char *xt_size_parse(const char *str, void *dest, struct mempool *pool UNUSED)
+static const char *xt_size_parse(const char *str, void *dest, struct mempool *pool)
 {
   errno = 0;
   char *units_start = NULL;
-  u64 parsed = strtol(str, &units_start, 10);
+  u64 parsed = strtoul(str, &units_start, 10);
   if(str == units_start) {
     return mp_printf(pool, "Invalid value of size: '%s'.", str);
   }
@@ -92,7 +92,7 @@ static const char *xt_size_parse(const char *str, void *dest, struct mempool *po
 
   int unit_idx = xtype_unit_parser(units_start, xtype_units_size);
   if(unit_idx == -1) {
-    return mp_printf(pool, "Invalid format of size: '%s'.", str);
+    return mp_printf(pool, "Invalid units: '%s'.", units_start);
   }
 
   *(u64*) dest = parsed * xtype_units_size[unit_idx].num;
@@ -136,7 +136,7 @@ static const char *xt_timestamp_format(void *src, u32 fmt, struct mempool *pool)
   return mp_printf(pool, "%s", formatted_time_buf);
 }
 
-static const char * xt_timestamp_fmt_parse(const char *opt_str, u32 *dest, struct mempool *pool)
+static const char *xt_timestamp_fmt_parse(const char *opt_str, u32 *dest, struct mempool *pool)
 {
   if(opt_str == NULL) {
     return "NULL is not supported as a column argument.";
@@ -153,11 +153,11 @@ static const char * xt_timestamp_fmt_parse(const char *opt_str, u32 *dest, struc
   return mp_printf(pool, "Invalid column format option: '%s'.", opt_str);
 }
 
-static const char *xt_timestamp_parse(const char *str, void *dest, struct mempool *pool UNUSED)
+static const char *xt_timestamp_parse(const char *str, void *dest, struct mempool *pool)
 {
   errno = 0;
   char *parse_end = NULL;
-  u64 parsed = strtol(str, &parse_end, 10);
+  u64 parsed = strtoul(str, &parse_end, 10);
   if(str == parse_end) {
     return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
   }
@@ -174,14 +174,14 @@ static const char *xt_timestamp_parse(const char *str, void *dest, struct mempoo
     return NULL;
   }
 
-
   struct tm parsed_time;
-  //"%Y-%m-%d %H:%M:%S"
-  //"%F %T"
-  parse_end = strptime("%F %T", "%Y-%m-%d %H:%M:%S", &parsed_time);
+  parse_end = strptime(str, "%F %T", &parsed_time);
   if(parse_end == NULL) {
     return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
   }
+  if(*parse_end != 0) {
+    return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
+  }
 
   time_t tmp_time = mktime(&parsed_time);
   *(u64*)dest = (u64) tmp_time;