2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
10 #include <sys/types.h>
15 extern char *sprintf();
17 #define max(a,b) (a > b ? a : b)
21 #define NEWSP "/usr/news" /* MUST be same as login News's login dir */
22 #define MAXTOPICS 50 /* Enough for a while */
25 int topicspec
; /* topic argument(s) given */
26 char *topics
[MAXTOPICS
+1];
28 int fdisplay
, fcheck
, fupdate
, fsend
, freview
, fbody
; /* flags */
29 int frevback
, fverbose
, fhelp
, ftopics
; /* flags */
35 } nts
[MAXTOPICS
+1], *check();
36 struct nts
*ntps
[MAXTOPICS
];
37 int nnts
; /* number of actual topics */
39 struct swit switches
[] = {
44 "review [#]", 0, /* 4 */
45 "send topic ...",0, /* 5 */
52 extern char _sobuf
[]; /* MLW standard out buffer */
60 register char *cp
, **ap
;
61 char *arguments
[50], **argp
;
64 setbuf(stdout
, _sobuf
);
68 if (chdir (NEWSP
) < 0) { /* <-- N.B. */
69 fprintf(stderr
, "Can't change directory to ");
74 cp
= r1bindex(argv
[0], '/');
75 if((cp
= m_find(cp
)) != NULL
) {
76 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
77 ap
= copyip(ap
, arguments
);
80 VOID
copyip(argv
+1, ap
);
84 switch(smatch(++cp
, switches
)) {
85 case -2:ambigsw(cp
, switches
); /* ambiguous */
88 case -1:vec
[vecp
++] = --cp
; continue;
90 case 5: fsend
= YES
; continue;
92 vec
[vecp
++] = --cp
; continue;
93 case 2: fcheck
= YES
; continue;
94 case 3: fdisplay
= YES
; continue;
95 case 4: freview
= YES
;
96 if(**argp
>= '0' && **argp
<= '9')
97 frevback
= atoi(*argp
++);
99 case 7: fupdate
= YES
; continue;
109 VOID
addtopic (cp
, YES
);
116 /* user didn't specify topics so give him his defaults */
121 "news [topic ...] [switches] [switches for \"c\" or \"mail\" ]", switches
);
130 fprintf(stderr
, "Usage: news -send topic [mail switches]\n");
133 for(i
= 0; i
< topicp
; i
++)
137 printf("Unknown topic: %s\n", topics
[i
]);
140 for(i
= 0; i
< topicp
; i
++)
141 if(check(topics
[i
]) == NULL
)
142 printf("Topic: %s unknown.\n", topics
[i
]);
144 disp(topics
[i
], fverbose
|| topicspec
);
148 } else if(!hit
&& !topicspec
&& !fupdate
&& !fdisplay
)
159 register struct nts
*t
;
161 for(t
= nts
; t
->t_name
[0]; t
++)
162 if(strncmp(topic
, t
->t_name
, DIRSIZ
) == 0)
169 register char *topic
;
172 register struct nts
*t
;
173 register char *cp
, *np
;
178 if((t
= check(topic
)) == 0)
179 fprintf(stderr
, "HUH?\n");
180 if((cp
= m_find(np
= concat("news-", topic
, NULLCP
))) == NULL
)
184 if(t
->t_num
> high
) {
186 printf("Unread news in");
189 printf(" '%s'", topic
);
194 if(t
->t_num
> high
) {
195 m_replace(np
, getcpy(m_name(t
->t_num
)));
196 printf("Skipping %d items in %s.\n",
197 t
->t_num
- high
, topic
);
203 msgnum
= max(high
- frevback
, 0);
208 /*** msgnum = freview? frevback? high - frevback : 0 : high; */
209 if(msgnum
>= t
->t_num
) {
211 printf("%s: no new news.\n", topic
);
214 VOID
sprintf(buf
, "%s/%s", NEWSP
, topic
);
215 if(chdir(buf
) == -1) {
220 for( ; msgnum
< t
->t_num
;) {
221 cp
= m_name(++msgnum
);
223 printf("\nPress <return> for %s:%s...", topic
, cp
);
225 VOID
read(0, buf
, sizeof buf
);
227 printf("News item %s:%s\n", topic
, cp
);
229 m_replace(np
, getcpy(cp
));
232 putenv("mhfolder", topic
);
244 register int pid
, child
;
248 while((child
= fork()) == -1) {
249 printf("No forks...\n"); VOID
fflush(stdout
);
253 execv(vector
[0], vector
);
257 while((pid
= wait(&status
)) != -1 && pid
!= child
) ;
258 if(pid
== -1 || status
) {
259 fprintf(stderr
, "Abnormal termination from %s\n", vector
[0]);
266 register char *topic
;
269 vec
[1] = concat("news.", topic
, NULLCP
);
271 printf("Enter text for %s\n", topic
);
283 "News reporters on strike",
284 "Report your own news",
285 "News presses broken"
287 #define NONS (sizeof nons/ sizeof nons[0])
293 #include <sys/timeb.h>
297 printf("%s.\n", nons
[tb
.millitm
% NONS
]);
299 printf("No new news.\n");
308 printf("Chk Items Topics\n");
309 printf("--- ----- ------\n");
310 for(i
= 0; i
< nnts
; i
++)
311 printf(" %s %4d %s\n",
312 addtopic (ntps
[i
]->t_name
, NO
) ? "*" : " ",
313 ntps
[i
]->t_num
, ntps
[i
]->t_name
);
322 VOID
addtopic ("everyone", YES
);
323 if((cp
= m_find("news-topics")) != NULL
) {
324 for (ap
= brkstring (cp
= getcpy(cp
), " ", "\n")
326 VOID
addtopic (*ap
, YES
);
337 for (cpp
= topics
; *cpp
; cpp
++)
338 if (!strcmp (*cpp
, cp
))
339 return YES
; /* We have it already */
341 if (!strcmp ("*", cp
)) {
344 for(i
= 0; i
< nnts
; i
++)
345 VOID
addtopic (nts
[i
].t_name
, YES
);
347 else if (topicp
< MAXTOPICS
- 1)
348 topics
[topicp
++] = cp
;
350 return NO
; /* We don't have it already */
355 /* shouldn't ALWAYS look up all news folders.
356 * Should only do that for a -topics or -help.
360 register struct nts
*t
;
362 char tbuf
[DIRSIZ
+ 2];
365 /* we've done it already */
368 if((d
= fopen(".", "r")) == NULL
) {
369 fprintf(stderr
, "Can't open ");
374 while(fread((char *)&dir
, sizeof dir
, 1, d
)) {
375 if(dir
.d_ino
&& dir
.d_name
[0] != '.') {
376 strncpy(t
->t_name
, dir
.d_name
, DIRSIZ
);
377 strcpy(&tbuf
[1], t
->t_name
);
378 if(stat(tbuf
, &st
) != -1)
379 t
->t_num
= st
.st_size
;
393 for (i
= 0; i
< nnts
; i
++)
395 qsort ((char *) ntps
, nnts
, sizeof ntps
[0], ntcmp
);
403 return strcmp ((*n1
)->t_name
, (*n2
)->t_name
);