#include #include "db.h" #include "addressbook_record.h" int printRecord(int key, char *data) { Address *addr; deserialize(&addr, data); printf("Personal details:\n" \ "LastName: %s\n" \ "FirstName: %s\n" \ "NickName: %s\n" \ "Phone: %s\n" \ "Mobile: %s\n" \ "Fax: %s\n" \ "Email 1: %s\n" \ "Email 2: %s\n" \ "Email 3: %s\n" \ "Address: %s\n" \ "City: %s\n" \ "Business details:\n" \ "Company: %s\n" \ "Job Title: %s\n" \ "Address: %s\n" \ "City: %s\n" \ "Country: %s\n" \ "Phone: %s\n" \ "Mobile: %s\n" \ "Fax: %s\n" \ "Email: %s\n" \ "AsstNAme: %s\n" \ "AsstPhone: %s\n", addr->personal->lastName, addr->personal->firstName, addr->personal->nickName, addr->personal->phone, addr->personal->mobile, addr->personal->fax, addr->personal->email1, addr->personal->email2, addr->personal->email3, addr->personal->address, addr->personal->city, addr->business->company, addr->business->jobTitle, addr->business->address, addr->business->city, addr->business->country, addr->business->phone, addr->business->mobile, addr->business->fax, addr->business->email, addr->business->assistantName, addr->business->assistantPhone); return TRUE; } int printPool(int key, char *data) { printf("%d \n", key); return TRUE; } int main(int argc, char **argv) { PersonalAddress p[12] = { {"","","","","","","","","","",""}, {"abd co.","","","12345678","","","","","","",""}, {"abe","","","","","","","","","",""}, {"Business","Mobile","","","","","","","","",""}, {"Leung","Wilson","","","","","","","","",""}, {"Mobile","Personal","","88888888","","","","","","",""}, {"No phone","","","","","","","","","",""}, {"Spare","","","","","","","","","",""}, {"Spare","","","","","","","","","",""}, {"Spare","","","","","","","","","",""}, {"z","","","","","","","","","",""}, {"","","","","","","","","","",""} }; BusinessAddress b[12] = { {"ABC Co.", "", "", "", "", "", "", "28881888", "", "", ""}, {"","","","","","","","","","",""}, {"","","","","","23000000","","","","",""}, {"","","","","","","97666666","","","",""}, {"","","","","","28020283","","","","",""}, {"","","","","","","","","","",""}, {"","","","","","","","","","",""}, {"","","","","","","","","","",""}, {"","","","","","","","","","",""}, {"Spare","","","","","","","","","",""}, {"","","","","","","","","","",""}, {"Emsoft Ltd","","","","","28020283","","","","",""} }; Address addr[12] = { {0, &p[0], &b[0], TRUE, TRUE}, {0, &p[1], &b[1], TRUE, TRUE}, {0, &p[2], &b[2], TRUE, TRUE}, {0, &p[3], &b[3], TRUE, TRUE}, {0, &p[4], &b[4], TRUE, TRUE}, {0, &p[5], &b[5], TRUE, TRUE}, {0, &p[6], &b[6], TRUE, TRUE}, {0, &p[7], &b[7], TRUE, TRUE}, {0, &p[8], &b[8], TRUE, TRUE}, {0, &p[9], &b[9], TRUE, TRUE}, {0, &p[10], &b[10], TRUE, TRUE}, {0, &p[11], &b[11], TRUE, TRUE} }; int db; int i; db = addressbook_record_db_open(); #define GENERATE_DATA #ifdef GENERATE_DATA for (i = 0; i < 12; i++) { addressbook_record_save(db, &addr[i]); } #else printf("current records: \n"); db_iterate(db, printRecord); printf("\nUnused key pool: \n"); db_iterate_pool(db, printPool); #endif addressbook_record_db_close(db); return 0; }