[BACK]Return to printw.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libcurses

Annotation of src/lib/libcurses/printw.c, Revision 1.10

1.10    ! perry       1: /*     $NetBSD: printw.c,v 1.9 1997/07/22 07:36:56 mikel Exp $ */
1.9       mikel       2:
1.1       cgd         3: /*
1.8       cgd         4:  * Copyright (c) 1981, 1993, 1994
1.5       cgd         5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *     This product includes software developed by the University of
                     18:  *     California, Berkeley and its contributors.
                     19:  * 4. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  */
                     35:
1.9       mikel      36: #include <sys/cdefs.h>
1.1       cgd        37: #ifndef lint
1.9       mikel      38: #if 0
1.8       cgd        39: static char sccsid[] = "@(#)printw.c   8.3 (Berkeley) 5/4/94";
1.9       mikel      40: #else
1.10    ! perry      41: __RCSID("$NetBSD: printw.c,v 1.9 1997/07/22 07:36:56 mikel Exp $");
1.9       mikel      42: #endif
1.4       mycroft    43: #endif /* not lint */
1.1       cgd        44:
1.7       cgd        45: #ifdef __STDC__
1.4       mycroft    46: #include <stdarg.h>
                     47: #else
                     48: #include <varargs.h>
                     49: #endif
1.8       cgd        50:
                     51: #include "curses.h"
1.4       mycroft    52:
1.1       cgd        53: /*
                     54:  * printw and friends.
                     55:  *
                     56:  * These routines make nonportable assumptions about varargs if __STDC__
                     57:  * is not in effect.
                     58:  */
                     59:
1.4       mycroft    60: static int __winwrite __P((void *, const char *, int));
1.1       cgd        61:
                     62: /*
1.4       mycroft    63:  * printw --
                     64:  *     Printf on the standard screen.
1.1       cgd        65:  */
1.4       mycroft    66: int
1.7       cgd        67: #ifdef __STDC__
1.1       cgd        68: printw(const char *fmt, ...)
                     69: #else
                     70: printw(fmt, va_alist)
                     71:        char *fmt;
                     72:        va_dcl
                     73: #endif
                     74: {
1.4       mycroft    75:        va_list ap;
                     76:        int ret;
1.1       cgd        77:
1.7       cgd        78: #ifdef __STDC__
1.1       cgd        79:        va_start(ap, fmt);
                     80: #else
                     81:        va_start(ap);
                     82: #endif
1.5       cgd        83:        ret = vwprintw(stdscr, fmt, ap);
1.1       cgd        84:        va_end(ap);
                     85:        return (ret);
                     86: }
                     87:
                     88: /*
1.4       mycroft    89:  * wprintw --
                     90:  *     Printf on the given window.
1.1       cgd        91:  */
1.4       mycroft    92: int
1.7       cgd        93: #ifdef __STDC__
1.4       mycroft    94: wprintw(WINDOW * win, const char *fmt, ...)
1.1       cgd        95: #else
                     96: wprintw(win, fmt, va_alist)
                     97:        WINDOW *win;
                     98:        char *fmt;
                     99:        va_dcl
                    100: #endif
                    101: {
1.4       mycroft   102:        va_list ap;
                    103:        int ret;
1.1       cgd       104:
                    105: #ifdef __STDC__
                    106:        va_start(ap, fmt);
                    107: #else
                    108:        va_start(ap);
                    109: #endif
1.5       cgd       110:        ret = vwprintw(win, fmt, ap);
1.4       mycroft   111:        va_end(ap);
                    112:        return (ret);
                    113: }
                    114:
                    115: /*
                    116:  * mvprintw, mvwprintw --
                    117:  *     Implement the mvprintw commands.  Due to the variable number of
                    118:  *     arguments, they cannot be macros.  Sigh....
                    119:  */
                    120: int
1.7       cgd       121: #ifdef __STDC__
1.10    ! perry     122: mvprintw(int y, int x, const char *fmt, ...)
1.4       mycroft   123: #else
                    124: mvprintw(y, x, fmt, va_alist)
1.10    ! perry     125:        int y, x;
1.4       mycroft   126:        char *fmt;
                    127:        va_dcl
                    128: #endif
                    129: {
                    130:        va_list ap;
                    131:        int ret;
                    132:
1.7       cgd       133: #ifdef __STDC__
1.4       mycroft   134:        va_start(ap, fmt);
                    135: #else
                    136:        va_start(ap);
                    137: #endif
                    138:        if (move(y, x) != OK)
                    139:                return (ERR);
1.5       cgd       140:        ret = vwprintw(stdscr, fmt, ap);
1.4       mycroft   141:        va_end(ap);
                    142:        return (ret);
                    143: }
                    144:
                    145: int
1.7       cgd       146: #ifdef __STDC__
1.10    ! perry     147: mvwprintw(WINDOW * win, int y, int x,
1.4       mycroft   148:     const char *fmt, ...)
                    149: #else
                    150: mvwprintw(win, y, x, fmt, va_alist)
1.10    ! perry     151:        WINDOW *win;
        !           152:        int y, x;
1.4       mycroft   153:        char *fmt;
                    154:        va_dcl
                    155: #endif
                    156: {
                    157:        va_list ap;
                    158:        int ret;
                    159:
1.7       cgd       160: #ifdef __STDC__
1.4       mycroft   161:        va_start(ap, fmt);
                    162: #else
                    163:        va_start(ap);
                    164: #endif
                    165:        if (wmove(win, y, x) != OK)
                    166:                return (ERR);
                    167:
1.5       cgd       168:        ret = vwprintw(win, fmt, ap);
1.1       cgd       169:        va_end(ap);
                    170:        return (ret);
                    171: }
                    172:
                    173: /*
1.4       mycroft   174:  * Internal write-buffer-to-window function.
1.1       cgd       175:  */
                    176: static int
1.4       mycroft   177: __winwrite(cookie, buf, n)
1.1       cgd       178:        void *cookie;
1.10    ! perry     179:        const char *buf;
1.1       cgd       180:        int n;
                    181: {
1.10    ! perry     182:        WINDOW *win;
        !           183:        int c;
1.1       cgd       184:
1.4       mycroft   185:        for (c = n, win = cookie; --c >= 0;)
                    186:                if (waddch(win, *buf++) == ERR)
1.1       cgd       187:                        return (-1);
1.4       mycroft   188:        return (n);
1.1       cgd       189: }
                    190:
                    191: /*
1.5       cgd       192:  * vwprintw --
1.1       cgd       193:  *     This routine actually executes the printf and adds it to the window.
                    194:  */
1.5       cgd       195: int
                    196: vwprintw(win, fmt, ap)
1.1       cgd       197:        WINDOW *win;
                    198:        const char *fmt;
1.4       mycroft   199:        va_list ap;
1.1       cgd       200: {
                    201:        FILE *f;
                    202:
1.4       mycroft   203:        if ((f = funopen(win, NULL, __winwrite, NULL, NULL)) == NULL)
                    204:                return (ERR);
                    205:        (void)vfprintf(f, fmt, ap);
                    206:        return (fclose(f) ? ERR : OK);
1.1       cgd       207: }

CVSweb <webmaster@jp.NetBSD.org>