home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / mytinfo / part01 / caps.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  3.2 KB  |  164 lines

  1. /*
  2.  * caps.c
  3.  * 
  4.  * By Ross Ridge
  5.  * Public Domain
  6.  * 92/02/01 07:29:45
  7.  *
  8.  * caps [-c | -t] [term]
  9.  *
  10.  * -c        use termcap names instead of terminfo variable names
  11.  * -t        use terminfo capnames instead of variables names
  12.  * term     name of terminal to use
  13.  *
  14.  * prints out all the capabilities given the specified terminal. If no
  15.  * terminal is given, it is taken from the environment variable TERM.
  16.  *
  17.  */
  18.  
  19. #define NOTLIB
  20. #include "defs.h"
  21. #include "term.h"
  22.  
  23. static const char SCCSid[] = "@(#) mytinfo caps.c 3.2 92/02/01 public domain, By Ross Ridge";
  24.  
  25. /* output a string in a human readable format */
  26. void
  27. putstr(s)
  28. char *s; {
  29.     while(*s != '\0') {
  30.         switch(*s) {
  31.         case '\n': printf("\\n"); break;
  32.         case '\b': printf("\\b"); break;
  33.         case '\t': printf("\\t"); break;
  34.         case '\r': printf("\\r"); break;
  35.         case '\f': printf("\\f"); break;
  36.         case ' ': printf("\\s"); break;
  37.         case '\177': printf("^?"); break;
  38.         case '\200': printf("\\0"); break;
  39.         default:
  40.             if (*s > 0 && *s < 32)
  41.                 printf("^%c", *s + 64);
  42.             else if (*s < 0 || *s > 127)
  43.                 printf("\\%03o", *s & 0xff);
  44.             else
  45.                 putchar(*s);
  46.             break;
  47.         }
  48.         s++;
  49.     }
  50. }
  51.  
  52. void
  53. do_cleanup(e)
  54. int e; {
  55.     fprintf(stderr, "usage: %s [-c | -t ] [terminal]\n", prg_name);
  56.     return;
  57. }
  58.  
  59. int
  60. main(argc, argv)
  61. int argc;
  62. char **argv; {
  63.     int names = 0;
  64.     register int i;
  65.     int flag, num;
  66.     char *str;
  67.  
  68.     prg_name = argv[0];
  69.     cleanup = do_cleanup;
  70.  
  71.     if (argc > 3)
  72.         quit(-1, "argument count");
  73.  
  74.     if (argc == 1)
  75.         setupterm(NULL, 2, (int *) 0);
  76.     else if (argc == 2)
  77.         setupterm(argv[1], 2, (int *) 0);
  78.     else {
  79.         if (argv[1][0] != '-')
  80.             quit(-1, "bad switch");
  81.         if (argv[1][1] == 'c')
  82.             names = 2;
  83.         else if (argv[1][1] == 't')
  84.             names = 1;
  85.         else
  86.             quit(-1, "unknown switch '%c'", argv[1][1]);
  87.         setupterm(argv[2], 2, (int *) 0);
  88.  
  89.     }
  90.  
  91.     fflush(stderr);
  92.     fflush(stdout);
  93.     printf("\n");
  94. #ifdef _CUR_TERM
  95.     printf("%s: %s\n", cur_term->name, cur_term->name_all);
  96.     printf("pad: %d xon: %d termcap: %d\n",
  97.             cur_term->pad, cur_term->xon, cur_term->termcap);
  98.     printf("true_columns: %d true_lines: %d baudrate: %d\n",
  99.         cur_term->true_columns, cur_term->true_lines,
  100.         cur_term->baudrate);
  101.     printf("\n");
  102. #endif
  103.  
  104.     printf("Booleans:\n");
  105.     for(i = 0; boolnames[i] != NULL; i++) {
  106. #ifdef _CUR_TERM
  107.         flag = cur_term->bools[i];
  108. #else
  109.         flag = tigetflag(boolnames[i]);
  110. #endif
  111.         if (flag != -1 && flag != 0) {
  112.             switch(names) {
  113.             case 0:
  114.                 printf("  %s\n", boolfnames[i]);
  115.                 break;
  116.             case 1:
  117.                 printf("  %s\n", boolnames[i]);
  118.                 break;
  119.             case 2:
  120.                 printf("  %s\n", boolcodes[i]);
  121.                 break;
  122.             }
  123.         }
  124.     }
  125.  
  126.     printf("\nNumerics:\n");
  127.     for(i = 0; numnames[i] != NULL; i++) {
  128.         num = tigetnum(numnames[i]);
  129.         if (num != -2 && num != -1) {
  130.             switch(names) {
  131.             case 0:
  132.                 printf("  %-32s: %d\n", numfnames[i], num);
  133.                 break;
  134.             case 1:
  135.                 printf("  %-5s: %d\n", numnames[i], num);
  136.                 break;
  137.             case 2:
  138.                 printf("  %-2s: %d\n", numcodes[i], num);
  139.                 break;
  140.             }
  141.         }
  142.     }
  143.     printf("\nStrings:\n");
  144.     for(i = 0; strnames[i] != NULL; i++) {
  145.         str = tigetstr(strnames[i]);
  146.         if (str != (char *) -1 && str != (char *) 0) {
  147.             switch(names) {
  148.             case 0:
  149.                 printf("  %-32s: ", strfnames[i]);
  150.                 break;
  151.             case 1:
  152.                 printf("  %-5s: ", strnames[i]);
  153.                 break;
  154.             case 2:
  155.                 printf("  %-2s: ", strcodes[i]);
  156.                 break;
  157.             }
  158.             putstr(str);
  159.             putchar('\n');
  160.         }
  161.     }
  162.     return 0;
  163. }
  164.