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