From c0c2ef5511967ceed79a1bdc9d35d8dbf9e304e6 Mon Sep 17 00:00:00 2001 From: hackbard Date: Thu, 24 Mar 2005 23:47:38 +0000 Subject: [PATCH] some data structures by now --- blackbook.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ blackbook.h | 39 ++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 blackbook.c create mode 100644 blackbook.h diff --git a/blackbook.c b/blackbook.c new file mode 100644 index 0000000..317f351 --- /dev/null +++ b/blackbook.c @@ -0,0 +1,95 @@ +/* + * 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))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;iaccount.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;iaccount.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))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;iaccount.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; +} diff --git a/blackbook.h b/blackbook.h new file mode 100644 index 0000000..4ffea0e --- /dev/null +++ b/blackbook.h @@ -0,0 +1,39 @@ +/* + * blackbook header file + * + * author: hackbard@hackdaworld.org + * + */ + +#define MAX_CHARS 64; + +typedef struct s_category { + char name[MAX_CHARS]; +} t_category; + +typedef struct s_transfer { + /* date */ + int year; + int month; + int day; + t_category category; + unsigned char sign; + float value; +} t_transfer; + +typedef struct s_account { + char name[MAX_CHARS]; + int amount_categories; + t_category *category; + int amount_transfers; + t_transfer *transfer; +} t_account; + +typedef struct s_bb { + int outfd; + t_account account; + t_display display; + t_event event; + t_input input; +} t_bb; + -- 2.39.2