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

Annotation of src/lib/libterm/tputws.c, Revision 1.1

1.1     ! christos    1: /*     $NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry Exp $ */
        !             2:
        !             3: /*
        !             4:  * Copyright (c) 1980, 1993
        !             5:  *     The Regents of the University of California.  All rights reserved.
        !             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. Neither the name of the University nor the names of its contributors
        !            16:  *    may be used to endorse or promote products derived from this software
        !            17:  *    without specific prior written permission.
        !            18:  *
        !            19:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
        !            20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        !            21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
        !            22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
        !            23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        !            24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
        !            25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
        !            26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
        !            27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
        !            28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
        !            29:  * SUCH DAMAGE.
        !            30:  */
        !            31:
        !            32: #include <sys/cdefs.h>
        !            33: #ifndef lint
        !            34: #if 0
        !            35: static char sccsid[] = "@(#)tputs.c    8.1 (Berkeley) 6/4/93";
        !            36: #else
        !            37: __RCSID("$NetBSD: tputs.c,v 1.22 2005/02/04 15:52:08 perry Exp $");
        !            38: #endif
        !            39: #endif /* not lint */
        !            40:
        !            41: #include <assert.h>
        !            42: #include <wctype.h>
        !            43: #include <wchar.h>
        !            44: #include <termcap.h>
        !            45: #include <stdio.h>
        !            46: #include <stdlib.h>
        !            47: #include "termcap_private.h"
        !            48: #undef ospeed
        !            49:
        !            50: /* internal functions */
        !            51: int _tputws_convert(const wchar_t **, int);
        !            52:
        !            53: /*
        !            54:  * The following array gives the number of tens of milliseconds per
        !            55:  * character for each speed as returned by gtty.  Thus since 300
        !            56:  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
        !            57:  */
        !            58: extern short   ospeed;
        !            59: extern char    PC;
        !            60:
        !            61: int
        !            62: _tputws_convert(const wchar_t **ptr, int affcnt)
        !            63: {
        !            64:        int i = 0;
        !            65:
        !            66:        _DIAGASSERT(ptr != NULL);
        !            67:        _DIAGASSERT(*ptr != NULL);
        !            68:
        !            69:        /*
        !            70:         * Convert the number representing the delay.
        !            71:         */
        !            72:        if (iswdigit(**ptr)) {
        !            73:                do
        !            74:                        i = i * 10 + *(*ptr)++ - '0';
        !            75:                while (iswdigit(**ptr));
        !            76:        }
        !            77:        i *= 10;
        !            78:        if (*(*ptr) == '.') {
        !            79:                (*ptr)++;
        !            80:                if (iswdigit(**ptr))
        !            81:                        i += *(*ptr) - '0';
        !            82:                /*
        !            83:                 * Only one digit to the right of the decimal point.
        !            84:                 */
        !            85:                while (iswdigit(**ptr))
        !            86:                        (*ptr)++;
        !            87:        }
        !            88:
        !            89:        /*
        !            90:         * If the delay is followed by a `*', then
        !            91:         * multiply by the affected lines count.
        !            92:         */
        !            93:        if (*(*ptr) == '*')
        !            94:                (*ptr)++, i *= affcnt;
        !            95:
        !            96:        return i;
        !            97: }
        !            98:
        !            99: int
        !           100: t_putws(struct tinfo *info, const wchar_t *cp, int affcnt,
        !           101:     void (*outc)(wchar_t, void *), void *args)
        !           102: {
        !           103:        int i = 0;
        !           104:        size_t limit;
        !           105:        int mspc10;
        !           106:        char pad[2], *pptr;
        !           107:        char *pc;
        !           108:
        !           109:        /* XXX: info may be NULL ? */
        !           110:        /* cp is handled below */
        !           111:        _DIAGASSERT(outc != NULL);
        !           112:        _DIAGASSERT(args != NULL);
        !           113:
        !           114:        if (info != NULL) {
        !           115:                /*
        !           116:                 * if we have info then get the pad char from the
        !           117:                 * termcap entry if it exists, otherwise use the
        !           118:                 * default NUL char.
        !           119:                 */
        !           120:                pptr = pad;
        !           121:                limit = sizeof(pad);
        !           122:                pc = t_getstr(info, "pc", &pptr, &limit);
        !           123:                if (pc == NULL)
        !           124:                        pad[0] = '\0';
        !           125:                else
        !           126:                        free(pc);
        !           127:        }
        !           128:
        !           129:        if (cp == 0)
        !           130:                return -1;
        !           131:
        !           132:        /* scan and convert delay digits (if any) */
        !           133:        i = _tputws_convert(&cp, affcnt);
        !           134:
        !           135:        /*
        !           136:         * The guts of the string.
        !           137:         */
        !           138:        while (*cp)
        !           139:                (*outc)(*cp++, args);
        !           140:
        !           141:        /*
        !           142:         * If no delay needed, or output speed is
        !           143:         * not comprehensible, then don't try to delay.
        !           144:         */
        !           145:        if (i == 0)
        !           146:                return 0;
        !           147:        if (ospeed <= 0 || ospeed >= TMSPC10SIZE)
        !           148:                return 0;
        !           149:
        !           150:        /*
        !           151:         * Round up by a half a character frame,
        !           152:         * and then do the delay.
        !           153:         * Too bad there are no user program accessible programmed delays.
        !           154:         * Transmitting pad characters slows many
        !           155:         * terminals down and also loads the system.
        !           156:         */
        !           157:        mspc10 = __tmspc10[ospeed];
        !           158:        i += mspc10 / 2;
        !           159:        for (i /= mspc10; i > 0; i--)
        !           160:                (*outc)(pad[0], args);
        !           161:
        !           162:        return 0;
        !           163: }

CVSweb <webmaster@jp.NetBSD.org>