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

Annotation of src/lib/libterm/tputs.c, Revision 1.9

1.9     ! christos    1: /*     $NetBSD: tputs.c,v 1.8 1998/07/27 01:57:26 mycroft Exp $        */
1.3       cgd         2:
1.1       cgd         3: /*
1.3       cgd         4:  * Copyright (c) 1980, 1993
                      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.6       lukem      36: #include <sys/cdefs.h>
1.1       cgd        37: #ifndef lint
1.3       cgd        38: #if 0
                     39: static char sccsid[] = "@(#)tputs.c    8.1 (Berkeley) 6/4/93";
                     40: #else
1.9     ! christos   41: __RCSID("$NetBSD: tputs.c,v 1.8 1998/07/27 01:57:26 mycroft Exp $");
1.3       cgd        42: #endif
1.1       cgd        43: #endif /* not lint */
                     44:
                     45: #include <ctype.h>
1.7       lukem      46: #include <termcap.h>
1.4       pk         47: #undef ospeed
1.1       cgd        48:
                     49: /*
                     50:  * The following array gives the number of tens of milliseconds per
                     51:  * character for each speed as returned by gtty.  Thus since 300
                     52:  * baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
                     53:  */
                     54: static
                     55: short  tmspc10[] = {
                     56:        0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
                     57: };
                     58:
                     59: short  ospeed;
                     60: char   PC;
                     61:
                     62: /*
                     63:  * Put the character string cp out, with padding.
                     64:  * The number of affected lines is affcnt, and the routine
                     65:  * used to output one character is outc.
                     66:  */
1.4       pk         67: void
1.1       cgd        68: tputs(cp, affcnt, outc)
1.8       mycroft    69:        const char *cp;
1.1       cgd        70:        int affcnt;
1.5       pk         71:        void (*outc) __P((int));
1.1       cgd        72: {
1.7       lukem      73:        int i = 0;
                     74:        int mspc10;
1.1       cgd        75:
                     76:        if (cp == 0)
                     77:                return;
                     78:
                     79:        /*
                     80:         * Convert the number representing the delay.
                     81:         */
                     82:        if (isdigit(*cp)) {
                     83:                do
                     84:                        i = i * 10 + *cp++ - '0';
                     85:                while (isdigit(*cp));
                     86:        }
                     87:        i *= 10;
                     88:        if (*cp == '.') {
                     89:                cp++;
                     90:                if (isdigit(*cp))
                     91:                        i += *cp - '0';
                     92:                /*
                     93:                 * Only one digit to the right of the decimal point.
                     94:                 */
                     95:                while (isdigit(*cp))
                     96:                        cp++;
                     97:        }
                     98:
                     99:        /*
                    100:         * If the delay is followed by a `*', then
                    101:         * multiply by the affected lines count.
                    102:         */
                    103:        if (*cp == '*')
                    104:                cp++, i *= affcnt;
                    105:
                    106:        /*
                    107:         * The guts of the string.
                    108:         */
                    109:        while (*cp)
                    110:                (*outc)(*cp++);
                    111:
                    112:        /*
                    113:         * If no delay needed, or output speed is
                    114:         * not comprehensible, then don't try to delay.
                    115:         */
                    116:        if (i == 0)
                    117:                return;
                    118:        if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
                    119:                return;
                    120:
                    121:        /*
                    122:         * Round up by a half a character frame,
                    123:         * and then do the delay.
                    124:         * Too bad there are no user program accessible programmed delays.
                    125:         * Transmitting pad characters slows many
                    126:         * terminals down and also loads the system.
                    127:         */
                    128:        mspc10 = tmspc10[ospeed];
                    129:        i += mspc10 / 2;
                    130:        for (i /= mspc10; i > 0; i--)
                    131:                (*outc)(PC);
                    132: }

CVSweb <webmaster@jp.NetBSD.org>