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