source: mainline/uspace/srv/net/app/parse.h@ 3be62bc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3be62bc was 3be62bc, checked in by Lukas Mejdrech <lukasmejdrech@…>, 15 years ago
  • net app command line argument checks, * code reorganization
  • Property mode set to 100644
File size: 5.5 KB
Line 
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
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.
46 */
47int parse_address_family(const char * name);
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 */
62int parse_parameter_int(int argc, char ** argv, int * index, int * value, const char * name, int offset);
63
64/** Parses the next named parameter as an integral number.
65 * The actual parameter is pointed by the index.
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.
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.
75 * @param[in] parse_value The translation function to parse the named value.
76 * @returns EOK on success.
77 * @returns EINVAL if the parameter is missing.
78 * @returns ENOENT if the parameter name has not been found.
79 */
80int parse_parameter_name_int(int argc, char ** argv, int * index, int * value, const char * name, int offset, int (*parse_value)(const char * value));
81
82/** Parses the next parameter as a character string.
83 * The actual parameter is pointed by the index.
84 * Uses the offseted actual parameter value if the offset is set or the next one if not.
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 */
95int 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 */
102int 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 */
109int 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 */
115void print_unrecognized(int index, const char * parameter);
116
117#endif
118
119/** @}
120 */
Note: See TracBrowser for help on using the repository browser.