home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / mush5.7 / part02 / rite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-16  |  4.5 KB  |  177 lines

  1. /* rite.c    (c) copyright 1986 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4.  
  5. #define LASTLINE       (msg_rect.r_height - l_height(LARGE)-5)
  6.  
  7. static char *_unctrl[] = {
  8.     "^@", "^A", "^B", "^C", "^D", "^E", "^F", "^G", "^H", "^I", "^J", "^K",
  9.     "^L", "^M", "^N", "^O", "^P", "^Q", "^R", "^S", "^T", "^U", "^V", "^W",
  10.     "^X", "^Y", "^Z", "^[", "^\\", "^]", "^~", "^_",
  11.     " ", "!", "\"", "#", "$",  "%", "&", "'", "(", ")", "*", "+", ",", "-",
  12.     ".", "/", "0",  "1", "2",  "3", "4", "5", "6", "7", "8", "9", ":", ";",
  13.     "<", "=", ">",  "?", "@",  "A", "B", "C", "D", "E", "F", "G", "H", "I",
  14.     "J", "K", "L",  "M", "N",  "O", "P", "Q", "R", "S", "T", "U", "V", "W",
  15.     "X", "Y", "Z",  "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e",
  16.     "f", "g", "h",  "i", "j",  "k", "l", "m", "n", "o", "p", "q", "r", "s",
  17.     "t", "u", "v",  "w", "x",  "y", "z", "{", "|", "}", "~", "^?"
  18. };
  19.  
  20. static char String[BUFSIZ];
  21. static int count, backchars, save_orig_x;
  22.  
  23. char *
  24. rite(c)
  25. register char c;
  26. {
  27.     static int literal_next;
  28.  
  29.     if (c == ltchars.t_lnextc || literal_next) {
  30.     if (literal_next)
  31.         Addch(c);
  32.     else /* don't call Addch to prevent cursor from advancing */
  33.         pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], '^');
  34.     literal_next = !literal_next;
  35.     return NULL;
  36.     }
  37.     literal_next = 0;
  38.     if (c == _tty.sg_erase) {
  39.     if (count)
  40.         backspace(), String[count--] = 0;
  41.     } else if (c == _tty.sg_kill) {
  42.     if (count) {
  43.         Clrtoeol(msg_win, txt.x = save_orig_x, txt.y,curfont);
  44.         String[count=0] = 0;
  45.     }
  46.     } else if (c == ltchars.t_werasc)
  47.     while (count) {
  48.         backspace();
  49.         String[count--] = 0;
  50.         if (!count || (String[count-1]==' ' && !isspace(String[count])))
  51.         break;
  52.     }
  53.     else if (c == '\n' || c == '\r' || c == 13) {
  54.     String[count] = 0;
  55.     if ((txt.y += l_height(curfont)) >= LASTLINE && !getting_opts)
  56.         scroll_win(1);
  57.     /* else Clrtoeol(msg_win, txt.x, txt.y, curfont); */
  58.     count = 0, txt.x = 5;
  59.     return String;
  60.     } else if (c == 12) {
  61.     if (ison(glob_flags, IS_GETTING))
  62.         Addch(c);
  63.     else do_clear();
  64.     } else if (count == BUFSIZ-1)
  65.     print("Text too long for String!"), count--;
  66.     else if (c == '\t')
  67.     do Addch(' ');
  68.     while (count % 8 && count < BUFSIZ);
  69.     else
  70.     Addch(c);
  71.     return NULL;
  72. }
  73.  
  74. backspace()
  75. {
  76.     if (backchars) {
  77.     pw_text(msg_win, save_orig_x, txt.y, PIX_SRC, fonts[curfont],
  78.         &String[--backchars]);
  79.     Clrtoeol(msg_win, msg_rect.r_width-10-l_width(curfont), txt.y, curfont);
  80.     } else if ((txt.x -= l_width(curfont)) >= 5)
  81.     pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], ' ');
  82.     else
  83.     txt.x = 5;
  84. }
  85.  
  86. static
  87. Addch(c)
  88. register char c;
  89. {
  90.     if (!count)
  91.     save_orig_x = txt.x, bzero(String, BUFSIZ);
  92.     if (c > 31 && c != 127)
  93.     String[count++] = c;
  94.     else {
  95.     Addch('^');
  96.     Addch(_unctrl[c][1]);
  97.     return;
  98.     }
  99.     pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], c);
  100.     if ((txt.x += l_width(curfont)) <= msg_rect.r_width-5-l_width(curfont))
  101.     return;
  102.     if (getting_opts) {
  103.     pw_text(msg_win, save_orig_x, txt.y, PIX_SRC, fonts[curfont],
  104.         &String[++backchars]);
  105.     txt.x -= l_width(curfont);
  106.     pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], ' ');
  107.     } else {
  108.     txt.x = 5;
  109.     if ((txt.y += l_height(curfont)) >= LASTLINE)
  110.         scroll_win(1);
  111.     }
  112. }
  113.  
  114. Addstr(s)
  115. register char *s;
  116. {
  117.     char buf[BUFSIZ];
  118.     register int cnt = 0, max_len;
  119.     register char *p = buf, newline = 0;
  120.  
  121.     max_len = (msg_rect.r_width - 10) / l_width(curfont) + 1;
  122.  
  123.     while ((*p = *s++) && *p != '\n' && cnt < max_len)
  124.     if (*p == '\t')
  125.         do *p++ = ' ';
  126.         while (++cnt % 8);
  127.     else p++, cnt++;
  128.     *p = 0;
  129.  
  130.     if (*--s)
  131.     newline = *s, *s = 0; /* newline may or may not be a '\n' */
  132.     else
  133.     s = 0;
  134.  
  135.     if (*buf) {
  136.     if (msg_pix) {
  137.         struct pr_prpos pixr;
  138.         pixr.pr = msg_pix;
  139.         pixr.pos = txt;
  140.         pf_text(pixr, PIX_SRC, fonts[curfont], buf);
  141.     } else
  142.         pw_text(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], buf);
  143.     txt.x += cnt * l_width(curfont);
  144.     }
  145.     if (newline) {
  146.     if (newline != '\n')
  147.         *s = newline;
  148.     if ((txt.y += l_height(curfont)) >= LASTLINE && !msg_pix)
  149.         scroll_win(1);
  150.     txt.x = 5;
  151.     if (newline == '\n' && !*++s)
  152.         return;
  153.     Addstr(s);
  154.     }
  155. }
  156.  
  157. tool_more(p)
  158. register char *p;
  159. {
  160.     int percent;
  161.     /* we are typing -- scrool the window */
  162.     if (!msg_pix) {
  163.     scroll_win(1);
  164.     return;
  165.     }
  166.     if (p)
  167.     print(p);
  168.     else {
  169.     if ((percent = (still_more * 100) / msg_pix->pr_size.y) >= 100)
  170.         print( "--End of Message %d--", current_msg+1);
  171.     else
  172.         print("--Message %d--(%d%%)", current_msg+1, percent);
  173.     if (ison(glob_flags, IS_GETTING))
  174.         print_more(" ('q' returns to type-in mode)");
  175.     }
  176. }
  177.