+
+static int
+assign_fieldname(const char *name, int i)
+{
+ char *s;
+
+ assert(name);
+ assert(i >= 0 && i < ITEM_FIELDS);
+
+ if(strcasecmp(abook_fields[i].name, name)) { /* name differs */
+ /*
+ * check if we are overwriting statically allocated default
+ */
+ if(strcasecmp(abook_fields[i].name, abook_fields[i].key))
+ xfree(abook_fields[i].name);
+
+ s = xmalloc_inc(MAX_FIELDNAME_LEN, 1);
+ snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
+ abook_fields[i].name = s;
+ }
+
+ return 0;
+}
+
+int
+change_custom_field_name(const char *name, int n)
+{
+ int i;
+ char keyname[21];
+
+ assert(name);
+
+ snprintf(keyname, sizeof(keyname), "custom%d", n);
+
+ for(i = CUSTOM_MIN; i <= CUSTOM_MAX; i++) {
+ if(!strcasecmp(abook_fields[i].key, keyname)) {
+ assign_fieldname(name, i);
+ return i;
+ }
+ }
+
+ return -1;
+}
+