* checknews - news checking program
static char *SccsId
= "@(#)checknews.c 2.15 5/3/83";
char bfr
[BUFLEN
]; /* general-use scratch area */
char optbuf
[BUFLEN
]; /* NEWSOPTS buffer */
char username
[BUFLEN
]; /* user's login name */
char userhome
[BUFLEN
]; /* user's home directory */
char SPOOL
[BUFLEN
]; /* spool directory */
char LIB
[BUFLEN
]; /* library directory */
char ACTIVE
[BUFLEN
]; /* active newsgroups file */
char *NEWSU
= NEWSUSR
; /* login name for netnews */
char *NEWSG
= NEWSGRP
; /* group name for netnews */
int line
= -1, y
, e
, n
, q
;
int verbose
; /* For debugging. */
char newsrc
[BUFLEN
],*rcline
[LINES
],rcbuf
[LBUFLEN
],*argvrc
[LINES
];
struct passwd
*getpwuid();
char *malloc(),*getenv(), *index();
char coptbuf
[BUFLEN
],datebuf
[BUFLEN
];
register char *ptr
; /* pointer to rest of buffer */
int sflag
= 0, optflag
= FALSE
, space
= FALSE
;
for (argv
++; **argv
; ++*argv
) {
if (!n
&& !e
&& !y
&& !q
)
if ((user
= getenv("USER")) == NULL
)
user
= getenv("LOGNAME");
if ((home
= getenv("HOME")) == NULL
)
if (user
== NULL
|| home
== NULL
)
if (ptr
= getenv("NEWSOPTS"))
for (ptr
= rcbuf
;; ptr
++) {
xerror("Too many options.\n");
if ((rcline
[line
] = malloc(strlen(ptr
) + 1)) == NULL
)
xerror("Not enough memory.\n");
argvrc
[line
] = rcline
[line
];
strcpy(rcline
[line
], ptr
);
sprintf(newsrc
, "%s/%s", userhome
, NEWSRC
);
if ((rcfp
= fopen(newsrc
, "r")) != NULL
) {
while (fgets(rcbuf
, LBUFLEN
, rcfp
) != NULL
) {
if (!(space
= isspace(*rcbuf
)))
if (!strncmp(rcbuf
, "options ", 8))
xerror("Too many options.\n");
if ((rcline
[line
] = malloc(strlen(ptr
) + 1)) == NULL
)
xerror("Not enough memory.\n");
argvrc
[line
] = rcline
[line
];
strcpy(rcline
[line
], ptr
);
for (i
= 0; i
<= line
; i
++)
fprintf(stderr
, "options: %s\n", rcline
[i
]);
fprintf(stderr
, "Freeing %d\n", line
);
strcpy(header
.nbuf
, DFLTSUB
);
strcat(header
.nbuf
, ADMSUB
);
makehimask(header
.nbuf
, "junk");
makehimask(header
.nbuf
, "control");
makehimask(header
.nbuf
, "test");
if ((rcfp
= fopen(newsrc
, "r")) == NULL
)
xerror("Cannot open .newsrc file");
while (fgets(rcbuf
, LBUFLEN
, rcfp
) != NULL
) {
xerror(".newsrc line too long");
xerror("Too many .newsrc lines");
if ((rcline
[line
] = malloc(strlen(rcbuf
)+1)) == NULL
)
xerror("Not enough memory");
strcpy(rcline
[line
], rcbuf
);
if ((actfp
= fopen(ACTIVE
, "r")) == NULL
)
xerror("Cannot open active newsgroups file");
fprintf(stderr
, "header.nbuf = %s\n", header
.nbuf
);
fprintf(stderr
, "nchk()\n");
while (fgets(aline
, sizeof aline
, actfp
) != NULL
) {
sscanf(aline
, "%s %ld", bfr
, &narts
);
fprintf(stderr
, "bfr = '%s'\n", bfr
);
if (!ngmatch(bfr
, header
.nbuf
))
printf("No newsrc line for newsgroup %s\n", bfr
);
strcpy(rcbuf
, rcline
[i
]);
if (index(rcbuf
, '!') != NULL
)
if (index(rcbuf
, ',') != NULL
) {
printf("Comma in %s newsrc line\n", bfr
);
while (!isdigit(*--ptr
) && ptr
>= rcbuf
)
printf("Ran off beginning of %s newsrc line.\n", bfr
);
printf("News: %s ...\n", bfr
);
printf("No news is good news.\n");
printf("There is probably news.\n");
printf("There is news.\n");
execv("/usr/bin/readnews", argv
);
execvp("readnews", argv
);
fprintf(stderr
, "Cannot exec readnews.\n");
xerror(message
, arg1
, arg2
)
sprintf(buffer
, message
, arg1
, arg2
);
fprintf(stderr
, "checknews: %s.\n", buffer
);
* Append NGDELIM to string.
* nglist is a list of newsgroups.
* sublist is a list of subscriptions.
* sublist may have "meta newsgroups" in it.
* All fields are NGDELIM separated,
* and there is an NGDELIM at the end of each argument.
* Currently implemented glitches:
* sublist uses 'all' like shell uses '*', and '.' like shell '/'.
* If subscription X matches Y, it also matches Y.anything.
register char *nglist
, *sublist
;
for (n
= nglist
; *n
!= '\0' && rc
== FALSE
;) {
for (s
= sublist
; *s
!= '\0';) {
* Compare two newsgroups for equality.
* The first one may be a "meta" newsgroup.
register char *ng1
, *ng2
;
while (*ng1
!= NGDELIM
) {
if (ng1
[0]=='a' && ng1
[1]=='l' && ng1
[2]=='l') {
while (*ng2
!= NGDELIM
&& *ng2
!= '.')
return (ptrncmp(ng1
, ng2
));
} else if (*ng1
++ != *ng2
++)
return (*ng2
== '.' || *ng2
== NGDELIM
);
* Get user name and home directory.
register struct passwd
*p
;
if ((p
= getpwuid(getuid())) == NULL
)
xerror("Cannot get user's name");
strcpy(username
, p
->pw_name
);
strcpy(userhome
, p
->pw_dir
);
* Strip trailing newlines, blanks, and tabs from 's'.
* Return TRUE if newline was found, else FALSE.
while (--p
>= s
&& (*p
== '\n' || *p
== ' ' || *p
== '\t'));
* Delete trailing NGDELIM.
for (ptr
= s
; *ptr
; ptr
++)
* finds the line in your .newsrc file (actually the in-core "rcline"
* copy of it) and returns the index into the array where it was found.
* -1 means it didn't find it.
* We play clever games here to make this faster. It's inherently
* quadratic - we spend lots of CPU time here because we search through
* the whole .newsrc for each line. The "prev" variable remembers where
* the last match was found; we start the search there and loop around
* to the beginning, in the hopes that the calls will be roughly in order.
for (p
= name
, ptr
= rcline
[i
]; (cur
= *p
++); ) {
if (*ptr
!= ':' && *ptr
!= '!')
if (i
> line
&& line
> prev
-1) {
* Forbid newsgroup ng, unless he asked for it in nbuf.
* Return true if the string searchfor is in string, but not if preceeded by !.
findex(string
, searchfor
)
char *string
, *searchfor
;
for (p
=index(string
, first
); p
; p
= index(p
+1, first
)) {
if (p
>string
&& p
[-1] != '!' && strncmp(p
, searchfor
, strlen(searchfor
)) == 0)