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