17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*48bbca81SDaniel Hoffman * Copyright (c) 2016 by Delphix. All rights reserved.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
297c478bd9Sstevel@tonic-gate /* All Rights Reserved */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /* Copyright (c) 1979 Regents of the University of California */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <ctype.h>
377c478bd9Sstevel@tonic-gate #include "curses_inc.h"
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate * Put the character string cp out, with padding.
417c478bd9Sstevel@tonic-gate * The number of affected lines is affcnt, and the routine
427c478bd9Sstevel@tonic-gate * used to output one character is outc.
437c478bd9Sstevel@tonic-gate */
447c478bd9Sstevel@tonic-gate static char *ocp;
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate static char *
477c478bd9Sstevel@tonic-gate _tpad(char *, int, int (*)(char));
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate static char *
_tpad(char * cp,int affcnt,int (* outc)(char x))507c478bd9Sstevel@tonic-gate _tpad(char *cp, int affcnt, int (*outc)(char x))
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate int delay = 0;
537c478bd9Sstevel@tonic-gate char *icp = cp;
547c478bd9Sstevel@tonic-gate int ignorexon = 0, doaffcnt = 0;
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate #ifdef _VR2_COMPAT_CODE
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * Why is this here?
597c478bd9Sstevel@tonic-gate * Because mandatory padding must be used for flash_screen
607c478bd9Sstevel@tonic-gate * and bell. We cannot force users to code mandatory padding
617c478bd9Sstevel@tonic-gate * in their terminfo entries, as that would break compatibility.
627c478bd9Sstevel@tonic-gate * We therefore, do it here.
637c478bd9Sstevel@tonic-gate *
64*48bbca81SDaniel Hoffman * When compatibility is to be broken, it will go away
657c478bd9Sstevel@tonic-gate * and users will be informed that they MUST use mandatory
667c478bd9Sstevel@tonic-gate * padding for flash and bell.
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate if (ocp == bell || ocp == flash_screen)
697c478bd9Sstevel@tonic-gate ignorexon = TRUE;
707c478bd9Sstevel@tonic-gate #endif /* _VR2_COMPAT_CODE */
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate /* Eat initial $< */
737c478bd9Sstevel@tonic-gate cp += 2;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate /* Convert the number representing the delay. */
767c478bd9Sstevel@tonic-gate if (isdigit(*cp)) {
777c478bd9Sstevel@tonic-gate do
787c478bd9Sstevel@tonic-gate delay = delay * 10 + *cp++ - '0';
797c478bd9Sstevel@tonic-gate while (isdigit(*cp));
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate delay *= 10;
827c478bd9Sstevel@tonic-gate if (*cp == '.') {
837c478bd9Sstevel@tonic-gate cp++;
847c478bd9Sstevel@tonic-gate if (isdigit(*cp))
857c478bd9Sstevel@tonic-gate delay += *cp - '0';
867c478bd9Sstevel@tonic-gate /* Only one digit to the right of the decimal point. */
877c478bd9Sstevel@tonic-gate while (isdigit(*cp))
887c478bd9Sstevel@tonic-gate cp++;
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate * If the delay is followed by a `*', then
937c478bd9Sstevel@tonic-gate * multiply by the affected lines count.
947c478bd9Sstevel@tonic-gate * If the delay is followed by a '/', then
957c478bd9Sstevel@tonic-gate * the delay is done irregardless of xon/xoff.
967c478bd9Sstevel@tonic-gate */
977c478bd9Sstevel@tonic-gate /*CONSTCOND*/
987c478bd9Sstevel@tonic-gate while (TRUE) {
997c478bd9Sstevel@tonic-gate if (*cp == '/')
1007c478bd9Sstevel@tonic-gate ignorexon = TRUE;
1017c478bd9Sstevel@tonic-gate else
1027c478bd9Sstevel@tonic-gate if (*cp == '*')
1037c478bd9Sstevel@tonic-gate doaffcnt = TRUE;
1047c478bd9Sstevel@tonic-gate else
1057c478bd9Sstevel@tonic-gate break;
1067c478bd9Sstevel@tonic-gate cp++;
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate if (doaffcnt)
1097c478bd9Sstevel@tonic-gate delay *= affcnt;
1107c478bd9Sstevel@tonic-gate if (*cp == '>')
1117c478bd9Sstevel@tonic-gate cp++; /* Eat trailing '>' */
1127c478bd9Sstevel@tonic-gate else {
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate * We got a "$<" with no ">". This is usually caused by
1157c478bd9Sstevel@tonic-gate * a cursor addressing sequence that happened to generate
1167c478bd9Sstevel@tonic-gate * $ < . To avoid an infinite loop, we output the $ here
1177c478bd9Sstevel@tonic-gate * and pass back the rest.
1187c478bd9Sstevel@tonic-gate */
1197c478bd9Sstevel@tonic-gate (*outc)(*icp++);
1207c478bd9Sstevel@tonic-gate return (icp);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate * If no delay needed, or output speed is
1257c478bd9Sstevel@tonic-gate * not comprehensible, then don't try to delay.
1267c478bd9Sstevel@tonic-gate */
1277c478bd9Sstevel@tonic-gate if (delay == 0)
1287c478bd9Sstevel@tonic-gate return (cp);
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate * Let handshaking take care of it - no extra cpu load from pads.
1317c478bd9Sstevel@tonic-gate * Also, this will be more optimal since the pad info is usually
1327c478bd9Sstevel@tonic-gate * worst case. We only use padding info for such terminals to
1337c478bd9Sstevel@tonic-gate * estimate the cost of a capability in choosing the cheapest one.
1347c478bd9Sstevel@tonic-gate * Some capabilities, such as flash_screen, really want the
1357c478bd9Sstevel@tonic-gate * padding irregardless.
1367c478bd9Sstevel@tonic-gate */
1377c478bd9Sstevel@tonic-gate if (xon_xoff && !ignorexon)
1387c478bd9Sstevel@tonic-gate return (cp);
1397c478bd9Sstevel@tonic-gate (void) _delay(delay, outc);
1407c478bd9Sstevel@tonic-gate return (cp);
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate int
tputs(char * cp,int affcnt,int (* outc)(char))1447c478bd9Sstevel@tonic-gate tputs(char *cp, int affcnt, int (*outc)(char))
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate if (cp != 0) {
1477c478bd9Sstevel@tonic-gate ocp = cp;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /* The guts of the string. */
1507c478bd9Sstevel@tonic-gate while (*cp)
1517c478bd9Sstevel@tonic-gate if (*cp == '$' && cp[1] == '<')
1527c478bd9Sstevel@tonic-gate cp = _tpad(cp, affcnt, outc);
1537c478bd9Sstevel@tonic-gate else
1547c478bd9Sstevel@tonic-gate (*outc)(*cp++);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate return (OK);
1577c478bd9Sstevel@tonic-gate }
158