--- /dev/null
+/*
+ * blackbook - a minimal finance manager
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+#include "blackbook.h"
+
+
+
+int load_account(int fd,t_bb *bb) {
+
+ int i;
+ int ret;
+
+ if(read(fd,&(bb->account),sizeof(t_account))<sizeof(t_account)) {
+ bb_write(bb,"failed to read account information");
+ return -1;
+ }
+
+ i=bb->account.amount_categories;
+ bb->account.category=(t_category *)malloc(i*sizeof(t_category));
+ if(bb->account.category==NULL) {
+ bb_write(bb,"malloc failed (categories)");
+ return -1;
+ }
+
+ for(i=0;i<bb->account.amount_categories;i++) {
+ ret=read(fd,bb->account.category,sizeof(t_category));
+ if(ret!=sizeof(t_category)) {
+ bb_write(bb,"failed to read categories");
+ return -1;
+ }
+ }
+
+ i=bb->account.amount_transfers;
+ bb->account.transfer=(t_transfer *)malloc(i*sizeof(t_transfer));
+ if(bb->account.transfer==NULL) {
+ bb_write(bb,"malloc failed (transfers)");
+ return -1;
+ }
+
+ for(i=0;i<bb->account.amount_transfers;i++) {
+ ret=read(fd,bb->account.transfer,sizeof(t_transfer));
+ if(ret!=sizeof(t_transfer)) {
+ bb_write(bb,"failed to read transfers");
+ return -1;
+ }
+ }
+
+ bb_write(bb,"loaded account information");
+
+ return 1;
+}
+
+int save_account(int fd,t_bb *bb) {
+
+ int i;
+ int ret;
+
+ if(write(fd,&(bb->account),sizeof(t_account))<sizeof(t_account)) {
+ bb_write(bb,"failed to write account information");
+ return -1;
+ }
+
+ for(i=0;i<bb->account.amount_categories;i++) {
+ ret=write(fd,bb->account.category[i],sizeof(t_category));
+ if(ret!=sizeof(t_category)) {
+ bb_write(bb,"failed to write categories");
+ return -1;
+ }
+ }
+
+ for(i=0;i<bb->account.amount_transfers;i++) {
+ ret=write(fd,bb->account.transfer[i],sizeof(t_transfer));
+ if(ret!=sizeof(t_transfer)) {
+ bb_write(bb,"failed to write transfers");
+ return -1;
+ }
+ }
+
+ bb_write(bb,"saved account information");
+
+ return 1;
+}
+
+
+
+int main(int argc,char **argv) {
+
+
+
+ return 1;
+}