home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume14 / mush6.0 / part02 / print.c < prev    next >
C/C++ Source or Header  |  1988-04-12  |  5KB  |  186 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. /*VARARGS1*/
  26. void
  27. print(fmt, va_alist)
  28. register char *fmt;
  29. va_dcl
  30. {
  31.     static char msgbuf[BUFSIZ];
  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.     va_start(args); /* have args point to the beginning of argument stack */
  40.  
  41. #ifdef CURSES
  42.     if (iscurses) {
  43.     if (isoff(glob_flags, CONT_PRNT))
  44.         move(LINES-1, x = 0), refresh();
  45.     } else
  46. #endif /* CURSES */
  47.     if (istool < 2) {
  48. #ifdef VPRINTF
  49.         vprintf(fmt, args);
  50. #else /* VPRINTF */
  51.         _doprnt(fmt, args, stdout);
  52. #endif /* VPRINTF */
  53.         fflush(stdout);
  54.         va_end(args);
  55.         return;
  56.     }
  57. #ifdef VPRINTF
  58.     if (fmt)
  59.     vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  60. #else /* VPRINTF */
  61.     foo._cnt = BUFSIZ;
  62.     foo._base = foo._ptr = msgbuf; /* may have to be cast(unsigned char *) */
  63.     foo._flag = _IOWRT+_IOSTRG;
  64.     if (fmt) {   /* passing NULL (not "") reprints last message */
  65.     (void) _doprnt(fmt, args, &foo);
  66.     *foo._ptr = '\0'; /* plant terminating null character */
  67.     }
  68. #endif /* VPIRNTF */
  69.     va_end(args);
  70.     p = msgbuf;
  71.     if (iscurses || istool)
  72.     while (p = index(p, '\n'))
  73.         *p = ' ';
  74. #ifdef CURSES
  75.     if (iscurses) {
  76.     p = msgbuf;
  77.     for (;;) {
  78.         int len = COLS-1-x; /* space remaining at till the eol */
  79.         /* don't wrap the line! Just print it and refresh() */
  80.         printw("%-.*s", len, p), clrtoeol(), refresh();
  81.         /* if length(p) (remainder of msgbuf) doesn't wrap, break loop */
  82.         if ((x += strlen(p)) < COLS-1)
  83.         break;
  84.         /* the next print will overwrite bottom line, so \n first */
  85.         putchar('\n'), move(LINES-1, x = 0); /* reset x */
  86.         /* move p forward the number of chars we were able to display */
  87.         p += len;
  88.         turnon(glob_flags, CNTD_CMD); /* display ...continue... prompt */
  89.     }
  90.     turnoff(glob_flags, CONT_PRNT);
  91.     return;
  92.     }
  93. #endif /* CURSES */
  94. #ifdef SUNTOOL
  95.     if (isoff(glob_flags, CONT_PRNT))
  96.     x = 5;
  97.     turnoff(glob_flags, CONT_PRNT);
  98.     pw_text(print_win, x,   l_height(LARGE), PIX_SRC, fonts[LARGE], msgbuf);
  99.     pw_text(print_win, x+1, l_height(LARGE), PIX_SRC|PIX_DST,
  100.                fonts[LARGE], msgbuf);
  101.     x += strlen(msgbuf) * l_width(LARGE);
  102.     Clrtoeol(print_win, x, l_height(LARGE), LARGE);
  103. #endif /* SUNTOOL */
  104. }
  105. #endif /* SUNTOOL || CURSES */
  106.  
  107. #ifdef SUNTOOL
  108. /*VARARGS*/
  109. void
  110. wprint(fmt, va_alist)
  111. register char *fmt;
  112. va_dcl
  113. {
  114. #ifndef VPRINTF
  115.     FILE foo;
  116. #endif /* VPRINTF */
  117.     char msgbuf[BUFSIZ]; /* we're not getting huge strings */
  118.     va_list args;
  119.  
  120.     va_start(args);
  121.  
  122.     if (istool < 2) {
  123. #ifdef VPRINTF
  124.     vprintf(fmt, args);
  125. #else /* VPRINTF */
  126.     _doprnt(fmt, args, stdout);
  127. #endif /* VPRINTF */
  128.     va_end(args);
  129.     fflush(stdout);
  130.     return;
  131.     }
  132.     if (!fmt)
  133.     return;
  134. #ifdef VPRINTF
  135.     vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  136. #else /* VPRINTF */
  137.     foo._cnt = BUFSIZ;
  138.     foo._base = foo._ptr = msgbuf; /* may have to typecast (unsigned char *) */
  139.     foo._flag = _IOWRT+_IOSTRG;
  140.     _doprnt(fmt, args, &foo); /* format like printf into msgbuf via foo */
  141.     *foo._ptr = '\0'; /* plant terminating null character */
  142. #endif /* VPRINTF */
  143.     Addstr(msgbuf);  /* addstr() will scroll if necessary */
  144. }
  145.  
  146. /*
  147.  * scroll the msg_win "lines"
  148.  * if `lines' is negative (backwards scroll) msg_pix can't be NULL
  149.  */
  150. void
  151. scroll_win(lines)
  152. register int lines;
  153. {
  154.     register int y = lines * l_height(curfont);
  155.     if (txt.y + y < msg_rect.r_height)
  156.     y = 0;  /* temporary */
  157.     txt.x = 5;
  158.  
  159.     if (msg_pix) {
  160.     if (txt.y + y >= msg_pix->pr_size.y - 5)
  161.         y = msg_pix->pr_size.y - txt.y;
  162.     still_more += y; /* let scrolling know where we are */
  163.     txt.y += y;
  164.     pw_rop(msg_win, 0, 5,
  165.            msg_rect.r_width, crt * l_height(curfont),
  166.            PIX_SRC, msg_pix, 0, txt.y - msg_rect.r_height + 3);
  167.     tool_more(NULL);
  168.     return;
  169.     }
  170.     /* y must be positive (forward scrolling) so we're scrolling typed
  171.      * text or something like that (~p, ~?, etc...)
  172.      */
  173.     pw_copy(msg_win, 0, 0,
  174.     msg_rect.r_width, msg_rect.r_height - y,
  175.     PIX_SRC, msg_win, 0, y);
  176.     pw_writebackground(msg_win, 0, msg_rect.r_height - y,
  177.     msg_rect.r_width, y, PIX_CLR);
  178.     txt.y -= y;
  179. }
  180. #endif /* SUNTOOL */
  181.  
  182. clr_bot_line()
  183. {
  184.     print("");
  185. }
  186.