diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-02-05 19:06:21 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-02-05 19:06:21 +0000 |
commit | 4aa11b915e718d739d7bbfc737b77164d79af116 (patch) | |
tree | 4cd88e5cca9df66f069a2eb1b639ec0ad938948c /conf.c | |
parent | c93ad1a4ef2625ffb849b8868fe32f930594ac70 (diff) | |
parent | f3410da7f0bd208a5f2d792131b215454e782e93 (diff) | |
download | wavemon-4aa11b915e718d739d7bbfc737b77164d79af116.tar.gz |
Resolve 0.7.3 import conflict
Diffstat (limited to '')
-rw-r--r-- | conf.c | 216 |
1 files changed, 116 insertions, 100 deletions
@@ -22,9 +22,50 @@ #include <sys/types.h> /* GLOBALS */ -struct wavemon_conf conf; +static char **if_list; /* array of WiFi interface names */ int conf_items; /* index into array storing menu items */ -static int if_list; /* index into array of WiFi interface names */ + +static char *on_off_names[] = { [false] = "Off", [true] = "On", NULL }; +static char *action_items[] = { + [TA_DISABLED] = "Disabled", + [TA_BEEP] = "Beep", + [TA_FLASH] = "Flash", + [TA_BEEP_FLASH] = "Beep+Flash", + NULL +}; + +static char *screen_names[] = { + [SCR_INFO] = "Info screen", + [SCR_LHIST] = "Histogram", + [SCR_APLIST] = "Scan window", + NULL +}; + +struct wavemon_conf conf = { + .if_idx = 0, + + .stat_iv = 100, + .info_iv = 10, + .slotsize = 4, + .meter_decay = 0, + + .check_geometry = false, + .cisco_mac = false, + .override_bounds = false, + .random = false, + + .sig_min = -102, + .sig_max = 10, + .noise_min = -102, + .noise_max = 10, + + .lthreshold_action = TA_DISABLED, + .lthreshold = -80, + .hthreshold_action = TA_DISABLED, + .hthreshold = -10, + + .startup_scr = 0, +}; static void version(void) { @@ -36,6 +77,7 @@ 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"); @@ -44,23 +86,25 @@ static void usage(void) static void getargs(int argc, char *argv[]) { - int arg, tmp; + int arg; - while ((arg = getopt(argc, argv, "dhi:rv")) >= 0) + 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': - if ((tmp = ll_scan(if_list, "S", optarg)) >= 0) { - strncpy(conf.ifname, ll_get(if_list, tmp), - sizeof(conf.ifname)); - break; - } - err_quit("no wireless extensions found on '%s'", optarg); + 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; @@ -73,6 +117,39 @@ static void getargs(int argc, char *argv[]) } } +/** Populate interface list */ +void conf_get_interface_list(void) +{ + char *old_if = NULL; + int idx; + + if (if_list) { + for (idx = 0; if_list[idx]; idx++) + if (idx == conf.if_idx) + old_if = if_list[idx]; + else + free(if_list[idx]); + free(if_list); + } + if_list = iw_get_interface_list(); + if (if_list == NULL) + err_quit("no wireless interfaces found!"); + + conf.if_idx = 0; + if (old_if) { + idx = argv_find(if_list, old_if); + if (idx > 0) + conf.if_idx = idx; + free(old_if); + } +} + +/** Return currently selected interface name */ +const char *conf_ifname(void) +{ + return if_list ? if_list[conf.if_idx] : "(none)"; +} + /* Return full path of rcfile. Allocates string which must bee free()-d. */ static char *get_confname(void) { @@ -162,38 +239,13 @@ static void read_cf(void) *ci->v.i = v_int; } break; - case t_string: - if (strlen(rv) > ci->max) - err_quit("parse error in %s, line %d: argument too long (max %d chars)", - cfname, lnum, ci->max); - strncpy(ci->v.s, rv, LISTVAL_MAX); - break; - case t_switch: - if (!strcasecmp(rv, "on") || !strcasecmp(rv, "yes") || - !strcasecmp(rv, "enabled") || !strcasecmp(rv, "1")) { - *(ci->v.b) = 1; - } else if (!strcasecmp(rv, "off") || !strcasecmp(rv, "no") || - !strcasecmp(rv, "disabled") || !strcasecmp(rv, "0")) { - *(ci->v.b) = 0; - } else { - err_quit("parse error in %s, line %d: boolean expected, '%s' found instead", - cfname, lnum, rv); - } - break; case t_list: - v_int = ll_scan(ci->list, "S", rv); - if (v_int < 0) - err_quit("parse error in %s, line %d: '%s' is not a valid argument here", - cfname, lnum, rv); - *ci->v.b = v_int; - break; - case t_listval: - v_int = ll_scan(ci->list, "S", rv); + v_int = argv_find(ci->list, rv); if (v_int < 0) - err_quit("parse error in %s, line %d: '%s' is not a valid argument here", - cfname, lnum, rv); - strncpy(ci->v.s, ll_get(ci->list, v_int), LISTVAL_MAX); - break; + err_msg("%s, line %d: '%s = %s' is not valid - using defaults", + cfname, lnum, lv, rv); + else + *ci->v.i = v_int; case t_sep: /* These two cases are missing from the enum, they are not handled */ case t_func: /* To pacify gcc -Wall, fall through here */ break; @@ -230,15 +282,8 @@ static void write_cf(void) case t_int: sprintf(rv, "%d", *ci->v.i); break; - case t_string: /* fall through */ - case t_listval: - strcpy(rv, ci->v.s); - break; - case t_switch: - sprintf(rv, "%s", *ci->v.b ? "on" : "off"); - break; case t_list: - sprintf(rv, "%s", (char *)ll_get(ci->list, *ci->v.b)); + sprintf(rv, "%s", ci->list[*ci->v.i]); str_tolower(rv); break; /* Fall through, the rest are dummy statements to pacify gcc -Wall */ @@ -305,13 +350,20 @@ static void init_conf_items(void) item = calloc(1, sizeof(*item)); item->name = strdup("Interface"); item->cfname = strdup("interface"); - item->type = t_listval; - item->v.s = conf.ifname; - item->max = 10; + item->type = t_list; + item->v.i = &conf.if_idx; item->list = if_list; ll_push(conf_items, "*", item); item = calloc(1, sizeof(*item)); + item->name = strdup("Cisco-style MAC addresses"); + item->cfname = strdup("cisco_mac"); + item->type = t_list; + item->v.i = &conf.cisco_mac; + item->list = on_off_names; + ll_push(conf_items, "*", item); + + item = calloc(1, sizeof(*item)); item->name = strdup("Statistics updates"); item->cfname = strdup("stat_updates"); item->type = t_int; @@ -367,8 +419,9 @@ static void init_conf_items(void) item = calloc(1, sizeof(*item)); item->name = strdup("Override scale autodetect"); item->cfname = strdup("override_auto_scale"); - item->type = t_switch; - item->v.b = &conf.override_bounds; + item->type = t_list; + item->v.i = &conf.override_bounds; + item->list = on_off_names; ll_push(conf_items, "*", item); item = calloc(1, sizeof(*item)); @@ -422,8 +475,9 @@ static void init_conf_items(void) item = calloc(1, sizeof(*item)); item->name = strdup("Random signals"); item->cfname = strdup("random"); - item->type = t_switch; - item->v.b = &conf.random; + item->type = t_list; + item->v.i = &conf.random; + item->list = on_off_names; ll_push(conf_items, "*", item); /* thresholds */ @@ -431,12 +485,8 @@ static void init_conf_items(void) item->name = strdup("Low threshold action"); item->cfname = strdup("lo_threshold_action"); item->type = t_list; - item->v.b = &conf.lthreshold_action; - item->list = ll_create(); - ll_push(item->list, "s", "Disabled"); - ll_push(item->list, "s", "Beep"); - ll_push(item->list, "s", "Flash"); - ll_push(item->list, "s", "Beep+Flash"); + item->v.i = &conf.lthreshold_action; + item->list = action_items; ll_push(conf_items, "*", item); item = calloc(1, sizeof(*item)); @@ -455,12 +505,8 @@ static void init_conf_items(void) item->name = strdup("High threshold action"); item->cfname = strdup("hi_threshold_action"); item->type = t_list; - item->v.b = &conf.hthreshold_action; - item->list = ll_create(); - ll_push(item->list, "s", "Disabled"); - ll_push(item->list, "s", "Beep"); - ll_push(item->list, "s", "Flash"); - ll_push(item->list, "s", "Beep+Flash"); + item->v.i = &conf.hthreshold_action; + item->list = action_items; ll_push(conf_items, "*", item); item = calloc(1, sizeof(*item)); @@ -489,11 +535,8 @@ static void init_conf_items(void) item->name = strdup("Startup screen"); item->cfname = strdup("startup_screen"); item->type = t_list; - item->v.b = &conf.startup_scr; - item->list = ll_create(); - ll_push(item->list, "s", "Info"); - ll_push(item->list, "s", "Histogram"); - ll_push(item->list, "s", "Access points"); + item->v.i = &conf.startup_scr; + item->list = screen_names; ll_push(conf_items, "*", item); /* separator (dummy entry) */ @@ -509,36 +552,9 @@ static void init_conf_items(void) ll_push(conf_items, "*", item); } -static void set_defaults(void) -{ - strncpy(conf.ifname, ll_get(if_list, 0), sizeof(conf.ifname)); - - conf.stat_iv = 100; - conf.info_iv = 10; - conf.slotsize = 4; - conf.meter_decay = 0; - - conf.override_bounds = false; - conf.random = false; - - conf.sig_min = -102; - conf.sig_max = 10; - conf.noise_min = -102; - conf.noise_max = 10; - - - conf.lthreshold_action = TA_DISABLED; - conf.lthreshold = -80; - conf.hthreshold_action = TA_DISABLED; - conf.hthreshold = -10; - - conf.startup_scr = 0; -} - void getconf(int argc, char *argv[]) { - if_list = iw_get_interface_list(); - set_defaults(); + conf_get_interface_list(); init_conf_items(); read_cf(); getargs(argc, argv); |