home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / linux / old-src / ncurses-1.8.5 / dump.c < prev    next >
C/C++ Source or Header  |  1993-11-04  |  3KB  |  139 lines

  1.  
  2. /* This work is copyrighted. See COPYRIGHT.OLD & COPYRIGHT.NEW for   *
  3. *  details. If they are missing then this copy is in violation of    *
  4. *  the copyright conditions.                                        */
  5.  
  6. /*
  7.  *    dump.c - dump the contents of a compiled terminfo file in a
  8.  *         human-readable format.
  9.  *
  10.  */
  11.  
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14. #include <term.h>
  15. /*
  16. #include "compiler.h"
  17. */
  18.  
  19. #define SRCDIR "/usr/lib/terminfo"
  20.  
  21. static void expand(unsigned char *);
  22. static void usage(void);
  23.  
  24. void main(argc, argv)
  25. int    argc;
  26. char    *argv[];
  27. {
  28. int        i;
  29. int        cur_column;
  30. char        buffer[1024];
  31. TERMINAL    current_term;
  32. char        *terminal;
  33. char        *terminfo;
  34.  
  35.     cur_term = ¤t_term;
  36.     
  37.     if((terminal = getenv("TERM")) == NULL)
  38.     {
  39.         fprintf(stderr,"untic: environment variable TERM not set\n");
  40.         exit(1);
  41.     }
  42.     
  43.     if((terminfo = getenv("TERMINFO")) == NULL)
  44.     {
  45.         terminfo = SRCDIR;
  46.     }
  47.     
  48.     switch(argc) {
  49.     case 1:
  50.         /* no parameters */
  51.         sprintf(buffer, "%s/%c/%s", terminfo, *terminal, terminal);
  52.         break;
  53.     case 2:
  54.         /* parameter is terminal name */
  55.         if(argv[1][0] == '-' && (argv[1][1] == '?' || argv[1][1] == 'h'))
  56.             usage();
  57.         else
  58.             sprintf(buffer, "%s/%c/%s", terminfo, *argv[1], argv[1]);
  59.         break;
  60.     case 3:
  61.         /* parameter is "-f filename" */
  62.         if(argv[1][0] == '-' && argv[1][1] == 'f')
  63.             sprintf(buffer, "%s", &argv[1][3]);
  64.         else
  65.             usage();
  66.         break;
  67.     default:
  68.         usage();
  69.     }
  70.     
  71.     if (read_entry(buffer, cur_term) < 0) {
  72.         fprintf(stderr, "file %s may not be a terminfo entry\n", buffer);
  73.         exit(1);
  74.     }
  75.  
  76.     printf("%s,\n\t", cur_term->term_names);
  77.     cur_column = 9;
  78.  
  79.     for (i=0; i < BOOLCOUNT; i++)
  80.     {
  81.             printf("%s\n", boolnames[i]);
  82.             cur_column += strlen(boolnames[i]) + 2;
  83.     }
  84.  
  85.     for (i=0; i < NUMCOUNT; i++)
  86.     {
  87.             printf("%s#%d\n", numnames[i], cur_term->Numbers[i]);
  88.             cur_column += strlen(numnames[i]) + 5;
  89.     }
  90.  
  91.     for (i=0; i < STRCOUNT; i++)
  92.     {
  93.             sprintf(buffer, "%s=%s, ", strnames[i], cur_term->Strings[i]);
  94.             expand(buffer);
  95.             printf("%s\n", buffer);
  96.             cur_column += strlen(buffer);
  97.     }
  98.     putchar('\n');
  99. }
  100.  
  101.  
  102. void expand(unsigned char *str)
  103. {
  104. char    buffer[1024];
  105. int    bufp;
  106. unsigned char    *ptr;
  107.  
  108.     bufp = 0;
  109.     ptr = str;
  110.     while (*str) {
  111.         if (*str < ' ') {
  112.         buffer[bufp++] = '^';
  113.         buffer[bufp++] = *str + '@';
  114.         }
  115.         else if (*str < '\177')
  116.         buffer[bufp++] = *str;
  117.         else {
  118.         sprintf(&buffer[bufp], "\\%03o", *str);
  119.         bufp += 4;
  120.         }
  121.  
  122.         str++;
  123.     }
  124.  
  125.     buffer[bufp] = '\0';
  126.     strcpy(ptr, buffer);
  127. }
  128.  
  129. void
  130. usage()
  131. {
  132.     fprintf(stderr,"\nusage: untic [term] [-f file] - decompile terminfo database entry\n");
  133.     fprintf(stderr,"  term       - terminal name to be decompiled\n");
  134.     fprintf(stderr,"  -f file    - filename to be used to decompile\n");
  135.     fprintf(stderr,"  no options - terminal name and terminfo path got from TERM/TERMINFO\n\n");
  136.     exit(1);
  137. }
  138.  
  139.