unix/byteyears.c:7,10 c byteyears.c:7,8
< #include <stdio.h>
< #include <sys/types.h>
< #include <sys/stat.h>
< #include <ftw.h>
---
> #include <u.h>
> #include <libc.h>
unix/byteyears.c:14 c byteyears.c:12
< time_t now, year;
---
> long now, year;
unix/byteyears.c:18,21 c byteyears.c:16
< consider (name, buf, code)
< char *name;
< register struct stat *buf;
< int code;
---
> consider(char *name, Dir *d)
unix/byteyears.c:24,26 c byteyears.c:19,20
< register char *p;
< char *ctime();
< time_t t;
---
> char *p;
> long t;
unix/byteyears.c:28 c byteyears.c:22,23
< switch (code) {
---
> t = aflag? d->atime: d->mtime;
> by = (double) d->length * (double) (now - t) / YEAR;
unix/byteyears.c:30,32 c byteyears.c:25,31
< case FTW_F:
< t = aflag? buf->st_atime: buf->st_mtime;
< by = (double) buf->st_size * (double) (now - t) / YEAR;
---
> print ("%12.0f %10d", by + 0.5, d->length);
> p = ctime (t);
> if (t < year)
> print(" %-7.7s %-4.4s ", p+4, p+20);
> else
> print(" %-12.12s ", p+4);
> print ("%s\n", name);
unix/byteyears.c:34,41 c byteyears.c:33,34
< printf ("%12.0f %10d", by + 0.5, buf->st_size);
< p = ctime (&t);
< if (t < year)
< printf(" %-7.7s %-4.4s ", p+4, p+20);
< else
< printf(" %-12.12s ", p+4);
< printf ("%s\n", name);
< break;
---
> return 0;
> }
unix/byteyears.c:43,45 c byteyears.c:36,46
< case FTW_NS:
< perror (name);
< break;
---
> int
> check(char *s, int (*by) (char*, Dir*))
> {
> Dir *d;
> int fd, rc;
> int n, i;
>
> d = dirstat (s);
> if (d == nil) {
> perror (s);
> return -1;
unix/byteyears.c:47 a byteyears.c:49,67
> if ((d->mode&DMDIR) == 0)
> return by (s, d);
>
> if ((fd = open (s, OREAD)) == -1) {
> perror (s);
> return -1;
> }
>
> if ((n = dirreadall (fd, &d)) < 0) {
> perror (s);
> return -1;
> }
>
> for (i = 0; i < n; i++)
> if ((rc = by ((d+i)->name, d+i)) < 0)
> return rc; /* in case */
>
> close (fd);
>
unix/byteyears.c:50,53 c byteyears.c:70,72
<
< main (argc, argv)
< int argc;
< char **argv;
---
>
> int
> main (int argc, char **argv)
unix/byteyears.c:56,59 c byteyears.c:75
< extern char _sobuf[BUFSIZ];
< register int c;
< extern int optind;
< int rc = 0;
---
> int rc = 1;
unix/byteyears.c:61 c byteyears.c:77
< setbuf (stdout, _sobuf);
---
> ARGBEGIN {
unix/byteyears.c:63,65 d byteyears.c:78
< while ((c = getopt (argc, argv, "a")) != EOF) {
< switch (c) {
<
unix/byteyears.c:72,73 c byteyears.c:85
< }
< }
---
> } ARGEND
unix/byteyears.c:76,77 c byteyears.c:88,89
< fprintf (stderr, "usage: byteyears [-a] [file]...\n");
< exit (1);
---
> fprint (2, "usage: byteyears [-a] [file]...\n");
> exits ("usage");
unix/byteyears.c:83,85 c byteyears.c:95,97
< if (argc <= optind) {
< if (ftw ("", consider, 8) < 0) {
< fprintf (stderr, "cannot access current directory\n");
---
> if (!argc) {
> if (check (".", consider) < 0) {
> fprint (2, "cannot access current directory\n");
unix/byteyears.c:89,91 c byteyears.c:101,103
< for (i = optind; i < argc; i++) {
< if (ftw (argv[i], consider, 8) < 0) {
< fprintf (stderr, "cannot access %s\n", argv[i]);
---
> for (i = 0; i < argc; i++) {
> if (check (argv[i], consider) < 0) {
> fprint (2, "cannot access %s\n", argv[i]);
|