X-Git-Url: https://git.deb.at/?a=blobdiff_plain;ds=sidebyside;f=options.c;h=9724103818794cc5db1075b025a5c56850347e24;hb=24be624311cedd42ed09acfc605cdf51546bb5ab;hp=1eed8d489aa885da960c82236da8d9f6a6a8d5d2;hpb=260365f6312bdbadc5c65ee6aec86e2bfaea1494;p=pkg%2Fabook.git diff --git a/options.c b/options.c index 1eed8d4..9724103 100644 --- a/options.c +++ b/options.c @@ -65,18 +65,19 @@ 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" }, { 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; } @@ -103,7 +104,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]; } @@ -282,12 +283,41 @@ 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 = 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 } };