home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum7.lzh
/
C
/
FKEYS
/
fkeys.lex
< prev
next >
Wrap
Text File
|
1988-10-04
|
2KB
|
178 lines
%{
/* fkeys ein Program um bei VT220-kompatiblen Terminals die Funktionstasten zu belegen */
/* */
/* Uwe Simon 2.10.88 */
#include <ctype.h>
#define OK 10
#define ERROR 11
#define LOCK 12
#define CLEAR 13
int key_tab[] = { 17,18,19,20,21,23,24,25,26,28,29,31,32,33,34};
char *handle_back(p)
char *p;
{
char c;
char h;
p++;
h=toupper(*p);
p++;
if(isxdigit(h))
{
c=(h>='A')?h-'A'+10:h-'0';
h=toupper(*p);
if(isxdigit(h))
{
p++;
c = c<<4;
c |= (h>='A')?h-'A'+10:h-'0';
}
}
else
{
switch(toupper(h))
{
case 'N':
c='\n';
break;
case 'T':
c='\t';
break;
default:
c=*p;
break;
}
}
printf("%02x",c);
return(p);
}
char *handle_char(p)
char *p;
{
if(*p == '\\')
p=handle_back(p);
else
{
printf("%02x",*p);
p++;
}
return(p);
}
handle(s)
char *s;
{
int key_nr;
int nr;
char *p;
key_nr=atoi(s);
p=index(s,'=');
p++;
printf("Key %d:%s\n",key_nr,p);
if((key_nr>=6) && (key_nr<=20))
nr=key_tab[key_nr-6];
else
nr=0;
if(nr == 0)
{
printf("illegal Key-number %d\n",key_nr);
return;
}
printf("%cP1;1|%d/",0x1b,nr);
while(*p && (*p != '\n'))
p= handle_char(p);
printf("%c\\",0x1b);
fflush(stdout);
}
line_nr(n)
int n;
{
printf("Line %d:",n);
}
usage()
{
fprintf(stderr,"Syntax: fkeys [<path>]\n");
fprintf(stderr,"Function:set User-Defined Keys on VT220 Terminals\n");
fprintf(stderr,"Options: none\n");
exit(0);
}
yywrap()
{
return(feof(stdin));
}
main(argc, argv)
int argc;
char *argv[];
{
int h;
int line=1;
if(argc > 1)
{
if(strcmp(argv[1], "-?") == 0)
usage();
if(freopen(argv[1],"r", stdin) == NULL)
{
fprintf(stderr,"can't open %s\n", argv[1]);
exit(1);
}
}
cleareof(stdin);
while(h=yylex())
{
switch(h)
{
case OK:
handle(yytext);
break;
case LOCK:
printf("lock\n");
printf("%cP1;0|%c\\",0x1b,0x1b);
break;
case CLEAR:
printf("clear\n");
printf("%cP0;1|%c\\",0x1b,0x1b);
break;
default:
line_nr(line);
printf("Syntax-Error\n");
break;
}
line++;
}
}
%}
%%
[ ]* ;
#[ -~]*$ ;
"clear" return(CLEAR);
"lock" return(LOCK);
[0-9]+=[ -~]*$ return(OK);
[
] ;