Resync with broadcom drivers 5.100.138.20 and utilities.
[tomato.git] / release / src-rt / include / miniopt.h
blob6018e1f83ddc7488d501e8359207fd926b9e725c
1 /*
2 * Command line options parser.
4 * Copyright (C) 2010, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * $Id: miniopt.h,v 1.3 2009-01-15 00:06:54 Exp $
21 #ifndef MINI_OPT_H
22 #define MINI_OPT_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* ---- Include Files ---------------------------------------------------- */
29 /* ---- Constants and Types ---------------------------------------------- */
31 #define MINIOPT_MAXKEY 128 /* Max options */
32 typedef struct miniopt {
34 /* These are persistent after miniopt_init() */
35 const char* name; /* name for prompt in error strings */
36 const char* flags; /* option chars that take no args */
37 bool longflags; /* long options may be flags */
38 bool opt_end; /* at end of options (passed a "--") */
40 /* These are per-call to miniopt() */
42 int consumed; /* number of argv entries cosumed in
43 * the most recent call to miniopt()
45 bool positional;
46 bool good_int; /* 'val' member is the result of a sucessful
47 * strtol conversion of the option value
49 char opt;
50 char key[MINIOPT_MAXKEY];
51 char* valstr; /* positional param, or value for the option,
52 * or null if the option had
53 * no accompanying value
55 uint uval; /* strtol translation of valstr */
56 int val; /* strtol translation of valstr */
57 } miniopt_t;
59 void miniopt_init(miniopt_t *t, const char* name, const char* flags, bool longflags);
60 int miniopt(miniopt_t *t, char **argv);
63 /* ---- Variable Externs ------------------------------------------------- */
64 /* ---- Function Prototypes ---------------------------------------------- */
67 #ifdef __cplusplus
69 #endif
71 #endif /* MINI_OPT_H */