/* ruler [cols] -- print a column-count ruler */
#include <u.h>
#include <libc.h>
void
main (int argc, char **argv)
{
int cols, rows, i, j, skip;
char *buf, *p;
cols = 80;
if (argc > 1)
cols = atoi(argv[1]);
if (cols < 1)
exits("bad cols");
buf = malloc(cols + 1);
if (buf == nil)
sysfatal("out of memory");
rows = log10(cols);
for (i = rows; i >= 0 ; i--) {
skip = pow(10, i);
p = buf;
for (j = 1; j <= cols; j++) {
if (j % skip)
*p++ = ' ';
else
sprint(p++, "%d", (j / skip) % 10);
}
buf[cols] = '\0';
print("%s\n", buf);
}
exits(nil);
}
|