home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1995 Fall / PD-ROM F95.toast / Programming / Programming Languages / UCB Logo 3.0 ƒ / sources / standard source / term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-14  |  4.4 KB  |  225 lines  |  [TEXT/ttxt]

  1. /*
  2.  *    term.c        terminal cursor control            dvb
  3.  *
  4.  *    Copyright (C) 1993 by the Regents of the University of California
  5.  *
  6.  *      This program is free software; you can redistribute it and/or modify
  7.  *      it under the terms of the GNU General Public License as published by
  8.  *      the Free Software Foundation; either version 2 of the License, or
  9.  *      (at your option) any later version.
  10.  *  
  11.  *      This program is distributed in the hope that it will be useful,
  12.  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *      GNU General Public License for more details.
  15.  *  
  16.  *      You should have received a copy of the GNU General Public License
  17.  *      along with this program; if not, write to the Free Software
  18.  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  */
  21.  
  22. #include "logo.h"
  23. #include "globals.h"
  24.  
  25. #ifdef mac
  26. #include <console.h>
  27. #endif
  28. #ifdef unix
  29. #ifdef SYSV
  30. #include <termio.h>
  31. #else
  32. #include <sgtty.h>
  33. #endif
  34. #endif
  35.  
  36. int x_coord, y_coord, x_max, y_max;
  37.  
  38. char PC;
  39. char *BC;
  40. char *UP;
  41. short ospeed;
  42. char bp[1024];
  43. char cl_arr[40];
  44. char cm_arr[40];
  45. char so_arr[40];
  46. char se_arr[40];
  47.  
  48. #ifdef unix
  49. #ifdef SYSV
  50. struct termio tty_cooked, tty_cbreak;
  51. #else
  52. struct sgttyb tty_cooked, tty_cbreak;
  53. #endif
  54. #endif
  55.  
  56. int interactive, tty_charmode;
  57.  
  58. extern char **environ, *tgoto(), *tgetstr();
  59.  
  60. char *termcap_ptr;
  61.  
  62. void termcap_putter(char ch)
  63. {
  64.     *termcap_ptr++ = ch;
  65. }
  66.  
  67. #ifdef unix
  68. void termcap_getter(char *cap, char *buf)
  69. {
  70.     char temp[40];
  71.     char *temp_ptr = temp;
  72.  
  73.     termcap_ptr = buf;
  74.     tgetstr(cap,&temp_ptr);
  75.     tputs(temp,1,termcap_putter);
  76. }
  77. #endif
  78.  
  79. void term_init()
  80. {
  81.     int term_sg;
  82.  
  83.     interactive = isatty(0);
  84. #ifdef mac
  85.     term_init_mac();
  86.     return;
  87. #else
  88. #ifdef ibm
  89.     term_init_ibm();
  90. #else
  91.     if (interactive) {
  92. #ifdef SYSV
  93.     ioctl(0,TCGETA,(char *)(&tty_cooked));
  94.     tty_cbreak = tty_cooked;
  95.     tty_cbreak.c_cc[VMIN] = '\01';
  96.     tty_cbreak.c_cc[VTIME] = '\0';
  97.     tty_cbreak.c_lflag &= ~ECHO;
  98. #else
  99.     ioctl(0,TIOCGETP,(char *)(&tty_cooked));
  100.     tty_cbreak = tty_cooked;
  101.     tty_cbreak.sg_flags |= CBREAK;
  102.     tty_cbreak.sg_flags &= ~ECHO;
  103. #endif
  104.     }
  105.     tty_charmode = 0;
  106.     tgetent(bp, getenv("TERM"));
  107.     x_max = tgetnum("co");
  108.     y_max = tgetnum("li");
  109.     term_sg = tgetnum("sg");
  110.  
  111.     x_coord = y_coord = 0;
  112.     termcap_getter("cm", cm_arr);
  113.     termcap_getter("cl", cl_arr);
  114.  
  115.     if (term_sg <= 0) {
  116.     termcap_getter("so", so_arr);
  117.     termcap_getter("se", se_arr);
  118.     } else    /* don't mess with stupid standout modes */
  119.     so_arr[0] = se_arr[0] = '\0';
  120. #endif
  121. #endif
  122. }
  123.  
  124. void charmode_on() {
  125. #ifdef unix
  126.     if ((readstream == stdin) && interactive && !tty_charmode) {
  127. #ifdef SYSV
  128.     ioctl(0,TCSETA,(char *)(&tty_cbreak));
  129. #else
  130.     ioctl(0,TIOCSETP,(char *)(&tty_cbreak));
  131. #endif
  132.     tty_charmode++;
  133.     }
  134. #endif
  135. }
  136.  
  137. void charmode_off() {
  138. #ifdef unix
  139.     if (tty_charmode) {
  140. #ifdef SYSV
  141.     ioctl(0,TCSETA,(char *)(&tty_cooked));
  142. #else
  143.     ioctl(0,TIOCSETP,(char *)(&tty_cooked));
  144. #endif
  145.     tty_charmode = 0;
  146.     }
  147. #endif
  148. }
  149.  
  150. NODE *lcleartext()
  151. {
  152. #ifdef mac
  153.     cgotoxy(x_margin + 1, y_margin + 1, stdout);
  154.     ccleos(stdout);
  155. #else
  156. #ifdef ibm
  157.     ibm_clear_text();
  158.     ibm_gotoxy(x_margin, y_margin);
  159. #else
  160.     printf("%s", cl_arr);
  161.     printf("%s", tgoto(cm_arr, x_margin, y_margin));
  162. #endif
  163. #endif
  164.     x_coord = x_margin;
  165.     y_coord = y_margin;
  166.     return(UNBOUND);
  167. }
  168.  
  169. NODE *lcursor()
  170. {
  171.     return(cons(make_intnode((FIXNUM)(x_coord-x_margin)),
  172.         cons(make_intnode((FIXNUM)(y_coord-y_margin)), NIL)));
  173. }
  174.  
  175. NODE *lsetcursor(NODE *args)
  176. {
  177.     NODE *arg;
  178.  
  179.     arg = pos_int_vector_arg(args);
  180.     if (NOT_THROWING) {
  181.     x_coord = x_margin + getint(car(arg));
  182.     y_coord = y_margin + getint(cadr(arg));
  183. #ifdef mac
  184.     mac_gotoxy(x_coord, y_coord);
  185. #else
  186. #ifdef ibm
  187.     ibm_gotoxy(x_coord, y_coord);
  188. #else
  189.     printf("%s", tgoto(cm_arr, x_coord, y_coord));
  190. #endif
  191. #endif
  192.     fflush(stdout);
  193. #ifdef __ZTC__
  194.     zflush();
  195. #endif
  196.     }
  197.     return(UNBOUND);
  198. }
  199.  
  200. NODE *lsetmargins(NODE *args)
  201. {
  202.     NODE *arg;
  203.  
  204.     arg = pos_int_vector_arg(args);
  205.     if (NOT_THROWING) {
  206.     x_margin = getint(car(arg));
  207.     y_margin = getint(cadr(arg));
  208.     lcleartext();
  209.     }
  210.     return(UNBOUND);
  211. }
  212.  
  213. NODE *lstandout(NODE *args)
  214. {
  215.     char textbuf[300];
  216.     char fmtbuf[100];
  217.  
  218.     sprintf(fmtbuf,"%s%%p%s",so_arr,se_arr);
  219.     print_stringptr = textbuf;
  220.     print_stringlen = 300;
  221.     ndprintf((FILE *)NULL,fmtbuf,car(args));
  222.     *print_stringptr = '\0';
  223.     return(make_strnode(textbuf,NULL,(int)strlen(textbuf),STRING,strnzcpy));
  224. }
  225.