1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * SPDX-License-Identifier: MPL-2.0
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
9  *
10  * See the COPYRIGHT file distributed with this work for additional
11  * information regarding copyright ownership.
12  */
13 
14 #ifndef ISC_COMMANDLINE_H
15 #define ISC_COMMANDLINE_H 1
16 
17 /*! \file isc/commandline.h */
18 
19 #include <stdbool.h>
20 
21 #include <isc/lang.h>
22 #include <isc/platform.h>
23 #include <isc/result.h>
24 
25 /*% Index into parent argv vector. */
26 LIBISC_EXTERNAL_DATA extern int isc_commandline_index;
27 /*% Character checked for validity. */
28 LIBISC_EXTERNAL_DATA extern int isc_commandline_option;
29 /*% Argument associated with option. */
30 LIBISC_EXTERNAL_DATA extern char *isc_commandline_argument;
31 /*% For printing error messages. */
32 LIBISC_EXTERNAL_DATA extern char *isc_commandline_progname;
33 /*% Print error message. */
34 LIBISC_EXTERNAL_DATA extern bool isc_commandline_errprint;
35 /*% Reset getopt. */
36 LIBISC_EXTERNAL_DATA extern bool isc_commandline_reset;
37 
38 ISC_LANG_BEGINDECLS
39 
40 int
41 isc_commandline_parse(int argc, char *const *argv, const char *options);
42 /*%<
43  * Parse a command line (similar to getopt())
44  */
45 
46 isc_result_t
47 isc_commandline_strtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp,
48 			  char ***argvp, unsigned int n);
49 /*%<
50  * Tokenize the string "s" into whitespace-separated words,
51  * returning the number of words in '*argcp' and an array
52  * of pointers to the words in '*argvp'.  The caller
53  * must free the array using isc_mem_free().  The string
54  * is modified in-place.
55  */
56 
57 ISC_LANG_ENDDECLS
58 
59 #endif /* ISC_COMMANDLINE_H */
60