]> git.deb.at Git - pkg/abook.git/commitdiff
Updated extra_column initialization
authorJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 12 Oct 2001 10:04:00 +0000 (10:04 +0000)
committerJaakko Heinonen <jheinonen@users.sourceforge.net>
Fri, 12 Oct 2001 10:04:00 +0000 (10:04 +0000)
list.c

diff --git a/list.c b/list.c
index 32c12ed8b8466c0c6aa3ee72573c619bf8f7a2e5..6cb8ed791b8bd71065d62cd63657e7387cd50210 100644 (file)
--- a/list.c
+++ b/list.c
@@ -9,6 +9,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 #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