fix all the <time.h> vs. <sys/time.h> issues, hopefully
[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
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
24 # include <time.h>
25 #else
26 # if HAVE_SYS_TIME_H
27 #  include <sys/time.h>
28 # else
29 #  include <time.h>
30 # endif
31 #endif
32
33 #include "citadel.h"
34
35 void get_config(void);
36 struct config config;
37
38 int main(int argc, char **argv)
39 {
40         int a;
41         char flnm[128],tname[128];
42         FILE *minput, *mout;
43         char compressed_input = 0;
44         char spool_only = 0;
45
46         get_config();
47         sprintf(flnm,"./network/spoolin/rcit.%ld", (long)getpid());
48         strcpy(tname, tmpnam(NULL));
49
50         for (a=1; a<argc; ++a) {
51                 if (!strcmp(argv[a],"-z")) compressed_input = 1;
52                 if (!strcmp(argv[a],"-s")) spool_only = 1;
53         }
54
55         minput=stdin;
56         if (compressed_input) minput=popen(UNCOMPRESS,"r");
57         if (minput==NULL) fprintf(stderr,"rnews: can't open input!!!!\n");
58
59         mout=fopen(flnm,"w");
60         while ((a=getc(minput))>=0) putc(a,mout);
61         putc(0,mout);
62         fclose(mout);
63
64         unlink(tname);
65         if (compressed_input) pclose(minput);
66         if (!spool_only) execlp("./netproc", "netproc", "-i", NULL);
67         exit(0);
68 }
69
70