X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=options.c;h=41bde1b920644eb332b4c2d48548403003b8a5dc;hb=67d7885c6f6e11e16488cac7117c503e03248183;hp=e9885a98aa9b8e1d5b0e86e70aa60753f390027a;hpb=6d57d82c3743c7321d7f664e8e57e0a9b2ddc7d2;p=pkg%2Fabook.git diff --git a/options.c b/options.c index e9885a9..41bde1b 100644 --- a/options.c +++ b/options.c @@ -65,6 +65,7 @@ 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 } }; @@ -256,6 +257,8 @@ opt_set_set_option(char *var, char *p, struct option *opt) else return "invalid value"; break; + default: + assert(0); } return NULL; @@ -282,12 +285,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 } };