home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Utilities / amiCheck / Source / dataBaseFile.c < prev    next >
C/C++ Source or Header  |  1998-06-11  |  9KB  |  335 lines

  1. /************************************************
  2. * dataBaseFile.c
  3. *
  4. *       This library loads structures
  5. *    reguardless of the version number
  6. *
  7. ************************************************/
  8.  
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. #include <fcntl.h>
  14.  
  15. #include "amiCheck.h"
  16. #include "dataBase.h"
  17. #include "dataBaseFile.h"
  18.  
  19. /* local routines */
  20. DataConvertOldEntry(UWORD, char *, entryNode *en);
  21.  
  22. /**********************************************************
  23. *  read in the default tax, net worth variable information 
  24. **********************************************************/
  25. DataReadTaxVars(UWORD magicnum, int fd, struct netInfoVars *netInfo)
  26. {
  27. struct netInfoVarsAAA9 oldnet;
  28. amountType amnt;
  29. UBYTE decim;
  30.  
  31.  memset(netInfo,0,sizeof(struct netInfoVars));
  32.  
  33.  /* read tax vars */
  34.  if (magicnum < MAGICNUMOLD3)
  35.     return 0;
  36.  
  37.  if (magicnum <= MAGICNUMOLD9) {
  38.  
  39.     decim = usrAccount.decimal;
  40.     usrAccount.decimal = 2;    
  41.     read (fd, &oldnet,sizeof(struct netInfoVarsAAA9));
  42.  
  43.     DataInitBal(DEPOSITTYPE,(amountType *)&oldnet.currbal,&netInfo->currAmnt);
  44.     DataInitBal(DEPOSITTYPE,(amountType *)&oldnet.statebal,&netInfo->stateAmnt);
  45.     DataInitBal(DEPOSITTYPE,(amountType *)&oldnet.taxdeductstate,&netInfo->taxdeductstate);
  46.     DataInitBal(DEPOSITTYPE,(amountType *)&oldnet.taxdeductcurr,&netInfo->taxdeductcurr);
  47.  
  48.     netInfo->decimal = 2;
  49.     usrAccount.decimal = decim;
  50.  }
  51.  else     read (fd, netInfo, sizeof(struct netInfoVars));
  52.  
  53.  return 0;
  54. }
  55.  
  56. /****************************************************************
  57. * read in the filter setting structure 
  58. *****************************************************************/
  59. DataReadFilterSetting(UWORD magicnum, int fd, filterSetting *fs)
  60. {
  61.  filterSettingAAA9 filtold;
  62.  
  63.  memset(fs,0,sizeof(filterSetting));
  64.  
  65.  if (magicnum <= MAGICNUMOLD9) {
  66.     memset(&filtold,0,sizeof(filterSettingAAA9));
  67.  
  68.     if (magicnum == MAGICNUMOLD1)
  69.         read(fd,&filtold,sizeof(filterSettingAAA1));
  70.     else     read (fd,&filtold,sizeof(filterSettingAAA9));
  71.  
  72.     /* now put in newer form */
  73.     fs->checks = filtold.checks;
  74.     fs->withdrawals = filtold.withdrawals;
  75.      fs->deposits = filtold.deposits;
  76.     fs->andflag = filtold.andflag;
  77.     fs->notflag = filtold.notflag;
  78.     fs->checkrange = filtold.checkrange;
  79.     fs->checkfrom = filtold.checkfrom;
  80.     fs->checkto = filtold.checkto;
  81.     fs->amntrange = filtold.amntrange;
  82.     fs->amountFrom = filtold.dollarfrom * 100 + filtold.centfrom;
  83.     fs->amountTo = filtold.dollarto * 100 + filtold.centto;
  84.     fs->daterange = filtold.daterange;
  85.     fs->dateFrom.day = filtold.dayfrom;
  86.     fs->dateFrom.month = filtold.monthfrom;
  87.     fs->dateFrom.year = filtold.yearfrom;
  88.     fs->dateTo.day = filtold.dayto;
  89.     fs->dateTo.month = filtold.monthto;
  90.     fs->dateTo.year = filtold.yearto;
  91.     fs->usecategory = filtold.usecategory;
  92.     fs->printcode = filtold.printcode;
  93.     fs->taxcode = filtold.taxcode;
  94.     fs->voidcode = filtold.voidcode;
  95.     fs->reconcilecode = filtold.reconcilecode;
  96.     fs->clearcode = filtold.clearcode;
  97.     fs->usepayee = filtold.usepayee;
  98.     fs->usememo = filtold.usememo;
  99.     strcpy(fs->payee,filtold.payee);
  100.     strcpy(fs->memo,filtold.memo);
  101.     strcpy(fs->payeetoken,filtold.payeetoken);
  102.     strcpy(fs->memotoken,filtold.memotoken);
  103.  
  104.  }
  105.  else read (fd, fs, sizeof(filterSetting));
  106.  
  107.  return 0;
  108. }
  109.  
  110. /******************************************************
  111. * read in the search control structure 
  112. ******************************************************/
  113. DataReadSearchControl(UWORD magicnum, int fd, searchState *ss)
  114. {
  115.  searchStateAAA9 old;
  116.  
  117.  memset(ss,0,sizeof(searchState));
  118.  
  119.  if (magicnum <= MAGICNUMOLD9) {
  120.     read (fd, &old, sizeof(searchStateAAA9));
  121.  
  122.     /* now copy it over */
  123.     ss->check = old.check;
  124.     ss->checknum = old.checknum;
  125.     ss->memo = old.memo;
  126.     strcpy(ss->memostr,old.memostr);
  127.     strcpy(ss->memostrtoken,old.memostrtoken);
  128.     ss->name = old.name;
  129.     strcpy(ss->namestr,old.namestr);
  130.     strcpy(ss->namestr,old.namestr);
  131.     ss->amnt = old.amnt;
  132.     ss->amount = old.dollar * 100 + old.cent;
  133.     ss->date = old.date;
  134.     ss->searchdate.day = old.day;
  135.     ss->searchdate.month = old.month;
  136.     ss->searchdate.year = old.year;
  137.     ss->category = old.category;
  138.     strcpy(ss->catstr,old.catstr);
  139.     strcpy(ss->catstrtoken,old.catstrtoken);
  140.  }
  141.  else read (fd,ss,sizeof(searchState));
  142.  
  143.  return 0;
  144. }
  145.  
  146. /*******************************************************
  147. * read account information
  148. *******************************************************/
  149. DataReadAccountInfo(UWORD magicnum, int fd, accntState *as)
  150. {
  151.  accntStateAAA9 old;
  152.  
  153.  memset(as,0,sizeof(accntState));
  154.  
  155.  if (magicnum <= MAGICNUMOLD9) {
  156.     read(fd,&old,sizeof(accntStateAAA9));
  157.     
  158.     /* copy stuff over */
  159.     strcpy(as->accnt,old.accnt);
  160.     strcpy(as->bank,old.bank);
  161.     strcpy(as->holder,old.holder);
  162.  
  163.     as->negative = old.negative;
  164.     as->beginAmount = old.begindollar * 100 + old.begincent;
  165.     
  166.     as->openDate.day = old.openday;
  167.     as->openDate.month = old.openmonth;
  168.     as->openDate.year = old.openyear;
  169.     
  170.     as->closed = old.closed;
  171.     as->closeDate.day = old.closeday;
  172.     as->closeDate.month = old.closemonth;
  173.     as->closeDate.year = old.closeyear;
  174.  
  175.     as->checknumber = old.checknumber;
  176.  
  177.     as->decimal = 2;
  178.  }
  179.  else read(fd,as,sizeof(accntState));
  180.  
  181.  return 0;
  182. }
  183.  
  184. /**********************************************************
  185. * read in the template structures 
  186. ***********************************************************/
  187. DataReadTemplate(UWORD magicnum, int fd, templateNode *tn)
  188. {
  189.  templateNodeAAA9 old;
  190.  
  191.  memset(tn,0,sizeof(templateNode));
  192.  
  193.  if (magicnum <= MAGICNUMOLD9) {
  194.     read(fd,&old,sizeof(templateNodeAAA9));
  195.  
  196.     /* move over */
  197.     strcpy(tn->tempname,old.tempname);
  198.     DataConvertOldEntry(magicnum,(char *)&old.template,
  199.                 &tn->template);
  200.  }
  201.  else  {
  202.     read (fd,tn->tempname,TEMPNAMESIZE);
  203.     DataReadEntry(magicnum,fd,&tn->template);
  204.  }
  205.  
  206.  return 0;
  207. }
  208.  
  209. /**********************************************************
  210. * read in entry item node
  211. ***********************************************************/
  212. DataReadEntry(UWORD magicnum, int fd, entryNode *en)
  213. {
  214.  entryNodeAAA9 entry;
  215.  struct packitAAA9 oldout;
  216.  struct packit newout;
  217.  UBYTE catsize;
  218.  amountType budget;
  219.  
  220.  if (magicnum <= MAGICNUMOLD9) {
  221.     if (magicnum <= MAGICNUMOLD4) {
  222.         read(fd,&entry,sizeof(entryNodeAAA9));
  223.     }
  224.     else {
  225.          /* read in basics */
  226.          read(fd,&oldout,sizeof(struct packitAAA9));
  227.          entry.type = oldout.type;
  228.          entry.check = oldout.check;
  229.          entry.flags = oldout.flags;
  230.          entry.amnt_dollar = oldout.dollar;
  231.          entry.amnt_cent = oldout.cent; 
  232.          entry.year = oldout.year;
  233.          entry.day = oldout.day;
  234.          entry.month = oldout.month;
  235.  
  236.          /* read in strings */
  237.          memset(entry.name,0,STRINGSIZE);
  238.          memset(entry.memo,0,STRINGSIZE);
  239.          memset(entry.category,0,CATNAMESIZE);
  240.          read(fd,entry.name,oldout.namesize);
  241.          read(fd,entry.memo,oldout.memosize);
  242.          read(fd,entry.category,oldout.catsize);
  243.     }
  244.  
  245.     DataConvertOldEntry(MAGICNUMOLD9,(char *)&entry,en);
  246.  }
  247.  else  {
  248.     read(fd,&newout,sizeof(struct packit));
  249.  
  250.     /* fill in entry fields */
  251.     en->type = newout.type;
  252.     en->check = newout.check;
  253.     en->flags = newout.flags;
  254.     memcpy(&en->amount,&newout.amount,sizeof(amountType));
  255.     memcpy(&en->date,&newout.date,sizeof(dateType));
  256.  
  257.     /* read in strings */
  258.     memset(en->name,0,STRINGSIZE);
  259.     memset(en->memo,0,STRINGSIZE);
  260.     read(fd,en->name,newout.namesize);
  261.     read(fd,en->memo,newout.memosize);
  262.  
  263.     /* now read in the category - always one category right now */
  264.     memset(en->category,0,CATNAMESIZE);
  265.     read(fd,&catsize,sizeof(UBYTE));
  266.     read(fd,en->category,catsize);
  267.     read(fd,&budget,sizeof(amountType));
  268.  }
  269.  
  270.  return 0;
  271. }
  272.  
  273. /*********************************************************
  274. * read the state variables
  275. ***********************************************************/
  276. DataReadStateVars(UWORD magicnum, int fd, struct stateVars *sv)
  277. {
  278.  struct stateVarsAAA9 old;
  279.  amountType oldamnt;
  280.  
  281.  memset(sv,0,sizeof(struct stateVars));
  282.  
  283.  if (magicnum <= MAGICNUMOLD9) {
  284.     read(fd,&old.currDollar,sizeof(old.currDollar));
  285.     read(fd,&old.currCent,sizeof(old.currCent));
  286.     read(fd,&old.currTemplate,sizeof(old.currTemplate));
  287.     read(fd,&old.stateDollar,sizeof(old.stateDollar));
  288.     read(fd,&old.stateCent,sizeof(old.stateCent));
  289.     read(fd,&old.currCheckNumber,sizeof(old.currCheckNumber));
  290.  
  291.      if (magicnum < MAGICNUMOLD3) {
  292.         read (fd, &oldamnt, sizeof(amountType));
  293.          read (fd, &oldamnt, sizeof(amountType));
  294.      }
  295.  
  296.     /* now move over */
  297.     usrAccount.decimal = 2; /* just make sure */
  298.     oldamnt =  old.currDollar * 100 + old.currCent;
  299.     DataInitBal(DEPOSITTYPE,&oldamnt,&sv->currAmnt);
  300.  
  301.     oldamnt =  old.stateDollar * 100 + old.stateCent;
  302.     DataInitBal(DEPOSITTYPE,&oldamnt, &sv->stateAmnt);
  303.  
  304.     sv->currTemplate = old.currTemplate;
  305.     sv->currCheckNumber = old.currCheckNumber;
  306.     
  307.  }
  308.  else read (fd,sv,sizeof(struct stateVars));
  309.  
  310.  return 0;
  311. }
  312.  
  313. /********************************************************
  314. * convert an old entrynode to a current one
  315. *********************************************************/
  316. DataConvertOldEntry(UWORD magicnum, char *old, entryNode *en)
  317. {
  318.  entryNodeAAA9 *olde = (entryNodeAAA9 *)old;
  319.  memset(en,0,sizeof(entryNode));
  320.  
  321.  /* currently only AAA9 is needed */
  322.  en->type = olde->type;
  323.  en->check = olde->check;
  324.  strcpy(en->name,olde->name);
  325.  strcpy(en->memo,olde->memo);
  326.  en->date.day = olde->day;
  327.  en->date.month = olde->month;
  328.  en->date.year = olde->year;
  329.  en->amount = olde->amnt_dollar * 100 + olde->amnt_cent;
  330.  en->flags = olde->flags;
  331.  strcpy(en->category,olde->category);
  332.  
  333.  return 0;
  334. }
  335.