1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
27 * command line option parse interface
35 #define OPT_VERSION 20070319L
37 #define OPT_USER (1L<<16) /* first user flag bit */
42 typedef int (*Optinfo_f
)(struct Opt_s
*, Sfio_t
*, const char*, struct Optdisc_s
*);
44 typedef struct Optdisc_s
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 */
52 /* NOTE: Opt_t member order fixed by a previous binary release */
55 #define _OPT_PRIVATE_ \
56 char pad[3*sizeof(void*)];
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];
77 #if _BLD_ast && defined(__EXPORT__)
78 #define extern extern __EXPORT__
80 #if !_BLD_ast && defined(__IMPORT__)
81 #define extern extern __IMPORT__
84 extern Opt_t
* _opt_infop_
;
86 #define opt_info (*_opt_infop_)
90 #define optinit(d,f) (memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d))
92 #if _BLD_ast && defined(__EXPORT__)
93 #define extern __EXPORT__
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
*);