* lots of warning fixes; builds with -std1 on dec unix
[citadel.git] / citadel / aidepost.c
1 /* aidepost.c
2  * This is just a little hack to copy standard input to a message in Aide>
3  * v1.6
4  */
5
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <stdio.h>
9 #include <time.h>
10 #include <limits.h>
11 #include "citadel.h"
12 #include "config.h"
13
14 void make_message(char *filename)
15 {
16         FILE *fp;
17         int a;
18         long bb,cc;
19         time_t now;
20         time(&now);
21         fp=fopen(filename,"wb"); if (fp==NULL) exit(22);
22         putc(255,fp);
23         putc(MES_NORMAL,fp);
24         putc(1,fp);
25         fprintf(fp,"Proom_aide"); putc(0,fp);
26         fprintf(fp,"T%ld",now); putc(0,fp);
27         fprintf(fp,"ACitadel"); putc(0,fp);
28         fprintf(fp,"OAide"); putc(0,fp);
29         fprintf(fp,"N%s",NODENAME); putc(0,fp);
30         putc('M',fp);
31         bb=ftell(fp);
32         while (a=getc(stdin), a>0) {
33                 if (a!=8) putc(a,fp);
34                 else {
35                         cc=ftell(fp);
36                         if (cc!=bb) fseek(fp,(-1L),1);
37                         }
38                 }
39         putc(0,fp);
40         putc(0,fp);
41         putc(0,fp);
42         fclose(fp);
43         }
44
45 int main(int argc, char **argv)
46 {
47         char tempbase[32];
48         char temptmp[64];
49         char tempspool[64];
50         char movecmd[256];
51         
52         get_config();
53         sprintf(tempbase,"ap.%d",getpid());
54         sprintf(temptmp,"/tmp/%s", tempbase);
55         sprintf(tempspool,"./network/spoolin/%s", tempbase);
56         make_message(temptmp);
57
58         sprintf(movecmd, "/bin/mv %s %s", temptmp, tempspool);
59         system(movecmd);
60
61         execlp("./netproc","netproc",NULL);
62         fprintf(stderr,"aidepost: could not run netproc\n");
63         exit(1);
64         }