/* aidepost.c
 * This is just a little hack to copy standard input to a message in Aide>
 * v1.5
 */

#include <stdio.h>
#include "citadel.h"

struct config config;

make_message(filename)
char *filename; {
	FILE *fp;
	int a;
	long bb,cc,now;
	time(&now);
	fp=fopen(filename,"wb"); if (fp==NULL) exit(22);
	putc(255,fp);
	putc(MES_NORMAL,fp);
	putc(1,fp);
	fprintf(fp,"Proom_aide"); putc(0,fp);
	fprintf(fp,"T%ld",now); putc(0,fp);
	fprintf(fp,"ACitadel"); putc(0,fp);
	fprintf(fp,"OAide"); putc(0,fp);
	fprintf(fp,"N%s",NODENAME); putc(0,fp);
	putc('M',fp);
	bb=ftell(fp);
	while (a=getc(stdin), a>0) {
		if (a!=8) putc(a,fp);
		else {
			cc=ftell(fp);
			if (cc!=bb) fseek(fp,(-1L),1);
			}
		}
	putc(0,fp);
	fclose(fp);
	return(0);
}

main(argc,argv)
int argc;
char *argv[];
{
	char temp[32];
	
	get_config();
	sprintf(temp,"./network/spoolin/ap.%d",getpid());
	make_message(temp);
	execlp("./netproc","netproc",NULL);
	fprintf(stderr,"aidepost: could not run netproc\n");
	exit(1);
	}
