17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
220d8b5334Sceastha /*
230d8b5334Sceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240d8b5334Sceastha * Use is subject to license terms.
250d8b5334Sceastha */
260d8b5334Sceastha
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate news foo prints /var/news/foo
327c478bd9Sstevel@tonic-gate news -a prints all news items, latest first
337c478bd9Sstevel@tonic-gate news -n lists names of new items
347c478bd9Sstevel@tonic-gate news -s tells count of new items only
357c478bd9Sstevel@tonic-gate news prints items changed since last news
367c478bd9Sstevel@tonic-gate */
377c478bd9Sstevel@tonic-gate
387c478bd9Sstevel@tonic-gate #include <stdio.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <stdlib.h>
417c478bd9Sstevel@tonic-gate #include <unistd.h>
427c478bd9Sstevel@tonic-gate #include <sys/stat.h>
437c478bd9Sstevel@tonic-gate #include <setjmp.h>
447c478bd9Sstevel@tonic-gate #include <signal.h>
457c478bd9Sstevel@tonic-gate #include <dirent.h>
467c478bd9Sstevel@tonic-gate #include <pwd.h>
477c478bd9Sstevel@tonic-gate #include <time.h>
487c478bd9Sstevel@tonic-gate #include <locale.h>
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate #define INDENT 3
517c478bd9Sstevel@tonic-gate #define RD_WR_ALL (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate #define DATE_FMT "%a %b %e %H:%M:%S %Y"
547c478bd9Sstevel@tonic-gate /*
557c478bd9Sstevel@tonic-gate * %a abbreviated weekday name
567c478bd9Sstevel@tonic-gate * %b abbreviated month name
577c478bd9Sstevel@tonic-gate * %e day of month
587c478bd9Sstevel@tonic-gate * %H hour (24-hour clock)
597c478bd9Sstevel@tonic-gate * %M minute
607c478bd9Sstevel@tonic-gate * %S second
617c478bd9Sstevel@tonic-gate * %Y year
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate The following items should not be printed.
657c478bd9Sstevel@tonic-gate */
667c478bd9Sstevel@tonic-gate char *ignore[] = {
677c478bd9Sstevel@tonic-gate "core",
687c478bd9Sstevel@tonic-gate NULL
697c478bd9Sstevel@tonic-gate };
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate struct n_file {
727c478bd9Sstevel@tonic-gate long n_time;
737c478bd9Sstevel@tonic-gate char n_name[MAXNAMLEN];
747c478bd9Sstevel@tonic-gate } *n_list;
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate char NEWS[] = "/var/news"; /* directory for news items */
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate int aopt = 0; /* 1 say -a specified */
797c478bd9Sstevel@tonic-gate int n_count; /* number of items in NEWS directory */
807c478bd9Sstevel@tonic-gate int number_read; /* number of items read */
817c478bd9Sstevel@tonic-gate int nopt = 0; /* 1 say -n specified */
827c478bd9Sstevel@tonic-gate int optsw; /* for getopt */
837c478bd9Sstevel@tonic-gate int opt = 0; /* number of options specified */
847c478bd9Sstevel@tonic-gate int sopt = 0; /* 1 says -s specified */
857c478bd9Sstevel@tonic-gate char stdbuf[BUFSIZ];
867c478bd9Sstevel@tonic-gate char time_buf[50]; /* holds date and time string */
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate jmp_buf save_addr;
897c478bd9Sstevel@tonic-gate
900d8b5334Sceastha void all_news(void);
910d8b5334Sceastha int ck_num(void);
920d8b5334Sceastha void count(char *);
930d8b5334Sceastha void initialize(void);
940d8b5334Sceastha void late_news(void(*)(), int);
950d8b5334Sceastha void notify(char *);
960d8b5334Sceastha void print_item(char *);
970d8b5334Sceastha void read_dir(void);
980d8b5334Sceastha
990d8b5334Sceastha int
main(int argc,char ** argv)1000d8b5334Sceastha main(int argc, char **argv)
1017c478bd9Sstevel@tonic-gate {
1020d8b5334Sceastha int i;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate (void)setlocale(LC_ALL, "");
1057c478bd9Sstevel@tonic-gate setbuf (stdout, stdbuf);
1067c478bd9Sstevel@tonic-gate initialize();
1077c478bd9Sstevel@tonic-gate read_dir();
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate if (argc <= 1) {
1107c478bd9Sstevel@tonic-gate late_news (print_item, 1);
1117c478bd9Sstevel@tonic-gate ck_num();
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate else while ((optsw = getopt(argc, argv, "ans")) != EOF)
1147c478bd9Sstevel@tonic-gate switch(optsw) {
1157c478bd9Sstevel@tonic-gate case 'a':
1167c478bd9Sstevel@tonic-gate aopt++;
1177c478bd9Sstevel@tonic-gate opt++;
1187c478bd9Sstevel@tonic-gate break;
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate case 'n':
1217c478bd9Sstevel@tonic-gate nopt++;
1227c478bd9Sstevel@tonic-gate opt++;
1237c478bd9Sstevel@tonic-gate break;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate case 's':
1267c478bd9Sstevel@tonic-gate sopt++;
1277c478bd9Sstevel@tonic-gate opt++;
1287c478bd9Sstevel@tonic-gate break;
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate default:
1317c478bd9Sstevel@tonic-gate fprintf (stderr, "usage: news [-a] [-n] [-s] [items]\n");
1327c478bd9Sstevel@tonic-gate exit (1);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate if (opt > 1) {
1367c478bd9Sstevel@tonic-gate fprintf(stderr, "news: options are mutually exclusive\n");
1377c478bd9Sstevel@tonic-gate exit(1);
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate if (opt > 0 && argc > 2) {
1417c478bd9Sstevel@tonic-gate fprintf(stderr, "news: options are not allowed with file names\n");
1427c478bd9Sstevel@tonic-gate exit(1);
1437c478bd9Sstevel@tonic-gate }
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gate if (aopt) {
1467c478bd9Sstevel@tonic-gate all_news();
1477c478bd9Sstevel@tonic-gate ck_num();
1487c478bd9Sstevel@tonic-gate exit(0);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate if (nopt) {
1527c478bd9Sstevel@tonic-gate late_news (notify, 0);
1537c478bd9Sstevel@tonic-gate ck_num();
1547c478bd9Sstevel@tonic-gate exit(0);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate if (sopt) {
1587c478bd9Sstevel@tonic-gate late_news (count, 0);
1597c478bd9Sstevel@tonic-gate exit(0);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate for (i=1; i<argc; i++) print_item (argv[i]);
1637c478bd9Sstevel@tonic-gate
1640d8b5334Sceastha return (0);
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate * read_dir: get the file names and modification dates for the
1697c478bd9Sstevel@tonic-gate * files in /var/news into n_list; sort them in reverse by
1707c478bd9Sstevel@tonic-gate * modification date. We assume /var/news is the working directory.
1717c478bd9Sstevel@tonic-gate */
1727c478bd9Sstevel@tonic-gate
1730d8b5334Sceastha void
read_dir(void)1740d8b5334Sceastha read_dir(void)
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate struct dirent *nf, *readdir();
1777c478bd9Sstevel@tonic-gate struct stat sbuf;
1787c478bd9Sstevel@tonic-gate char fname[MAXNAMLEN];
1797c478bd9Sstevel@tonic-gate DIR *dirp;
1807c478bd9Sstevel@tonic-gate int i, j;
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /* Open the current directory */
1837c478bd9Sstevel@tonic-gate if ((dirp = opendir(".")) == NULL) {
1847c478bd9Sstevel@tonic-gate fprintf (stderr, "Cannot open %s\n", NEWS);
1857c478bd9Sstevel@tonic-gate exit (1);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /* Read the file names into n_list */
1897c478bd9Sstevel@tonic-gate n_count = 0;
1907c478bd9Sstevel@tonic-gate while (nf = readdir(dirp)) {
1917c478bd9Sstevel@tonic-gate strncpy (fname, nf->d_name, (unsigned) strlen(nf->d_name) + 1);
1927c478bd9Sstevel@tonic-gate if (nf->d_ino != (ino_t)0 && stat (fname, &sbuf) >= 0
1937c478bd9Sstevel@tonic-gate && (sbuf.st_mode & S_IFMT) == S_IFREG) {
1947c478bd9Sstevel@tonic-gate register char **p;
1957c478bd9Sstevel@tonic-gate p = ignore;
1967c478bd9Sstevel@tonic-gate while (*p && strncmp (*p, nf->d_name, MAXNAMLEN))
1977c478bd9Sstevel@tonic-gate ++p;
1987c478bd9Sstevel@tonic-gate if (!*p) {
1997c478bd9Sstevel@tonic-gate if (n_count++ > 0)
2007c478bd9Sstevel@tonic-gate n_list = (struct n_file *)
2017c478bd9Sstevel@tonic-gate realloc ((char *) n_list,
2027c478bd9Sstevel@tonic-gate (unsigned)
2037c478bd9Sstevel@tonic-gate (sizeof (struct n_file)
2047c478bd9Sstevel@tonic-gate * n_count));
2057c478bd9Sstevel@tonic-gate else
2067c478bd9Sstevel@tonic-gate n_list = (struct n_file *) malloc
2077c478bd9Sstevel@tonic-gate ((unsigned)
2087c478bd9Sstevel@tonic-gate (sizeof (struct n_file) *
2097c478bd9Sstevel@tonic-gate n_count));
2107c478bd9Sstevel@tonic-gate if (n_list == NULL) {
2117c478bd9Sstevel@tonic-gate fprintf (stderr, "No storage\n");
2127c478bd9Sstevel@tonic-gate exit (1);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate n_list[n_count-1].n_time = sbuf.st_mtime;
2157c478bd9Sstevel@tonic-gate strncpy (n_list[n_count-1].n_name,
2167c478bd9Sstevel@tonic-gate nf->d_name, MAXNAMLEN);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate /* Sort the elements of n_list in decreasing time order */
2227c478bd9Sstevel@tonic-gate for (i=1; i<n_count; i++)
2237c478bd9Sstevel@tonic-gate for (j=0; j<i; j++)
2247c478bd9Sstevel@tonic-gate if (n_list[j].n_time < n_list[i].n_time) {
2257c478bd9Sstevel@tonic-gate struct n_file temp;
2267c478bd9Sstevel@tonic-gate temp = n_list[i];
2277c478bd9Sstevel@tonic-gate n_list[i] = n_list[j];
2287c478bd9Sstevel@tonic-gate n_list[j] = temp;
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate /* Clean up */
2327c478bd9Sstevel@tonic-gate closedir(dirp);
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate
2350d8b5334Sceastha void
initialize(void)2360d8b5334Sceastha initialize(void)
2377c478bd9Sstevel@tonic-gate {
2387c478bd9Sstevel@tonic-gate if (signal (SIGQUIT, SIG_IGN) != (void(*)())SIG_IGN)
2397c478bd9Sstevel@tonic-gate signal (SIGQUIT, _exit);
2407c478bd9Sstevel@tonic-gate umask (((~(S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)) & S_IAMB));
2417c478bd9Sstevel@tonic-gate if (chdir (NEWS) < 0) {
2427c478bd9Sstevel@tonic-gate fprintf (stderr, "Cannot chdir to %s\n", NEWS);
2437c478bd9Sstevel@tonic-gate exit (1);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate
2470d8b5334Sceastha void
all_news(void)2480d8b5334Sceastha all_news(void)
2497c478bd9Sstevel@tonic-gate {
2507c478bd9Sstevel@tonic-gate int i;
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate for (i=0; i<n_count; i++)
2537c478bd9Sstevel@tonic-gate print_item (n_list[i].n_name);
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate
2560d8b5334Sceastha void
print_item(char * f)2570d8b5334Sceastha print_item(char *f)
2587c478bd9Sstevel@tonic-gate {
2597c478bd9Sstevel@tonic-gate FILE *fd;
2607c478bd9Sstevel@tonic-gate char fname[MAXNAMLEN+1];
2617c478bd9Sstevel@tonic-gate static int firstitem = 1;
2627c478bd9Sstevel@tonic-gate void onintr();
2637c478bd9Sstevel@tonic-gate struct passwd *getpwuid();
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate if (f == NULL) {
2667c478bd9Sstevel@tonic-gate return;
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate strncpy (fname, f, MAXNAMLEN);
2697c478bd9Sstevel@tonic-gate fname[MAXNAMLEN] = '\0';
2707c478bd9Sstevel@tonic-gate if ((fd = fopen (fname, "r")) == NULL)
2717c478bd9Sstevel@tonic-gate printf ("Cannot open %s/%s\n", NEWS, fname);
2727c478bd9Sstevel@tonic-gate else {
2737c478bd9Sstevel@tonic-gate register int c, ip, op;
2747c478bd9Sstevel@tonic-gate struct stat sbuf;
2757c478bd9Sstevel@tonic-gate struct passwd *pw;
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate fstat (fileno (fd), &sbuf);
2787c478bd9Sstevel@tonic-gate if (firstitem) {
2797c478bd9Sstevel@tonic-gate firstitem = 0;
2807c478bd9Sstevel@tonic-gate putchar ('\n');
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate if (setjmp(save_addr))
2837c478bd9Sstevel@tonic-gate goto finish;
2847c478bd9Sstevel@tonic-gate if (signal(SIGINT, SIG_IGN) != (void(*)())SIG_IGN)
2857c478bd9Sstevel@tonic-gate signal(SIGINT, onintr);
2867c478bd9Sstevel@tonic-gate printf ("%s ", fname);
2877c478bd9Sstevel@tonic-gate pw = getpwuid (sbuf.st_uid);
2887c478bd9Sstevel@tonic-gate if (pw)
2897c478bd9Sstevel@tonic-gate printf ("(%s)", pw->pw_name);
2907c478bd9Sstevel@tonic-gate else
2917c478bd9Sstevel@tonic-gate printf (".....");
292*2a8bcb4eSToomas Soome cftime(time_buf, DATE_FMT, &sbuf.st_mtime);
2937c478bd9Sstevel@tonic-gate printf (" %s\n", time_buf);
2947c478bd9Sstevel@tonic-gate op = 0;
2957c478bd9Sstevel@tonic-gate ip = INDENT;
2967c478bd9Sstevel@tonic-gate while ((c = getc (fd)) != EOF) {
2977c478bd9Sstevel@tonic-gate switch (c) {
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate case '\r':
3007c478bd9Sstevel@tonic-gate case '\n':
3017c478bd9Sstevel@tonic-gate putchar (c);
3027c478bd9Sstevel@tonic-gate op = 0;
3037c478bd9Sstevel@tonic-gate ip = INDENT;
3047c478bd9Sstevel@tonic-gate break;
3057c478bd9Sstevel@tonic-gate
3067c478bd9Sstevel@tonic-gate case ' ':
3077c478bd9Sstevel@tonic-gate ip++;
3087c478bd9Sstevel@tonic-gate break;
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate case '\b':
3117c478bd9Sstevel@tonic-gate if (ip > INDENT)
3127c478bd9Sstevel@tonic-gate ip--;
3137c478bd9Sstevel@tonic-gate break;
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate case '\t':
3167c478bd9Sstevel@tonic-gate ip = ((ip - INDENT + 8) & -8) + INDENT;
3177c478bd9Sstevel@tonic-gate break;
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate default:
3207c478bd9Sstevel@tonic-gate while (ip < op) {
3217c478bd9Sstevel@tonic-gate putchar ('\b');
3227c478bd9Sstevel@tonic-gate op--;
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate while ((ip & -8) > (op & -8)) {
3257c478bd9Sstevel@tonic-gate putchar ('\t');
3267c478bd9Sstevel@tonic-gate op = (op + 8) & -8;
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate while (ip > op) {
3297c478bd9Sstevel@tonic-gate putchar (' ');
3307c478bd9Sstevel@tonic-gate op++;
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate putchar (c);
3337c478bd9Sstevel@tonic-gate ip++;
3347c478bd9Sstevel@tonic-gate op++;
3357c478bd9Sstevel@tonic-gate break;
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate fflush (stdout);
3397c478bd9Sstevel@tonic-gate finish:
3407c478bd9Sstevel@tonic-gate putchar ('\n');
3417c478bd9Sstevel@tonic-gate fclose (fd);
3427c478bd9Sstevel@tonic-gate number_read++;
3437c478bd9Sstevel@tonic-gate if (signal(SIGINT, SIG_IGN) != (void(*)())SIG_IGN)
3447c478bd9Sstevel@tonic-gate signal(SIGINT, SIG_DFL);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate
3480d8b5334Sceastha void
late_news(void (* emit)(),int update)3490d8b5334Sceastha late_news(void(*emit)(), int update)
3507c478bd9Sstevel@tonic-gate {
3517c478bd9Sstevel@tonic-gate long cutoff;
3527c478bd9Sstevel@tonic-gate int i;
3537c478bd9Sstevel@tonic-gate char fname[50], *cp;
3547c478bd9Sstevel@tonic-gate struct stat newstime;
3557c478bd9Sstevel@tonic-gate int fd;
3567c478bd9Sstevel@tonic-gate struct {
3577c478bd9Sstevel@tonic-gate long actime, modtime;
3587c478bd9Sstevel@tonic-gate } utb;
3597c478bd9Sstevel@tonic-gate extern char *getenv();
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate /* Determine the time when last called */
3627c478bd9Sstevel@tonic-gate cp = getenv ("HOME");
3637c478bd9Sstevel@tonic-gate if (cp == NULL) {
3647c478bd9Sstevel@tonic-gate fprintf (stderr, "Cannot find HOME variable\n");
3657c478bd9Sstevel@tonic-gate exit (1);
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate strcpy (fname, cp);
3687c478bd9Sstevel@tonic-gate strcat (fname, "/");
3697c478bd9Sstevel@tonic-gate strcat (fname, ".news_time");
3707c478bd9Sstevel@tonic-gate cutoff = stat (fname, &newstime) < 0? 0: newstime.st_mtime;
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate /* Print the recent items */
3737c478bd9Sstevel@tonic-gate for (i=0; i<n_count && n_list[i].n_time > cutoff; i++) {
3747c478bd9Sstevel@tonic-gate (*emit) (n_list[i].n_name);
3757c478bd9Sstevel@tonic-gate number_read++;
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate (*emit) ((char *) NULL);
3787c478bd9Sstevel@tonic-gate fflush (stdout);
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate if (update) {
3817c478bd9Sstevel@tonic-gate /* Re-create the file and refresh the update time */
3827c478bd9Sstevel@tonic-gate if (n_count > 0 && (fd = creat (fname, RD_WR_ALL)) >= 0) {
3837c478bd9Sstevel@tonic-gate utb.actime = utb.modtime = n_list[0].n_time;
3847c478bd9Sstevel@tonic-gate close (fd);
3857c478bd9Sstevel@tonic-gate utime (fname, &utb);
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate
3900d8b5334Sceastha void
notify(char * s)3910d8b5334Sceastha notify(char *s)
3927c478bd9Sstevel@tonic-gate {
3937c478bd9Sstevel@tonic-gate static int first = 1;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate if (s) {
3967c478bd9Sstevel@tonic-gate if (first) {
3977c478bd9Sstevel@tonic-gate first = 0;
3987c478bd9Sstevel@tonic-gate printf ("news:", NEWS);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate printf (" %.14s", s);
4017c478bd9Sstevel@tonic-gate } else if (!first)
4027c478bd9Sstevel@tonic-gate putchar ('\n');
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4060d8b5334Sceastha void
count(char * s)4070d8b5334Sceastha count(char *s)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate static int nitems = 0;
4107c478bd9Sstevel@tonic-gate
4117c478bd9Sstevel@tonic-gate if (s)
4127c478bd9Sstevel@tonic-gate nitems++;
4137c478bd9Sstevel@tonic-gate else {
4147c478bd9Sstevel@tonic-gate if (nitems) {
4157c478bd9Sstevel@tonic-gate printf ("%d news item", nitems);
4167c478bd9Sstevel@tonic-gate if (nitems != 1)
4177c478bd9Sstevel@tonic-gate putchar ('s');
4187c478bd9Sstevel@tonic-gate printf (".\n");
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate else printf("No news.\n");
4217c478bd9Sstevel@tonic-gate }
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate void
onintr()4257c478bd9Sstevel@tonic-gate onintr()
4267c478bd9Sstevel@tonic-gate {
4277c478bd9Sstevel@tonic-gate sleep(2);
4287c478bd9Sstevel@tonic-gate longjmp(save_addr, 1);
4297c478bd9Sstevel@tonic-gate }
4300d8b5334Sceastha
4310d8b5334Sceastha int
ck_num(void)4320d8b5334Sceastha ck_num(void)
4337c478bd9Sstevel@tonic-gate {
4347c478bd9Sstevel@tonic-gate if (sopt && !number_read) printf("No news.\n");
4357c478bd9Sstevel@tonic-gate return(0);
4367c478bd9Sstevel@tonic-gate }
437