[21580dd] | 1 | /*
|
---|
| 2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup net_app
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /** @file
|
---|
| 34 | * Generic command line arguments parsing functions.
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef __NET_APP_PARSE__
|
---|
| 38 | #define __NET_APP_PARSE__
|
---|
| 39 |
|
---|
[3be62bc] | 40 | #include "../include/socket.h"
|
---|
| 41 |
|
---|
| 42 | /** Translates the character string to the address family number.
|
---|
| 43 | * @param[in] name The address family name.
|
---|
| 44 | * @returns The corresponding address family number.
|
---|
| 45 | * @returns EAFNOSUPPORTED if the address family is not supported.
|
---|
[21580dd] | 46 | */
|
---|
[3be62bc] | 47 | int parse_address_family(const char * name);
|
---|
[21580dd] | 48 |
|
---|
| 49 | /** Parses the next parameter as an integral number.
|
---|
| 50 | * The actual parameter is pointed by the index.
|
---|
| 51 | * Parses the offseted actual parameter value if the offset is set or the next one if not.
|
---|
| 52 | * @param[in] argc The total number of the parameters.
|
---|
| 53 | * @param[in] argv The parameters.
|
---|
| 54 | * @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
|
---|
| 55 | * @param[out] value The parsed parameter value.
|
---|
| 56 | * @param[in] name The parameter name to be printed on errors.
|
---|
| 57 | * @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
|
---|
| 58 | * @returns EOK on success.
|
---|
| 59 | * @returns EINVAL if the parameter is missing.
|
---|
| 60 | * @returns EINVAL if the parameter is in wrong format.
|
---|
| 61 | */
|
---|
[aadf01e] | 62 | int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset);
|
---|
[21580dd] | 63 |
|
---|
[3be62bc] | 64 | /** Parses the next named parameter as an integral number.
|
---|
[21580dd] | 65 | * The actual parameter is pointed by the index.
|
---|
[3be62bc] | 66 | * Uses the offseted actual parameter if the offset is set or the next one if not.
|
---|
| 67 | * Translates the parameter using the parse_value function.
|
---|
[21580dd] | 68 | * Increments the actual index by the number of processed parameters.
|
---|
| 69 | * @param[in] argc The total number of the parameters.
|
---|
| 70 | * @param[in] argv The parameters.
|
---|
| 71 | * @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
|
---|
| 72 | * @param[out] value The parsed parameter value.
|
---|
| 73 | * @param[in] name The parameter name to be printed on errors.
|
---|
| 74 | * @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
|
---|
[3be62bc] | 75 | * @param[in] parse_value The translation function to parse the named value.
|
---|
[21580dd] | 76 | * @returns EOK on success.
|
---|
| 77 | * @returns EINVAL if the parameter is missing.
|
---|
[3be62bc] | 78 | * @returns ENOENT if the parameter name has not been found.
|
---|
[21580dd] | 79 | */
|
---|
[3be62bc] | 80 | int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value));
|
---|
[21580dd] | 81 |
|
---|
[3be62bc] | 82 | /** Parses the next parameter as a character string.
|
---|
[21580dd] | 83 | * The actual parameter is pointed by the index.
|
---|
[3be62bc] | 84 | * Uses the offseted actual parameter value if the offset is set or the next one if not.
|
---|
[21580dd] | 85 | * Increments the actual index by the number of processed parameters.
|
---|
| 86 | * @param[in] argc The total number of the parameters.
|
---|
| 87 | * @param[in] argv The parameters.
|
---|
| 88 | * @param[in,out] index The actual parameter index. The index is incremented by the number of processed parameters.
|
---|
| 89 | * @param[out] value The parsed parameter value.
|
---|
| 90 | * @param[in] name The parameter name to be printed on errors.
|
---|
| 91 | * @param[in] offset The value offset in the actual parameter. If not set, the next parameter is parsed instead.
|
---|
| 92 | * @returns EOK on success.
|
---|
| 93 | * @returns EINVAL if the parameter is missing.
|
---|
| 94 | */
|
---|
[3be62bc] | 95 | int parse_parameter_string(int argc, char ** argv, int * index, char ** value, const char * name, int offset);
|
---|
| 96 |
|
---|
| 97 | /** Translates the character string to the protocol family number.
|
---|
| 98 | * @param[in] name The protocol family name.
|
---|
| 99 | * @returns The corresponding protocol family number.
|
---|
| 100 | * @returns EPFNOSUPPORTED if the protocol family is not supported.
|
---|
| 101 | */
|
---|
| 102 | int parse_protocol_family(const char * name);
|
---|
| 103 |
|
---|
| 104 | /** Translates the character string to the socket type number.
|
---|
| 105 | * @param[in] name The socket type name.
|
---|
| 106 | * @returns The corresponding socket type number.
|
---|
| 107 | * @returns ESOCKNOSUPPORTED if the socket type is not supported.
|
---|
| 108 | */
|
---|
| 109 | int parse_socket_type(const char * name);
|
---|
| 110 |
|
---|
| 111 | /** Prints the parameter unrecognized message and the application help.
|
---|
| 112 | * @param[in] index The index of the parameter.
|
---|
| 113 | * @param[in] parameter The parameter name.
|
---|
| 114 | */
|
---|
| 115 | void print_unrecognized(int index, const char * parameter);
|
---|
[21580dd] | 116 |
|
---|
| 117 | #endif
|
---|
| 118 |
|
---|
| 119 | /** @}
|
---|
| 120 | */
|
---|