xref: /titanic_51/usr/src/lib/libast/common/comp/getsubopt.c (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Xopen 4.2 compatibility
25  */
26 
27 #include <ast_lib.h>
28 
29 #undef	_lib_getsubopt	/* we can satisfy the api */
30 
31 #if _lib_getsubopt
32 
33 #include <ast.h>
34 
35 NoN(getsubopt)
36 
37 #else
38 
39 #define getsubopt	______getsubopt
40 
41 #include <ast.h>
42 
43 #undef	getsubopt
44 
45 #include <error.h>
46 
47 #if defined(__EXPORT__)
48 #define extern	__EXPORT__
49 #endif
50 
51 extern int
52 getsubopt(register char** op, char* const* tp, char** vp)
53 {
54 	register char*	b;
55 	register char*	s;
56 	register char*	v;
57 
58 	if (*(b = *op))
59 	{
60 		v = 0;
61 		s = b;
62 		for (;;)
63 		{
64 			switch (*s++)
65 			{
66 			case 0:
67 				s--;
68 				break;
69 			case ',':
70 				*(s - 1) = 0;
71 				break;
72 			case '=':
73 				if (!v)
74 				{
75 					*(s - 1) = 0;
76 					v = s;
77 				}
78 				continue;
79 			default:
80 				continue;
81 			}
82 			break;
83 		}
84 		*op = s;
85 		*vp = v;
86 		for (op = (char**)tp; *op; op++)
87 			if (streq(b, *op))
88 				return op - (char**)tp;
89 	}
90 	*vp = b;
91 	return -1;
92 }
93 
94 #endif
95