1 #include <config.h>
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <errno.h>
6 #include <string.h>
7 #include "suck_config.h"
8
9 /* get news data from stdin and post it to the local server */
10
main(int argc,char * argv[])11 int main(int argc,char *argv[]) {
12 FILE *pfp=NULL;
13 const int max_len = 1024;
14 char line[max_len];
15 int count=0,verbose=0, retval=0;
16 size_t len;
17
18 if (argc>1) {
19 verbose=1;
20 }
21
22 while(fgets(line, max_len, stdin) != NULL && retval == 0) {
23 len=strlen(line);
24 if (pfp == NULL) {
25 if (verbose != 0) {
26 printf("posting article %d\n", ++count);
27 }
28 pfp = popen(RNEWS, "w");
29 }
30 if(pfp == NULL) {
31 perror("Error: cannot open rnews: ");
32 retval = -1;
33 }
34 else if (line[0] == '.' && len == 1) {
35 /* end of article */
36 if (verbose != 0) {
37 printf("end of article %d\n",count);
38 }
39 if(pfp != NULL) {
40 pclose(pfp);
41 pfp = NULL;
42 }
43 }
44 else {
45 (void) fputs(line, pfp);
46 }
47 } /* end while */
48 exit(retval);
49 }
50