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 (c) 1995-1998 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * tparm.c
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * XCurses Library
317c478bd9Sstevel@tonic-gate  *
327c478bd9Sstevel@tonic-gate  * Copyright 1990, 1995 by Mrotice Kern Systems Inc.  All rights reserved.
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef M_RCSID
377c478bd9Sstevel@tonic-gate #ifndef lint
387c478bd9Sstevel@tonic-gate static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/tparm.c 1.2 1995/08/31 19:44:03 danv Exp $";
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate #endif
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*l
43*bbf21555SRichard Lowe  * Substitute the given parameters into the given string by the
44*bbf21555SRichard Lowe  * following rules (taken from terminfo(7)):
457c478bd9Sstevel@tonic-gate  *
467c478bd9Sstevel@tonic-gate  * Cursor addressing and other strings  requiring  parameters
477c478bd9Sstevel@tonic-gate  * in the terminal are described by a parameterized string
487c478bd9Sstevel@tonic-gate  * capability, with like escapes %x in  it.   For  example,  to
497c478bd9Sstevel@tonic-gate  * address  the  cursor, the cup capability is given, using two
507c478bd9Sstevel@tonic-gate  * parameters: the row and column to  address  to.   (Rows  and
517c478bd9Sstevel@tonic-gate  * columns  are  numbered  from  zero and refer to the physical
527c478bd9Sstevel@tonic-gate  * screen visible to the user, not to any  unseen  memory.)  If
537c478bd9Sstevel@tonic-gate  * the terminal has memory relative cursor addressing, that can
547c478bd9Sstevel@tonic-gate  * be indicated by
55*bbf21555SRichard Lowe  *
567c478bd9Sstevel@tonic-gate  * The parameter mechanism uses  a  stack  and  special  %
577c478bd9Sstevel@tonic-gate  * codes  to manipulate it.  Typically a sequence will push one
587c478bd9Sstevel@tonic-gate  * of the parameters onto the stack and then print it  in  some
597c478bd9Sstevel@tonic-gate  * format.  Often more complex operations are necessary.
60*bbf21555SRichard Lowe  *
617c478bd9Sstevel@tonic-gate  *      The % encodings have the following meanings:
62*bbf21555SRichard Lowe  *
637c478bd9Sstevel@tonic-gate  *      %%        outputs `%'
647c478bd9Sstevel@tonic-gate  *      %d        print pop() like %d in printf()
657c478bd9Sstevel@tonic-gate  *      %2d       print pop() like %2d in printf()
667c478bd9Sstevel@tonic-gate  *      %02d      print pop() like %02d in printf()
677c478bd9Sstevel@tonic-gate  *      %3d       print pop() like %3d in printf()
687c478bd9Sstevel@tonic-gate  *      %03d      print pop() like %03d in printf()
697c478bd9Sstevel@tonic-gate  *      %c        print pop() like %c in printf()
707c478bd9Sstevel@tonic-gate  *      %s        print pop() like %s in printf()
71*bbf21555SRichard Lowe  *
727c478bd9Sstevel@tonic-gate  *      %p[1-9]   push ith parm
737c478bd9Sstevel@tonic-gate  *      %P[a-z]   set variable [a-z] to pop()
747c478bd9Sstevel@tonic-gate  *      %g[a-z]   get variable [a-z] and push it
757c478bd9Sstevel@tonic-gate  *      %'c'      push char constant c
767c478bd9Sstevel@tonic-gate  *      %{nn}     push integer constant nn
77*bbf21555SRichard Lowe  *
787c478bd9Sstevel@tonic-gate  *      %+ %- %* %/ %m
797c478bd9Sstevel@tonic-gate  *                arithmetic (%m is mod): push(pop() op pop())
807c478bd9Sstevel@tonic-gate  *      %& %| %^  bit operations: push(pop() op pop())
817c478bd9Sstevel@tonic-gate  *      %= %> %<  logical operations: push(pop() op pop())
827c478bd9Sstevel@tonic-gate  *      %! %~     unary operations push(op pop())
837c478bd9Sstevel@tonic-gate  *      %i        add 1 to first two parms (for ANSI terminals)
84*bbf21555SRichard Lowe  *
857c478bd9Sstevel@tonic-gate  *      %? expr %t thenpart %e elsepart %;
867c478bd9Sstevel@tonic-gate  *                if-then-else, %e elsepart is optional.
877c478bd9Sstevel@tonic-gate  *                else-if's are possible ala Algol 68:
887c478bd9Sstevel@tonic-gate  *                %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e b5 %;
89*bbf21555SRichard Lowe  *
907c478bd9Sstevel@tonic-gate  * For those of the above operators which are binary and not commutative,
917c478bd9Sstevel@tonic-gate  * the stack works in the usual way, with
927c478bd9Sstevel@tonic-gate  * 		%gx %gy %m
937c478bd9Sstevel@tonic-gate  * resulting in x mod y, not the reverse.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #include <private.h>
977c478bd9Sstevel@tonic-gate #include <ctype.h>
987c478bd9Sstevel@tonic-gate #include <stdarg.h>
997c478bd9Sstevel@tonic-gate #include <string.h>
1007c478bd9Sstevel@tonic-gate #include <m_ord.h>
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #define STACKSIZE	20
1037c478bd9Sstevel@tonic-gate #define npush(x)	if (stack_ptr < STACKSIZE) {\
1047c478bd9Sstevel@tonic-gate 				stack[stack_ptr].num = x; stack_ptr++; }
1057c478bd9Sstevel@tonic-gate #define npop()	   	(stack_ptr > 0 ? stack[--stack_ptr].num : 0)
1067c478bd9Sstevel@tonic-gate #define spop()	   	(stack_ptr > 0 ? stack[--stack_ptr].str : (char *) 0)
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate typedef union {
1097c478bd9Sstevel@tonic-gate 	unsigned int num;
1107c478bd9Sstevel@tonic-gate 	char* str;
1117c478bd9Sstevel@tonic-gate } stack_frame;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate static char buffer[256];
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*f
1167c478bd9Sstevel@tonic-gate  * Do parameter substitution.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate const char *
1197c478bd9Sstevel@tonic-gate #ifdef STDARG_VERSION
tparm(const char * string,...)1207c478bd9Sstevel@tonic-gate tparm(const char *string, ...)
1217c478bd9Sstevel@tonic-gate #else
1227c478bd9Sstevel@tonic-gate tparm(string, p1, p2, p3, p4, p5, p6, p7, p8, p9)
1237c478bd9Sstevel@tonic-gate const char *string;
1247c478bd9Sstevel@tonic-gate long p1, p2, p3, p4, p5, p6, p7, p8, p9;
1257c478bd9Sstevel@tonic-gate #endif /* STDARG_VERSION */
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate 	char len;
1287c478bd9Sstevel@tonic-gate 	long parm[9];
1297c478bd9Sstevel@tonic-gate 	va_list vparm;
1307c478bd9Sstevel@tonic-gate 	int varyable[26];
1317c478bd9Sstevel@tonic-gate 	int number, level, x, y;
1327c478bd9Sstevel@tonic-gate 	int stack_ptr = 0;
1337c478bd9Sstevel@tonic-gate 	stack_frame stack[STACKSIZE];
1347c478bd9Sstevel@tonic-gate 	char *bufptr = buffer;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #ifdef STDARG_VERSION
137*bbf21555SRichard Lowe 	/* We've had too many problems porting this particular module
1387c478bd9Sstevel@tonic-gate 	 * to different compilers and machines, in particular RISC,
1397c478bd9Sstevel@tonic-gate 	 * that we can't make clever assumptions about how variable
1407c478bd9Sstevel@tonic-gate 	 * arguments might be handled.  The best solution is the
1417c478bd9Sstevel@tonic-gate 	 * slow and simple one.
1427c478bd9Sstevel@tonic-gate 	 *
1437c478bd9Sstevel@tonic-gate 	 * We read the va_args into an array, since the tparm format
1447c478bd9Sstevel@tonic-gate 	 * string may want to address parameters in arbitrary order.
1457c478bd9Sstevel@tonic-gate 	 */
1467c478bd9Sstevel@tonic-gate 	va_start(vparm, string);
1477c478bd9Sstevel@tonic-gate 	for (x = 0; x < 9; ++x)
1487c478bd9Sstevel@tonic-gate 		parm[x] = va_arg(vparm, long);
1497c478bd9Sstevel@tonic-gate 	va_end(vparm);
1507c478bd9Sstevel@tonic-gate #else
1517c478bd9Sstevel@tonic-gate 	parm[0] = p1;
1527c478bd9Sstevel@tonic-gate 	parm[1] = p2;
1537c478bd9Sstevel@tonic-gate 	parm[2] = p3;
1547c478bd9Sstevel@tonic-gate 	parm[3] = p4;
1557c478bd9Sstevel@tonic-gate 	parm[4] = p5;
1567c478bd9Sstevel@tonic-gate 	parm[5] = p6;
1577c478bd9Sstevel@tonic-gate 	parm[6] = p7;
1587c478bd9Sstevel@tonic-gate 	parm[7] = p8;
1597c478bd9Sstevel@tonic-gate 	parm[8] = p9;
1607c478bd9Sstevel@tonic-gate #endif /* STDARG_VERSION */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #ifdef M_CURSES_TRACE
1637c478bd9Sstevel@tonic-gate 	__m_trace(
1647c478bd9Sstevel@tonic-gate 		"tparm(\"%s\", %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld, %ld)",
1657c478bd9Sstevel@tonic-gate 		string, parm[0],
1667c478bd9Sstevel@tonic-gate 		parm[1], parm[2], parm[3], parm[4],
1677c478bd9Sstevel@tonic-gate 		parm[5], parm[6], parm[7], parm[8]
1687c478bd9Sstevel@tonic-gate 	);
1697c478bd9Sstevel@tonic-gate #endif
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	while (*string) {
1727c478bd9Sstevel@tonic-gate 		if (*string != '%')
1737c478bd9Sstevel@tonic-gate 			*(bufptr++) = *string;
1747c478bd9Sstevel@tonic-gate 		else {
1757c478bd9Sstevel@tonic-gate 			string++;
1767c478bd9Sstevel@tonic-gate 			switch (*string) {
1777c478bd9Sstevel@tonic-gate 			default:
1787c478bd9Sstevel@tonic-gate 				break;
1797c478bd9Sstevel@tonic-gate 			case '%':
1807c478bd9Sstevel@tonic-gate 				*(bufptr++) = '%';
1817c478bd9Sstevel@tonic-gate 				break;
1827c478bd9Sstevel@tonic-gate 			case 'd':
1837c478bd9Sstevel@tonic-gate 				bufptr += sprintf(bufptr, "%ld", npop());
1847c478bd9Sstevel@tonic-gate 				break;
1857c478bd9Sstevel@tonic-gate 			case '0':
1867c478bd9Sstevel@tonic-gate 				len = -(*++string - '0');
187*bbf21555SRichard Lowe 				if ((len == (char)-2 || len == (char)-3)
1887c478bd9Sstevel@tonic-gate 				&& *++string == 'd')
1897c478bd9Sstevel@tonic-gate 					bufptr += sprintf(
1907c478bd9Sstevel@tonic-gate 						bufptr, "%0*ld", len, npop()
1917c478bd9Sstevel@tonic-gate 					);
1927c478bd9Sstevel@tonic-gate 				break;
1937c478bd9Sstevel@tonic-gate 			case '2':
1947c478bd9Sstevel@tonic-gate 			case '3':
1957c478bd9Sstevel@tonic-gate 				len = *string++ - '0';
1967c478bd9Sstevel@tonic-gate 				if (*string == 'd')
1977c478bd9Sstevel@tonic-gate 					bufptr += sprintf(
1987c478bd9Sstevel@tonic-gate 						bufptr, "%*ld", len, npop()
1997c478bd9Sstevel@tonic-gate 					);
2007c478bd9Sstevel@tonic-gate 				break;
2017c478bd9Sstevel@tonic-gate 			case 'c':
2027c478bd9Sstevel@tonic-gate 				*(bufptr++) = (char) npop();
2037c478bd9Sstevel@tonic-gate 				break;
2047c478bd9Sstevel@tonic-gate 			case 's':
2057c478bd9Sstevel@tonic-gate 				strcpy(bufptr, spop());
2067c478bd9Sstevel@tonic-gate 				bufptr += strlen(bufptr);
2077c478bd9Sstevel@tonic-gate 				break;
2087c478bd9Sstevel@tonic-gate 			case 'p':
2097c478bd9Sstevel@tonic-gate 				string++;
2107c478bd9Sstevel@tonic-gate 				if ('1' <= *string && *string <= '9')
2117c478bd9Sstevel@tonic-gate 					npush(parm[*string - '1']);
2127c478bd9Sstevel@tonic-gate 				break;
2137c478bd9Sstevel@tonic-gate 			case 'P': {
2147c478bd9Sstevel@tonic-gate 				int i;
2157c478bd9Sstevel@tonic-gate 				int	c;
2167c478bd9Sstevel@tonic-gate 				++string;
2177c478bd9Sstevel@tonic-gate 				c = (int)*string;
2187c478bd9Sstevel@tonic-gate 				i = m_ord(c);
2197c478bd9Sstevel@tonic-gate 				if (0 < i)
2207c478bd9Sstevel@tonic-gate 					varyable[i-1] = npop();
2217c478bd9Sstevel@tonic-gate 				break;
2227c478bd9Sstevel@tonic-gate 			}
2237c478bd9Sstevel@tonic-gate 			case 'g': {
2247c478bd9Sstevel@tonic-gate 				int i;
2257c478bd9Sstevel@tonic-gate 				int	c;
2267c478bd9Sstevel@tonic-gate 				++string;
2277c478bd9Sstevel@tonic-gate 				c = (int)*string;
2287c478bd9Sstevel@tonic-gate 				i = m_ord(c);
2297c478bd9Sstevel@tonic-gate 				if (0 < i)
2307c478bd9Sstevel@tonic-gate 					npush(varyable[i-1]);
2317c478bd9Sstevel@tonic-gate 				break;
2327c478bd9Sstevel@tonic-gate 			}
2337c478bd9Sstevel@tonic-gate 			case '\'':
2347c478bd9Sstevel@tonic-gate 				string++;
2357c478bd9Sstevel@tonic-gate 				npush(*string);
2367c478bd9Sstevel@tonic-gate 				string++;
2377c478bd9Sstevel@tonic-gate 				break;
2387c478bd9Sstevel@tonic-gate 			case '{':
2397c478bd9Sstevel@tonic-gate 				number = 0;
2407c478bd9Sstevel@tonic-gate 				string++;
2417c478bd9Sstevel@tonic-gate 				while ('0' <= *string && *string <= '9') {
2427c478bd9Sstevel@tonic-gate 					number = number * 10 + *string - '0';
2437c478bd9Sstevel@tonic-gate 					string++;
2447c478bd9Sstevel@tonic-gate 				}
2457c478bd9Sstevel@tonic-gate 				npush(number);
2467c478bd9Sstevel@tonic-gate 				break;
2477c478bd9Sstevel@tonic-gate 			case '+':
2487c478bd9Sstevel@tonic-gate 				y = npop();
2497c478bd9Sstevel@tonic-gate 				x = npop();
2507c478bd9Sstevel@tonic-gate 				npush(x + y);
2517c478bd9Sstevel@tonic-gate 				break;
2527c478bd9Sstevel@tonic-gate 			case '-':
2537c478bd9Sstevel@tonic-gate 				y = npop();
2547c478bd9Sstevel@tonic-gate 				x = npop();
2557c478bd9Sstevel@tonic-gate 				npush(x - y);
2567c478bd9Sstevel@tonic-gate 				break;
2577c478bd9Sstevel@tonic-gate 			case '*':
2587c478bd9Sstevel@tonic-gate 				y = npop();
2597c478bd9Sstevel@tonic-gate 				x = npop();
2607c478bd9Sstevel@tonic-gate 				npush(x * y);
2617c478bd9Sstevel@tonic-gate 				break;
2627c478bd9Sstevel@tonic-gate 			case '/':
2637c478bd9Sstevel@tonic-gate 				y = npop();
2647c478bd9Sstevel@tonic-gate 				x = npop();
2657c478bd9Sstevel@tonic-gate 				npush(x / y);
2667c478bd9Sstevel@tonic-gate 				break;
2677c478bd9Sstevel@tonic-gate 			case 'm':
2687c478bd9Sstevel@tonic-gate 				y = npop();
2697c478bd9Sstevel@tonic-gate 				x = npop();
2707c478bd9Sstevel@tonic-gate 				npush(x % y);
2717c478bd9Sstevel@tonic-gate 				break;
2727c478bd9Sstevel@tonic-gate 			case '&':
2737c478bd9Sstevel@tonic-gate 				y = npop();
2747c478bd9Sstevel@tonic-gate 				x = npop();
2757c478bd9Sstevel@tonic-gate 				npush(x & y);
2767c478bd9Sstevel@tonic-gate 				break;
2777c478bd9Sstevel@tonic-gate 			case '|':
2787c478bd9Sstevel@tonic-gate 				y = npop();
2797c478bd9Sstevel@tonic-gate 				x = npop();
2807c478bd9Sstevel@tonic-gate 				npush(x | y);
2817c478bd9Sstevel@tonic-gate 				break;
2827c478bd9Sstevel@tonic-gate 			case '^':
2837c478bd9Sstevel@tonic-gate 				y = npop();
2847c478bd9Sstevel@tonic-gate 				x = npop();
2857c478bd9Sstevel@tonic-gate 				npush(x ^ y);
2867c478bd9Sstevel@tonic-gate 				break;
2877c478bd9Sstevel@tonic-gate 			case '=':
2887c478bd9Sstevel@tonic-gate 				y = npop();
2897c478bd9Sstevel@tonic-gate 				x = npop();
2907c478bd9Sstevel@tonic-gate 				npush(x == y);
2917c478bd9Sstevel@tonic-gate 				break;
2927c478bd9Sstevel@tonic-gate 			case '<':
2937c478bd9Sstevel@tonic-gate 				y = npop();
2947c478bd9Sstevel@tonic-gate 				x = npop();
2957c478bd9Sstevel@tonic-gate 				npush(x < y);
2967c478bd9Sstevel@tonic-gate 				break;
2977c478bd9Sstevel@tonic-gate 			case '>':
2987c478bd9Sstevel@tonic-gate 				y = npop();
2997c478bd9Sstevel@tonic-gate 				x = npop();
3007c478bd9Sstevel@tonic-gate 				npush(x > y);
3017c478bd9Sstevel@tonic-gate 				break;
3027c478bd9Sstevel@tonic-gate 			case '!':
3037c478bd9Sstevel@tonic-gate 				x = npop();
3047c478bd9Sstevel@tonic-gate 				npush(!x);
3057c478bd9Sstevel@tonic-gate 				break;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 			case '~':
3087c478bd9Sstevel@tonic-gate 				x = npop();
3097c478bd9Sstevel@tonic-gate 				npush(~x);
3107c478bd9Sstevel@tonic-gate 				break;
3117c478bd9Sstevel@tonic-gate 			case 'i':
3127c478bd9Sstevel@tonic-gate 				parm[0]++;
3137c478bd9Sstevel@tonic-gate 				parm[1]++;
3147c478bd9Sstevel@tonic-gate 				break;
3157c478bd9Sstevel@tonic-gate 			case '?':
3167c478bd9Sstevel@tonic-gate 				break;
3177c478bd9Sstevel@tonic-gate 			case 't':
3187c478bd9Sstevel@tonic-gate 			    x = npop();
3197c478bd9Sstevel@tonic-gate 			    if (x) {
3207c478bd9Sstevel@tonic-gate 				/* do nothing; keep executing */
3217c478bd9Sstevel@tonic-gate 			    } else {
322*bbf21555SRichard Lowe 				/* scan forward for %e or %; at
3237c478bd9Sstevel@tonic-gate 				 * level zero */
3247c478bd9Sstevel@tonic-gate 				string++;
3257c478bd9Sstevel@tonic-gate 				level = 0;
3267c478bd9Sstevel@tonic-gate 				while (*string) {
3277c478bd9Sstevel@tonic-gate 		 		    if (*string == '%') {
3287c478bd9Sstevel@tonic-gate 					string++;
3297c478bd9Sstevel@tonic-gate 					if (*string == '?')
3307c478bd9Sstevel@tonic-gate 					    level++;
3317c478bd9Sstevel@tonic-gate 					else if (*string == ';') {
3327c478bd9Sstevel@tonic-gate 					    if (level <= 0)
3337c478bd9Sstevel@tonic-gate 						break;
3347c478bd9Sstevel@tonic-gate 					    level--;
3357c478bd9Sstevel@tonic-gate 					} else if (*string == 'e' && level == 0)
3367c478bd9Sstevel@tonic-gate 					    break;
3377c478bd9Sstevel@tonic-gate 				    }
3387c478bd9Sstevel@tonic-gate 				    if (*string)
3397c478bd9Sstevel@tonic-gate 					string++;
3407c478bd9Sstevel@tonic-gate 				}
3417c478bd9Sstevel@tonic-gate 			    }
3427c478bd9Sstevel@tonic-gate 			    break;
3437c478bd9Sstevel@tonic-gate 			case 'e':
3447c478bd9Sstevel@tonic-gate 				/* scan forward for a %; at level zero */
3457c478bd9Sstevel@tonic-gate 				string++;
3467c478bd9Sstevel@tonic-gate 				level = 0;
3477c478bd9Sstevel@tonic-gate 				while (*string) {
3487c478bd9Sstevel@tonic-gate 					if (*string == '%') {
3497c478bd9Sstevel@tonic-gate 						string++;
3507c478bd9Sstevel@tonic-gate 						if (*string == '?')
3517c478bd9Sstevel@tonic-gate 							level++;
3527c478bd9Sstevel@tonic-gate 						else if (*string == ';') {
3537c478bd9Sstevel@tonic-gate 							if (level <= 0)
3547c478bd9Sstevel@tonic-gate 								break;
3557c478bd9Sstevel@tonic-gate 							level--;
3567c478bd9Sstevel@tonic-gate 						}
3577c478bd9Sstevel@tonic-gate 					}
3587c478bd9Sstevel@tonic-gate 					if (*string)
3597c478bd9Sstevel@tonic-gate 						string++;
3607c478bd9Sstevel@tonic-gate 				}
3617c478bd9Sstevel@tonic-gate 				break;
3627c478bd9Sstevel@tonic-gate 			case ';':
3637c478bd9Sstevel@tonic-gate 				break;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 			} /* endswitch (*string) */
3667c478bd9Sstevel@tonic-gate 		} /* endelse (*string == '%') */
3677c478bd9Sstevel@tonic-gate 		if (*string == '\0')
3687c478bd9Sstevel@tonic-gate 			break;
3697c478bd9Sstevel@tonic-gate 		string++;
3707c478bd9Sstevel@tonic-gate 	} /* endwhile (*string) */
3717c478bd9Sstevel@tonic-gate 	*bufptr = '\0';
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	return __m_return_pointer("tparm", buffer);
3747c478bd9Sstevel@tonic-gate }
375