Commit | Line | Data |
---|---|---|
0f4556f1 C |
1 | /* |
2 | * Batch: program to batch a list of news articles into an unbatch script. | |
3 | * Usage: /usr/lib/news/batch listfile | |
4 | * where listfile is a file containing a list, one per line, of full | |
5 | * path names of files containing articles, e.g. as produced by the F | |
6 | * transmission option in the sys file. | |
7 | * Output is placed on standard output. | |
8 | * | |
9 | * Intended usage: | |
10 | * uux -c -z -r rmt!rnews '<' =/usr/lib/news/batchnews_/usr/spool/outnews/rmt | |
11 | * where the -c option and the = notation require local mods to uucp. | |
12 | * This would be invoked every hour or two from crontab. | |
13 | * | |
14 | * Other possible usage: | |
15 | * /usr/lib/news/batchnews /usr/spool/outnews/rmt | uux - -z -r rmt!rnews | |
16 | * Also invoked from crontab every hour or two. This requires no changes | |
17 | * to your uucp, but eats up disk space storing copies of the articles | |
18 | * in the spool directory. The method you choose is transparent to the | |
19 | * other end, but the other end must be expecting this batching format. | |
20 | */ | |
21 | static char *sccsid = "@(#)batch.c 1.3 4/3/83"; | |
22 | #include <stdio.h> | |
23 | #include <sys/types.h> | |
24 | #include <sys/stat.h> | |
25 | #include "defs.h" | |
26 | struct stat sbuf; | |
27 | ||
28 | main(argc,argv) | |
29 | char **argv; | |
30 | { | |
31 | register FILE *fd, *nfd; | |
32 | register int c; | |
33 | register char *cp; | |
34 | char fname[512]; | |
35 | char *index(); | |
36 | ||
37 | if (argc != 2) { | |
38 | fprintf(stderr, "Usage: batchnews listfile\n"); | |
39 | exit(1); | |
40 | } | |
41 | ||
42 | if (strncmp(BATCHDIR, argv[1], strlen(BATCHDIR))) { | |
43 | fprintf(stderr, "Permission denied - BATCHDIR mismatch\n"); | |
44 | fprintf(stderr, "BATCHDIR %s, arg %s\n", BATCHDIR, argv[1]); | |
45 | exit(2); | |
46 | } | |
47 | ||
48 | fd = fopen(argv[1], "r"); | |
49 | if (fd == NULL) { | |
50 | /* | |
51 | * This is not necessarily an error condition, if the | |
52 | * file doesn't exist perhaps there's just no news. | |
53 | */ | |
54 | perror(argv[1]); | |
55 | exit(2); | |
56 | } | |
57 | ||
58 | while (fgets(fname, sizeof fname, fd) != NULL) { | |
59 | cp = index(fname, '\n'); | |
60 | if (cp) | |
61 | *cp = '\0'; | |
62 | nfd = fopen(fname, "r"); | |
63 | if (nfd == NULL) { | |
64 | printf(": cannot open %s\n", fname); | |
65 | continue; | |
66 | } | |
67 | fstat(fileno(nfd), &sbuf); | |
68 | printf("#! rnews %ld\n", sbuf.st_size); | |
69 | while ((c = getc(nfd)) != EOF) | |
70 | putchar(c); | |
71 | fclose(nfd); | |
72 | } | |
73 | fclose(fd); | |
74 | ||
75 | /* | |
76 | * We have reached EOF. We assume that even if more news | |
77 | * came in while we were generating this, we got it. So | |
78 | * it's safe to truncate the file. | |
79 | */ | |
80 | close(creat(argv[1], 0666)); | |
81 | exit(0); | |
82 | } |