X-Git-Url: https://git.deb.at/?a=blobdiff_plain;f=edit.c;h=67a8e2d7bd88e59a319a1656169b462dfee9e80e;hb=a7c0a4d347393550a0671c68cb848d142226f5ba;hp=9cfbf26bab89737706b785ccd0a4d090d40fd18b;hpb=ba218a8c82df9b5e5bdedf4c4bcb3e1094361b0b;p=pkg%2Fabook.git diff --git a/edit.c b/edit.c index 9cfbf26..67a8e2d 100644 --- a/edit.c +++ b/edit.c @@ -37,18 +37,29 @@ editor_tab(int tab) { int i; char *tab_names[] = { - "/ CONTACT \\", - "/ ADDRESS \\", - "/ PHONE \\", - "/ OTHER \\" + " CONTACT ", + " ADDRESS ", + " PHONE ", + " OTHER " }; mvwhline(editw, TABLINE+1, 0, UI_HLINE_CHAR, EDITW_COLS); + for(i=0; i < TABS; i++) { + mvwaddch(editw, TABLINE+1, 16 * i + 2, UI_TEE_CHAR); + mvwaddch(editw, TABLINE+1, 16 * i + 14, UI_TEE_CHAR); + } - for(i=0; i < TABS; i++) - mvwaddstr(editw, TABLINE, 16 * i + 3, tab_names[i]); + for(i=0; i < TABS; i++) { + mvwaddch(editw, TABLINE, 16 * i + 2, UI_ULCORNER_CHAR); + mvwaddch(editw, TABLINE, 16 * i + 3, UI_LBOXLINE_CHAR); + mvwaddstr(editw, TABLINE, 16 * i + 4, tab_names[i]); + mvwaddch(editw, TABLINE, 16 * i + 13, UI_RBOXLINE_CHAR); + mvwaddch(editw, TABLINE, 16 * i + 14, UI_URCORNER_CHAR); + } - mvwaddstr(editw, TABLINE+1, 16 * tab + 2, "/ \\"); + mvwaddch(editw, TABLINE+1, 16 * tab + 2, UI_LRCORNER_CHAR); + mvwaddstr(editw, TABLINE+1, 16 * tab + 3, " "); + mvwaddch(editw, TABLINE+1, 16 * tab + 14, UI_LLCORNER_CHAR); } void @@ -120,12 +131,12 @@ print_editor_header(int item) { char *header; char email[MAX_EMAIL_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], @@ -165,7 +176,7 @@ editor_print_data(int tab, int item) } continue; } - + if(j > 1) { getyx(editw, y, x); y++; } else @@ -184,14 +195,14 @@ 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 + * a pointer to a 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 @@ -200,24 +211,30 @@ editor_print_data(int tab, int item) 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 @@ -246,25 +263,24 @@ 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 + if(change_field("E-mail: ", &field)) return; /* user cancelled ( C-g ) */ - } + 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++) { @@ -342,7 +358,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; @@ -361,7 +377,7 @@ edit_loop(int item) { static int tab = 0; /* first tab */ int c; - + werase(editw); headerline(EDITOR_HELPLINE); refresh_statusline();