xref: /illumos-gate/usr/src/cmd/sgs/libelf/misc/args.c (revision 7dbbfe7762f9eabac3999ee1a8b38311d428f7a8)
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) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  *
277c478bd9Sstevel@tonic-gate  *	Copyright (c) 1998 by Sun Microsystems, Inc.
287c478bd9Sstevel@tonic-gate  *	All rights reserved.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include	<ctype.h>
327c478bd9Sstevel@tonic-gate #include	<stdlib.h>
337c478bd9Sstevel@tonic-gate #include	<string.h>
347c478bd9Sstevel@tonic-gate #include	"elf_dem.h"
357c478bd9Sstevel@tonic-gate #include	"String.h"
367c478bd9Sstevel@tonic-gate #include	"msg.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /* This structure is used to keep
397c478bd9Sstevel@tonic-gate  * track of pointers to argument
407c478bd9Sstevel@tonic-gate  * descriptions in the mangled string.
417c478bd9Sstevel@tonic-gate  * This is needed for N and T encodings
427c478bd9Sstevel@tonic-gate  * to work.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate typedef struct {
457c478bd9Sstevel@tonic-gate 	char *list[10];
467c478bd9Sstevel@tonic-gate 	int pos;
477c478bd9Sstevel@tonic-gate } Place;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static Place here;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* Strings and flags needed by the argument demangles.  The declarator
527c478bd9Sstevel@tonic-gate  * is built up in ptr.  Type modifiers are held in the flag fields.
537c478bd9Sstevel@tonic-gate  * The type itself is passed in separately.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate typedef struct {
567c478bd9Sstevel@tonic-gate 	String *ptr;
577c478bd9Sstevel@tonic-gate 	int Sign,Uns,Cons,Vol;
587c478bd9Sstevel@tonic-gate } Arg_Remem;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* initialize Arg_Remem */
617c478bd9Sstevel@tonic-gate static void
mkar(Arg_Remem * r)62*7dbbfe77SToomas Soome mkar(Arg_Remem *r)
637c478bd9Sstevel@tonic-gate {
647c478bd9Sstevel@tonic-gate 	r->ptr = mk_String((String *)0);
657c478bd9Sstevel@tonic-gate 	r->Sign = r->Uns = r->Cons = r->Vol = 0;
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* free data for Arg_Remem */
697c478bd9Sstevel@tonic-gate static void
delar(Arg_Remem * r)70*7dbbfe77SToomas Soome delar(Arg_Remem *r)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	free_String(r->ptr);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /* This routine formats a single argument
767c478bd9Sstevel@tonic-gate  * on the buffer sptr.
777c478bd9Sstevel@tonic-gate  * c is the type or class name, n is its length.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate static void
nsetarg(String ** sptr,Arg_Remem * r,const char * c,int n)807c478bd9Sstevel@tonic-gate nsetarg(String ** sptr, Arg_Remem * r, const char * c, int n)
817c478bd9Sstevel@tonic-gate {
827c478bd9Sstevel@tonic-gate 	r->ptr = nprep_String(c, r->ptr, n);
837c478bd9Sstevel@tonic-gate 	if(r->Cons)
847c478bd9Sstevel@tonic-gate 		r->ptr = prep_String(MSG_ORIG(MSG_STR_CONST_1), r->ptr);
857c478bd9Sstevel@tonic-gate 	if(r->Vol)
867c478bd9Sstevel@tonic-gate 		r->ptr = prep_String(MSG_ORIG(MSG_STR_VOLATILE_1), r->ptr);
877c478bd9Sstevel@tonic-gate 	if(r->Uns)
887c478bd9Sstevel@tonic-gate 		r->ptr = prep_String(MSG_ORIG(MSG_STR_UNSIGNED), r->ptr);
897c478bd9Sstevel@tonic-gate 	else if(r->Sign)
907c478bd9Sstevel@tonic-gate 		r->ptr = prep_String(MSG_ORIG(MSG_STR_SIGNED), r->ptr);
917c478bd9Sstevel@tonic-gate 	*sptr = app_String(*sptr,PTR(r->ptr));
927c478bd9Sstevel@tonic-gate 	delar(r);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /* This routine formats a single argument
967c478bd9Sstevel@tonic-gate  * on the buffer sptr.
977c478bd9Sstevel@tonic-gate  * c is the null terminated type or class name.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate static void
setarg(String ** sptr,Arg_Remem * r,const char * c)1007c478bd9Sstevel@tonic-gate setarg(String ** sptr, Arg_Remem * r, const char * c)
1017c478bd9Sstevel@tonic-gate {
1027c478bd9Sstevel@tonic-gate 	nsetarg(sptr, r, c, ID_NAME_MAX);
1037c478bd9Sstevel@tonic-gate }
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /* Demangle a single function argument.
1077c478bd9Sstevel@tonic-gate  * Returns the number of characters processed from c.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate int
demangle_doarg(String ** sptr,char * c)110*7dbbfe77SToomas Soome demangle_doarg(String **sptr, char *c)
1117c478bd9Sstevel@tonic-gate {
112*7dbbfe77SToomas Soome 	int i;
1137c478bd9Sstevel@tonic-gate 	Arg_Remem ar;
1147c478bd9Sstevel@tonic-gate 	mkar(&ar);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	if(here.pos < 10 && here.pos >= 0)
1177c478bd9Sstevel@tonic-gate 		here.list[here.pos++] = c;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	for(i=0;c[i];i++) {
1207c478bd9Sstevel@tonic-gate 		/* Loop until you find a type.
1217c478bd9Sstevel@tonic-gate 		   Then call setarg and return.
1227c478bd9Sstevel@tonic-gate 		*/
1237c478bd9Sstevel@tonic-gate 		switch(c[i]) {
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 		case 'T':
1267c478bd9Sstevel@tonic-gate 			{
1277c478bd9Sstevel@tonic-gate 				Place tmp;
1287c478bd9Sstevel@tonic-gate 				tmp = here;
1297c478bd9Sstevel@tonic-gate 				here.pos = c[1] - '1';
1307c478bd9Sstevel@tonic-gate 				if(here.pos < 0 || here.pos >= tmp.pos-1) {
1317c478bd9Sstevel@tonic-gate 					delar(&ar);
1327c478bd9Sstevel@tonic-gate 					return -1;
1337c478bd9Sstevel@tonic-gate 				}
1347c478bd9Sstevel@tonic-gate 				(void) demangle_doarg(sptr,here.list[here.pos]);
1357c478bd9Sstevel@tonic-gate 				here = tmp;
1367c478bd9Sstevel@tonic-gate 				delar(&ar);
1377c478bd9Sstevel@tonic-gate 				return 2;
1387c478bd9Sstevel@tonic-gate 			}
1397c478bd9Sstevel@tonic-gate 		case 'N':
1407c478bd9Sstevel@tonic-gate 			{
1417c478bd9Sstevel@tonic-gate 				Place tmp;
1427c478bd9Sstevel@tonic-gate 				int cycles,pos;
1437c478bd9Sstevel@tonic-gate 				cycles = c[1] - '0'; pos = c[2] - '1';
1447c478bd9Sstevel@tonic-gate 				here.pos += cycles - 1;
1457c478bd9Sstevel@tonic-gate 				tmp = here;
1467c478bd9Sstevel@tonic-gate 				if(cycles <= 1 || cycles > 9 || pos < 0 || pos >= tmp.pos-1) {
1477c478bd9Sstevel@tonic-gate 					delar(&ar);
1487c478bd9Sstevel@tonic-gate 					return -1;
1497c478bd9Sstevel@tonic-gate 				}
1507c478bd9Sstevel@tonic-gate 				while(cycles--) {
1517c478bd9Sstevel@tonic-gate 					here = tmp;
1527c478bd9Sstevel@tonic-gate 					here.pos = pos;
1537c478bd9Sstevel@tonic-gate 					(void) demangle_doarg(sptr,here.list[here.pos]);
1547c478bd9Sstevel@tonic-gate 					(*sptr) = app_String(*sptr,
1557c478bd9Sstevel@tonic-gate 					    MSG_ORIG(MSG_STR_COMMA));
1567c478bd9Sstevel@tonic-gate 				}
1577c478bd9Sstevel@tonic-gate 				*sptr = trunc_String(*sptr, 1);
1587c478bd9Sstevel@tonic-gate 				here = tmp;
1597c478bd9Sstevel@tonic-gate 				delar(&ar);
1607c478bd9Sstevel@tonic-gate 				return 3;
1617c478bd9Sstevel@tonic-gate 			}
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 		/* Qualifiers to type names */
1647c478bd9Sstevel@tonic-gate 		case 'S':
1657c478bd9Sstevel@tonic-gate 			ar.Sign = 1;
1667c478bd9Sstevel@tonic-gate 			break;
1677c478bd9Sstevel@tonic-gate 		case 'U':
1687c478bd9Sstevel@tonic-gate 			ar.Uns = 1;
1697c478bd9Sstevel@tonic-gate 			break;
1707c478bd9Sstevel@tonic-gate 		case 'C':
1717c478bd9Sstevel@tonic-gate 			ar.Cons = 1;
1727c478bd9Sstevel@tonic-gate 			break;
1737c478bd9Sstevel@tonic-gate 		case 'V':
1747c478bd9Sstevel@tonic-gate 			ar.Vol = 1;
1757c478bd9Sstevel@tonic-gate 			break;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 		/* Pointers, references, and Member Pointers */
1787c478bd9Sstevel@tonic-gate 		case 'P':
1797c478bd9Sstevel@tonic-gate 		case 'R':
1807c478bd9Sstevel@tonic-gate 		case 'M':
1817c478bd9Sstevel@tonic-gate 			if(ar.Cons) {
1827c478bd9Sstevel@tonic-gate 				ar.ptr = prep_String(MSG_ORIG(MSG_STR_CONST_2),
1837c478bd9Sstevel@tonic-gate 				    ar.ptr);
1847c478bd9Sstevel@tonic-gate 				ar.Cons = 0;
1857c478bd9Sstevel@tonic-gate 			}
1867c478bd9Sstevel@tonic-gate 			if(ar.Vol) {
1877c478bd9Sstevel@tonic-gate 				ar.ptr =
1887c478bd9Sstevel@tonic-gate 				    prep_String(MSG_ORIG(MSG_STR_VOLATILE_2),
1897c478bd9Sstevel@tonic-gate 				    ar.ptr);
1907c478bd9Sstevel@tonic-gate 				ar.Vol = 0;
1917c478bd9Sstevel@tonic-gate 			}
1927c478bd9Sstevel@tonic-gate 			if(c[i] == 'P')
1937c478bd9Sstevel@tonic-gate 				ar.ptr = prep_String(MSG_ORIG(MSG_STR_STAR),
1947c478bd9Sstevel@tonic-gate 				    ar.ptr);
1957c478bd9Sstevel@tonic-gate 			else if(c[i] == 'R')
1967c478bd9Sstevel@tonic-gate 				ar.ptr = prep_String(MSG_ORIG(MSG_STR_AMP),
1977c478bd9Sstevel@tonic-gate 				    ar.ptr);
1987c478bd9Sstevel@tonic-gate 			else {
1997c478bd9Sstevel@tonic-gate 				int cnt = 0;
2007c478bd9Sstevel@tonic-gate 				char *s;
2017c478bd9Sstevel@tonic-gate 				ar.ptr =
2027c478bd9Sstevel@tonic-gate 				    prep_String(MSG_ORIG(MSG_STR_DBLCOLSTAR),
2037c478bd9Sstevel@tonic-gate 				    ar.ptr);
2047c478bd9Sstevel@tonic-gate 				/* Skip over the 'M' */
2057c478bd9Sstevel@tonic-gate 				i++;
2067c478bd9Sstevel@tonic-gate 				cnt = strtol(c+i, &s, 10);
2077c478bd9Sstevel@tonic-gate 				i = s - c;
2087c478bd9Sstevel@tonic-gate 				ar.ptr = nprep_String(c+i,ar.ptr,cnt);
2097c478bd9Sstevel@tonic-gate 				ar.ptr = prep_String(MSG_ORIG(MSG_STR_SPACE),
2107c478bd9Sstevel@tonic-gate 				    ar.ptr);
2117c478bd9Sstevel@tonic-gate 				i += cnt;
2127c478bd9Sstevel@tonic-gate 				/* The loop increments i */
2137c478bd9Sstevel@tonic-gate 				i--;
2147c478bd9Sstevel@tonic-gate 			}
2157c478bd9Sstevel@tonic-gate 			break;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 		/* Demangle for basic built-in types */
2187c478bd9Sstevel@tonic-gate 		case 'i':
2197c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_INT));
2207c478bd9Sstevel@tonic-gate 			return i + 1;
2217c478bd9Sstevel@tonic-gate 		case 'c':
2227c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_CHAR));
2237c478bd9Sstevel@tonic-gate 			return i + 1;
2247c478bd9Sstevel@tonic-gate 		case 's':
2257c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_SHORT));
2267c478bd9Sstevel@tonic-gate 			return i + 1;
2277c478bd9Sstevel@tonic-gate 		case 'l':
2287c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_LONG));
2297c478bd9Sstevel@tonic-gate 			return i + 1;
2307c478bd9Sstevel@tonic-gate 		case 'f':
2317c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_FLOAT));
2327c478bd9Sstevel@tonic-gate 			return i + 1;
2337c478bd9Sstevel@tonic-gate 		case 'd':
2347c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_DOUBLE));
2357c478bd9Sstevel@tonic-gate 			return i + 1;
2367c478bd9Sstevel@tonic-gate 		case 'r':
2377c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_LONGDOUBLE));
2387c478bd9Sstevel@tonic-gate 			return i + 1;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 		/* Class encodings */
2417c478bd9Sstevel@tonic-gate 		case '1': case '2': case '3':
2427c478bd9Sstevel@tonic-gate 		case '4': case '5': case '6':
2437c478bd9Sstevel@tonic-gate 		case '7': case '8': case '9':
2447c478bd9Sstevel@tonic-gate 			{
2457c478bd9Sstevel@tonic-gate 				int cnt = 0;
2467c478bd9Sstevel@tonic-gate 				char *s;
2477c478bd9Sstevel@tonic-gate 				cnt = strtol(c+i, &s, 10);
2487c478bd9Sstevel@tonic-gate 				i = s - c;
2497c478bd9Sstevel@tonic-gate 				if ((int) strlen(c+i) < cnt) {
2507c478bd9Sstevel@tonic-gate 					delar(&ar);
2517c478bd9Sstevel@tonic-gate 					return -1;
2527c478bd9Sstevel@tonic-gate 				}
2537c478bd9Sstevel@tonic-gate 				nsetarg(sptr,&ar,c+i,cnt);
2547c478bd9Sstevel@tonic-gate 				return i+cnt;
2557c478bd9Sstevel@tonic-gate 			}
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 		/* Ellipsis and void */
2587c478bd9Sstevel@tonic-gate 		case 'e':
2597c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_ELIPSE));
2607c478bd9Sstevel@tonic-gate 			return i + 1;
2617c478bd9Sstevel@tonic-gate 		case 'v':
2627c478bd9Sstevel@tonic-gate 			setarg(sptr, &ar, MSG_ORIG(MSG_STR_VOID));
2637c478bd9Sstevel@tonic-gate 			return i + 1;
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 		/* Arrays */
2667c478bd9Sstevel@tonic-gate 		case 'A':
2677c478bd9Sstevel@tonic-gate 			if(*PTR(ar.ptr)) {
2687c478bd9Sstevel@tonic-gate 				ar.ptr = prep_String(MSG_ORIG(MSG_STR_OPENPAR),
2697c478bd9Sstevel@tonic-gate 				   ar.ptr);
2707c478bd9Sstevel@tonic-gate 				ar.ptr = app_String(ar.ptr,
2717c478bd9Sstevel@tonic-gate 				   MSG_ORIG(MSG_STR_CLOSEPAR));
2727c478bd9Sstevel@tonic-gate 			}
2737c478bd9Sstevel@tonic-gate 			ar.ptr = app_String(ar.ptr, MSG_ORIG(MSG_STR_OPENBRAK));
2747c478bd9Sstevel@tonic-gate 			{
2757c478bd9Sstevel@tonic-gate 				int cnt = 0;
2767c478bd9Sstevel@tonic-gate 				i++;
2777c478bd9Sstevel@tonic-gate 				while(isdigit(c[i+cnt]))
2787c478bd9Sstevel@tonic-gate 					cnt++;
2797c478bd9Sstevel@tonic-gate 				ar.ptr = napp_String(ar.ptr,c+i,cnt);
2807c478bd9Sstevel@tonic-gate 				i += cnt;
2817c478bd9Sstevel@tonic-gate 				if(c[i] != '_') {
2827c478bd9Sstevel@tonic-gate 					delar(&ar);
2837c478bd9Sstevel@tonic-gate 					return -1;
2847c478bd9Sstevel@tonic-gate 				}
2857c478bd9Sstevel@tonic-gate 			}
2867c478bd9Sstevel@tonic-gate 			ar.ptr = app_String(ar.ptr,
2877c478bd9Sstevel@tonic-gate 			    MSG_ORIG(MSG_STR_CLOSEBRAK));
2887c478bd9Sstevel@tonic-gate 			break;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 		/* Functions
2917c478bd9Sstevel@tonic-gate 		 * This will always be called as a pointer
2927c478bd9Sstevel@tonic-gate 		 * to a function.
2937c478bd9Sstevel@tonic-gate 		 */
2947c478bd9Sstevel@tonic-gate 		case 'F':
2957c478bd9Sstevel@tonic-gate 			ar.ptr = prep_String(MSG_ORIG(MSG_STR_OPENPAR), ar.ptr);
2967c478bd9Sstevel@tonic-gate 			ar.ptr = app_String(ar.ptr, MSG_ORIG(MSG_STR_CLOSEPAR));
2977c478bd9Sstevel@tonic-gate 			{
2987c478bd9Sstevel@tonic-gate 				Place tmp;
2997c478bd9Sstevel@tonic-gate 				tmp = here;
3007c478bd9Sstevel@tonic-gate 				i++;
3017c478bd9Sstevel@tonic-gate 				i += demangle_doargs(&ar.ptr,c+i);
3027c478bd9Sstevel@tonic-gate 				if(c[i] != '_') {
3037c478bd9Sstevel@tonic-gate 					delar(&ar);
3047c478bd9Sstevel@tonic-gate 					return -1;
3057c478bd9Sstevel@tonic-gate 				}
3067c478bd9Sstevel@tonic-gate 				here = tmp;
3077c478bd9Sstevel@tonic-gate 			}
3087c478bd9Sstevel@tonic-gate 			break;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 		/* Needed when this is called to demangle
3117c478bd9Sstevel@tonic-gate 		 * an argument of a pointer to a function.
3127c478bd9Sstevel@tonic-gate 		 */
3137c478bd9Sstevel@tonic-gate 		case '_':
3147c478bd9Sstevel@tonic-gate 			delar(&ar);
3157c478bd9Sstevel@tonic-gate 			return 0;
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 		default:
3187c478bd9Sstevel@tonic-gate 			delar(&ar);
3197c478bd9Sstevel@tonic-gate 			return -1;
3207c478bd9Sstevel@tonic-gate 		}
3217c478bd9Sstevel@tonic-gate 	}
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	/* Did the argument list terminate properly? */
3247c478bd9Sstevel@tonic-gate 	{
3257c478bd9Sstevel@tonic-gate 		int rc = 0;
3267c478bd9Sstevel@tonic-gate 		if(*PTR(ar.ptr) || ar.Uns || ar.Sign || ar.Cons || ar.Vol)
3277c478bd9Sstevel@tonic-gate 			rc = -1;
3287c478bd9Sstevel@tonic-gate 		delar(&ar);
3297c478bd9Sstevel@tonic-gate 		return rc;
3307c478bd9Sstevel@tonic-gate 	}
3317c478bd9Sstevel@tonic-gate }
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate /* This function is called to demangle
3347c478bd9Sstevel@tonic-gate  * an argument list.
3357c478bd9Sstevel@tonic-gate  * Returns the number of characters processed from c.
3367c478bd9Sstevel@tonic-gate  */
3377c478bd9Sstevel@tonic-gate int
demangle_doargs(String ** sptr,char * c)338*7dbbfe77SToomas Soome demangle_doargs(String **sptr, char *c)
3397c478bd9Sstevel@tonic-gate {
340*7dbbfe77SToomas Soome 	int i = 0, n = 0;
3417c478bd9Sstevel@tonic-gate 	here.pos = 0;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	*sptr = app_String(*sptr,MSG_ORIG(MSG_STR_OPENPAR));
3447c478bd9Sstevel@tonic-gate 	while (*c && (i = demangle_doarg(sptr,c)) > 0) {
3457c478bd9Sstevel@tonic-gate 		c += i;
3467c478bd9Sstevel@tonic-gate 		n += i;
3477c478bd9Sstevel@tonic-gate 		(*sptr) = app_String(*sptr,(*c && *c == 'e') ?
3487c478bd9Sstevel@tonic-gate 		    MSG_ORIG(MSG_STR_SPACE) : MSG_ORIG(MSG_STR_COMMA));
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	if(i < 0)
3527c478bd9Sstevel@tonic-gate 		return -1;
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	*sptr = app_String(trunc_String(*sptr, 1), MSG_ORIG(MSG_STR_CLOSEPAR));
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	return n;
3577c478bd9Sstevel@tonic-gate }
358