xref: /onnv-gate/usr/src/lib/libast/common/string/fmtident.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin 
244887Schin #include <ast.h>
254887Schin #include <ctype.h>
264887Schin 
274887Schin #define IDENT	01
284887Schin #define USAGE	02
294887Schin 
304887Schin /*
314887Schin  * format what(1) and/or ident(1) string a
324887Schin  */
334887Schin 
344887Schin char*
fmtident(const char * a)354887Schin fmtident(const char* a)
364887Schin {
374887Schin 	register char*	s = (char*)a;
384887Schin 	register char*	t;
394887Schin 	char*		buf;
404887Schin 	int		i;
414887Schin 
424887Schin 	i = 0;
434887Schin 	for (;;)
444887Schin 	{
454887Schin 		while (isspace(*s))
464887Schin 			s++;
474887Schin 		if (s[0] == '[')
484887Schin 		{
494887Schin 			while (*++s && *s != '\n');
504887Schin 			i |= USAGE;
514887Schin 		}
524887Schin 		else if (s[0] == '@' && s[1] == '(' && s[2] == '#' && s[3] == ')')
534887Schin 			s += 4;
544887Schin 		else if (s[0] == '$' && s[1] == 'I' && s[2] == 'd' && s[3] == ':' && isspace(s[4]))
554887Schin 		{
564887Schin 			s += 5;
574887Schin 			i |= IDENT;
584887Schin 		}
594887Schin 		else
604887Schin 			break;
614887Schin 	}
624887Schin 	if (i)
634887Schin 	{
644887Schin 		i &= IDENT;
654887Schin 		for (t = s; isprint(*t) && *t != '\n'; t++)
664887Schin 			if (i && t[0] == ' ' && t[1] == '$')
674887Schin 				break;
684887Schin 		while (t > s && isspace(t[-1]))
694887Schin 			t--;
704887Schin 		i = t - s;
714887Schin 		buf = fmtbuf(i + 1);
724887Schin 		memcpy(buf, s, i);
734887Schin 		s = buf;
744887Schin 		s[i] = 0;
754887Schin 	}
764887Schin 	return s;
774887Schin }
78