c594d6c973cb7de9b8cbf6cff1643337c8909651
[citadel.git] / citadel / rcit.c
1 /* $Id$
2  *
3  * This program simply feeds its standard input to the networker.  It is
4  * used primarily to hook up to UUCP feeds of Citadel data.
5  *
6  * 
7  * usage:
8  *      rcit [-z] [-s]
9  * flags:
10  *      -z      Input is compressed, run uncompress on it before processing
11  *      -s      Don't run netproc now, just accept the input into spoolin
12  */
13
14 #define UNCOMPRESS "/usr/bin/gunzip"
15 #include <stdlib.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <stdio.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include <time.h>
22 #include "citadel.h"
23
24 void get_config(void);
25 struct config config;
26
27 int main(int argc, char **argv)
28 {
29         int a;
30         char flnm[128],tname[128];
31         FILE *minput, *mout;
32         char compressed_input = 0;
33         char spool_only = 0;
34
35         get_config();
36         sprintf(flnm,"./network/spoolin/rcit.%ld", (long)getpid());
37         strcpy(tname, tmpnam(NULL));
38
39         for (a=1; a<argc; ++a) {
40                 if (!strcmp(argv[a],"-z")) compressed_input = 1;
41                 if (!strcmp(argv[a],"-s")) spool_only = 1;
42         }
43
44         minput=stdin;
45         if (compressed_input) minput=popen(UNCOMPRESS,"r");
46         if (minput==NULL) fprintf(stderr,"rnews: can't open input!!!!\n");
47
48         mout=fopen(flnm,"w");
49         while ((a=getc(minput))>=0) putc(a,mout);
50         putc(0,mout);
51         fclose(mout);
52
53         unlink(tname);
54         if (compressed_input) pclose(minput);
55         if (!spool_only) execlp("./netproc", "netproc", "-i", NULL);
56         exit(0);
57 }
58
59