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

  1. /* @(#)print.c    2.4    (c) copyright 10/15/86 (Dan Heller) */
  2.  
  3. #include "mush.h"
  4.  
  5. /*ARGSUSED*/
  6. /*VARARGS1*/
  7. void
  8. error(fmt, arg1, arg2, arg3, arg4)
  9. register char *fmt;
  10. char *arg1, *arg2, *arg3, *arg4;
  11. {
  12.     print(fmt, arg1, arg2, arg3, arg4);
  13.     print_more(": %s\n", sys_errlist[errno]);
  14. }
  15.  
  16. #if defined(SUNTOOL) || defined(CURSES)
  17. /*
  18.  * print just like printf -- to a window, to curses, or to stdout.  Use vprintf
  19.  * if available.  msgbuf is the buffer used to print into if necessary.
  20.  * If you're running SUN3.2 or higher, the typecast (unsigned char *)msgbuf
  21.  * (where indicated) otherwise, msgbuf is not typecast at all.
  22.  * Also note same casting in wprint().
  23.  */
  24. /*VARARGS1*/
  25. void
  26. print(fmt, args)
  27. register char *fmt;
  28. char *args;
  29. {
  30.     static char msgbuf[BUFSIZ];
  31. #ifndef VPRINTF
  32.     FILE foo;
  33. #endif VPRINTF
  34. #ifdef SUNTOOL
  35.     static int x;
  36. #endif SUNTOOL
  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, 0), refresh();
  43.     turnoff(glob_flags, CONT_PRNT);
  44.     } else
  45. #endif CURSES
  46.     if (istool < 2) {
  47. #ifdef VPRINTF
  48.         vprintf(fmt, &args), fflush(stdout);
  49. #else
  50.         _doprnt(fmt, &args, stdout), fflush(stdout);
  51. #endif VPRINTF
  52.         return;
  53.     }
  54. #ifdef VPRINTF
  55.     if (fmt)
  56.     vsprintf(msgbuf, fmt, &args); /* NULL in fmt reprints last msg */
  57. #else VPRINTF
  58.     foo._cnt = BUFSIZ;
  59.     foo._base = foo._ptr = msgbuf; /* may have to be cast(unsigned char *) */
  60.     foo._flag = _IOWRT+_IOSTRG;
  61.     if (fmt) {   /* passing NULL (not "") reprints last message */
  62.     (void) _doprnt(fmt, &args, &foo);
  63.     *foo._ptr = '\0'; /* plant terminating null character */
  64.     }
  65. #endif VPIRNTF
  66.     p = msgbuf;
  67.     if (iscurses || istool)
  68.     while (p = index(p, '\n'))
  69.         *p = ' ';
  70. #ifdef CURSES
  71.     if (iscurses) {
  72.     addstr(msgbuf), clrtoeol(), refresh();
  73.     return;
  74.     }
  75. #endif CURSES
  76. #ifdef SUNTOOL
  77.     if (isoff(glob_flags, CONT_PRNT))
  78.     x = 5;
  79.     turnoff(glob_flags, CONT_PRNT);
  80.     pw_text(print_win, x,   l_height(LARGE), PIX_SRC, fonts[LARGE], msgbuf);
  81.     pw_text(print_win, x+1, l_height(LARGE), PIX_SRC|PIX_DST,
  82.                fonts[LARGE], msgbuf);
  83.     x += strlen(msgbuf) * l_width(LARGE);
  84.     Clrtoeol(print_win, x, l_height(LARGE), LARGE);
  85. #endif SUNTOOL
  86. }
  87. #endif SUNTOOL || CURSES
  88.  
  89. #ifdef SUNTOOL
  90. /*VARARGS*/
  91. void
  92. wprint(fmt, args)
  93. char *fmt, *args;
  94. {
  95. #ifndef VPRINTF
  96.     FILE foo;
  97. #endif VPRINTF
  98.     char msgbuf[BUFSIZ]; /* we're not getting huge strings */
  99.  
  100.     if (istool < 2) {
  101. #ifdef VPRINTF
  102.     vprintf(fmt, &args);
  103. #else VPRINTF
  104.     _doprnt(fmt, &args, stdout);
  105. #endif VPRINTF
  106.     fflush(stdout);
  107.     return;
  108.     }
  109.     if (!fmt)
  110.     return;
  111. #ifdef VPRINTF
  112.     vsprintf(msgbuf, fmt, &args); /* NULL in fmt reprints last msg */
  113. #else VPRINTF
  114.     foo._cnt = BUFSIZ;
  115.     foo._base = foo._ptr = msgbuf; /* may have to typecast (unsigned char *) */
  116.     foo._flag = _IOWRT+_IOSTRG;
  117.     _doprnt(fmt, &args, &foo); /* format like printf into msgbuf via foo */
  118.     *foo._ptr = '\0'; /* plant terminating null character */
  119. #endif VPRINTF
  120.     Addstr(msgbuf);  /* addstr() will scroll if necessary */
  121. }
  122.  
  123. /*
  124.  * scroll the msg_win "lines"
  125.  * if `lines' is negative (backwards scroll) msg_pix can't be NULL
  126.  */
  127. void
  128. scroll_win(lines)
  129. register int lines;
  130. {
  131.     register int y = lines * l_height(curfont);
  132.     if (txt.y + y < msg_rect.r_height)
  133.     y = 0;  /* temporary */
  134.     txt.x = 5;
  135.  
  136.     if (msg_pix) {
  137.     if (txt.y + y >= msg_pix->pr_size.y - 5)
  138.         y = msg_pix->pr_size.y - txt.y;
  139.     still_more += y; /* let scrolling know where we are */
  140.     txt.y += y;
  141.     pw_rop(msg_win, 0, 5,
  142.            msg_rect.r_width, crt * l_height(curfont),
  143.            PIX_SRC, msg_pix, 0, txt.y - msg_rect.r_height + 3);
  144.     tool_more(NULL);
  145.     return;
  146.     }
  147.     /* y must be positive (forward scrolling) so we're scrolling typed
  148.      * text or something like that (~p, ~?, etc...)
  149.      */
  150.     pw_copy(msg_win, 0, 0,
  151.     msg_rect.r_width, msg_rect.r_height - y,
  152.     PIX_SRC, msg_win, 0, y);
  153.     pw_writebackground(msg_win, 0, msg_rect.r_height - y,
  154.     msg_rect.r_width, y, PIX_CLR);
  155.     txt.y -= y;
  156. }
  157. #endif SUNTOOL
  158.  
  159. #ifdef CURSES
  160. clr_bot_line()
  161. {
  162.     print("");
  163. }
  164. #endif CURSES
  165.