ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL print_units_table (const struct units *units, FILE *f) { const struct units *u, *u2; size_t max_sz = 0; for (u = units; u->name; ++u) { max_sz = max(max_sz, strlen(u->name)); } for (u = units; u->name;) { char buf[1024]; const struct units *next; for (next = u + 1; next->name && next->mult == u->mult; ++next) ; if (next->name) { for (u2 = next; u2->name && u->mult % u2->mult != 0; ++u2) ; if (u2->name == NULL) --u2; unparse_units (u->mult, u2, buf, sizeof(buf)); fprintf (f, "1 %*s = %s\n", (int)max_sz, u->name, buf); } else { fprintf (f, "1 %s\n", u->name); } u = next; } }
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL unparse_bytes (int t, char *s, size_t len) { return unparse_units (t, bytes_units, s, len); }
size_t ROKEN_LIB_FUNCTION unparse_time (int t, char *s, size_t len) { return unparse_units (t, time_units, s, len); }