+ old = parse_date_string(s, &date[0], &date[1], &date[2]);
+
+ for(i = 0; i < 3; i++) {
+ s = (old && date[i]) ? strdup_printf("%d", date[i]) : NULL;
+ if(change_field(gettext(field[i]), &s, 5))
+ return; /* user aborted with ^G */
+
+ date[i] = (s && is_number(s)) ? atoi(s) : 0;
+
+ if(!s) {
+ switch(i) {
+ case 0: db_fput_byid(item, nb, NULL); /*delete*/
+ case 1: /* fall through */ return;
+ }
+ } else
+ xfree(s);
+ }
+
+ /* ISO 8601 date, of the YYYY-MM-DD or --MM-DD format */
+ if(is_valid_date(date[0], date[1], date[2])) {
+ if(date[2])
+ s = strdup_printf("%04d-%02d-%02d",
+ date[2], date[1], date[0]);
+ else
+ s = strdup_printf("--%02d-%02d", date[1], date[0]);
+
+ db_fput_byid(item, nb, xstrdup(s));
+ } else
+ statusline_msg(_("Invalid date"));
+}
+
+/* input range: 1-9A-Z
+ * output range: 0-34 */
+static int
+key_to_field_number(char c)
+{
+ int n = c - '1';
+ if(n >= 0 && n < 9)
+ return n;
+
+ n = c - 'A' + 9;
+ if(n > 8 && n < 35)
+ return n;
+
+ return -1;
+}
+
+static void
+edit_field(int tab, char c, int item_number)
+{
+ ui_enable_mouse(FALSE);
+ int i = 0, number, idx;
+ char *msg;
+ abook_field_list *f;
+ list_item item;
+
+ if((number = key_to_field_number(c)) < 0)
+ goto detachfield;
+
+ edit_undo(item_number, BACKUP_ITEM);
+
+ view_info(tab, NULL, &f);
+
+ while(1) {
+ if(!f)
+ goto detachfield;
+
+ if(i == number)
+ break;
+
+ f = f->next;
+ i++;
+ }
+
+ find_field_number(f->field->key, &idx);
+
+ switch(f->field->type) {
+ case FIELD_STRING:
+ msg = strdup_printf("%s: ", f->field->name);
+ item = db_item_get(item_number);
+ if(strcmp(f->field->key, "name") == 0)
+ change_name_field(msg,&item[idx],MAX_FIELD_LEN);
+ else
+ change_field(msg,&item[idx],MAX_FIELD_LEN);
+ free(msg);
+ break;
+ case FIELD_LIST:
+ edit_list(item_number, idx, 0);
+ break;
+ case FIELD_EMAILS:
+ edit_list(item_number, idx, 1);
+ break;
+ case FIELD_DATE:
+ edit_date(item_number, idx);
+ goto detachfield;
+ default:
+ assert(0);
+ }
+
+ detachfield:
+ if(opt_get_bool(BOOL_USE_MOUSE))
+ ui_enable_mouse(TRUE);