Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * <:copyright-BRCM:2016:DUAL/GPL:standard |
| 4 | * |
| 5 | * Copyright (c) 2016 Broadcom |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * Unless you and Broadcom execute a separate written software license |
| 9 | * agreement governing use of this software, this software is licensed |
| 10 | * to you under the terms of the GNU General Public License version 2 |
| 11 | * (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 12 | * with the following added to such license: |
| 13 | * |
| 14 | * As a special exception, the copyright holders of this software give |
| 15 | * you permission to link this software with independent modules, and |
| 16 | * to copy and distribute the resulting executable under terms of your |
| 17 | * choice, provided that you also meet, for each linked independent |
| 18 | * module, the terms and conditions of the license of that module. |
| 19 | * An independent module is a module which is not derived from this |
| 20 | * software. The special exception does not apply to any modifications |
| 21 | * of the software. |
| 22 | * |
| 23 | * Not withstanding the above, under no circumstances may you combine |
| 24 | * this software in any way with any other Broadcom software provided |
| 25 | * under a license other than the GPL, without Broadcom's express prior |
| 26 | * written consent. |
| 27 | * |
| 28 | * :> |
| 29 | * |
| 30 | *****************************************************************************/ |
| 31 | /* |
| 32 | * cmdline.h - Command line argument helper |
| 33 | */ |
| 34 | |
| 35 | #ifndef _CMDLINE_H_ |
| 36 | #define _CMDLINE_H_ |
| 37 | |
| 38 | #include <bcmos_system.h> |
| 39 | |
| 40 | /** Argument flags */ |
| 41 | typedef enum |
| 42 | { |
| 43 | CL_ARGUMENT_FLAG_NONE = 0, |
| 44 | CL_ARGUMENT_FLAG_MANDATORY = 0x1, |
| 45 | } cl_argument_flags; |
| 46 | |
| 47 | /** Command line argument */ |
| 48 | typedef struct cl_argument |
| 49 | { |
| 50 | const char *long_name; /**< Command line option: long form */ |
| 51 | const char *short_name; /**< Command line option: short form */ |
| 52 | const char *extra_arg; /**< Extra arguments */ |
| 53 | const char *description; /**< Description */ |
| 54 | const char *owner; /**< Owner module */ |
| 55 | cl_argument_flags flags; /**< Command line argument flags */ |
| 56 | } cl_argument; |
| 57 | |
| 58 | /** Print usage flags */ |
| 59 | typedef enum |
| 60 | { |
| 61 | CL_ARGUMENT_USAGE_FLAG_NONE = 0, |
| 62 | CL_ARGUMENT_USAGE_FLAG_OWNER = 0x1, /**< Print argument owners */ |
| 63 | } cl_argument_usage_flags; |
| 64 | |
| 65 | /** Print usage |
| 66 | * \param[in] app Application name. Can be NULL |
| 67 | * \param[in] arg Argument that triggered command line parsing error. Can be NULL |
| 68 | * \param[in] supported_args Array of supported arguments |
| 69 | * \param[in] num_supported_args Number of elements in supported_args[] array |
| 70 | * \param[in] flags Usage flags |
| 71 | * \returns BCM_ERR_PARM |
| 72 | */ |
| 73 | bcmos_errno cl_print_usage(const char *app, const char *arg, |
| 74 | const cl_argument supported_args[], int num_supported_args, |
| 75 | cl_argument_usage_flags flags); |
| 76 | |
| 77 | /** Validate parameters |
| 78 | * |
| 79 | * - make sure that there are no unknown parameters |
| 80 | * - make sure that all mandatory parameters are present |
| 81 | * |
| 82 | * \param[in] argc Number of command line arguments |
| 83 | * \param[in] argv Command line arguments |
| 84 | * \param[in] supported_args Array of supported arguments |
| 85 | * \param[in] num_supported_args Number of elements in supported_args[] array |
| 86 | * \returns BCM_ERR_OK or BCM_ERR_PARM |
| 87 | */ |
| 88 | bcmos_errno cl_validate(int argc, char *argv[], |
| 89 | const cl_argument supported_args[], int num_supported_args); |
| 90 | |
| 91 | /** Get CL parameter by name |
| 92 | * |
| 93 | * \param[in] name Parameter name |
| 94 | * \param[in] supported_args Supported arguments array |
| 95 | * \param[in] num_supported_args Supported arguments array size |
| 96 | * \returns argument descriptor pointer or NULL if not found |
| 97 | */ |
| 98 | const cl_argument *cl_parm_get(const char *name, const cl_argument supported_args[], |
| 99 | int num_supported_args); |
| 100 | |
| 101 | #endif /* _CMDLINE_H_ */ |