Use getopt in the bsc_hack to parse options
Current options include a draft of the help screen, an option to disable the colors and to specify the debug categories to show.
This commit is contained in:
parent
5ee72eeeb1
commit
b332f61f0d
|
@ -19,5 +19,6 @@
|
||||||
|
|
||||||
void debugp(unsigned int subsys, char *file, int line, const char *format, ...);
|
void debugp(unsigned int subsys, char *file, int line, const char *format, ...);
|
||||||
void debug_parse_category_mask(const char* mask);
|
void debug_parse_category_mask(const char* mask);
|
||||||
|
void debug_use_color(int use_color);
|
||||||
|
|
||||||
#endif /* _DEBUG_H */
|
#endif /* _DEBUG_H */
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include <openbsc/gsm_data.h>
|
#include <openbsc/gsm_data.h>
|
||||||
#include <openbsc/select.h>
|
#include <openbsc/select.h>
|
||||||
#include <openbsc/abis_rsl.h>
|
#include <openbsc/abis_rsl.h>
|
||||||
|
@ -581,8 +584,58 @@ static int bootstrap_network(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void print_usage()
|
||||||
|
{
|
||||||
|
printf("Usage: bsc_hack\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_help()
|
||||||
|
{
|
||||||
|
printf(" Some useful help...\n");
|
||||||
|
printf(" -d option --debug=DRLL:DCC:DMM:DRR:DRSL:DNM enable debugging\n");
|
||||||
|
printf(" -n --disable-color\n");
|
||||||
|
printf(" -h --help this text\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_options(int argc, char** argv)
|
||||||
|
{
|
||||||
|
while (1) {
|
||||||
|
int option_index = 0, c;
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"help", 0, 0, 'h'},
|
||||||
|
{"debug", 1, 0, 'd'},
|
||||||
|
{"disable-color", 0, 0, 'n'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
c = getopt_long(argc, argv, "hnd:",
|
||||||
|
long_options, &option_index);
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
print_usage();
|
||||||
|
print_help();
|
||||||
|
exit(0);
|
||||||
|
case 'n':
|
||||||
|
debug_use_color(0);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
debug_parse_category_mask(optarg);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* ignore */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
/* parse options */
|
||||||
|
handle_options(argc, argv);
|
||||||
|
|
||||||
bootstrap_network();
|
bootstrap_network();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
@ -53,6 +53,11 @@ static const struct debug_info debug_info[] = {
|
||||||
|
|
||||||
static int use_color = 1;
|
static int use_color = 1;
|
||||||
|
|
||||||
|
void debug_use_color(int color)
|
||||||
|
{
|
||||||
|
use_color = color;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse the category mask.
|
* Parse the category mask.
|
||||||
* category1:category2:category3
|
* category1:category2:category3
|
||||||
|
|
Loading…
Reference in New Issue