1 /* 2 * Copyright (C) 2005-2015 FreeIPMI Core Team 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * 17 */ 18 19 #ifdef HAVE_CONFIG_H 20 #include <config.h> 21 #endif /* HAVE_CONFIG_H */ 22 23 #include <stdio.h> 24 #include <stdlib.h> 25 #if HAVE_ARGP_H 26 #include <argp.h> 27 #else /* !HAVE_ARGP_H */ 28 #include "freeipmi-argp.h" 29 #endif /* !HAVE_ARGP_H */ 30 #include <assert.h> 31 32 #include "ipmi-locate_.h" 33 #include "ipmi-locate-argp.h" 34 35 #include "freeipmi-portability.h" 36 37 const char *argp_program_version = 38 "ipmi-locate - " PACKAGE_VERSION "\n" 39 "Copyright (C) 2005-2015 FreeIPMI Core Team\n" 40 "This program is free software; you may redistribute it under the terms of\n" 41 "the GNU General Public License. This program has absolutely no warranty."; 42 43 const char *argp_program_bug_address = 44 "<" PACKAGE_BUGREPORT ">"; 45 46 static char cmdline_doc[] = 47 "ipmi-locate - IPMI probing utility"; 48 49 static char cmdline_args_doc[] = ""; 50 51 static struct argp_option cmdline_options[] = 52 { 53 { "defaults", DEFAULTS_KEY, NULL, 0, 54 "Display system defaults.", 40}, 55 { NULL, 0, NULL, 0, NULL, 0} 56 }; 57 58 static error_t cmdline_parse (int key, char *arg, struct argp_state *state); 59 60 static struct argp cmdline_argp = { cmdline_options, 61 cmdline_parse, 62 cmdline_args_doc, 63 cmdline_doc }; 64 65 static error_t 66 cmdline_parse (int key, char *arg, struct argp_state *state) 67 { 68 struct ipmi_locate_arguments *cmd_args; 69 70 assert (state); 71 72 cmd_args = state->input; 73 74 switch (key) 75 { 76 case DEFAULTS_KEY: 77 cmd_args->defaults++; 78 break; 79 case ARGP_KEY_ARG: 80 /* Too many arguments. */ 81 argp_usage (state); 82 break; 83 case ARGP_KEY_END: 84 break; 85 default: 86 return (ARGP_ERR_UNKNOWN); 87 } 88 89 return (0); 90 } 91 92 void 93 ipmi_locate_argp_parse (int argc, char **argv, struct ipmi_locate_arguments *cmd_args) 94 { 95 assert (argc >= 0); 96 assert (argv); 97 assert (cmd_args); 98 99 cmd_args->defaults = 0; 100 101 argp_parse (&cmdline_argp, 102 argc, 103 argv, 104 ARGP_IN_ORDER, 105 NULL, 106 cmd_args); 107 } 108 109