date and time created 91/04/12 13:40:37 by bostic
[unix-history] / usr / src / lib / libcurses / printw.c
CommitLineData
87c6fcf8 1/*
2f14f200
KB
2 * Copyright (c) 1981 Regents of the University of California.
3 * All rights reserved.
4 *
e21c485a 5 * %sccs.include.redist.c%
87c6fcf8
DF
6 */
7
8#ifndef lint
5e2f9f86 9static char sccsid[] = "@(#)printw.c 5.7 (Berkeley) %G%";
2f14f200 10#endif /* not lint */
87c6fcf8 11
113386fd
KA
12/*
13 * printw and friends
14 *
113386fd
KA
15 */
16
3a8b9a26 17# include <varargs.h>
113386fd
KA
18# include "curses.ext"
19
20/*
21 * This routine implements a printf on the standard screen.
22 */
3a8b9a26
CT
23printw(va_alist)
24va_dcl {
113386fd 25
3a8b9a26
CT
26 va_list ap;
27 int ret;
8543fbf9 28
3a8b9a26
CT
29 va_start(ap);
30 ret = _sprintw(stdscr, ap);
31 va_end(ap);
32 return (ret);
113386fd
KA
33}
34
35/*
36 * This routine implements a printf on the given window.
37 */
3a8b9a26
CT
38wprintw(va_alist)
39va_dcl {
40
41 va_list ap;
42 WINDOW *win;
43 int ret;
44
5e2f9f86 45 va_start(ap);
3a8b9a26
CT
46 win = va_arg(ap, WINDOW *);
47 ret = _sprintw(win, ap);
48 va_end(ap);
49 return (ret);
50}
51
52/*
53 * Internal write-buffer-to-window function.
54 */
55static int
56_winwrite(cookie, buf, n)
57void *cookie;
58reg char *buf;
59int n; {
60
61 reg WINDOW *win = (WINDOW *)cookie;
62 reg int c = n;
63
64 while (--c >= 0) {
65 if (waddch(win, *buf++) == ERR)
66 return (-1);
67 }
68 return n;
69}
70
71/*
72 * This routine actually executes the printf and adds it to the window.
73 * It must not be declared static as it is used in mvprintw.c.
74 */
75_sprintw(win, ap)
113386fd 76WINDOW *win;
3a8b9a26 77va_list ap; {
113386fd 78
3a8b9a26
CT
79 FILE *f;
80 char *fmt;
113386fd 81
3a8b9a26
CT
82 if ((f = fwopen((void *)win, _winwrite)) == NULL)
83 return ERR;
84 fmt = va_arg(ap, char *);
85 (void) vfprintf(f, fmt, ap);
86 return fclose(f) ? ERR : OK;
113386fd 87}