"enable"
};
#define kconf_id_strings ((const char *) &kconf_id_strings_contents)
-#if defined(__GNUC__) && __STDC_VERSION__ < 199901L
-__inline
-#endif
struct kconf_id *
kconf_id_lookup (register const char *str, register unsigned int len)
{
char *fmt;
)
+// Ensure there's one %f escape with correct attributes
+static void insanitize(char *f)
+{
+ char *s;
+ int found = 0;
+
+ for (s = f; *s; s++) {
+ if (*s != '%') continue;
+ if (*++s == '%') continue;
+ if (found++) break;
+ while (0 <= stridx("0'#-+ ", *s)) s++;
+ while (isdigit(*s)) s++;
+ if (*s == '.') s++;
+ while (isdigit(*s)) s++;
+ if (-1 == stridx("aAeEfFgG", *s)) break;
+ }
+
+ // The @ is a byte offset, not utf8 chars. Waiting for somebody to complain...
+ if (*s) error_exit("bad -f '%s'@%d", f, s-f+1);
+}
+
void seq_main(void)
{
double first, increment, last, dd;
default: last = atof(toys.optargs[toys.optc-1]);
}
- if (toys.optflags & FLAG_f) fmt_str = TT.fmt;
+ if (toys.optflags & FLAG_f) insanitize(fmt_str = TT.fmt);
if (toys.optflags & FLAG_s) sep_str = TT.sep;
// Yes, we're looping on a double. Yes rounding errors can accumulate if
*
* Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
*
- * TODO: I have no idea how the "io" and "system" categories are calculated.
+ * TODO: I have no idea how "system" category is calculated.
* whatever we're doing isn't matching what other implementations are doing.
USE_VMSTAT(NEWTOY(vmstat, ">2n", TOYFLAG_BIN))
uint64_t user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked;
// From /proc/meminfo (units are kb)
uint64_t memfree, buffers, cached, swapfree, swaptotal;
+ // From /proc/vmstat (units are kb)
+ uint64_t io_in, io_out;
// From /proc/vmstat (units are pages)
- uint64_t io_in, io_out, swap_in, swap_out;
+ uint64_t swap_in, swap_out;
};
// All the elements of vmstat_proc are the same size, so we can populate it as
// Print headers
if (rows>3 && !(loop % (rows-3))) {
+ char *header = headers;
+
if (isatty(1)) terminal_size(0, &rows);
else rows = 0;
printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
-
for (i=0; i<sizeof(lengths); i++) {
- printf(" %*s"+!i, lengths[i], headers);
- headers += strlen(headers)+1;
+ printf(" %*s"+!i, lengths[i], header);
+ header += strlen(header)+1;
}
xputc('\n');
}
// Adjust rate and units
if (i>5) out -= oldptr[order[i]];
if (order[i]<7) out = ((out*100) + (total_hz/2)) / total_hz;
- else if (order[i]>15) out = ((out * page_kb)+(units-1))/units;
+ else if (order[i]>17) out = ((out * page_kb)+(units-1))/units;
+ else if (order[i]>15) out = ((out)+(units-1))/units;
else if (order[i]<9) out = (out+(units-1)) / units;
// If a field was too big to fit in its slot, try to compensate later
if (!(flags&FLAG_g)) {
if (flags&FLAG_n) sprintf(ss = thyme, "%u", (unsigned)st->st_uid);
else strwidth(ss = getusername(st->st_uid));
- printf(" %*s", (int)totals[3], ss);
+ printf(" %-*s", (int)totals[3], ss);
}
// print group
if (!(flags&FLAG_o)) {
if (flags&FLAG_n) sprintf(ss = thyme, "%u", (unsigned)st->st_gid);
else strwidth(ss = getgroupname(st->st_gid));
- printf(" %*s", (int)totals[4], ss);
+ printf(" %-*s", (int)totals[4], ss);
}
if (flags & FLAG_Z)
- printf(" %*s", -(int)totals[7], (char *)sort[next]->extra);
+ printf(" %-*s", -(int)totals[7], (char *)sort[next]->extra);
// print major/minor
if (S_ISCHR(st->st_mode) || S_ISBLK(st->st_mode))
strftime(thyme, sizeof(thyme), "%F %H:%M", tm);
xprintf(" %s ", thyme);
} else if (flags & FLAG_Z)
- printf("%*s ", (int)totals[7], (char *)sort[next]->extra);
+ printf("%-*s ", (int)totals[7], (char *)sort[next]->extra);
if (flags & FLAG_color) {
color = color_from_mode(st->st_mode);