xref: /titanic_41/usr/src/lib/libast/common/include/option.h (revision ea394cb00fd96864e34d2841b4a22357b621c78f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
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  * Glenn Fowler
25  * AT&T Research
26  *
27  * command line option parse interface
28  */
29 
30 #ifndef _OPTION_H
31 #define _OPTION_H
32 
33 #include <ast.h>
34 
35 #define OPT_VERSION	20070319L
36 
37 #define OPT_USER	(1L<<16)	/* first user flag bit		*/
38 
39 struct Opt_s;
40 struct Optdisc_s;
41 
42 typedef int (*Optinfo_f)(struct Opt_s*, Sfio_t*, const char*, struct Optdisc_s*);
43 
44 typedef struct Optdisc_s
45 {
46 	unsigned long	version;	/* OPT_VERSION			*/
47 	unsigned long	flags;		/* OPT_* flags			*/
48 	char*		catalog;	/* error catalog id		*/
49 	Optinfo_f	infof;		/* runtime info function	*/
50 } Optdisc_t;
51 
52 /* NOTE: Opt_t member order fixed by a previous binary release */
53 
54 #ifndef _OPT_PRIVATE_
55 #define _OPT_PRIVATE_	\
56 	char		pad[3*sizeof(void*)];
57 #endif
58 
59 typedef struct Opt_s
60 {
61 	int		again;		/* see optjoin()		*/
62 	char*		arg;		/* {:,#} string argument	*/
63 	char**		argv;		/* most recent argv		*/
64 	int		index;		/* argv index			*/
65 	char*		msg;		/* error/usage message buffer	*/
66 	long		num;		/* OBSOLETE -- use number	*/
67 	int		offset;		/* char offset in argv[index]	*/
68 	char		option[8];	/* current flag {-,+} + option  */
69 	char		name[64];	/* current long name or flag	*/
70 	Optdisc_t*	disc;		/* user discipline		*/
71 	intmax_t	number;		/* # numeric argument		*/
72 	unsigned char	assignment;	/* option arg assigment op	*/
73 	unsigned char	pads[sizeof(void*)-1];
74 	_OPT_PRIVATE_
75 } Opt_t;
76 
77 #if _BLD_ast && defined(__EXPORT__)
78 #define extern		extern __EXPORT__
79 #endif
80 #if !_BLD_ast && defined(__IMPORT__)
81 #define extern		extern __IMPORT__
82 #endif
83 
84 extern Opt_t*		_opt_infop_;
85 
86 #define opt_info	(*_opt_infop_)
87 
88 #undef	extern
89 
90 #define optinit(d,f)	(memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d))
91 
92 #if _BLD_ast && defined(__EXPORT__)
93 #define extern		__EXPORT__
94 #endif
95 
96 extern int		optget(char**, const char*);
97 extern int		optjoin(char**, ...);
98 extern char*		opthelp(const char*, const char*);
99 extern char*		optusage(const char*);
100 extern int		optstr(const char*, const char*);
101 extern int		optesc(Sfio_t*, const char*, int);
102 extern Opt_t*		optctx(Opt_t*, Opt_t*);
103 
104 #undef	extern
105 
106 #endif
107