hp.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <ndraw.h>
  12. #include <bio.h>
  13. #include "cons.h"
  14. char *term = "2621";
  15. struct funckey fk[32];
  16. void
  17. emulate(void)
  18. {
  19. char buf[BUFS+1];
  20. int n;
  21. int c;
  22. int standout = 0;
  23. int insmode = 0;
  24. for (;;) {
  25. if (x > xmax || y > ymax) {
  26. x = 0;
  27. newline();
  28. }
  29. buf[0] = get_next_char();
  30. buf[1] = '\0';
  31. switch(buf[0]) {
  32. case '\000': /* nulls, just ignore 'em */
  33. break;
  34. case '\007': /* bell */
  35. ringbell();
  36. break;
  37. case '\t': /* tab modulo 8 */
  38. x = (x|7)+1;
  39. break;
  40. case '\033':
  41. switch(get_next_char()) {
  42. case 'j':
  43. get_next_char();
  44. break;
  45. case '&': /* position cursor &c */
  46. switch(get_next_char()) {
  47. case 'a':
  48. for (;;) {
  49. n = number(buf, nil);
  50. switch(buf[0]) {
  51. case 'r':
  52. case 'y':
  53. y = n;
  54. continue;
  55. case 'c':
  56. x = n;
  57. continue;
  58. case 'R':
  59. case 'Y':
  60. y = n;
  61. break;
  62. case 'C':
  63. x = n;
  64. break;
  65. }
  66. break;
  67. }
  68. break;
  69. case 'd': /* underline stuff */
  70. if ((n=get_next_char())>='A' && n <= 'O')
  71. standout++;
  72. else if (n == '@')
  73. standout = 0;
  74. break;
  75. default:
  76. get_next_char();
  77. break;
  78. }
  79. break;
  80. case 'i': /* back tab */
  81. if (x>0)
  82. x = (x-1) & ~07;
  83. break;
  84. case 'H': /* home cursor */
  85. case 'h':
  86. x = 0;
  87. y = 0;
  88. break;
  89. case 'L': /* insert blank line */
  90. scroll(y, ymax, y+1, y);
  91. break;
  92. case 'M': /* delete line */
  93. scroll(y+1, ymax+1, y, ymax);
  94. break;
  95. case 'J': /* clear to end of display */
  96. xtipple(Rpt(pt(0, y+1),
  97. pt(xmax+1, ymax+1)));
  98. /* flow */
  99. case 'K': /* clear to EOL */
  100. xtipple(Rpt(pt(x, y),
  101. pt(xmax+1, y+1)));
  102. break;
  103. case 'P': /* delete char */
  104. bitblt(&screen, pt(x, y),
  105. &screen, Rpt(pt(x+1, y),
  106. pt(xmax+1, y+1)),
  107. S);
  108. xtipple(Rpt(pt(xmax, y),
  109. pt(xmax+1, y+1)));
  110. break;
  111. case 'Q': /* enter insert mode */
  112. insmode++;
  113. break;
  114. case 'R': /* leave insert mode */
  115. insmode = 0;
  116. break;
  117. case 'S': /* roll up */
  118. scroll(1, ymax+1, 0, ymax);
  119. break;
  120. case 'T':
  121. scroll(0, ymax, 1, 0);
  122. break;
  123. case 'A': /* upline */
  124. case 't':
  125. if (y>0)
  126. y--;
  127. if (olines > 0)
  128. olines--;
  129. break;
  130. case 'B':
  131. case 'w':
  132. y++; /* downline */
  133. break;
  134. case 'C': /* right */
  135. case 'v':
  136. x++;
  137. break;
  138. case 'D': /* left */
  139. case 'u':
  140. x--;
  141. }
  142. break;
  143. case '\b': /* backspace */
  144. if(x > 0)
  145. --x;
  146. break;
  147. case '\n': /* linefeed */
  148. newline();
  149. standout = 0;
  150. if( ttystate[cs->raw].nlcr )
  151. x = 0;
  152. break;
  153. case '\r': /* carriage return */
  154. x = 0;
  155. standout = 0;
  156. if( ttystate[cs->raw].crnl )
  157. newline();
  158. break;
  159. default: /* ordinary char */
  160. n = 1;
  161. c = 0;
  162. while (!cs->raw && host_avail() && x+n<=xmax && n<BUFS
  163. && (c = get_next_char())>=' ' && c<'\177') {
  164. buf[n++] = c;
  165. c = 0;
  166. }
  167. buf[n] = 0;
  168. if (insmode) {
  169. bitblt(&screen, pt(x+n, y), &screen,
  170. Rpt(pt(x, y), pt(xmax-n+1, y+1)), S);
  171. }
  172. xtipple(Rpt(pt(x,y), pt(x+n, y+1)));
  173. string(&screen, pt(x, y), font, buf, DxorS);
  174. if (standout)
  175. rectf(&screen,
  176. Rpt(pt(x,y),pt(x+n,y+1)),
  177. DxorS);
  178. x += n;
  179. peekc = c;
  180. break;
  181. }
  182. }
  183. }