1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2012 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 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 1 32 33 #include <ast.h> 34 35 #define OPT_VERSION 20000401L 36 37 #define opt_info _opt_info_ 38 39 #define OPT_USER (1L<<16) /* first user flag bit */ 40 41 struct Opt_s; 42 struct Optdisc_s; 43 44 typedef int (*Optinfo_f)(struct Opt_s*, Sfio_t*, const char*, struct Optdisc_s*); 45 46 typedef struct Optdisc_s 47 { 48 unsigned long version; /* OPT_VERSION */ 49 unsigned long flags; /* OPT_* flags */ 50 char* catalog; /* error catalog id */ 51 Optinfo_f infof; /* runtime info function */ 52 } Optdisc_t; 53 54 /* NOTE: Opt_t member order fixed by a previous binary release */ 55 56 #ifndef _OPT_PRIVATE_ 57 #define _OPT_PRIVATE_ void* _opt_private; 58 #endif 59 60 typedef struct Opt_s 61 { 62 int again; /* see optjoin() */ 63 char* arg; /* {:,#} string argument */ 64 char** argv; /* most recent argv */ 65 int index; /* argv index */ 66 char* msg; /* error/usage message buffer */ 67 long num; /* # numeric argument */ 68 int offset; /* char offset in argv[index] */ 69 char option[8]; /* current flag {-,+} + option */ 70 char name[64]; /* current long name or flag */ 71 Optdisc_t* disc; /* user discipline */ 72 intmax_t number; /* # numeric argument */ 73 unsigned char assignment; /* option arg assigment op */ 74 unsigned char pads[sizeof(void*)-1]; 75 _OPT_PRIVATE_ 76 } Opt_t; 77 78 #define optinit(d,f) (memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d)) 79 80 #if _BLD_ast && defined(__EXPORT__) 81 #define __PUBLIC_DATA__ __EXPORT__ 82 #else 83 #if !_BLD_ast && defined(__IMPORT__) 84 #define __PUBLIC_DATA__ __IMPORT__ 85 #else 86 #define __PUBLIC_DATA__ 87 #endif 88 #endif 89 90 extern __PUBLIC_DATA__ Opt_t opt_info; 91 92 #undef __PUBLIC_DATA__ 93 94 #if _BLD_ast && defined(__EXPORT__) 95 #define extern __EXPORT__ 96 #endif 97 98 extern int optget(char**, const char*); 99 extern int optjoin(char**, ...); 100 extern char* opthelp(const char*, const char*); 101 extern char* optusage(const char*); 102 extern int optstr(const char*, const char*); 103 104 #undef extern 105 106 #endif 107