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-2023 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#ifndef BU_GETOPT_H
22#define BU_GETOPT_H
23
24#include "common.h"
25#include "bu/defines.h"
26
27__BEGIN_DECLS
28
29/** @addtogroup bu_getopt
30 * @brief
31 * Special portable re-entrant version of getopt.
32 *
33 * Everything is prefixed with bu_, to distinguish it from the various
34 * getopt routines found in libc.
35 *
36 * Important note -
37 * If bu_getopt() is going to be used more than once, it is necessary
38 * to reinitialize bu_optind=1 before beginning on the next argument
39 * list.
40 */
41/** @{ */
42/** @file bu/getopt.h */
43
44/**
45 * for bu_getopt(). set to zero to suppress errors.
46 */
47BU_EXPORT extern int bu_opterr;
48
49/**
50 * for bu_getopt(). current index into parent argv vector.
51 */
52BU_EXPORT extern int bu_optind;
53
54/**
55 * for bu_getopt(). current option being checked for validity.
56 */
57BU_EXPORT extern int bu_optopt;
58
59/**
60 * for bu_getopt(). current argument associated with current option.
61 */
62BU_EXPORT extern char *bu_optarg;
63
64/**
65 * Get option letter from argument vector.
66 *
67 * @param nargc number of arguments
68 * @param nargv array of argument strings
69 * @param ostr option string
70 *
71 * The 'ostr' option string may contain individual characters (e.g.,
72 * "abc"), characters followed by a colon to indicate a required
73 * argument (e.g., "a:bc", 'a' requires an argument, 'b' and 'c' do
74 * not), and characters followed by two colons to indicate an optional
75 * argument (e.g., "ab::c", 'b' may be followed by an argument, but
76 * none require an argument).
77 *
78 * Returns -1 when the argument list is exhausted, otherwise it
79 * returns the next known option character. If bu_getopt() encounters
80 * a character not found in ostr or if it detects a required missing
81 * option argument, it returns `?' (question mark). If ostr has a
82 * leading `:' then a missing option argument causes `:' to be
83 * returned instead of `?'. In either case, the variable bu_optopt is
84 * set to the character that caused the error.
85 */
86BU_EXPORT extern int bu_getopt(int nargc, char * const nargv[], const char *ostr);
87
88/** @} */
89
90__END_DECLS
91
92#endif /* BU_GETOPT_H */
93
94/*
95 * Local Variables:
96 * mode: C
97 * tab-width: 8
98 * indent-tabs-mode: t
99 * c-file-style: "stroustrup"
100 * End:
101 * ex: shiftwidth=4 tabstop=8
102 */
Header file for the BRL-CAD common definitions.
char * bu_optarg
int bu_optopt
int bu_getopt(int nargc, char *const nargv[], const char *ostr)
int bu_opterr
int bu_optind