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