This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
neels gerrit-no-reply at lists.osmocom.orgneels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/23588 ) Change subject: omldummy: introduce using getopt_long ...................................................................... omldummy: introduce using getopt_long Prepare for adding the --features cmdline arg following in a subsequent patch. Related: SYS#4895 Change-Id: I72ccf65ba894e87ee7b0f6bed879f94728f34ccc --- M src/osmo-bts-omldummy/main.c 1 file changed, 68 insertions(+), 12 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/88/23588/1 diff --git a/src/osmo-bts-omldummy/main.c b/src/osmo-bts-omldummy/main.c index 22d8758..fe28b05 100644 --- a/src/osmo-bts-omldummy/main.c +++ b/src/osmo-bts-omldummy/main.c @@ -1,3 +1,9 @@ +#include <unistd.h> +#include <stdlib.h> +#include <stdio.h> + +#define _GNU_SOURCE +#include <getopt.h> #include <osmocom/core/talloc.h> #include <osmocom/core/application.h> @@ -6,6 +12,64 @@ #include <osmo-bts/bts.h> #include <osmo-bts/oml.h> +static void print_usage(const char *prog_name) +{ + printf("Usage: %s [-h] dst_host site_id [trx_num]\n", prog_name); +} + +static void print_help(const char *prog_name) +{ + print_usage(prog_name); + printf(" -h --help This text.\n"); +} + +struct { + char *dst_host; + int site_id; + int trx_num; +} cmdline = { + .trx_num = 8, +}; + +void parse_cmdline(int argc, char **argv) +{ + while (1) { + int option_index = 0, c; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {0} + }; + + c = getopt_long(argc, argv, "hd", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'h': + print_help(argv[0]); + exit(0); + default: + /* catch unknown options *as well as* missing arguments. */ + fprintf(stderr, "Error in command line options. Exiting.\n"); + exit(-1); + } + } + + if (optind + 2 > argc) { + print_usage(argv[0]); + exit(1); + } + + cmdline.dst_host = argv[optind]; + cmdline.site_id = atoi(argv[optind + 1]); + if (optind + 2 < argc) + cmdline.trx_num = atoi(argv[optind + 2]); + + if (optind + 3 < argc) { + print_usage(argv[0]); + exit(1); + } +} int main(int argc, char **argv) { @@ -14,14 +78,7 @@ struct e1inp_line *line; int i; - if (argc < 3) { - fprintf(stderr, "Usage: %s dst_host site_id [trx_num]\n", argv[0]); - return 1; - } - - char *dst_host = argv[1]; - int site_id = atoi(argv[2]); - int trx_num = argc > 3 ? atoi(argv[3]) : 8; + parse_cmdline(argc, argv); tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context"); msgb_talloc_ctx_init(tall_bts_ctx, 10*1024); @@ -31,11 +88,11 @@ bts = gsm_bts_alloc(tall_bts_ctx, 0); if (!bts) exit(1); - bts->ip_access.site_id = site_id; + bts->ip_access.site_id = cmdline.site_id; bts->ip_access.bts_id = 0; /* Additional TRXs */ - for (i = 1; i < trx_num; i++) { + for (i = 1; i < cmdline.trx_num; i++) { trx = gsm_bts_trx_alloc(bts); if (!trx) exit(1); @@ -46,8 +103,7 @@ //btsb = bts_role_bts(bts); abis_init(bts); - - line = abis_open(bts, dst_host, "OMLdummy"); + line = abis_open(bts, cmdline.dst_host, "OMLdummy"); if (!line) exit(2); -- To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/23588 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-bts Gerrit-Branch: master Gerrit-Change-Id: I72ccf65ba894e87ee7b0f6bed879f94728f34ccc Gerrit-Change-Number: 23588 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210402/df9b0723/attachment.htm>