]> hackdaworld.org Git - my-code/blackbook.git/commitdiff
some data structures by now master origin
authorhackbard <hackbard>
Thu, 24 Mar 2005 23:47:38 +0000 (23:47 +0000)
committerhackbard <hackbard>
Thu, 24 Mar 2005 23:47:38 +0000 (23:47 +0000)
blackbook.c [new file with mode: 0644]
blackbook.h [new file with mode: 0644]

diff --git a/blackbook.c b/blackbook.c
new file mode 100644 (file)
index 0000000..317f351
--- /dev/null
@@ -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))<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;
+}
diff --git a/blackbook.h b/blackbook.h
new file mode 100644 (file)
index 0000000..4ffea0e
--- /dev/null
@@ -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;
+