aboutsummaryrefslogtreecommitdiffstats
path: root/conf.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--conf.c132
1 files changed, 77 insertions, 55 deletions
diff --git a/conf.c b/conf.c
index 45fa42e..376ea99 100644
--- a/conf.c
+++ b/conf.c
@@ -34,6 +34,17 @@ static char *action_items[] = {
NULL
};
+static char *sort_order[] = {
+ [SO_CHAN] = "Channel",
+ [SO_CHAN_REV] = "Rev Channel",
+ [SO_SIGNAL] = "Signal",
+ [SO_OPEN] = "Open",
+ [SO_CHAN_SIG] = "Chan/Sig",
+ [SO_OPEN_SIG] = "Open/Sig",
+ [SO_OPEN_CH_SI] = "Open/Chan/Sig",
+ NULL
+};
+
static char *screen_names[] = {
[SCR_INFO] = "Info screen",
[SCR_LHIST] = "Histogram",
@@ -59,6 +70,7 @@ struct wavemon_conf conf = {
.noise_min = -102,
.noise_max = 10,
+ .scan_sort_order = SO_CHAN,
.lthreshold_action = TA_DISABLED,
.lthreshold = -80,
.hthreshold_action = TA_DISABLED,
@@ -67,58 +79,8 @@ struct wavemon_conf conf = {
.startup_scr = 0,
};
-static void version(void)
-{
- printf("wavemon wireless monitor %s\n", PACKAGE_VERSION);
- printf("Distributed under the terms of the GPLv3.\n");
-}
-
-static void usage(void)
-{
- printf("Usage: wavemon [ -dhlrv ] [ -i ifname ]\n\n");
- printf(" -d Dump the current device status to stdout and exit\n");
- printf(" -g Ensure screen is sufficiently dimensioned\n");
- printf(" -h This help screen\n");
- printf(" -i <ifname> Use specified network interface (default: auto)\n");
- printf(" -r Generate random levels (for testing purposes)\n");
- printf(" -v Print version number and exit\n\n");
-}
-
-static void getargs(int argc, char *argv[])
-{
- int arg;
-
- while ((arg = getopt(argc, argv, "dghi:rv")) >= 0)
- switch (arg) {
- case 'd':
- dump_parameters();
- exit(EXIT_SUCCESS);
- case 'g':
- conf.check_geometry = true;
- break;
- case 'h':
- usage();
- exit(EXIT_SUCCESS);
- case 'i':
- conf.if_idx = argv_find(if_list, optarg);
- if (conf.if_idx < 0)
- err_quit("no wireless extensions found on '%s'",
- optarg);
- break;
- case 'r':
- conf.random = true;
- break;
- case 'v':
- version();
- exit(EXIT_SUCCESS);
- default:
- /* bad argument. bad bad */
- exit(EXIT_FAILURE);
- }
-}
-
/** Populate interface list */
-void conf_get_interface_list(void)
+void conf_get_interface_list(bool init)
{
char *old_if = NULL;
int idx;
@@ -132,7 +94,7 @@ void conf_get_interface_list(void)
free(if_list);
}
if_list = iw_get_interface_list();
- if (if_list == NULL)
+ if (if_list == NULL && !init)
err_quit("no wireless interfaces found!");
conf.if_idx = 0;
@@ -240,7 +202,7 @@ static void read_cf(void)
}
break;
case t_list:
- v_int = argv_find(ci->list, rv);
+ v_int = ci->list ? argv_find(ci->list, rv) : -1;
if (v_int < 0)
err_msg("%s, line %d: '%s = %s' is not valid - using defaults",
cfname, lnum, lv, rv);
@@ -364,6 +326,14 @@ static void init_conf_items(void)
ll_push(conf_items, "*", item);
item = calloc(1, sizeof(*item));
+ item->name = strdup("Scan sort order");
+ item->cfname = strdup("sort_order");
+ item->type = t_list;
+ item->v.i = &conf.scan_sort_order;
+ item->list = sort_order;
+ ll_push(conf_items, "*", item);
+
+ item = calloc(1, sizeof(*item));
item->name = strdup("Statistics updates");
item->cfname = strdup("stat_updates");
item->type = t_int;
@@ -554,8 +524,60 @@ static void init_conf_items(void)
void getconf(int argc, char *argv[])
{
- conf_get_interface_list();
+ int arg, dump = 0, help = 0, version = 0;
+
+ conf_get_interface_list(true);
init_conf_items();
read_cf();
- getargs(argc, argv);
+
+ while ((arg = getopt(argc, argv, "dghi:rv")) >= 0) {
+ switch (arg) {
+ case 'd':
+ if (if_list)
+ dump++;
+ break;
+ case 'g':
+ conf.check_geometry = true;
+ break;
+ case 'h':
+ help++;
+ break;
+ case 'i':
+ conf.if_idx = if_list ? argv_find(if_list, optarg) : -1;
+ if (conf.if_idx < 0)
+ err_quit("no wireless extensions found on '%s'",
+ optarg);
+ break;
+ case 'r':
+ conf.random = true;
+ break;
+ case 'v':
+ version++;
+ break;
+ default:
+ /* bad argument. bad bad */
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (version) {
+ printf("wavemon wireless monitor %s\n", PACKAGE_VERSION);
+ printf("Distributed under the terms of the GPLv3.\n%s", help ? "\n" : "");
+ }
+ if (help) {
+ printf("usage: wavemon [ -dhlrv ] [ -i ifname ]\n");
+ printf(" -d Dump the current device status to stdout and exit\n");
+ printf(" -g Ensure screen is sufficiently dimensioned\n");
+ printf(" -h This help screen\n");
+ printf(" -i <ifname> Use specified network interface (default: auto)\n");
+ printf(" -r Generate random levels (for testing purposes)\n");
+ printf(" -v Print version number\n");
+ } else if (dump) {
+ dump_parameters();
+ }
+
+ if (version || help || dump)
+ exit(EXIT_SUCCESS);
+ else if (if_list == NULL)
+ err_quit("no supported wireless interfaces found");
}