]> git.deb.at Git - pkg/abook.git/blobdiff - options.c
- replace abook_malloc, abook_realloc and my_free with new xmalloc routines
[pkg/abook.git] / options.c
index fa0531352973a04d35e8f72686002d0922403ef5..d43f0e725793683162fcbd0b5ce31595afeda445 100644 (file)
--- a/options.c
+++ b/options.c
@@ -64,17 +64,21 @@ static struct option abook_vars[] = {
 
        { "use_ascii_only", OT_BOOL, BOOL_USE_ASCII_ONLY, FALSE },
 
+       { "add_email_prevent_duplicates", OT_BOOL, BOOL_ADD_EMAIL_PREVENT_DUPLICATES, FALSE },
+       { "sort_field", OT_STR, STR_SORT_FIELD, UL "nick" },
+       { "show_cursor", OT_BOOL, BOOL_SHOW_CURSOR, FALSE },
+
        { NULL }
 };
 
 static unsigned char bool_opts[BOOL_MAX];
-static int int_opts[INT_MAX];
+static int int_opts[INT_MAXIMUM];
 static char *str_opts[STR_MAX];
 
 static void
 set_int(enum int_opts opt, int value)
 {
-       assert(opt >= 0 && opt < INT_MAX);
+       assert(opt >= 0 && opt < INT_MAXIMUM);
 
        int_opts[opt] = value;
 }
@@ -101,7 +105,7 @@ set_str(enum str_opts opt, char *value)
 int
 opt_get_int(enum int_opts opt)
 {
-       assert(opt >= 0 && opt < INT_MAX);
+       assert(opt >= 0 && opt < INT_MAXIMUM);
 
        return int_opts[opt];
 }
@@ -254,6 +258,8 @@ opt_set_set_option(char *var, char *p, struct option *opt)
                        else
                                return "invalid value";
                        break;
+               default:
+                       assert(0);
        }
        
        return NULL;
@@ -280,12 +286,39 @@ opt_parse_set(buffer *b)
        return "unknown option";
 }
 
+#include "database.h" /* needed for change_custom_field_name */
+
+static char *
+opt_parse_customfield(buffer *b)
+{
+       char *p, num[5];
+       int n;
+       size_t len;
+
+       find_token_start(b);
+       p = b -> ptr;
+       find_token_end(b);
+
+       memset(num, 0, sizeof(num));
+
+       len = (b -> ptr - p);
+       strncpy(num, p, min(sizeof(num) - 1, len));
+       n = safe_atoi(num);
+
+       find_token_start(b);
+
+       if(change_custom_field_name(b->ptr, n) == -1)
+               return "invalid custom field number";
+
+       return NULL;
+}
 
 static struct {
        char *token;
        char * (*func) (buffer *line);
 } opt_parsers[] = {
        { "set", opt_parse_set },
+       { "customfield", opt_parse_customfield },
        { NULL }
 };
 
@@ -337,7 +370,7 @@ load_opts(char *filename)
        FILE *in;
        char *line = NULL;
        int n;
-       bool err = FALSE;
+       int err = 0;
        
        if((in = fopen(filename, "r")) == NULL)
                return -1;
@@ -352,19 +385,15 @@ load_opts(char *filename)
                if(line && *line) {
                        opt_line_remove_comments(line);
                        if(*line)
-                               err = opt_parse_line(line, n, filename);
+                               err += opt_parse_line(line, n, filename) ? 1:0;
                }
 
-               my_free(line);
+               free(line);
+               line = NULL;
        }
 
        free(line);
 
-       if(err) {
-               printf("Press enter to continue...\n");
-               fgetc(stdin);
-       }
-       
        return err;
 }