1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2011 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 <glenn.s.fowler@gmail.com> * 18 * David Korn <dgkorn@gmail.com> * 19 * Phong Vo <phongvo@gmail.com> * 20 * * 21 ***********************************************************************/ 22 /* 23 * Glenn Fowler 24 * AT&T Research 25 * 26 * command line option parse interface 27 */ 28 #ifndef _OPTION_H 29 #define _OPTION_H 1 30 31 #include "ast.h" 32 #include "optlib.h" 33 34 #define OPT_VERSION 20070319L 35 36 struct Opt_s; 37 struct Optdisc_s; 38 39 typedef int (*Optinfo_f)(struct Opt_s *, Sfio_t *, const char *, struct Optdisc_s *); 40 41 struct Optdisc_s { 42 unsigned long version; /* OPT_VERSION */ 43 unsigned long flags; /* OPT_* flags */ 44 char *catalog; /* error catalog id */ 45 Optinfo_f infof; /* runtime info function */ 46 }; 47 48 // NOTE: Opt_t member order fixed by a previous binary release 49 typedef struct Opt_s { 50 int again; /* see optjoin() */ 51 char *arg; /* {:,#} string argument */ 52 char **argv; /* most recent argv */ 53 int index; /* argv index */ 54 char *msg; /* error/usage message buffer */ 55 long num; /* OBSOLETE -- use number */ 56 int offset; /* char offset in argv[index] */ 57 char option[8]; /* current flag {-,+} + option */ 58 char name[64]; /* current long name or flag */ 59 Optdisc_t *disc; /* user discipline */ 60 int64_t number; /* # numeric argument */ 61 unsigned char assignment; /* option arg assigment op */ 62 unsigned char pads[sizeof(void *) - 1]; 63 char pad[2 * sizeof(void *)]; 64 Optstate_t *state; 65 } Opt_t; 66 67 extern Optstate_t *optstate(Opt_t *); 68 extern Opt_t *_opt_infop_; 69 70 #define opt_info (*_opt_infop_) 71 72 #define optinit(d, f) \ 73 (memset(d, 0, sizeof(*(d))), (d)->version = OPT_VERSION, (d)->infof = (f), opt_info.disc = (d)) 74 75 extern int optget(char **, const char *); 76 extern char *opthelp(const char *, const char *); 77 extern char *optusage(const char *); 78 extern int optstr(const char *, const char *); 79 80 #endif // _OPTION_H 81