|
|
1.1 root 1: /*
2: * byte-years --
3: * the size of a file times the length of time since
4: * last modified, expressed in years.
5: * Also print size, date, name
6: */
7: #include <stdio.h>
8: #include <sys/types.h>
9: #include <sys/stat.h>
10: #include <ftw.h>
11:
12: #define YEAR (24L*60L*60L*365L)
13:
14: time_t now, year;
15: int aflag, errflag;
16:
17: int
18: consider (name, buf, code)
19: char *name;
20: register struct stat *buf;
21: int code;
22: {
23: double by;
24: register char *p;
25: char *ctime();
26: time_t t;
27:
28: switch (code) {
29:
30: case FTW_F:
31: t = aflag? buf->st_atime: buf->st_mtime;
32: by = (double) buf->st_size * (double) (now - t) / YEAR;
33:
34: printf ("%12.0f %10d", by + 0.5, buf->st_size);
35: p = ctime (&t);
36: if (t < year)
37: printf(" %-7.7s %-4.4s ", p+4, p+20);
38: else
39: printf(" %-12.12s ", p+4);
40: printf ("%s\n", name);
41: break;
42:
43: case FTW_NS:
44: perror (name);
45: break;
46: }
47:
48: return 0;
49: }
50:
51: main (argc, argv)
52: int argc;
53: char **argv;
54: {
55: int i;
56: extern char _sobuf[BUFSIZ];
57: register int c;
58: extern int optind;
59: int rc = 0;
60:
61: setbuf (stdout, _sobuf);
62:
63: while ((c = getopt (argc, argv, "a")) != EOF) {
64: switch (c) {
65:
66: case 'a':
67: aflag++;
68: break;
69:
70: case '?':
71: errflag++;
72: }
73: }
74:
75: if (errflag) {
76: fprintf (stderr, "usage: byteyears [-a] [file]...\n");
77: exit (1);
78: }
79:
80: time (&now);
81: year = now - (YEAR/2);
82:
83: if (argc <= optind) {
84: if (ftw ("", consider, 8) < 0) {
85: fprintf (stderr, "cannot access current directory\n");
86: rc++;
87: }
88: } else {
89: for (i = optind; i < argc; i++) {
90: if (ftw (argv[i], consider, 8) < 0) {
91: fprintf (stderr, "cannot access %s\n", argv[i]);
92: rc++;
93: }
94: }
95: }
96: return rc;
97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.