home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume14 / mine / part01 / screen.c < prev   
C/C++ Source or Header  |  1992-08-31  |  4KB  |  241 lines

  1. #include <curses.h>
  2. #include <term.h>
  3.  
  4. static char *st_smkx;
  5. static char *st_rmkx;
  6. extern int l_up;
  7. extern char *k_up;
  8. extern int l_dwn;
  9. extern char *k_dwn;
  10. extern int l_lft;
  11. extern char *k_lft;
  12. extern int l_rgt;
  13. extern char *k_rgt;
  14. static char *st_cup;
  15. static char *st_clear;
  16. static char *st_enacs;
  17. static char *st_smacs;
  18. static char *st_rmacs;
  19. static char *st_acsc;
  20. static int l_acsc;
  21. static char *st_bold;
  22. static char *st_rmso;
  23. static int l_bold;
  24. static int l_rmso;
  25. static char *st_civis;
  26. static char *st_cnorm;
  27. static int l_cnorm;
  28. static int l_civis;
  29.  
  30. char A_UL = '+';
  31. char A_LL = '+';
  32. char A_UR = '+';
  33. char A_LR = '+';
  34. char A_VL = '|';
  35. char A_HL = '-';
  36.  
  37. int pc();
  38.  
  39. #define TPUTS(x, y, z)  (tputs(y, z, pc), pc(0), pc(0), pc(0))
  40.  
  41. s_init()
  42. {
  43. int result;
  44. char *t;
  45. int i;
  46.  
  47.     if(setupterm((char *)0, 1, &result) == ERR) {
  48.         switch(result) {
  49.             case 0:
  50.                 fprintf(stderr, "Can't find terminal %s\n\r", getenv("TERM"));
  51.                 myexit(1);
  52.             case -1:
  53.                 fprintf(stderr, "Can't find termininfo database\n\r");
  54.                 myexit(1);
  55.             default:
  56.                 fprintf(stderr, "Bad terminfo error %d\n\r", result);
  57.                 myexit(1);
  58.         }
  59.     }
  60.     st_cup = tigetstr("cup");
  61.     if(!st_cup) {
  62.         fprintf(stderr, "cup not found\n\r");
  63.         myexit(1);
  64.     }
  65.     st_clear = tigetstr("clear");
  66.     if(!st_clear) {
  67.         fprintf(stderr, "clear not found\n\r");
  68.         myexit(1);
  69.     }
  70.     st_smkx = tigetstr("smkx");
  71.     st_rmkx = tigetstr("rmkx");
  72.     if(st_smkx)
  73.         TPUTS(1, st_smkx, strlen(st_smkx));
  74.     st_bold = tigetstr("bold");
  75.     if(st_bold) {
  76.         l_bold = strlen(st_bold);
  77.         st_rmso = tigetstr("rmso");
  78.         if(st_rmso) {
  79.             l_rmso = strlen(st_rmso);
  80.         } else st_bold = 0;
  81.     }
  82.     st_civis = tigetstr("civis");
  83.     if(st_civis) {
  84.         l_civis = strlen(st_civis);
  85.         st_cnorm = tigetstr("cnorm");
  86.         if(st_cnorm) {
  87.             l_cnorm = strlen(st_cnorm);
  88.         } else st_civis = 0;
  89.     }
  90.     st_enacs = tigetstr("enacs");
  91.     st_rmacs = tigetstr("rmacs");
  92.     st_smacs = tigetstr("smacs");
  93.     if (t = tigetstr("kcuu1")) {
  94.         k_up = t;
  95.         l_up = strlen(t);
  96.     }
  97.     if (t = tigetstr("kcud1")) {
  98.         k_dwn = t;
  99.         l_dwn = strlen(t);
  100.     }
  101.     if (t = tigetstr("kcub1")) {
  102.         k_lft = t;
  103.         l_lft = strlen(t);
  104.     }
  105.     if (t = tigetstr("kcuf1")) {
  106.         k_rgt = t;
  107.         l_rgt = strlen(t);
  108.     }
  109.     if(st_smacs) {
  110.         if(st_enacs)
  111.             TPUTS(1, st_enacs, strlen(st_enacs));
  112.         st_acsc = tigetstr("acsc");
  113.         if(st_acsc) {
  114.             l_acsc = strlen(st_acsc);
  115.             for(i = 0; i < l_acsc; i+= 2) {
  116.                 switch(st_acsc[i]) {
  117.                     case 'l':
  118.                         A_UL = st_acsc[i+1];
  119.                         break;
  120.                     case 'm':
  121.                         A_LL = st_acsc[i+1];
  122.                         break;
  123.                     case 'k':
  124.                         A_UR = st_acsc[i+1];
  125.                         break;
  126.                     case 'j':
  127.                         A_LR = st_acsc[i+1];
  128.                         break;
  129.                     case 'q':
  130.                         A_HL = st_acsc[i+1];
  131.                         break;
  132.                     case 'x':
  133.                         A_VL = st_acsc[i+1];
  134.                         break;
  135.                 }
  136.             }
  137.         }
  138.     }
  139.     fl();
  140. }
  141.  
  142. s_term()
  143. {
  144.     if(st_rmkx)
  145.         TPUTS(1, st_rmkx, strlen(st_rmkx));
  146.     fl();
  147. }
  148.  
  149. static unsigned char buf[1024];
  150. int pbuf;
  151.  
  152. static pc(c)
  153. char c;
  154. {
  155.     buf[pbuf++] = c;
  156. }
  157.  
  158. static fl()
  159. {
  160.     write(1, buf, pbuf);
  161.     pbuf = 0;
  162. }
  163.  
  164. s_pr(x, y, s, v1, v2)
  165. int x;
  166. int y;
  167. char *s;
  168. int v1;
  169. int v2;
  170. {
  171. char *p = tgoto(st_cup, x, y);
  172.     TPUTS(1, p, strlen(p));
  173.     pbuf += sprintf(buf+pbuf, s, v1, v2);
  174.     fl();
  175. }
  176.  
  177. s_pc(x, y, c)
  178. int x;
  179. int y;
  180. char c;
  181. {
  182. char *p = tgoto(st_cup, x, y);
  183.     TPUTS(1, p, strlen(p));
  184.     if(c != 0)
  185.         pc(c);
  186.     fl();
  187. }
  188.  
  189. s_clear()
  190. {
  191.     TPUTS(1, st_clear, strlen(st_clear));
  192.     fl();
  193. }
  194.  
  195. s_box(x, y, l, h)
  196. int x,y;
  197. int l,h;
  198. {
  199. int i;
  200.     if(st_smacs)
  201.         TPUTS(1, st_smacs, strlen(st_smacs));
  202.     s_pc(x, y, A_UL);
  203.     s_pc(x + l, y, A_UR);
  204.     s_pc(x, y + h, A_LL);
  205.     s_pc(x + l, y + h, A_LR);
  206.     for(i = 1; i < l; i++) {
  207.         s_pc(x+i, y, A_HL);
  208.         s_pc(x+i, y+h, A_HL);
  209.     }
  210.     for(i = 1; i < h; i++) {
  211.         s_pc(x, y+i, A_VL);
  212.         s_pc(x+l, y+i, A_VL);
  213.     }
  214.     if(st_rmacs)
  215.         TPUTS(1, st_rmacs, strlen(st_rmacs));
  216. }
  217.  
  218. s_bold()
  219. {
  220.     if(st_bold)
  221.         TPUTS(1, st_bold, l_bold);
  222. }
  223.  
  224. s_rmso()
  225. {
  226.     if(st_rmso)
  227.         TPUTS(1, st_rmso, l_rmso);
  228. }
  229.  
  230. s_civis()
  231. {
  232.     if(st_civis)
  233.         TPUTS(1, st_civis, l_civis);
  234. }
  235.  
  236. s_cnorm()
  237. {
  238.     if(st_cnorm)
  239.         TPUTS(1, st_cnorm, l_cnorm);
  240. }
  241.