]> git.deb.at Git - pkg/abook.git/blobdiff - edit.c
- replace abook_malloc, abook_realloc and my_free with new xmalloc routines
[pkg/abook.git] / edit.c
diff --git a/edit.c b/edit.c
index 8d39660156e90ca5ce884e8ba7b1080019e9f6ce..7a4004a71ffd60342a81008ca7b724b15c95d2da 100644 (file)
--- a/edit.c
+++ b/edit.c
@@ -9,6 +9,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <assert.h>
 #include "abook_curses.h"
 #include "ui.h"
 #include "abook.h"
@@ -16,6 +17,7 @@
 #include "list.h"
 #include "edit.h"
 #include "misc.h"
+#include "xmalloc.h"
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
@@ -37,7 +39,7 @@ editor_tab(const int tab)
 {
        int i;
        const int spacing = 12;
-       const char *tab_names[] = {
+       static char *tab_names[] = {
                "CONTACT",
                "ADDRESS",
                " PHONE ",
@@ -134,7 +136,7 @@ print_editor_header(int item)
        char *header;
        char email[MAX_EMAIL_LEN];
 
-       if( (header = (char *)malloc(EDITW_COLS)) == NULL )
+       if( (header = xmalloc(EDITW_COLS)) == NULL )
                return;
 
        get_first_email(email, item);
@@ -146,7 +148,7 @@ print_editor_header(int item)
        else
                snprintf(header, EDITW_COLS, "%s", database[item][NAME]);
 
-       mvwaddstr(editw, 0, (EDITW_COLS - strlen(header)) / 2,
+       mvwaddstr(editw, 0, (EDITW_COLS - strwidth(header)) / 2,
                        header);
 
        free(header);
@@ -227,7 +229,7 @@ change_field(char *msg, char **field)
        if(*field) {
                free(old);
                if(!**field)
-                       my_free(*field);
+                       xfree(*field);
        } else {
                *field = old;
                ret = 1;
@@ -248,11 +250,11 @@ change_name_field(char **field)
        change_field("Name: ", field);
 
        if( *field == NULL || ! **field ) {
-               my_free(*field);
+               xfree(*field);
                *field = strdup(tmp);
        }
 
-       my_free(tmp);
+       xfree(tmp);
 }
 
 static void
@@ -283,7 +285,7 @@ edit_emails(char c, int item)
        } else
                *emails[email_num] = 0;
 
-       my_free(database[item][EMAIL]);
+       xfree(database[item][EMAIL]);
 
        for(i = 0; i < MAX_EMAILS; i++) {
                if( *emails[i] ) {
@@ -352,15 +354,15 @@ edit_undo(int item, int mode)
                case CLEAR_UNDO:
                        if(backup) {
                                free_list_item(backup[0]);
-                               my_free(backup);
+                               xfree(backup);
                        }
                        break;
                case BACKUP_ITEM:
                        if(backup) {
                                free_list_item(backup[0]);
-                               my_free(backup);
+                               xfree(backup);
                        }
-                       backup = (list_item *)abook_malloc(sizeof(list_item));
+                       backup = xmalloc(sizeof(list_item));
                        for(i = 0; i < ITEM_FIELDS; i++)
                                backup[0][i] = safe_strdup(database[item][i]);
                        break;
@@ -368,7 +370,7 @@ edit_undo(int item, int mode)
                        if(backup) {
                                free_list_item(database[item]);
                                itemcpy(database[item], backup[0]);
-                               my_free(backup);
+                               xfree(backup);
                        }
                        break;
                default:
@@ -398,6 +400,7 @@ edit_loop(int item)
                case 'a': tab = TAB_ADDRESS; break;
                case 'p': tab = TAB_PHONE; break;
                case 'o': tab = TAB_OTHER; break;
+               case 'C': tab = TAB_CUSTOM; break;
                case 'h':
                case KEY_LEFT: tab = tab == 0 ? MAX_TAB : tab - 1;
                               break;