|
|
1.1 root 1: /*
2: * unbatchnews: extract news in batched format and process it one article
3: * at a time. The format looks like
4: * #! rnews 1234
5: * article containing 1234 characters
6: * #! rnews 4321
7: * article containing 4321 characters
8: */
9:
10: # include <stdio.h>
11: static char *sccsid = "@(#)unbatch.c 1.3 4/23/83";
12:
13: char buf[512];
14:
15: main(ac, av)
16: char **av;
17: {
18: register int c;
19: register FILE *pfn;
20: register long size;
21: char *filename;
22: int pid, wpid, exstat;
23: char *mktemp();
24: long atol();
25:
26: filename = mktemp("/tmp/unbnewsXXXXXX");
27: while(gets(buf) != NULL) {
28: while (strncmp(buf, "#! rnews ", 9)) {
29: fprintf(stderr, "out of sync, skipping %s\n", buf);
30: if (gets(buf) == NULL)
31: exit(0);
32: }
33: size = atol(buf+9);
34: if(size <= 0)
35: break;
36: pfn = fopen(filename, "w");
37: while(--size >= 0 && (c = getc(stdin)) != EOF)
38: putc(c, pfn);
39: fclose(pfn);
40:
41: /*
42: * If we got a truncated batch, don't process the
43: * last article; it will probably be received again.
44: */
45: if (size > 0)
46: break;
47:
48: /*
49: * rnews < filename
50: */
51: while ((pid = fork()) == -1) {
52: fprintf(stderr, "fork failed, waiting...\r\n");
53: sleep(60);
54: }
55: if (pid == 0) {
56: close(0);
57: open(filename, 0);
58: execlp("rnews", "rnews", 0);
59: perror("rnews");
60: exit(1);
61: }
62: while ((wpid = wait(&exstat)) >= 0 && wpid != pid)
63: ;
64: }
65: unlink(filename);
66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.