#include #include #include #include #include #include #include "graf/graf.h" #define KB_BACKSPACE (int)'\b' /* kb */ #define KB_ENTER (int)'\r' /* RT */ #define KB_TAB (int)'\t' /* TB */ #define KB_ESC 0x1b /* EC */ #define KB_HOME -71 /* kh or HM */ #define KB_END -79 /* EN */ #define KB_UP -72 /* ku or UP */ #define KB_DOWN -80 /* kd */ #define KB_LEFT -75 /* kl */ #define KB_RIGHT -77 /* kr */ #define KB_PGUP -73 /* PU */ #define KB_PGDN -81 /* PD */ #define KB_BACK_TAB -15 /* BT */ #define KB_INS -82 /* al */ #define KB_DEL -83 /* DL */ #define KB_F1 -59 /* k1 */ #define KB_F2 -60 /* k2 */ #define KB_F3 -61 /* k3 */ #define KB_F4 -62 /* k4 */ #define KB_F5 -63 /* k5 */ #define KB_F6 -64 /* k6 */ #define KB_F7 -65 /* k7 */ #define KB_F8 -66 /* k8 */ #define KB_F9 -67 /* k9 */ #define KB_F10 -68 /* k0 */ #define KB_STR_EXISTS 1 /* string exists in tree or his prefix */ #define KB_TOO_MANY_STRINGS 2 #define KB_NULL_STRING 3 #define KB_OUT_OF_MEMORY 4 #define KB_OK 0 #include "depend.h" #include "genint.h" #include "int.h" #include "process.h" #include "intproto.h" #define TERMINAL 0 #define KEYBOARD 1 static char *capability,*capability_value; typedef struct _tree_node *tree; /* drzewo zawierajace ciagi znakow */ struct _tree_node { /* odpowiadajace klawiszowi klawiatury */ int key; tree way; int outkey; }; #ifndef NO_PROTOTYPES static int tfirst(int); static int tnext(void); static void *___allocate_object(unsigned); static void ___free_object(void *); static char *object_str(char *); /* allocate space and copy string */ static int __testkey(int*,int*); static int getkey(void); static int __inkey(void); static void kbinit(void); static tree new_tree_node(void); static int _create_new_leaf(tree,int,unsigned char *,int); static int inskey(int,char *); #else static int tfirst(); static int tnext(); static void *___allocate_object(); static void ___free_object(); static char *object_str(); static int __testkey(); static int getkey(); static int __inkey(); static void kbinit(); static tree new_tree_node(); static int _create_new_leaf(); static int inskey(); #endif #define object_kill(i) (___free_object(i),(i)=NULL) #define object_new(type) ((type *)___allocate_object(sizeof(type))) #define object_dim(i,type) ((type *)___allocate_object((i)*sizeof(type))) #define KB_NDEF 0xff /* KN - key suppressed by inkey() */ #define NODE_SIZE 100 #define QSIZE 256 static int cqueue[QSIZE]; /* implementacja kolejki */ static int qh=0,qt=0,qs=0; static int bget(){ int c; if( qs == 0 ) return -1; c = cqueue[ qh++ ]; qh &= QSIZE - 1 ; qs--; return c; } static void bput( c ) int c; { if( qs == QSIZE ) return; cqueue[ qt++ ] = c; qt &= QSIZE - 1 ; qs++; } static int qq; static int bfirst(){ if( qs == 0 ) return -1; qq = qh + 1 ; qq &= QSIZE - 1 ; return cqueue[ qh ]; } static int bnext(){ int c; if( qq == qt ) return -1; c = cqueue[ qq++ ]; qq &= QSIZE - 1 ; return c; } static tree troot=NULL; #ifndef NDEBUG static FILE *f=NULL; static void _show_tree(root,r) tree root;int r;{ int i,j; for(i=0;(i'7') return 1; *ptr*=8; *ptr+=*(tptr++)-'0'; } ptr++; ptr_size--; } break; case '^': tptr++; c=*(tptr++); *(ptr++)=(char)((toupper(c))-'A'+1); ptr_size--; break; default: *(ptr++)=*(tptr++); ptr_size--; } *ptr='\0'; if( ptr_size<=0 ){ fprintf(stderr,"buffer exceeded in convert(%s)",__FILE__); fflush(stderr); exit(7); } return 0; } /* FUNCTIONS looking for entries in /ETC/TERMCAP */ static char etcname[80]; static char termname[80]; static char *fname; static char *envset(envname,envfile) char *envname,*envfile;{ extern char *getenv(); char *TERM=getenv("TERM"); char *env=getenv(envname); char *str,*ptr; FILE *f; int c,continued=1; ptr=str=object_dim(32000,char); if(str==NULL){ fprintf(stderr,"Out of memory.\n"); fflush(stderr); exit(7); } if(TERM==NULL){ fprintf(stderr,"\n\renvironment variable TERM not found\n\r"); fflush(stderr); exit(7); } strcpy(termname,TERM); f=fopen(env,"r"); if( f==NULL ) f=fopen(envfile,"r"); else fname=env; if( f==NULL ) f=fopen(strcat(strcpy(etcname,"/etc/"),envfile),"r"); else fname=envfile; if( f==NULL ) return NULL; else fname=etcname; while( continued ){ char *rev,*tnm; if( find_name(f,termname)==0 ) return object_str(":"); *(ptr++)=':'; c=' '; do{ c=next_char(f); if( c!='\0' ) *(ptr++)=(char)c; }while( c!='\0' ); *(ptr)='\0'; rev=ptr-1; while( rev>str && rev[-1]!=':' ) rev--; if( rev[0]=='t' && rev[1]=='c' ){ ptr=rev-1; rev+=3; tnm=termname; while( *rev!=':' ) *(tnm++)=*(rev++); *tnm='\0'; continued=1; }else continued=0; } ptr=object_str(str); object_kill(str); return ptr; } static int find_name(f,termname) FILE *f; char *termname;{ int i,c,lastc,found=0; fseek(f,0L,0); do{ do{ c=fgetc(f); if(c==EOF) return 0; if(c=='#' || c=='\t' || c==':' || c=='\n') while(c!='\n'){ lastc=c; c=fgetc(f); if(c==EOF) return 0; if( lastc=='\\' ) c=' '; } }while(c=='\n'); while( !found ){ for(i=0;termname[i]!='\0';i++){ if((char)c!=termname[i]) break; c=fgetc(f); } if( termname[i]=='\0' ){ found=1; break; } while( isalpha((char)c) ) c=fgetc(f); if( c=='|' ) c=fgetc(f); else{ ungetc('#',f); break; } } } while( !found ); while(c!=':'){ c=fgetc(f); if(c==EOF) return 0; } return 1; } static int next_char(f) FILE *f;{ int c; static int lastc='\0'; if( lastc!='\0' ){ c=lastc; lastc='\0'; return c; } c=fgetc(f); if( c==EOF || c=='\n' ) return '\0'; if( c=='\\' ){ c=fgetc(f); if( c=='\n' ){ while( c=='\n' || c=='\t' || c==':' || c==' ' ) c=fgetc(f); return c; } lastc=c; return '\\'; } return c; } static void *___allocate_object(size) unsigned size;{ char *p; extern void *calloc(); if(size==0) return NULL; p=calloc(size,1); if( p==NULL ){ printf("\r\n"); printf("=======================================\r\n"); printf("Memory overflow ... \r\n"); printf("=======================================\r\n"); fflush(stdout); system("stty sane"); exit(7); } return (void *)p; } static void ___free_object(ff) void *ff;{ assert(ff!=NULL); free((char *)ff); } static char *object_str(str) char *str;{ char *buf=object_dim(strlen(str)+1,char); strcpy(buf,str); return buf; } .