#include "misc.h"
#include "options.h"
#include "filter.h"
+#include "xmalloc.h"
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
{"Name", "name", TAB_CONTACT},/* NAME */
{"E-mails", "email", TAB_CONTACT},/* EMAIL */
{"Address", "address", TAB_ADDRESS},/* ADDRESS */
- {"Address2", "address2", TAB_ADDRESS},/* ADDRESS2 */
+ {"Address2", "address2", TAB_ADDRESS},/* ADDRESS2 */
{"City", "city", TAB_ADDRESS},/* CITY */
{"State/Province","state", TAB_ADDRESS},/* STATE */
{"ZIP/Postal Code","zip", TAB_ADDRESS},/* ZIP */
list_item item;
memset(&item, 0, sizeof(item));
-
+
for(;;) {
line = getaline(in);
if( feof(in) ) {
return 0;
}
-
+
int
load_database(char *filename)
if ( (in = abook_fopen(filename, "r")) == NULL )
return -1;
-
+
parse_database(in);
return (items == 0) ? 2 : 0;
return 1;
}
-
+
write_database(out, e);
-
+
fclose(out);
-
+
return 0;
}
int i;
for(i=0; i<ITEM_FIELDS; i++)
- my_free(item[i]);
+ xfree(item[i]);
}
void
close_database()
{
int i;
-
+
for(i=0; i < items; i++)
free_item(i);
{
int i;
char *tmp;
-
+
if(item[EMAIL] == NULL)
item[EMAIL] = strdup("");
else
return;
- database = (list_item *)abook_realloc(database,
- sizeof(list_item) * list_capacity);
- selected = (char *)abook_realloc(selected, list_capacity);
+ database = xrealloc(database, sizeof(list_item) * list_capacity);
+ selected = xrealloc(selected, list_capacity);
}
int
if( ! selected_items() )
selected[ curitem ] = 1;
-
+
for( j = LAST_ITEM; j >= 0; j-- ) {
if( selected[j] ) {
free_item(j); /* added for .4 data_s_ */
itemcpy(database[ i ], database[ i + 1 ]);
selected[ i ] = selected[ i + 1 ];
}
- items--;
+ items--;
}
}
itemcpy(a, i1);
itemcpy(b, i2);
-
+
return safe_strcoll( a[sort_field], b[sort_field] );
}
}
sort_field = field;
-
+
qsort((void *)database, items, sizeof(list_item), namecmp);
refresh_screen();
ret = e.item;
goto out;
}
- my_free(tmp);
+ xfree(tmp);
}
}
{
int item = max(0, e.item + 1);
int i;
-
+
switch(e.mode) {
#ifdef DEBUG
case ENUM_ALL:
{
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))
- my_free(abook_fields[i].name);
-
- s = abook_malloc(MAX_FIELDNAME_LEN + 1);
+ xfree(abook_fields[i].name);
+
+ s = xmalloc_inc(MAX_FIELDNAME_LEN, 1);
snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
abook_fields[i].name = s;
}
int i;
char keyname[21];
+ assert(name);
+
snprintf(keyname, sizeof(keyname), "custom%d", n);
for(i = CUSTOM_MIN; i <= CUSTOM_MAX; i++) {