/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* Glenn Fowler24* AT&T Research25*26* command line option parse interface27*/2829#ifndef _OPTION_H30#define _OPTION_H3132#include <ast.h>3334#define OPT_VERSION 20070319L3536#define OPT_USER (1L<<16) /* first user flag bit */3738struct Opt_s;39struct Optdisc_s;4041typedef int (*Optinfo_f)(struct Opt_s*, Sfio_t*, const char*, struct Optdisc_s*);4243typedef struct Optdisc_s44{45unsigned long version; /* OPT_VERSION */46unsigned long flags; /* OPT_* flags */47char* catalog; /* error catalog id */48Optinfo_f infof; /* runtime info function */49} Optdisc_t;5051/* NOTE: Opt_t member order fixed by a previous binary release */5253#ifndef _OPT_PRIVATE_54#define _OPT_PRIVATE_ \55char pad[3*sizeof(void*)];56#endif5758typedef struct Opt_s59{60int again; /* see optjoin() */61char* arg; /* {:,#} string argument */62char** argv; /* most recent argv */63int index; /* argv index */64char* msg; /* error/usage message buffer */65long num; /* OBSOLETE -- use number */66int offset; /* char offset in argv[index] */67char option[8]; /* current flag {-,+} + option */68char name[64]; /* current long name or flag */69Optdisc_t* disc; /* user discipline */70intmax_t number; /* # numeric argument */71unsigned char assignment; /* option arg assigment op */72unsigned char pads[sizeof(void*)-1];73_OPT_PRIVATE_74} Opt_t;7576#if _BLD_ast && defined(__EXPORT__)77#define extern extern __EXPORT__78#endif79#if !_BLD_ast && defined(__IMPORT__)80#define extern extern __IMPORT__81#endif8283extern Opt_t* _opt_infop_;8485#define opt_info (*_opt_infop_)8687#undef extern8889#define optinit(d,f) (memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d))9091#if _BLD_ast && defined(__EXPORT__)92#define extern __EXPORT__93#endif9495extern int optget(char**, const char*);96extern int optjoin(char**, ...);97extern char* opthelp(const char*, const char*);98extern char* optusage(const char*);99extern int optstr(const char*, const char*);100extern int optesc(Sfio_t*, const char*, int);101extern Opt_t* optctx(Opt_t*, Opt_t*);102103#undef extern104105#endif106107108