BRL-CAD
getopt.h
Go to the documentation of this file.
1 /* G E T O P T . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 /** @file getopt.h
22  *
23  */
24 #ifndef BU_GETOPT_H
25 #define BU_GETOPT_H
26 
27 #include "common.h"
28 #include "bu/defines.h"
29 
31 
32 /** @addtogroup getopt */
33 /** @{ */
34 
35 /** @file libbu/getopt.c
36  *
37  * @brief
38  * Special portable re-entrant version of getopt.
39  *
40  * Everything is prefixed with bu_, to distinguish it from the various
41  * getopt routines found in libc.
42  *
43  * Important note -
44  * If bu_getopt() is going to be used more than once, it is necessary
45  * to reinitialize bu_optind=1 before beginning on the next argument
46  * list.
47  */
48 
49 /**
50  * for bu_getopt(). set to zero to suppress errors.
51  */
52 BU_EXPORT extern int bu_opterr;
53 
54 /**
55  * for bu_getopt(). current index into parent argv vector.
56  */
57 BU_EXPORT extern int bu_optind;
58 
59 /**
60  * for bu_getopt(). current option being checked for validity.
61  */
62 BU_EXPORT extern int bu_optopt;
63 
64 /**
65  * for bu_getopt(). current argument associated with current option.
66  */
67 BU_EXPORT extern char *bu_optarg;
68 
69 /**
70  * Get option letter from argument vector.
71  *
72  * returns the next known option character in ostr. If bu_getopt()
73  * encounters a character not found in ostr or if it detects a missing
74  * option argument, it returns `?' (question mark). If ostr has a
75  * leading `:' then a missing option argument causes `:' to be
76  * returned instead of `?'. In either case, the variable bu_optopt is
77  * set to the character that caused the error. The bu_getopt()
78  * function returns -1 when the argument list is exhausted.
79  */
80 BU_EXPORT extern int bu_getopt(int nargc, char * const nargv[], const char *ostr);
81 
82 /** @} */
83 
85 
86 #endif /* BU_GETOPT_H */
87 
88 /*
89  * Local Variables:
90  * mode: C
91  * tab-width: 8
92  * indent-tabs-mode: t
93  * c-file-style: "stroustrup"
94  * End:
95  * ex: shiftwidth=4 tabstop=8
96  */
char * bu_optarg
Definition: globals.c:91
Header file for the BRL-CAD common definitions.
int bu_optind
Definition: globals.c:89
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
Definition: getopt.c:43
int bu_optopt
Definition: globals.c:90
#define __BEGIN_DECLS
Definition: common.h:73
int bu_opterr
Definition: globals.c:88
#define __END_DECLS
Definition: common.h:74