xref: /titanic_50/usr/src/lib/libast/common/include/option.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin *                                                                      *
3da2e3ebdSchin *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
5da2e3ebdSchin *                      and is licensed under the                       *
6da2e3ebdSchin *                  Common Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8da2e3ebdSchin *                                                                      *
9da2e3ebdSchin *                A copy of the License is available at                 *
10da2e3ebdSchin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11da2e3ebdSchin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12da2e3ebdSchin *                                                                      *
13da2e3ebdSchin *              Information and Software Systems Research               *
14da2e3ebdSchin *                            AT&T Research                             *
15da2e3ebdSchin *                           Florham Park NJ                            *
16da2e3ebdSchin *                                                                      *
17da2e3ebdSchin *                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
19da2e3ebdSchin *                   Phong Vo <kpv@research.att.com>                    *
20da2e3ebdSchin *                                                                      *
21da2e3ebdSchin ***********************************************************************/
22da2e3ebdSchin #pragma prototyped
23da2e3ebdSchin /*
24da2e3ebdSchin  * Glenn Fowler
25da2e3ebdSchin  * AT&T Research
26da2e3ebdSchin  *
27da2e3ebdSchin  * command line option parse interface
28da2e3ebdSchin  */
29da2e3ebdSchin 
30da2e3ebdSchin #ifndef _OPTION_H
31da2e3ebdSchin #define _OPTION_H
32da2e3ebdSchin 
33da2e3ebdSchin #include <ast.h>
34da2e3ebdSchin 
35da2e3ebdSchin #define OPT_VERSION	20070319L
36da2e3ebdSchin 
37da2e3ebdSchin #define OPT_USER	(1L<<16)	/* first user flag bit		*/
38da2e3ebdSchin 
39da2e3ebdSchin struct Opt_s;
40da2e3ebdSchin struct Optdisc_s;
41da2e3ebdSchin 
42da2e3ebdSchin typedef int (*Optinfo_f)(struct Opt_s*, Sfio_t*, const char*, struct Optdisc_s*);
43da2e3ebdSchin 
44da2e3ebdSchin typedef struct Optdisc_s
45da2e3ebdSchin {
46da2e3ebdSchin 	unsigned long	version;	/* OPT_VERSION			*/
47da2e3ebdSchin 	unsigned long	flags;		/* OPT_* flags			*/
48da2e3ebdSchin 	char*		catalog;	/* error catalog id		*/
49da2e3ebdSchin 	Optinfo_f	infof;		/* runtime info function	*/
50da2e3ebdSchin } Optdisc_t;
51da2e3ebdSchin 
52da2e3ebdSchin /* NOTE: Opt_t member order fixed by a previous binary release */
53da2e3ebdSchin 
54da2e3ebdSchin #ifndef _OPT_PRIVATE_
55da2e3ebdSchin #define _OPT_PRIVATE_	\
56da2e3ebdSchin 	char		pad[3*sizeof(void*)];
57da2e3ebdSchin #endif
58da2e3ebdSchin 
59da2e3ebdSchin typedef struct Opt_s
60da2e3ebdSchin {
61da2e3ebdSchin 	int		again;		/* see optjoin()		*/
62da2e3ebdSchin 	char*		arg;		/* {:,#} string argument	*/
63da2e3ebdSchin 	char**		argv;		/* most recent argv		*/
64da2e3ebdSchin 	int		index;		/* argv index			*/
65da2e3ebdSchin 	char*		msg;		/* error/usage message buffer	*/
66da2e3ebdSchin 	long		num;		/* OBSOLETE -- use number	*/
67da2e3ebdSchin 	int		offset;		/* char offset in argv[index]	*/
68da2e3ebdSchin 	char		option[8];	/* current flag {-,+} + option  */
69da2e3ebdSchin 	char		name[64];	/* current long name or flag	*/
70da2e3ebdSchin 	Optdisc_t*	disc;		/* user discipline		*/
71da2e3ebdSchin 	intmax_t	number;		/* # numeric argument		*/
72da2e3ebdSchin 	unsigned char	assignment;	/* option arg assigment op	*/
73da2e3ebdSchin 	unsigned char	pads[sizeof(void*)-1];
74da2e3ebdSchin 	_OPT_PRIVATE_
75da2e3ebdSchin } Opt_t;
76da2e3ebdSchin 
77da2e3ebdSchin #if _BLD_ast && defined(__EXPORT__)
78da2e3ebdSchin #define extern		extern __EXPORT__
79da2e3ebdSchin #endif
80da2e3ebdSchin #if !_BLD_ast && defined(__IMPORT__)
81da2e3ebdSchin #define extern		extern __IMPORT__
82da2e3ebdSchin #endif
83da2e3ebdSchin 
84da2e3ebdSchin extern Opt_t*		_opt_infop_;
85da2e3ebdSchin 
86da2e3ebdSchin #define opt_info	(*_opt_infop_)
87da2e3ebdSchin 
88da2e3ebdSchin #undef	extern
89da2e3ebdSchin 
90da2e3ebdSchin #define optinit(d,f)	(memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d))
91da2e3ebdSchin 
92da2e3ebdSchin #if _BLD_ast && defined(__EXPORT__)
93da2e3ebdSchin #define extern		__EXPORT__
94da2e3ebdSchin #endif
95da2e3ebdSchin 
96da2e3ebdSchin extern int		optget(char**, const char*);
97da2e3ebdSchin extern int		optjoin(char**, ...);
98da2e3ebdSchin extern char*		opthelp(const char*, const char*);
99da2e3ebdSchin extern char*		optusage(const char*);
100da2e3ebdSchin extern int		optstr(const char*, const char*);
101da2e3ebdSchin extern int		optesc(Sfio_t*, const char*, int);
1027c2fbfb3SApril Chin extern Opt_t*		optctx(Opt_t*, Opt_t*);
103da2e3ebdSchin 
104da2e3ebdSchin #undef	extern
105da2e3ebdSchin 
106da2e3ebdSchin #endif
107