home *** CD-ROM | disk | FTP | other *** search
/ ftp.freefriends.org / ftp.freefriends.org.tar / ftp.freefriends.org / arnold / Source / mush.rstevens.tar.gz / mush.tar / print.c < prev    next >
C/C++ Source or Header  |  1990-10-21  |  5KB  |  218 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.     char buf[BUFSIZ];
  14.  
  15.     (void) sprintf(buf, fmt, arg1, arg2, arg3, arg4);
  16.     sprintf(buf+strlen(buf), ": %s\n", sys_errlist[errno]);
  17. #ifdef SUNTOOL
  18.     if (istool > 1)
  19.     ok_box(buf);
  20.     else
  21. #endif /* SUNTOOL */
  22.     print(buf);
  23. }
  24.  
  25. #if defined(SUNTOOL) || defined(CURSES)
  26. /*
  27.  * print just like printf -- to a window, to curses, or to stdout.  Use vprintf
  28.  * if available.  msgbuf is the buffer used to print into if necessary.
  29.  * If you're running SUN3.2 or higher, the typecast (unsigned char *)msgbuf
  30.  * (where indicated) otherwise, msgbuf is not typecast at all.
  31.  */
  32. /*VARARGS*/
  33. void
  34. print(va_alist)
  35. va_dcl
  36. {
  37.     static char msgbuf[BUFSIZ];
  38.     char *fmt;
  39.     va_list args;
  40. #ifndef VPRINTF
  41.     FILE foo;
  42. #endif /* VPRINTF */
  43.     static int x; /* position on line saved for continued prints */
  44.     char *p; /* same type as struct file _ptr,_buf in stdio.h */
  45.  
  46. #ifdef CURSES
  47.     if (iscurses) {
  48.     if (isoff(glob_flags, CONT_PRNT))
  49.         move(LINES-1, x = 0), refresh();
  50.     } else
  51. #endif /* CURSES */
  52.     if (istool < 2) {
  53.         va_start(args);
  54.         fmt = va_arg(args, char *);
  55. #ifdef VPRINTF
  56.         (void) vprintf(fmt, args);
  57. #else /* VPRINTF */
  58.         _doprnt(fmt, args, stdout);
  59. #endif /* VPRINTF */
  60.         va_end(args);
  61.         (void) fflush(stdout);
  62.         return;
  63.     }
  64.     va_start(args);
  65.     fmt = va_arg(args, char *);
  66.     if (fmt) {
  67. #ifdef VPRINTF
  68.     (void) vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  69. #else /* VPRINTF */
  70.     foo._cnt = BUFSIZ;
  71.     foo._base = foo._ptr = msgbuf; /* may have to cast(unsigned char *) */
  72.     foo._flag = _IOWRT+_IOSTRG;
  73.     (void) _doprnt(fmt, args, &foo);
  74.     *foo._ptr = '\0'; /* plant terminating null character */
  75. #endif /* VPRINTF */
  76.     }
  77.     va_end(args);
  78.     if (istool) {
  79.     wprint("%s", msgbuf);
  80.     return;
  81.     }
  82.     p = msgbuf;
  83.     if (iscurses)
  84.     while (p = index(p, '\n'))
  85.         *p = ' ';
  86. #ifdef CURSES
  87.     if (iscurses) {
  88.     p = msgbuf;
  89.     for (;;) {
  90.         int len = COLS-1-x; /* space remaining at till the eol */
  91.         /* don't wrap the line! Just print it and refresh() */
  92.         printw("%-.*s", len, p), clrtoeol(), refresh();
  93.         /* if length(p) (remainder of msgbuf) doesn't wrap, break loop */
  94.         if ((x += strlen(p)) < COLS-1)
  95.         break;
  96.         /* the next print will overwrite bottom line, so \n first */
  97.         putchar('\n'), move(LINES-1, x = 0); /* reset x */
  98.         /* move p forward the number of chars we were able to display */
  99.         p += len;
  100.         turnon(glob_flags, CNTD_CMD); /* display ...continue... prompt */
  101.     }
  102.     turnoff(glob_flags, CONT_PRNT);
  103.     (void) fflush(stdout); /* some sys-v's aren't fflushing \n's */
  104.     return;
  105.     }
  106. #endif /* CURSES */
  107. }
  108.  
  109. #endif /* SUNTOOL || CURSES */
  110.  
  111. /* for curses mode */
  112. clr_bot_line()
  113. {
  114.     print("");
  115. }
  116.  
  117. #ifdef SUNTOOL
  118.  
  119. /*
  120.  * wprint prints stuff to a scrollable textsw.  This is intended for
  121.  * print statements that need to be recalled since print() overwrites
  122.  * its last message.
  123.  * For non-suntool mode, wprint() is just like printf().  For curses mode,
  124.  * wprint() does -not- act like print() -- lines length is not counted
  125.  * and newlines are not stripped.
  126.  */
  127. /*VARARGS*/
  128. void
  129. wprint(va_alist)
  130. va_dcl
  131. {
  132. #ifndef VPRINTF
  133.     FILE foo;
  134. #endif /* VPRINTF */
  135.     char msgbuf[BUFSIZ]; /* we're not getting huge strings */
  136.     char *fmt;
  137.     va_list args;
  138.  
  139.     if (istool < 2) {
  140.     va_start(args);
  141.     fmt = va_arg(args, char *);
  142. #ifdef VPRINTF
  143.     (void) vprintf(fmt, args);
  144. #else /* VPRINTF */
  145.     _doprnt(fmt, args, stdout);
  146. #endif /* VPRINTF */
  147.     va_end(args);
  148.     (void) fflush(stdout);
  149.     return;
  150.     }
  151.  
  152.     if (!mfprint_sw)
  153.         return;
  154.     va_start(args);
  155.     fmt = va_arg(args, char *);
  156.     if (fmt) {
  157. #ifdef VPRINTF
  158.     (void) vsprintf(msgbuf, fmt, args); /* NULL in fmt reprints last msg */
  159. #else /* VPRINTF */
  160.     foo._cnt = BUFSIZ;
  161.     foo._base = foo._ptr = msgbuf; /* may have to cast (unsigned char *) */
  162.     foo._flag = _IOWRT+_IOSTRG;
  163.     _doprnt(fmt, args, &foo); /* format like printf into msgbuf via foo */
  164.     *foo._ptr = '\0'; /* plant terminating null character */
  165. #endif /* VPRINTF */
  166.     textsw_insert(mfprint_sw, msgbuf, strlen(msgbuf));
  167.     }
  168.     va_end(args);
  169. }
  170.  
  171. #include <sundev/kbio.h>
  172. #include <sundev/kbd.h>
  173.  
  174. bell()
  175. {
  176. #ifdef KIOCCMD
  177.     if (istool) {
  178.     int kbd = open("/dev/kbd", O_WRONLY, 0);
  179.     struct timeval timer;
  180.     timer.tv_sec = 0;
  181.     timer.tv_usec = 100000;
  182.     if (kbd != -1) {
  183.         int cmd = KBD_CMD_BELL;
  184.         (void) ioctl(kbd, KIOCCMD, &cmd);
  185.         (void) select(32, (fd_set *) 0,(fd_set *) 0,(fd_set *) 0, &timer);
  186.         cmd = KBD_CMD_NOBELL;
  187.         (void) ioctl(kbd, KIOCCMD, &cmd);
  188.         (void) close(kbd);
  189.     }
  190.     } else
  191. #endif /* KIOCCMD */
  192.     (void) fputc('\007', stderr), (void) fflush(stderr);
  193.     return 0;
  194. }
  195.  
  196. #endif /* SUNTOOL */
  197.  
  198. #ifdef BSD
  199. #undef fputs
  200.  
  201. /*
  202.  * The standard 4.x BSD fputs() does not return any useful value.
  203.  * For compatibility with Sun and SysV fputs(), we use this wrapper.
  204.  */
  205.  
  206. Fputs(line, fp)
  207. char *line;
  208. FILE *fp;
  209. {
  210.     clearerr(fp);
  211.     (void) fputs(line, fp);
  212.     if (ferror(fp))
  213.     return EOF;
  214.     return 0;
  215. }
  216.  
  217. #endif /* BSD */
  218.