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.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-10-04
|
10KB
|
548 lines
# include <stdio.h>
# define U(x) x
# define NLSTATE yyprevious=YYNEWLINE
# define BEGIN yybgin = yysvec + 1 +
# define INITIAL 0
# define YYLERR yysvec
# define YYSTATE (yyestate-yysvec-1)
# define YYOPTIM 1
# define YYLMAX 200
# define output(c) putc(c,yyout)
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==13?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
# define yymore() (yymorfg=1)
# define ECHO fprintf(yyout, "%s",yytext)
# define REJECT { nstr = yyreject(); goto yyfussy;}
int yyleng; extern char yytext[];
int yymorfg;
extern char *yysptr, yysbuf[];
int yytchar;
FILE *yyin ={stdin}, *yyout ={stdout};
extern int yylineno;
struct yysvf {
struct yywork *yystoff;
struct yysvf *yyother;
int *yystops;};
struct yysvf *yyestate;
extern struct yysvf yysvec[], *yybgin;
/* 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++;
}
}
# define YYNEWLINE 13
yylex(){
int nstr; extern int yyprevious;
while((nstr = yylook()) >= 0)
yyfussy: switch(nstr){
case 0:
if(yywrap()) return(0); break;
case 1:
;
break;
case 2:
;
break;
case 3:
return(CLEAR);
break;
case 4:
return(LOCK);
break;
case 5:
return(OK);
break;
case 6:
;
break;
case -1:
break;
default:
fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }
/* end of yylex */
int yyvstop[] ={
0,
1,
0,
1,
0,
6,
0,
1,
0,
-2,
0,
2,
0,
-5,
0,
5,
0,
4,
0,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,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 0,0, 0,0,
0,0, 0,0, 10,0, 0,0,
0,0};
struct yysvf yysvec[] ={
0, 0, 0,
yycrank+1, 0, yyvstop+1,
yycrank+0, yysvec+1, yyvstop+3,
yycrank+0, 0, yyvstop+5,
yycrank+2, 0, yyvstop+7,
yycrank+-58, 0, yyvstop+9,
yycrank+62, 0, 0,
yycrank+12, 0, 0,
yycrank+10, 0, 0,
yycrank+0, 0, yyvstop+11,
yycrank+-123, 0, yyvstop+13,
yycrank+56, 0, 0,
yycrank+59, 0, 0,
yycrank+0, 0, yyvstop+15,
yycrank+62, 0, 0,
yycrank+53, 0, 0,
yycrank+47, 0, 0,
yycrank+0, 0, yyvstop+17,
yycrank+0, 0, yyvstop+19,
0, 0, 0};
struct yywork *yytop = yycrank+250;
struct yysvf *yybgin = yysvec+1;
char yymatch[] ={
00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,015 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
040 ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
'0' ,'0' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,
'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,'!' ,01 ,
0};
char yyextra[] ={
0,0,1,0,0,1,0,0,
0};
/* ncform 4.1 83/08/11 */
int yylineno =1;
# define YYU(x) x
# define NLSTATE yyprevious=YYNEWLINE
char yytext[YYLMAX];
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
char yysbuf[YYLMAX];
char *yysptr = yysbuf;
int *yyfnd;
extern struct yysvf *yyestate;
int yyprevious = YYNEWLINE;
yylook(){
register struct yysvf *yystate, **lsp;
register struct yywork *yyt;
struct yysvf *yyz;
int yych;
struct yywork *yyr;
# ifdef LEXDEBUG
int debug;
# endif
char *yylastch;
/* start off machines */
# ifdef LEXDEBUG
debug = 0;
# endif
if (!yymorfg)
yylastch = yytext;
else {
yymorfg=0;
yylastch = yytext+yyleng;
}
for(;;){
lsp = yylstate;
yyestate = yystate = yybgin;
if (yyprevious==YYNEWLINE) yystate++;
for (;;){
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
# endif
yyt = yystate->yystoff;
if(yyt == yycrank){ /* may not be any transitions */
yyz = yystate->yyother;
if(yyz == 0)break;
if(yyz->yystoff == yycrank)break;
}
*yylastch++ = yych = input();
tryagain:
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"char ");
allprint(yych);
putchar('\n');
}
# endif
yyr = yyt;
if ( (int)yyt > (int)yycrank){
yyt = yyr + yych;
if (yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
}
# ifdef YYOPTIM
else if((int)yyt < (int)yycrank) { /* r < yycrank */
yyt = yyr = yycrank+(yycrank-yyt);
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"compressed state\n");
# endif
yyt = yyt + yych;
if(yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transitions */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
yyt = yyr + YYU(yymatch[yych]);
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"try fall back character ");
allprint(YYU(yymatch[yych]));
putchar('\n');
}
# endif
if(yyt <= yytop && yyt->verify+yysvec == yystate){
if(yyt->advance+yysvec == YYLERR) /* error transition */
{unput(*--yylastch);break;}
*lsp++ = yystate = yyt->advance+yysvec;
goto contin;
}
}
if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
# ifdef LEXDEBUG
if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
# endif
goto tryagain;
}
# endif
else
{unput(*--yylastch);break;}
contin:
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"state %d char ",yystate-yysvec-1);
allprint(yych);
putchar('\n');
}
# endif
;
}
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
allprint(yych);
putchar('\n');
}
# endif
while (lsp-- > yylstate){
*yylastch-- = 0;
if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
yyolsp = lsp;
if(yyextra[*yyfnd]){ /* must backup */
while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
lsp--;
unput(*yylastch--);
}
}
yyprevious = YYU(*yylastch);
yylsp = lsp;
yyleng = yylastch-yytext+1;
yytext[yyleng] = 0;
# ifdef LEXDEBUG
if(debug){
fprintf(yyout,"\nmatch ");
sprint(yytext);
fprintf(yyout," action %d\n",*yyfnd);
}
# endif
return(*yyfnd++);
}
unput(*yylastch);
}
if (yytext[0] == 0 /* && feof(yyin) */)
{
yysptr=yysbuf;
return(0);
}
yyprevious = yytext[0] = input();
if (yyprevious>0)
output(yyprevious);
yylastch=yytext;
# ifdef LEXDEBUG
if(debug)putchar('\n');
# endif
}
}
yyback(p, m)
int *p;
{
if (p==0) return(0);
while (*p)
{
if (*p++ == m)
return(1);
}
return(0);
}
/* the following are only used in the lex library */
yyinput(){
return(input());
}
yyoutput(c)
int c; {
output(c);
}
yyunput(c)
int c; {
unput(c);
}