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

  1. /*
  2.  * tcapconv.c
  3.  *
  4.  * By Ross Ridge
  5.  * Public Domain
  6.  * 92/02/01 07:30:20
  7.  *
  8.  */
  9.  
  10. #include "defs.h"
  11. #define SINGLE
  12. #include "term.h"
  13.  
  14. #ifdef USE_SCCS_IDS
  15. static const char SCCSid[] = "@(#) mytinfo tcapconv.c 3.2 92/02/01 public domain, By Ross Ridge";
  16. #endif
  17.  
  18. extern char **_sstrcodes[], **_sstrnames[];
  19.  
  20. static char *C_CR = "\r";
  21. static char *C_LF = "\n";
  22. static char *C_BS = "\b";
  23. /* static char *C_FF = "\f"; */
  24. static char *C_HT = "\t";
  25. /* static char *C_VT = "\013"; */
  26. /* static char *C_NL = "\r\n"; */
  27.  
  28. #define DEF(s) ((s) != (char *) -1 && (s) != NULL)
  29. #define NOTSET(s) ((s) == (char *) -1)
  30.  
  31. /*
  32.  * This routine fills in caps that either had defaults under termcap or
  33.  * can be manufactured from obsolete termcap capabilities. 
  34.  */
  35.  
  36. void
  37. _tcapdefault() {
  38.     char buf[MAX_LINE * 2 + 2];
  39.  
  40.     if (NOTSET(carriage_return)) {
  41.         if (carriage_return_delay > 0) {
  42.             sprintf(buf, "%s$<%d>", C_CR, carriage_return_delay);
  43.             carriage_return = _addstr(buf);
  44.         } else
  45.             carriage_return = _addstr(C_CR);
  46.     }
  47.     if (NOTSET(cursor_left)) {
  48.         if (backspace_delay > 0) {
  49.             sprintf(buf, "%s$<%d>", C_BS, backspace_delay);
  50.             cursor_left = _addstr(buf);
  51.         } else if (backspaces_with_bs == 1)
  52.             cursor_left = _addstr(C_BS);
  53.         else if (DEF(backspace_if_not_bs))
  54.             cursor_left = _addstr(backspace_if_not_bs);
  55.     }
  56. /* vi doesn't use "do", but it does seems to use nl (or '\n') instead */
  57.     if (NOTSET(cursor_down)) {
  58.         if (DEF(linefeed_if_not_lf)) 
  59.             cursor_down = _addstr(linefeed_if_not_lf);
  60.         else if (linefeed_is_newline != 1) {
  61.             if (new_line_delay > 0) {
  62.                 sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
  63.                 cursor_down = _addstr(buf);
  64.             } else
  65.                 cursor_down = _addstr(C_LF);
  66.         }
  67.     }
  68.     if (NOTSET(scroll_forward) && crt_without_scrolling != 1) {
  69.         if (DEF(linefeed_if_not_lf)) 
  70.             cursor_down = _addstr(linefeed_if_not_lf);
  71.         else if (linefeed_is_newline != 1) {
  72.             if (new_line_delay > 0) {
  73.                 sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
  74.                 scroll_forward = _addstr(buf);
  75.             } else
  76.                 scroll_forward = _addstr(C_LF);
  77.         }
  78.     }
  79.     if (NOTSET(newline)) {
  80.         if (linefeed_is_newline == 1) {
  81.             if (new_line_delay > 0) {
  82.                 sprintf(buf, "%s$<%d>", C_LF, new_line_delay);
  83.                 newline = _addstr(buf);
  84.             } else
  85.                 newline = _addstr(C_LF);
  86.         } else if (DEF(carriage_return) && DEF(scroll_forward)) {
  87.             strncpy(buf, carriage_return, MAX_LINE-2);
  88.             buf[MAX_LINE-1] = '\0';
  89.             strncat(buf, scroll_forward, MAX_LINE-strlen(buf)-1);
  90.             buf[MAX_LINE] = '\0';
  91.             newline = _addstr(buf);
  92.         } else if (DEF(carriage_return) && DEF(cursor_down)) {
  93.             strncpy(buf, carriage_return, MAX_LINE-2);
  94.             buf[MAX_LINE-1] = '\0';
  95.             strncat(buf, cursor_down, MAX_LINE-strlen(buf)-1);
  96.             buf[MAX_LINE] = '\0';
  97.             newline = _addstr(buf);
  98.         }
  99.     }
  100.  
  101. /*
  102.  * We wait until know to decide if we've got a working cr because even
  103.  * one that doesn't work can be used for newline. Unfortunately the
  104.  * space allocated for it is wasted.
  105.  */
  106.     if (return_does_clr_eol == 1 || no_correctly_working_cr == 1)
  107.         carriage_return = NULL;
  108.  
  109. /*
  110.  * supposedly most termcap entries have ta now and '\t' is no longer a
  111.  * default, but it doesn't seem to be true...
  112.  */
  113.     if (NOTSET(tab)) {
  114.         if (horizontal_tab_delay > 0) {
  115.             sprintf(buf, "%s$<%d>", C_HT, horizontal_tab_delay);
  116.             tab = _addstr(buf);
  117.         } else
  118.             tab = _addstr(C_HT);
  119.     }
  120. #if 0
  121. /* probably not needed and might confuse some programmes */
  122.     if (NOTSET(form_feed)) {
  123.         if (form_feed_delay > 0) {
  124.             sprintf(buf, "%s$<%d>", C_FF, form_feed_delay);
  125.             form_feed = _addstr(buf);
  126.         } else
  127.             form_feed = _addstr(C_FF);
  128.     }
  129. #endif
  130.     if (init_tabs == -1 && has_hardware_tabs == 1)
  131.         init_tabs = 8;
  132.  
  133.     if (NOTSET(key_backspace))
  134.         key_backspace = _addstr(C_BS);
  135.     if (NOTSET(key_left))
  136.         key_left = _addstr(C_BS);
  137.     if (NOTSET(key_down))
  138.         key_down = _addstr(C_LF);
  139. }
  140.  
  141. void
  142. _tcapconv() {
  143.     char buf[MAX_LINE+1];
  144.  
  145.     if (GNU_tab_width > 0 && init_tabs == -1)
  146.         init_tabs = GNU_tab_width;
  147.  
  148.     if (GNU_has_meta_key == 1 && has_meta_key == -1)
  149.         has_meta_key = 1;
  150.  
  151. /*
  152.  * this is some what a kludge, but should work unless someone breaks
  153.  * conventions.
  154.  */
  155.     if (DEF(other_non_function_keys)) {
  156.         register char *s;
  157.         static char *o;
  158.         static char name[MAX_NAME] = "k";
  159.         char *str;
  160.         int ind;
  161.  
  162.         s = strcpy(buf, other_non_function_keys);
  163.         while(*s != '\0') {
  164.             o = s;
  165.             while(*s != ',' && *s != '\0')
  166.                 s++;
  167.             if (*s != '\0')
  168.                 *s++ = '\0';
  169.             ind = _findstrcode(o);
  170.             if (ind == -1)
  171.                 continue;
  172.             str = _term_buf.strs[ind];
  173.             if (!DEF(str))
  174.                 continue;
  175.             strncpy(name + 1, strnames[ind], MAX_NAME - 2);
  176.             ind = _findstrname(name);
  177.             if (ind == -1)
  178.                 continue;
  179.             if (!NOTSET(_term_buf.strs[ind]))
  180.                 continue;
  181.             _term_buf.strs[ind] = _addstr(str);
  182.         }
  183.     }
  184. }
  185.