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 >
Text File  |  1988-10-04  |  2KB  |  178 lines

  1. %{
  2. /*  fkeys              ein Program um bei VT220-kompatiblen Terminals die Funktionstasten zu belegen */
  3. /*                                                                                                  */
  4. /*   Uwe Simon        2.10.88                                                                          */
  5.  
  6. #include <ctype.h>
  7. #define OK      10
  8. #define ERROR 11
  9. #define LOCK  12
  10. #define CLEAR 13
  11.  
  12. int key_tab[] = { 17,18,19,20,21,23,24,25,26,28,29,31,32,33,34};
  13.  
  14. char *handle_back(p)
  15. char *p;
  16. {
  17.     char c;
  18.     char h;
  19.     
  20.     p++;
  21.     h=toupper(*p);
  22.     p++;
  23.     if(isxdigit(h))
  24.     {
  25.         c=(h>='A')?h-'A'+10:h-'0';
  26.         h=toupper(*p);
  27.         if(isxdigit(h))
  28.         {
  29.             p++;
  30.             c = c<<4;
  31.             c |= (h>='A')?h-'A'+10:h-'0';
  32.         }
  33.     }
  34.     else
  35.     {
  36.         switch(toupper(h))
  37.         {
  38.             case 'N':
  39.                 c='\n';
  40.                 break;
  41.             
  42.             case 'T':
  43.                 c='\t';
  44.                 break;
  45.             
  46.             default:
  47.                 c=*p;
  48.                 break;
  49.         }
  50.     }
  51.     printf("%02x",c);
  52.     return(p);
  53.     
  54. }
  55.  
  56. char *handle_char(p)
  57. char *p;
  58. {
  59.     if(*p == '\\')
  60.         p=handle_back(p);
  61.     else
  62.     {
  63.         printf("%02x",*p);
  64.         p++;
  65.     }
  66.     return(p);
  67. }
  68.  
  69.  
  70. handle(s)
  71. char *s;
  72. {
  73.         int        key_nr;
  74.         int        nr;
  75.         char    *p;
  76.         
  77.         key_nr=atoi(s);   
  78.         p=index(s,'=');
  79.         p++;
  80.         printf("Key %d:%s\n",key_nr,p);
  81.         if((key_nr>=6) && (key_nr<=20))
  82.             nr=key_tab[key_nr-6];
  83.         else
  84.             nr=0;
  85.             
  86.         if(nr == 0)
  87.         {
  88.             printf("illegal Key-number %d\n",key_nr);
  89.             return;
  90.         }
  91.         
  92.         printf("%cP1;1|%d/",0x1b,nr);
  93.         while(*p && (*p != '\n'))
  94.             p= handle_char(p);
  95.             
  96.         printf("%c\\",0x1b);
  97.         fflush(stdout);
  98. }
  99.  
  100. line_nr(n)
  101. int n;
  102. {
  103.     printf("Line %d:",n);
  104. }
  105.  
  106.  
  107. usage()
  108. {
  109.     fprintf(stderr,"Syntax: fkeys [<path>]\n");
  110.     fprintf(stderr,"Function:set User-Defined Keys on VT220 Terminals\n");
  111.     fprintf(stderr,"Options: none\n");
  112.     exit(0);
  113. }
  114.  
  115.  
  116. yywrap()
  117. {
  118.     return(feof(stdin));
  119. }
  120.  
  121. main(argc, argv)
  122. int argc;
  123. char *argv[];
  124. {
  125.     int h;
  126.     int line=1;
  127.     
  128.     if(argc > 1)
  129.     {
  130.         if(strcmp(argv[1], "-?") == 0)
  131.             usage();
  132.             
  133.         if(freopen(argv[1],"r", stdin) == NULL) 
  134.         {
  135.             fprintf(stderr,"can't open %s\n", argv[1]);
  136.             exit(1);
  137.         }
  138.     }
  139.     cleareof(stdin);
  140.     
  141.     while(h=yylex())
  142.     {
  143.         switch(h)
  144.         {
  145.             case OK:
  146.                 handle(yytext);
  147.                 break;
  148.                 
  149.             case LOCK:
  150.                 printf("lock\n");
  151.                 printf("%cP1;0|%c\\",0x1b,0x1b);
  152.                 break;
  153.                 
  154.             case CLEAR:
  155.                 printf("clear\n");
  156.                 printf("%cP0;1|%c\\",0x1b,0x1b);
  157.                 break;
  158.             
  159.             default:
  160.                 line_nr(line);
  161.                 printf("Syntax-Error\n");
  162.                 break;
  163.         }
  164.         line++;
  165.     }
  166. }
  167. %}
  168.  
  169. %%
  170. [ ]*            ;
  171. #[ -~]*$        ;
  172. "clear"            return(CLEAR);
  173. "lock"            return(LOCK);
  174. [0-9]+=[ -~]*$    return(OK);
  175. [
  176. ]    ;
  177.  
  178.