home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume18 / mush6.4 / part03 / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-12  |  5.1 KB  |  195 lines

  1. /* @(#)print.c    2.4    (c) copyright 10/15/86 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4. #include <varargs.h>
  5.  
  6. /*ARGSUSED*/
  7. /*VARARGS1*/
  8. void
  9. error(fmt, arg1, arg2, arg3, arg4)
  10. register char *fmt;
  11. char *arg1, *arg2, *arg3, *arg4;
  12. {
  13.     print(fmt, arg1, arg2, arg3, arg4);
  14.     print_more(": %s\n", sys_errlist[errno]);
  15. }
  16.  
  17. #if defined(SUNTOOL) || defined(CURSES)
  18. /*
  19.  * print just like printf -- to a window, to curses, or to stdout.  Use vprintf
  20.  * if available.  msgbuf is the buffer used to print into if necessary.
  21.  * If you're running SUN3.2 or higher, the typecast (unsigned char *)msgbuf
  22.  * (where indicated) otherwise, msgbuf is not typecast at all.
  23.  * Also note same casting in wprint().
  24.  */
  25. /*VARARGS*/
  26. void
  27. print(va_alist)
  28. va_dcl
  29. {
  30.     static char msgbuf[BUFSIZ];
  31.     char *fmt;
  32.     va_list args;
  33. #ifndef VPRINTF
  34.     FILE foo;
  35. #endif /* VPRINTF */
  36.     static int x; /* position on line saved for continued prints */
  37.     char *p; /* same type as struct file _ptr,_buf in stdio.h */
  38.  
  39. #ifdef CURSES
  40.     if (iscurses) {
  41.     if (isoff(glob_flags, CONT_PRNT))
  42.         move(LINES-1, x = 0), refresh();
  43.     } else
  44. #endif /* CURSES */
  45.     if (istool < 2) {
  46.         va_start(args);
  47.         fmt = va_arg(args, char *);
  48. #ifdef VPRINTF
  49.         vprintf(fmt, args);
  50. #else /* VPRINTF */
  51.         _doprnt(fmt, args, stdout);
  52. #endif /* VPRINTF */
  53.         va_end(args);
  54.         fflush(stdout);
  55.         return;
  56.     }
  57.     va_start(args);
  58.     fmt = va_arg(args, char *);
  59.     if (fmt) {
  60. #ifdef VPRINTF
  61.     vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  62. #else /* VPRINTF */
  63.     foo._cnt = BUFSIZ;
  64.     foo._base = foo._ptr = msgbuf; /* may have to cast(unsigned char *) */
  65.     foo._flag = _IOWRT+_IOSTRG;
  66.     (void) _doprnt(fmt, args, &foo);
  67.     *foo._ptr = '\0'; /* plant terminating null character */
  68. #endif /* VPRINTF */
  69.     }
  70.     va_end(args);
  71.     p = msgbuf;
  72.     if (iscurses || istool)
  73.     while (p = index(p, '\n'))
  74.         *p = ' ';
  75. #ifdef CURSES
  76.     if (iscurses) {
  77.     p = msgbuf;
  78.     for (;;) {
  79.         int len = COLS-1-x; /* space remaining at till the eol */
  80.         /* don't wrap the line! Just print it and refresh() */
  81.         printw("%-.*s", len, p), clrtoeol(), refresh();
  82.         /* if length(p) (remainder of msgbuf) doesn't wrap, break loop */
  83.         if ((x += strlen(p)) < COLS-1)
  84.         break;
  85.         /* the next print will overwrite bottom line, so \n first */
  86.         putchar('\n'), move(LINES-1, x = 0); /* reset x */
  87.         /* move p forward the number of chars we were able to display */
  88.         p += len;
  89.         turnon(glob_flags, CNTD_CMD); /* display ...continue... prompt */
  90.     }
  91.     turnoff(glob_flags, CONT_PRNT);
  92.     fflush(stdout); /* some sys-v's aren't fflushing \n's */
  93.     return;
  94.     }
  95. #endif /* CURSES */
  96. #ifdef SUNTOOL
  97.     if (isoff(glob_flags, CONT_PRNT))
  98.     x = 5;
  99.     turnoff(glob_flags, CONT_PRNT);
  100.     pw_text(print_win, x,   l_height(LARGE), PIX_SRC, fonts[LARGE], msgbuf);
  101.     pw_text(print_win, x+1, l_height(LARGE), PIX_SRC|PIX_DST,
  102.                fonts[LARGE], msgbuf);
  103.     x += strlen(msgbuf) * l_width(LARGE);
  104.     Clrtoeol(print_win, x, l_height(LARGE), LARGE);
  105. #endif /* SUNTOOL */
  106. }
  107. #endif /* SUNTOOL || CURSES */
  108.  
  109. #ifdef SUNTOOL
  110. /*VARARGS*/
  111. void
  112. wprint(va_alist)
  113. va_dcl
  114. {
  115. #ifndef VPRINTF
  116.     FILE foo;
  117. #endif /* VPRINTF */
  118.     char msgbuf[BUFSIZ]; /* we're not getting huge strings */
  119.     char *fmt;
  120.     va_list args;
  121.  
  122.     if (istool < 2) {
  123.     va_start(args);
  124.     fmt = va_arg(args, char *);
  125. #ifdef VPRINTF
  126.     vprintf(fmt, args);
  127. #else /* VPRINTF */
  128.     _doprnt(fmt, args, stdout);
  129. #endif /* VPRINTF */
  130.     va_end(args);
  131.     fflush(stdout);
  132.     return;
  133.     }
  134.     va_start(args);
  135.     fmt = va_arg(args, char *);
  136.     if (fmt) {
  137. #ifdef VPRINTF
  138.     vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  139. #else /* VPRINTF */
  140.     foo._cnt = BUFSIZ;
  141.     foo._base = foo._ptr = msgbuf; /* may have to cast (unsigned char *) */
  142.     foo._flag = _IOWRT+_IOSTRG;
  143.     _doprnt(fmt, args, &foo); /* format like printf into msgbuf via foo */
  144.     *foo._ptr = '\0'; /* plant terminating null character */
  145. #endif /* VPRINTF */
  146.     Addstr(msgbuf);  /* addstr() will scroll if necessary */
  147.     }
  148.     va_end(args);
  149. }
  150.  
  151. /*
  152.  * scroll the msg_win "lines"
  153.  * if `lines' is negative (backwards scroll) msg_pix can't be NULL
  154.  */
  155. void
  156. scroll_win(lines)
  157. register int lines;
  158. {
  159.     register int y = lines * l_height(curfont);
  160.     /* if the user attempts to scroll back to before the beginning of the
  161.      * message [either with the middle mouse button or the keyboard command
  162.      * keys ('k', 'K', '-')], scroll back only to the beginning of the message.
  163.      */
  164.     if (txt.y + y < msg_rect.r_height)
  165.     y = - (txt.y - msg_rect.r_height);
  166.     txt.x = 5;
  167.  
  168.     if (msg_pix) {
  169.     if (txt.y + y >= msg_pix->pr_size.y - 5)
  170.         y = msg_pix->pr_size.y - txt.y;
  171.     still_more += y; /* let scrolling know where we are */
  172.     txt.y += y;
  173.     pw_rop(msg_win, 0, 5,
  174.            msg_rect.r_width, crt * l_height(curfont),
  175.            PIX_SRC, msg_pix, 0, txt.y - msg_rect.r_height + 3);
  176.     tool_more(NULL);
  177.     return;
  178.     }
  179.     /* y must be positive (forward scrolling) so we're scrolling typed
  180.      * text or something like that (~p, ~?, etc...)
  181.      */
  182.     pw_copy(msg_win, 0, 0,
  183.     msg_rect.r_width, msg_rect.r_height - y,
  184.     PIX_SRC, msg_win, 0, y);
  185.     pw_writebackground(msg_win, 0, msg_rect.r_height - y,
  186.     msg_rect.r_width, y, PIX_CLR);
  187.     txt.y -= y;
  188. }
  189. #endif /* SUNTOOL */
  190.  
  191. clr_bot_line()
  192. {
  193.     print("");
  194. }
  195.