Show misc_opt.h syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* \file misc_opt.h
*/
#ifndef __MISC_OPT_H__
#define __MISC_OPT_H__
/**
* misc_parse_out_option:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
*
* Parse out an option followed by an argument, e.g. "-o blah" or
* "--opt blah". Either @option_str or @option_char can be NULL, but
* not both.
*
* Returns: NULL if the option is not foundm "" if the option is
* found, but is not followed by an argument, and the argument if the
* option and its argument are present.
*/
char *
misc_parse_out_option(int *argc, char **argv, char *option_str, char option_char);
/**
* misc_parse_out_switch:
* @argc: argc from main
* @argv: argv from main
* @option_str: long switch string, for example: --switch
* @option_char: char switch, for example: -s
*
* Parse out a command-line switch, e.g. "-s" or "--swch". Either
* @option_str or @option_char can be NULL, but not both.
*
* Returns: 1 if the switch is present, 0 otherwise.
*/
int
misc_parse_out_switch(int *argc, char **argv, char *option_str, char option_char);
/**
* misc_parse_option_as_int:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
* @value: pointer to int to fill in option with
*
* Parse out an option followed by an int, e.g. "-n 5" or "--num
* 5". @value will get filled in with the int. Either @option_str or
* @option_char can by NULL, but not both.
*
* Returns: 0 on success, -1 otherwise
*/
int misc_parse_option_as_int(int *argc, char **argv,
char *option_str, char option_char, int *value);
/**
* misc_parse_option_as_uint:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
* @value: pointer to unsigned int to fill in option with
*
* Parse out an option followed by an unsigned int, e.g. "-n 5" or
* "--num 5". @value will get filled in with the uint. Either
* @option_str or @option_char can by NULL, but not both.
*
* Returns: 0 on success, -1 otherwise
*/
int misc_parse_option_as_uint(int *argc, char **argv,
char *option_str, char option_char, uint *value);
/**
* misc_parse_option_as_float:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
* @value: pointer to float to fill in option with
*
* Parse out an option followed by an unsigned int, e.g. "-n 5.3" or
* "--num .532". @value will get filled in with the float. Either
* @option_str or @option_char can by NULL, but not both.
*
* Returns: 0 on success, -1 otherwise
*/
int misc_parse_option_as_float(int *argc, char **argv,
char *option_str, char option_char, float *value);
/**
* misc_parse_option_as_uint8:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
* @value: pointer to uint8 to fill in option with
*
* Parse out an option followed by an int, e.g. "-n 5" or "--num
* 5". @value will get filled in with the uint8. If option is > 255,
* -1 is returned. Either @option_str or @option_char can by NULL, but
* not both.
*
* Returns: 0 on success, -1 if option is greater than 255 or some
* other error
*/
int misc_parse_option_as_uint8(int *argc, char **argv,
char *option_str, char option_char, uint8_t *value);
/**
* misc_parse_option_as_uint16:
* @argc: argc from main
* @argv: argv from main
* @option_str: long option string, for example: --myoption
* @option_char: char option. for example: -o
* @value: pointer to uint16 to fill in option with
*
* Parse out an option followed by an int, e.g. "-n 5" or "--num
* 5". @value will get filled in with the uint16. If option is greater
* than 65535, -1 is returned. Either @option_str or @option_char can
* by NULL, but not both.
*
* Returns: 0 on success, -1 if option is greater than 65535 or some
* other error
*/
int misc_parse_option_as_uint16(int *argc, char **argv,
char *option_str, char option_char, uint16_t *value);
/**
* misc_args_remain:
* @argc: argc from main
* @argv: argv from main
*
* Checks for other args, returns true if they exist. Also emits error
* messages if those args are not -h -? or --help.
*
* Returns: 1 if there are args left, -1 otherwise
*/
int misc_args_remain(int *argc, char **argv);
#endif
See more files for this project here