From: Jaakko Heinonen Date: Fri, 12 Oct 2001 10:04:00 +0000 (+0000) Subject: Updated extra_column initialization X-Git-Tag: upstream/0.6.1~2^2~326 X-Git-Url: https://git.deb.at/w?a=commitdiff_plain;h=b6053007306a73fefe0ed952862ae71da9483d0e;p=pkg%2Fabook.git Updated extra_column initialization --- diff --git a/list.c b/list.c index 32c12ed..6cb8ed7 100644 --- a/list.c +++ b/list.c @@ -9,6 +9,7 @@ #include #include +#include #include "abook.h" #include "ui.h" #include "database.h" @@ -33,47 +34,43 @@ extern struct abook_field abook_fields[]; WINDOW *list = NULL; -void -init_list() +static int +init_extra_field(char *option_name) { - int i; - char *e_column_str = options_get_str("extra_column"); - char *e_alternative_str = options_get_str("extra_alternative"); + int i, ret = -1; + char *option_str; - list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); - scrollok(list, TRUE); - - /* - * init extra_column and extra alternative - */ + assert(option_name != NULL); + + option_str = options_get_str(option_name); - if(e_column_str && *e_column_str) { + if(option_str && *option_str) { for(i = 0; i < ITEM_FIELDS; i++) { - if(!strcasecmp(e_column_str, abook_fields[i].key)) { - extra_column = i; + if(!strcasecmp(option_str, abook_fields[i].key)) { + ret = i; break; } } - if(extra_column < MIN_EXTRA_COLUMN || - extra_column > MAX_EXTRA_COLUMN) { - extra_column = -1; + if(ret < MIN_EXTRA_COLUMN || ret > MAX_EXTRA_COLUMN) { + ret = -1; } } - if(e_alternative_str && *e_alternative_str) { - for(i = 0; i < ITEM_FIELDS; i++) { - if(!strcasecmp(e_alternative_str, - abook_fields[i].key)) { - extra_alternative = i; - break; - } - } - if(extra_alternative < MIN_EXTRA_COLUMN || - extra_alternative > MAX_EXTRA_COLUMN) { - extra_alternative = -1; - } - } + return ret; +} + +void +init_list() +{ + list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0); + scrollok(list, TRUE); + + /* + * init extra_column and extra alternative + */ + extra_column = init_extra_field("extra_column"); + extra_alternative = init_extra_field("extra_alternative"); } void