|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 4015 (0xfaf)
Types: TextFile
Names: »master_talk.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Bridge/master_talk.c«
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include "talk.h"
#include <sys/time.h>
extern int errno;
xwin_t comwin[19];
int inport[5], outport[5], pid[5];
int INPORT, OUTPORT, ID;
int INEND,OUTEND;
char player[4][20];
char *getlogin(),*cp;
char *current_state;
long seed;
struct timeval wait;
int readmask;
main(argc, argv)
int argc;
char *argv[];
{ int fides1[2], fides2[2],endpipe[2];
int i,j, rtn, nb ,wp,read_set,read_template;
char ins[40],ch;
BMSG buf;
int nbuf=sizeof buf;
struct sgttyb tty;
struct ltchars ltc;
struct timeval wait;
int inmask[4], sinmask, readmask, readtmp,intyp;
char inp[40],*cp,tbuf[10];
time(&seed);
pipe(endpipe);
for (i=0; i<=4; i++){
rtn = pipe(fides1);
if (rtn == -1){
printf("Error in pipe1, errno = %d\n", errno);
exit(-1);
};
rtn = pipe(fides2);
if (rtn == -1){
printf("Error in pipe2, errno = %d\n", errno);
exit(-1);
};
for (pid[i]=fork(); pid[i]<0;pid[i]=fork());
if (pid[i] == 0){
ID = i;
INPORT = fides1[0];
OUTPORT = fides2[1];
switch(i){
case 4: INEND=endpipe[0];
bridge();
exit();
case 3: OUTEND=endpipe[1];
init_disp();
talk1();
exit();
case 2:
case 1:
case 0:
comm(2, &argv[i]);
exit();
}
};
inport[i] = fides2[0];
outport[i] = fides1[1];
cp=(char *)player[i];cp+=2;
if(i==3)strncpy(cp, getlogin(), 6);
if (i<3){strncpy(cp, argv[i+1], 6);
do{
rtn = read(inport[i], tbuf, 10);
}while(rtn <= 1);
}
};
read_template=0; wp=0; ins[0]=ins[1]=ins[2]=0;
for(i=0;i<=4;++i){read_template|=(1<<inport[i]);}
forever{
read_set=read_template;
wait.tv_sec=100000;
select(32,&read_set,0,0,&wait);
for(i=0;i<=3;++i){
if(!(read_set&(1<<inport[i]))) continue;
nb=read(inport[i],&buf,nbuf);
if(nb==nbuf){
if(TYPE==64)exit();
if(TYPE){
if(!(wp&(1<<i))) continue;
wp-=(1<<i);
for(j=0;j<=2;++j) ins[j]|=STR[j];
}
else{
for(j=0;j<=3;++j){
WN=14+(j-i+6)%4;
if(i!=j){
write(outport[j],&buf,sizeof buf);
}
}
}
}
}
if(read_set&(1<<inport[4])){
nb=read(inport[4],&buf,nbuf);
if(nb==nbuf){
intyp=TYPE;
for(i=0;i<=3;++i){
if(TYPE&(1<<i)) write(outport[i],&buf,nbuf);
}
if(TYPE>15) wp=TYPE&15; else wp=0;
ins[0]=ins[1]=ins[2]=0;
}
}
if(intyp<32&&intyp>15 && wp ==0){
strncpy(STR,ins,3);
write(outport[4],&buf,nbuf);intyp=0;}
if(intyp>31&&((intyp&15)^wp)){
write(outport[4],&buf,nbuf);intyp=0;}
}
}
comm(argc, argv)
int argc;
char *argv[];
{ char string[10];
get_names(argc, argv);
open_ctl();
open_sockt();
start_msgs();
if ( !check_local() ) {
invite_remote();
}
end_msgs();
write(OUTPORT, string, 10);
talk();
}
rsend(p, ww, rr, cc, s)
int p, ww, rr, cc;
char *s;
{ BMSG buf;
int nbuf = sizeof buf, rtn;
char w, r, c;
w = ww; r = rr; c = cc;
WN = w; ROW = r; COL = c; TYPE = p; strcpy(STR, s);
rtn = write(OUTPORT, &buf, nbuf);
if (rtn <= 0){
printf("lost pipe write %d, %d", p, errno);
exit();
};
}
rput(p,w,r,c,s)
int p,w,r,c;
char *s;
{
rsend(1<<p,w,r,c,s);
}
rwait(p, s, t)
int p;
long t;
char *s;
{
char ch;
int readset=0,rtn;
struct timeval wait;
BMSG buf;
if(t<100)p+=16;
rsend(p+16,12,0,0,s);
wait.tv_sec=0;
readset=(1<<INPORT);
while(select(32,&readset,0,0,&wait)>0){
wait.tv_sec=0;
read(INPORT,&buf,sizeof buf);
readset=(1<<INPORT);
}
wait.tv_sec=t;
wait.tv_usec=0;
readset=(1<<INPORT)|(1<<INEND);
rtn=select(32,&readset,0,0,&wait);
if (rtn>0){
if(readset&(1<<INEND)) exit();
read(INPORT,&buf,sizeof buf);
strncpy(s,STR,3);
}
return(rtn);
}
rget(p, s)
int p;
char *s;
{
rwait(p,s,99999);
}