2 * news foo prints /lib/news/foo
3 * news -a prints all news items, latest first
4 * news -n lists names of new items
5 * news prints items changed since last news
12 #define NINC 50 /* Multiples of directory allocation */
13 char *NEWS = "#9/news";
14 char TFILE[] = "%s/lib/newstime";
17 * The following items should not be printed.
38 int fcmp(const void *a, const void *b);
39 void read_dir(int update);
40 void print_item(char *f);
41 void eachitem(void (*emit)(char*), int all, int update);
45 main(int argc, char *argv[])
51 Binit(&bout, 1, OWRITE);
53 eachitem(print_item, 0, 1);
57 case 'a': /* print all */
58 eachitem(print_item, 1, 0);
61 case 'n': /* names only */
68 fprint(2, "news: bad option %c\n", ARGC());
77 fcmp(const void *a, const void *b)
81 x = ((File*)b)->time - ((File*)a)->time;
90 * read_dir: get the file names and modification dates for the
91 * files in /usr/news into n_list; sort them in reverse by
98 char newstime[100], *home;
102 n_list = malloc(NINC*sizeof(File));
104 home = getenv("HOME");
106 sprint(newstime, TFILE, home);
107 d = dirstat(newstime);
109 n_list[n_count].name = strdup("");
110 n_list[n_count].time =d->mtime-1;
111 n_list[n_count].length = 0;
116 fd = create(newstime, OWRITE, 0644);
121 fd = open(NEWS, OREAD);
128 n = dirreadall(fd, &d);
130 for(j=0; ignore[j]; j++)
131 if(strcmp(ignore[j], d[i].name) == 0)
135 n_list = realloc(n_list, na*sizeof(File));
137 n_list[n_count].name = strdup(d[i].name);
138 n_list[n_count].time = d[i].mtime;
139 n_list[n_count].length = d[i].length;
146 qsort(n_list, n_count, sizeof(File), fcmp);
150 print_item(char *file)
152 char name[4096], *p, *ep;
157 sprint(name, "%s/%s", NEWS, file);
158 f = open(name, OREAD);
168 Bprint(&bout, "\n%s (%s) %s\n", file,
169 dbuf->muid[0]? dbuf->muid : dbuf->uid,
170 asctime(localtime(dbuf->mtime)));
173 bol = 1; /* beginning of line ...\n */
174 bop = 1; /* beginning of page ...\n\n */
176 c = read(f, name, sizeof(name));
206 eachitem(void (*emit)(char*), int all, int update)
211 for(i=0; i<n_count; i++) {
212 if(n_list[i].name[0] == 0) { /* newstime */
217 if(n_list[i].length == 0) /* in progress */
219 (*emit)(n_list[i].name);
228 Bprint(&bout, "news:");
229 Bprint(&bout, " %s", file);