X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=o-du%2Fphy.git;a=blobdiff_plain;f=fapi_5g%2Fsource%2Futils%2Fnr5g_fapi_args.c;fp=fapi_5g%2Fsource%2Futils%2Fnr5g_fapi_args.c;h=552f4728790eae5965632e718de0ced8e8b17df1;hp=0000000000000000000000000000000000000000;hb=9d66fca5c45c8b3e0d6eab6d51a90c8e9d2614dc;hpb=2fbf70096f64af622da983e88c5a64e90ad9bdbd diff --git a/fapi_5g/source/utils/nr5g_fapi_args.c b/fapi_5g/source/utils/nr5g_fapi_args.c new file mode 100644 index 0000000..552f472 --- /dev/null +++ b/fapi_5g/source/utils/nr5g_fapi_args.c @@ -0,0 +1,83 @@ +/****************************************************************************** +* +* Copyright (c) 2019 Intel. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +*******************************************************************************/ + +#include "nr5g_fapi_args.h" +#include +#include + +static const char usage[] = + " \n" + " %s \n" + " \n" + "Application mandatory parameters: \n" + " --cfg FILE : configuration to load \n" + " \n" + " --f FILE : configuration to load \n"; + +/* display usage */ +static void nr5g_fapi_usage( + const char *prgname) +{ + printf(usage, prgname); +} + +const char *nr5g_fapi_parse_args( + int argc, + char **argv) +{ + int opt; + int option_index; + const char *optname; + char *cfg_file = NULL; + char *prgname = argv[0]; + + static struct option lgopts[] = { + {"cfg", 1, 0, 0}, + {NULL, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, "f", lgopts, &option_index)) != EOF) { + switch (opt) { + case 'f': + printf("short opts"); + cfg_file = optarg; + break; + + /* long options */ + case 0: + printf("long opts"); + optname = lgopts[option_index].name; + if (0 == strcmp(optname, "cfg")) { + cfg_file = optarg; + } + break; + + default: + nr5g_fapi_usage(prgname); + printf("in default"); + return NULL; + } + } + + if (cfg_file) + printf("config file: %s\n", cfg_file); + else + nr5g_fapi_usage(prgname); + + return cfg_file; +}