home *** CD-ROM | disk | FTP | other *** search
- /*
- * backwater - print file names for articles that got stuck in a net backwater
- */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/timeb.h>
- #include <sys/stat.h> /* for modified time (date received) */
- #include <string.h>
- #include "config.h"
- #include "fgetmfs.h"
- #include "alloc.h"
- #include "case.h"
-
- #define STRLEN(s) (sizeof(s) - 1) /* s must be a char array */
- #define DAYSECS (60*60*24L)
-
- long dateoffset = DAYSECS*10;
- char *progname;
- int debug;
- struct timeb ftnow; /* ftime() result for getdate() */
-
- FILE *efopen();
-
- char *spdir;
- int spdirlen;
-
- /*
- * main - parse arguments and handle options
- */
- main(argc, argv)
- int argc;
- char *argv[];
- {
- int c;
- int errflg = 0;
- FILE *in;
- char *inname;
- extern int optind;
- extern char *optarg;
-
- progname = argv[0];
- ftime(&ftnow);
- while ((c = getopt(argc, argv, "d")) != EOF)
- switch (c) {
- case 'd':
- ++debug;
- break;
- default:
- errflg++;
- break;
- }
- if (optind < argc) {
- dateoffset=atoi(argv[optind++])*DAYSECS;
- if (dateoffset<DAYSECS) ++errflg;
- }
- if (optind < argc || errflg) {
- (void) fprintf(stderr, "usage: %s [-d] [days]\n", progname);
- exit(2);
- }
-
- spdir = artfile((char *)NULL);
- spdirlen = strlen(spdir);
-
- while ((inname = fgetms(stdin)) != NULL) {
- inname[strlen(inname)-1] = '\0'; /* kill newline */
- if (strchr(inname, '.') == NULL) { /* skip dot names */
- in = efopen(inname, "r");
- process(in, inname);
- (void) fclose(in);
- }
- free(inname);
- }
- exit(0);
- }
-
- /*
- * process - process input file
- */
- process(in, inname)
- FILE *in;
- char *inname;
- {
- char *name;
- char *line;
- char *date;
- time_t datercv,origdate;
- struct stat statb;
- static char datenm[] = "Date: ";
- register char *p;
-
- date = NULL;
-
- /* read until EOF or blank line (end of headers) */
- while ((line = fgetms(in)) != NULL && strcmp(line, "\n") != 0) {
- line[strlen(line)-1] = '\0'; /* trim newline */
- if (CISTREQN(line, datenm, STRLEN(datenm))) {
- if (date != NULL)
- free(date);
- date = strsave(line+STRLEN(datenm));
- }
- free(line);
- }
- if (line != NULL)
- free(line);
-
- if (date!=NULL) {
- /* generate the date received */
- (void) fstat(fileno(in), &statb);
- datercv = statb.st_mtime;
-
- /* find out when it was posted */
- origdate = getdate(date, &ftnow);
-
- if (origdate == -1)
- fprintf(stderr,"%s: Invalid date in %s:`%s'\n",progname,inname,date);
- else if (origdate+dateoffset<datercv) {
- /* whomp out the file name */
- (void) fputs(inname, stdout);
- (void) putchar('\n');
- (void) fflush(stdout);
- }
- free(date);
- }
- }
-
- /*
- * unprivileged - no-op to keep pathname stuff happy
- */
- void
- unprivileged(reason)
- char *reason;
- {
- }
-