|
|
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 k
Length: 2286 (0x8ee)
Types: TextFile
Names: »key.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Yahtzee/key.c«
#include "types.h"
#include <ctype.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/timeb.h>
static int esc_used,sg;
static char refr=12;
static char *ku,*kd,*kl,*kr,*ks,*ke,*so,*se;
static myout(c) char c; { putchar(c); }
extern int select;
static
readkey()
{
char c;
int i;
i = read(0, &c, 1);
if(i < 0) return(i);
else return(c);
}
key()
{
int i=1,j;
char c,ttt[10];
struct timeb begin,end;
int x,y;
while(1) {
c=readkey();
if(c == refr) wrefresh(curscr);
if(c != -1 && c != refr) break;
}
ttt[0] = c;
ttt[1] = 0;
if(c == 033 && esc_used) {
while(1) {
ftime(&begin);
while((c=readkey()) == -1) {
ftime(&end);
if(timeout(&begin,&end))
if(c==ESC || i==1) return(ESC);
else return(ERR_KEY);
}
ttt[i++]=c;
ttt[i]=0;
if(!strcmp(ttt,ku)) return(UP_ARROW);
else if(!strcmp(ttt,kd)) return(DN_ARROW);
else if(!strcmp(ttt,kl)) return(LF_ARROW);
else if(!strcmp(ttt,kr)) return(RT_ARROW);
}
} else {
if(!strcmp(ttt,ku)) return(UP_ARROW);
else if(!strcmp(ttt,kd)) return(DN_ARROW);
else if(!strcmp(ttt,kl)) return(LF_ARROW);
else if(!strcmp(ttt,kr)) return(RT_ARROW);
else return(c);
}
}
timeout(b,e)
struct timeb *b,*e;
{
long c,d;
if(b->time == e->time) {
if((e->millitm - b->millitm) > 500) return(1);
else return(0);
} else {
c = ((e->time - b->time) * 1000) + e->millitm;
d = (long) b->millitm;
if((c-d) > 500) return(1);
else return(0);
}
}
initkey(del1,del2)
char *del1, *del2;
{
char *malloc(), *getenv(), *tgetstr(), *p, *op;
int myout(),i;
/*
i = fcntl(0, F_GETFL, 0);
i |= FNDELAY;
fcntl(0, F_SETFL, i);
*/
*del1 = 8;
*del2 = 127;
op = malloc(400);
p = malloc(1024);
tgetent(p, getenv("TERM"));
ku = tgetstr("ku", &op);
kd = tgetstr("kd", &op);
kl = tgetstr("kl", &op);
kr = tgetstr("kr", &op);
ks = tgetstr("ks", &op);
ke = tgetstr("ke", &op);
so = tgetstr("so", &op);
se = tgetstr("se", &op);
sg = tgetnum("sg");
if(ks) tputs(ks, 1, myout);
free(p);
esc_used = (ku[0] == 033);
if(kr[0]==8 || kl[0]==8 || ku[0]==8 || kd[0]==8) *del1 = 127;
if(kr[0]==12 || kl[0]==12 || ku[0]==12 || kd[0]==12) refr = 18;
}
endkey()
{
int myout(),i;
if(ke) tputs(ke, 1, myout);
i = fcntl(0, F_GETFL, 0);
i &= ~FNDELAY;
i = fcntl(0, F_SETFL, i);
}