#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);
}


syntax highlighted by Code2HTML, v. 0.9.1