anjana_sreekumar@infosys.com | 991c206 | 2020-01-08 11:42:57 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd. |
| 3 | * Copyright (c) 2017 Intel Corporation |
| 4 | * Copyright (c) 2019, Infosys Ltd. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <unistd.h> |
| 22 | #include <getopt.h> |
| 23 | |
| 24 | #include "options.h" |
| 25 | #include "log.h" |
| 26 | |
| 27 | void parse_args(int argc, char **argv) |
| 28 | { |
| 29 | int args_set = 0; |
| 30 | int c = 0; |
| 31 | |
| 32 | const struct option long_options[] = { |
| 33 | {"config_file", required_argument, NULL, 'f'}, |
| 34 | {0, 0, 0, 0} |
| 35 | }; |
| 36 | |
| 37 | do { |
| 38 | int option_index = 0; |
| 39 | |
| 40 | c = getopt_long(argc, argv, "f:", long_options, |
| 41 | &option_index); |
| 42 | |
| 43 | if (c == -1) |
| 44 | break; |
| 45 | |
| 46 | switch (c) { |
| 47 | case 'f': |
| 48 | break; |
| 49 | default: |
| 50 | log_msg(LOG_ERROR, "Unknown argument - %s.", argv[optind]); |
| 51 | exit(0); |
| 52 | } |
| 53 | } while (c != -1); |
| 54 | |
| 55 | if ((args_set & REQ_ARGS) != REQ_ARGS) { |
| 56 | log_msg(LOG_ERROR, "Usage: %s\n", argv[0]); |
| 57 | for (c = 0; long_options[c].name; ++c) { |
| 58 | log_msg(LOG_ERROR, "\t[ -%s | -%c ] %s\n", |
| 59 | long_options[c].name, |
| 60 | long_options[c].val, |
| 61 | long_options[c].name); |
| 62 | } |
| 63 | exit(0); |
| 64 | } |
| 65 | } |
| 66 | |