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