-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlpost.c
49 lines (44 loc) · 936 Bytes
/
lpost.c
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
49
#include <config.h>
#include <stdlib.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;
const int max_len = 1024;
char line[max_len];
int count=0,verbose=0, retval=0;
size_t len;
if (argc>1) {
verbose=1;
}
while(fgets(line, max_len, stdin) != 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);
}
} /* end while */
exit(retval);
}