X-Git-Url: https://git.deb.at/w?a=blobdiff_plain;f=edit.c;h=9403975263bc1520a48031cc81eb0f1b2e943d9b;hb=4128f78f5543bebc7cd1868736855207019f1f71;hp=e6ba4342494912c9a455b58cf8c80d677718e5c3;hpb=d4cd6aada86c2d1c3e046b91a271184e659716fa;p=pkg%2Fabook.git diff --git a/edit.c b/edit.c index e6ba434..9403975 100644 --- a/edit.c +++ b/edit.c @@ -120,13 +120,12 @@ print_editor_header(int item) { char *header; char email[MAX_EMAIL_LEN]; - int i, x, len; - + if( (header = (char *)malloc(EDITW_COLS)) == NULL ) return; get_first_email(email, item); - + if( *database[item][EMAIL] ) snprintf(header, EDITW_COLS, "%s <%s>", database[item][NAME], @@ -134,11 +133,9 @@ print_editor_header(int item) else snprintf(header, EDITW_COLS, "%s", database[item][NAME]); - len = strlen(header); - x = (EDITW_COLS - len) / 2; - mvwaddstr(editw, 0, x, header); - for(i = x; i < x + len; i++) - mvwaddch(editw, 1, i, '^'); + mvwaddstr(editw, 0, (EDITW_COLS - strlen(header)) / 2, + header); + free(header); } @@ -157,23 +154,24 @@ editor_print_data(int tab, int item) char emails[MAX_EMAILS][MAX_EMAIL_LEN]; split_emailstr(item, emails); getyx(editw, y, x); - mvwaddstr(editw, y+1, TAB_START_X, "E-mail addresses:"); + mvwaddstr(editw, y+1, FIELDS_START_X, + "E-mail addresses:"); for(k = 0; k < MAX_EMAILS; k++) { getyx(editw, y, x); - mvwprintw(editw, y+1, TAB_START_X, + mvwprintw(editw, y+1, FIELDS_START_X, "%c -", '2' + k); mvwprintw(editw, y +1, TAB_COLON_POS, ": %s", emails[k]); } continue; } - + if(j > 1) { getyx(editw, y, x); y++; } else - y = TAB_START_Y; + y = FIELDS_START_Y; - mvwprintw(editw, y, TAB_START_X, "%d - %s", + mvwprintw(editw, y, FIELDS_START_X, "%d - %s", j, abook_fields[i].name); mvwaddch(editw, y, TAB_COLON_POS, ':'); @@ -184,42 +182,33 @@ editor_print_data(int tab, int item) } } -/* - * function: change_field - * - * parameters: - * (char *msg) - * message to display as a prompt - * (char **field) - * a pointer to pointer which will point a new string. if the latter - * pointer != NULL it will be freed (if user doesn't cancel) - * - * returns (int) - * a nonzero value if user has cancelled and zero if user has typed a - * valid string - */ - static int change_field(char *msg, char **field) { - char tmp[MAX_FIELD_LEN]; int max_len = MAX_FIELD_LEN; - int ret; - + char *old; + int ret = 0; + if( !strncmp("E-mail", msg, 6) ) max_len = MAX_EMAIL_LEN; - - statusline_addstr(msg); - if( (ret = statusline_getnstr( tmp, max_len - 1, 0 ) ? 1:0 ) ) { - my_free(*field); - if( *tmp ) - *field = strdup(tmp); + + old = *field; + + *field = ui_readline(msg, old, max_len - 1, 0); + + if(*field) { + free(old); + if(!**field) + my_free(*field); + } else { + *field = old; + ret = 1; } clear_statusline(); refresh_statusline(); - return !ret; + return ret; } static void @@ -248,25 +237,27 @@ fix_email_str(char *str) static void edit_emails(char c, int item) { - char *field = NULL; + char *field; char emails[MAX_EMAILS][MAX_EMAIL_LEN]; char tmp[MAX_EMAILSTR_LEN] = ""; int i, len; + int email_num = c - '2'; split_emailstr(item, emails); + field = strdup(emails[email_num]); if(change_field("E-mail: ", &field)) { #ifdef DEBUG fprintf(stderr, "change_field = TRUE\n"); #endif - return; /* user cancelled ( C-g ) */ + return; } if(field) { - strncpy(emails[c - '2'], field, MAX_EMAIL_LEN); - fix_email_str(emails[c - '2']); + strncpy(emails[email_num], field, MAX_EMAIL_LEN); + fix_email_str(emails[email_num]); } else - *emails[c - '2'] = 0; - + *emails[email_num] = 0; + my_free(database[item][EMAIL]); for(i = 0; i < MAX_EMAILS; i++) { @@ -290,7 +281,7 @@ edit_field(int tab, char c, int item) int n = c - '1' + 1; char *str; - if(n < 1 || n > MAX_TAB_LINES) + if(n < 1 || n > MAX_TAB_FIELDS) return 0; edit_undo(item, BACKUP_ITEM); @@ -344,7 +335,7 @@ edit_undo(int item, int mode) free_list_item(backup[0]); my_free(backup); } - backup = abook_malloc(sizeof(list_item)); + backup = (list_item *)abook_malloc(sizeof(list_item)); for(i = 0; i < ITEM_FIELDS; i++) backup[0][i] = safe_strdup(database[item][i]); break; @@ -363,7 +354,7 @@ edit_loop(int item) { static int tab = 0; /* first tab */ int c; - + werase(editw); headerline(EDITOR_HELPLINE); refresh_statusline();