home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 170_01 / funkey.c < prev    next >
Text File  |  1979-12-31  |  4KB  |  164 lines

  1. /*         FUNKEY.C - a program for redefining fyunction keys  */
  2. /*                                 */
  3. /*         Copyright    (C)  1983  Kenneth C. Wood         */
  4. /*                                 */
  5. /*         From PC Magazine - - June 1983  Page 424         */
  6. /*                                 */
  7. /*     Works with IBM PC-DOS 2.0 - to use it, have on your     */
  8. /*     system disk the files:                     */
  9. /*     ANSI.SYS - supplied with DOS                 */
  10. /*     CONFIG.SYS - file with the line "device = ansi.sys" in it */
  11. /*     and one or more files with the extension .KEY i.e.     */
  12. /*     WORDSTAR.KEY, MYOWN.KEY, FUNKEY.KEY, or             */
  13. /*     DOS.KEY - supplied by you and containing          */
  14. /*     your chosen new key definitions, and of course         */
  15. /*     FUNKEY.EXE - the compiled and linked FUNKEY.C         */
  16. /*                                 */
  17. /*     Now when the system is booted, the ANSI terminal      */
  18. /*     emulator device driver will be installed, giving      */
  19. /*     you the capability to do marvelous things, including     */
  20. /*     redefine the function keys by issuing the command:     */
  21. /*        FUNKEY MYOWN.KEY                 */
  22.  
  23.  
  24. #define  SEQ "\033[0;"       /* Initial sequence to ANSI driver */
  25.  
  26. #include "stdio.h"          /* Copy in the standard I/O routines */
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char *argv[];
  31.  
  32. {
  33.     FILE *fp, *fopen();
  34.  
  35.     if  (argc == 1)
  36.         {
  37.         printf("\nEnter new key definitions\n\n");
  38.         fkey(stdin);         /* get input from keyboard */
  39.         }
  40.     else
  41.         {
  42.         fp = fopen(*++argv,"r");
  43.         fkey(fp);    /* get input from the file */
  44.         }
  45. }
  46.  
  47. int count = 0;    /* counter for tracking size of the table */
  48.  
  49. fkey(fp)
  50. FILE *fp;
  51. {
  52.     int c,offset;
  53.     /* input character and function key identifier */
  54.  
  55.     while((c=getch(fp)) != EOF)
  56.     {
  57.         switch (c)
  58.         {
  59.         case 'f':       /* F1 through F10 */
  60.             offset = 58;
  61.             func(getch(fp),offset,fp);
  62.             break;
  63.         case 's':       /* Shift F1 through F10 */
  64.             offset = 83;
  65.             func(getch(fp),offset,fp);
  66.             break;
  67.         case 'c':       /* Control F1 through F10 */
  68.             offset = 93;
  69.             func(getch(fp),offset,fp);
  70.             break;
  71.         case 'a':       /* Alt F1 through F10 */
  72.             offset = 103;
  73.             func(getch(fp),offset,fp);
  74.             break;
  75.         case 'F':       /* F1 through F10 */
  76.             offset = 58;
  77.             func(getch(fp),offset,fp);
  78.             break;
  79.         case 'S':       /* Shift F1 through F10 */
  80.             offset = 83;
  81.             func(getch(fp),offset,fp);
  82.             break;
  83.         case 'C':       /* Control F1 through F10 */
  84.             offset = 93;
  85.             func(getch(fp),offset,fp);
  86.             break;
  87.         case 'A':       /* Alt F1 through F10 */
  88.             offset = 103;
  89.             func(getch(fp),offset,fp);
  90.             break;
  91.         default:
  92.             printf("Unknown function key\n");
  93.             break;
  94.         }
  95.     }
  96. }
  97.  
  98. getch(fp)
  99. /* throw away white space until a character */
  100. FILE *fp;
  101. {
  102. int x;
  103.  
  104.     while((x=getc(fp)) == ' '|| x == '\n' || x == '\t')
  105.         ;    /* ignore white space */
  106.     return(x);
  107. }
  108.  
  109.  
  110. func(c,offset,fp)
  111. /* send out the required definition sequence */
  112. int c,offset;
  113. FILE  *fp;
  114. {
  115.     int x,save;
  116.  
  117.     save = ' ';
  118.     while ((x = getch(fp)) != '=')
  119.         if (x == '0') c = ':';
  120.         /* read until get = sign */
  121.         /* if character is 0 then F10 was chosen */
  122.         /* rather than F1.  Change c so that offset is */
  123.         /* calculated correctly */
  124.     printf(SEQ);
  125.     printf("%d",offset+(c-'0'));
  126.  
  127. /*    putchar(';');
  128.     putchar('"');
  129. */
  130.     while ((x = getc(fp)) != '\n')
  131.         {
  132.         if (x != '!')
  133.             {
  134. /*            putchar(x);  */
  135.             printf(";%2d",x);
  136.  
  137.             if (++count == 128)
  138.             {
  139.         printf("\nTable size exceeded.  Program terminated...\n");
  140.         exit();
  141.             }
  142.         }
  143.         else
  144.             save = x;
  145.     }
  146.     /*putchar('"');*/
  147.     if (save == '!')
  148.         {
  149.         printf(";13p");
  150.         count++;
  151.         }
  152.     else
  153.         printf("p");
  154.     save = ' ';
  155.     if (count  == 128)
  156.     {
  157.         printf("\nTable size exceeded.  Program terminated...\n");
  158.         exit();
  159.     }
  160. }
  161.  
  162. /* end of Program Funkey.C  */
  163.  
  164.