home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume14 / mush6.0 / part02 / rite.c < prev    next >
C/C++ Source or Header  |  1988-04-12  |  4KB  |  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 String[BUFSIZ];
  8. static int count, overflow, save_orig_x;
  9.  
  10. char *
  11. rite(c)
  12. register char c;
  13. {
  14.     static int literal_next;
  15.  
  16.     if (c == ltchars.t_lnextc || literal_next) {
  17.     if (literal_next)
  18.         Addch(c);
  19.     else /* don't call Addch to prevent cursor from advancing */
  20.         pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], '^');
  21.     literal_next = !literal_next;
  22.     return NULL;
  23.     }
  24.     literal_next = 0;
  25.     if (c == _tty.sg_erase || c == CTRL(127) || c == CTRL(H)) {
  26.     if (count)
  27.         backspace();
  28.     } else if (c == _tty.sg_kill) {
  29.     if (count) {
  30.         Clrtoeol(msg_win, txt.x = save_orig_x, txt.y,curfont);
  31.         overflow = count = String[0] = 0;
  32.     }
  33.     } else if (c == ltchars.t_werasc)
  34.     while (count) {
  35.         char c = String[count-1];
  36.         backspace();
  37.         if (!count ||
  38.         isspace(String[count-1]) && !isspace(c) ||
  39.         !isalnum(String[count-1]) && isalnum(c))
  40.         break;
  41.     }
  42.     else if (c == '\n' || c == '\r' || c == 13) {
  43.     String[count] = 0;
  44.     if ((txt.y += l_height(curfont)) >= LASTLINE && !getting_opts)
  45.         scroll_win(1);
  46.     /* else Clrtoeol(msg_win, txt.x, txt.y, curfont); */
  47.     overflow = count = 0, txt.x = 5;
  48.     return String;
  49.     } else if (c == 12)
  50.     if (ison(glob_flags, IS_GETTING))
  51.         Addch(c);
  52.     else
  53.         do_clear();
  54.     else if (count == BUFSIZ-1)
  55.     print("Text too long for String!"), count--;
  56.     else if (c == '\t')
  57.     do Addch(' ');
  58.     while (count % 8 && count < BUFSIZ);
  59.     else
  60.     Addch(c);
  61.     return NULL;
  62. }
  63.  
  64. static
  65. backspace()
  66. {
  67.     if (overflow) {
  68.     pw_text(msg_win, save_orig_x, txt.y, PIX_SRC, fonts[curfont],
  69.         &String[--overflow]);
  70.     Clrtoeol(msg_win, msg_rect.r_width-10-l_width(curfont), txt.y, curfont);
  71.     String[--count] = 0;
  72.     } else if ((txt.x -= l_width(curfont)) >= 5) {
  73.     if (iscntrl(String[count-1])) {
  74.         pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], ' ');
  75.         txt.x -= l_width(curfont);
  76.     }
  77.     pw_char(msg_win, txt.x, txt.y, PIX_SRC, fonts[curfont], ' ');
  78.     String[--count] = 0;
  79.     } else
  80.     txt.x = 5;
  81. }
  82.  
  83. static
  84. Addch(c)
  85. register char c;
  86. {
  87.     extern char *_unctrl[];
  88.  
  89.     if (!count)
  90.     save_orig_x = txt.x, bzero(String, BUFSIZ);
  91.     if (c > 31 && c != 127)
  92.     String[count++] = c;
  93.     else {
  94.     Addch('^'), count--;
  95.     Addch(_unctrl[c][1]);
  96.     String[count-1] = c;
  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[++overflow]);
  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.