[go: up one dir, main page]

File: lpost.c

package info (click to toggle)
suck 4.3.2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 1,568 kB
  • ctags: 1,448
  • sloc: ansic: 12,075; perl: 528; sh: 363; makefile: 350; java: 144
file content (48 lines) | stat: -rw-r--r-- 894 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <config.h>

#include <stdio.h>
#include <errno.h>	
#include <string.h>
#include "suck_config.h"

/* get news data from stdin and post it to the local server */

int main(int argc,char *argv[]) {
	FILE *pfp=NULL;
	char line[1024];
	int count=0,verbose=0, retval=0;
	size_t len;

	if (argc>1)  {
		verbose=1;
	}

	while(gets(line) != NULL && retval == 0) {
  		len=strlen(line);
		if (pfp == NULL) {
			if (verbose != 0) {
				printf("posting article %d\n", ++count);
			}
			pfp = popen(RNEWS, "w");
		}
		if(pfp == NULL) {
			perror("Error: cannot open rnews: ");
			retval = -1;
		}
		else if (line[0] == '.' && len == 1) {
			/* end of article */
			if (verbose != 0) {
				printf("end of article %d\n",count);
			}
			if(pfp != NULL) {
				pclose(pfp);
				pfp = NULL;
			}
		}
		else {
			(void) fputs(line, pfp);
			(void) putc('\n', pfp);
		}
	} /* end while */
	exit(retval);
}