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

  1. /*
  2.  * tgoto.c
  3.  *
  4.  * By Ross Ridge
  5.  * Public Domain
  6.  * 92/02/01 07:30:33
  7.  *
  8.  * A few kludged attempts to worry outputing ^D's and NL's...
  9.  * My advice is to get a decent terminal.
  10.  *
  11.  */
  12.  
  13. #include "defs.h"
  14. #include "term.h"
  15.  
  16. #ifdef USE_SCCS_IDS
  17. static const char SCCSid[] = "@(#) mytinfo tgoto.c 3.2 92/02/01 public domain, By Ross Ridge";
  18. #endif
  19.  
  20. #ifdef USE_LITOUT_KLUDGE
  21.  
  22. /*
  23.  * This kludge works by telling tputs to switch the tty driver to
  24.  * "literal output" when printing the string so we don't have worry
  25.  * about newlines and EOTs. The problem is that ioctls used to
  26.  * switch modes might flush buffers and cause other problems.
  27.  */
  28.  
  29.  
  30. char *
  31. tgoto(str, x, y)
  32. char *str;
  33. int x,y; {
  34.     register char *sp;
  35.     
  36.     static char buf[MAX_LINE] = {'\\', '@'};
  37.  
  38.     sp = str = tparm(str, y, x);
  39.  
  40.     while (*sp != '\0') {
  41.         if (*sp == '\004' || *sp == '\n') {
  42.             strncpy(buf + 2, str, MAX_LINE - 2);
  43.             buf[MAX_LINE - 2] = '\0';
  44.             return buf;
  45.         }
  46.         sp++;
  47.     }
  48.     return sp;
  49. }
  50. #else
  51.  
  52. #ifdef USE_UPBC_KLUDGE
  53.  
  54. #ifdef USE_EXTERN_UPBC
  55. extern char *BC, *UP;
  56. #else
  57. #define BC    cursor_left
  58. #define UP    cursor_right
  59. #endif
  60.  
  61. #ifdef __GNUC__
  62. __inline__
  63. #endif
  64. static int
  65. checkit(s)
  66. register char *s; {
  67.     while(*s != '\0') {
  68.         if (*s == '\004' || *s == '\n')
  69.             return 1;
  70.         s++;
  71.     }
  72.     return 0;
  73. }
  74.  
  75. /*
  76.  * Major kludge, basically we just change the parmeters until we get
  77.  * a string that doesn't contain a newline or EOT.
  78.  */
  79.  
  80. char *
  81. tgoto(str, x, y)
  82. char *str;
  83. int x,y; {
  84.     static char buf[MAX_LINE];
  85.     register char *orig, *s;
  86.     int l;
  87.  
  88.     orig = tparm(str, y, x);
  89.  
  90.     if (!checkit(orig))
  91.         return orig;
  92.  
  93.     s = tparm(str, y + 1, x);
  94.  
  95.     if (!checkit(s)) {
  96.         if (BC == NULL)
  97.             return s;
  98.         l = strlen(s);
  99.         strncpy(buf, s, MAX_LINE - 1);
  100.         if (l < MAX_LINE - 1)
  101.             strncpy(buf + l, BC, MAX_LINE - 1 - l);
  102.         return s;
  103.     }
  104.  
  105.     s = tparm(str, y, x + 1);
  106.  
  107.     if (!checkit(s)) {
  108.         if (UP == NULL)
  109.             return s;
  110.         l = strlen(s);
  111.         strncpy(buf, s, MAX_LINE - 1);
  112.         if (l < MAX_LINE - 1)
  113.             strncpy(buf + l, UP, MAX_LINE - 1 - l);
  114.         return s;
  115.     }
  116.  
  117.     s = tparm(str, y + 1, x + 1);
  118.  
  119.     if (!checkit(s)) {
  120.         if (UP == NULL || BC == NULL)
  121.             return s;
  122.         l = strlen(s);
  123.         strncpy(buf, s, MAX_LINE - 1);
  124.         if (l < MAX_LINE - 1)
  125.             strncpy(buf + l, UP, MAX_LINE - 1 - l);
  126.         l += strlen(UP);
  127.         if (l < MAX_LINE - 1)
  128.             strncpy(buf + l, BC, MAX_LINE - 1 - l);
  129.         return s;
  130.     }
  131.  
  132.     return orig;
  133. }
  134.  
  135. #else
  136.  
  137. /* the simple tgoto, don't worry about any of this newline/EOT crap */
  138.  
  139. char *
  140. tgoto(str, x, y)
  141. char *str;
  142. int x,y; {
  143.     return tparm(str, y, x);
  144. }
  145.  
  146. #endif
  147.  
  148. #endif
  149.