Initial (manual) import

This commit is contained in:
minexew committed 2017-01-22 20:26:44 +01:00
1 parent f39611c506
commit 895fe109de
661 files changed
+245862

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
$FG,6$JOB
$FG,1$BANK
$FG,4$CREDIT
$FG,2$CASH
$FG,0$RENT
CAR
UTILITIES
MISC
CLOTHS
HEALTH
CHARITY
+83
View File
@@ -0,0 +1,83 @@
U0 BgtAcctsUpdate()
{
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
tmpb->credit_idx=StrFileAdd(tmpb->credit,
&accts_table_strs,accts_table);
tmpb->debit_idx =StrFileAdd(tmpb->debit,
&accts_table_strs,accts_table);
}
tmpb=tmpb->next;
}
tmpt=t_head.next;
while (tmpt!=&t_head) {
tmpt->b.credit_idx=StrFileAdd(tmpt->b.credit,
&accts_table_strs,accts_table);
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,
&accts_table_strs,accts_table);
tmpt=tmpt->next;
}
}
U0 BgtAcctsWrite()
{
BgtAcctsUpdate;
StrFileWrite(BGT_ACCTS_FILE,accts_table,TRUE);
}
U0 BgtAcctsRead()
{
I64 i,max_num;
U8 *colors,**s=StrFileRead(BGT_ACCTS_FILE,&max_num,&colors,TRUE);
StrFileDel(accts_table);
accts_table=HashTableNew(512);
accts_table_strs=0;
for (i=0;i<=max_num;i++)
if (s[i])
StrFileAdd(s[i],&accts_table_strs,accts_table,colors[i]);
StrFileArrDel(s,max_num);
Free(colors);
}
I64 BgtAcctColor(U8 *st)
{
CHashGeneric *tmph;
if (tmph=HashFind(st,accts_table,SFT_GENERIC))
return tmph->user_data1;
else
return BLACK;
}
U8 *BgtPopUpAcct(U8 *header=NULL,U8 *dft=NULL)
{
I64 i;
U8 *res;
CDoc *doc=DocNew;
CDocEntry *doc_e,*doc_dft=NULL;
CHashGeneric *tmph;
if (header)
DocPrint(doc,"%s",header);
for (i=0;i<=accts_table->mask;i++) {
tmph=accts_table->body[i];
while (tmph) {
doc_e=DocPrint(doc,"$$FG,%d$$$$MU-UL,\"%s\",LE=0x%X$$\n",
tmph->user_data1,tmph->str,tmph->str);
if (dft && !StrCmp(dft,tmph->str))
doc_dft=doc_e;
tmph=tmph->next;
}
}
if (doc_dft) {
doc->cur_entry=doc_dft;
doc->cur_col=0;
}
res=PopUpMenu(doc,DOF_DONT_HOME);
DocDel(doc);
return res;
}
+83
View File
@@ -0,0 +1,83 @@
U0 BgtEntryDel2(CBgtEntry *tmpb)
{
if (tmpb->type!=BE_TEMPLATE_COPY) {
Free(tmpb->credit);
Free(tmpb->debit);
Free(tmpb->desc);
}
}
CBgtEntry *BgtEntryCopy(CBgtEntry *tmpb,Bool periodic_copy)
{
CBgtEntry *res=MAlloc(sizeof(CBgtEntry));
MemCpy(res,tmpb,sizeof(CBgtEntry));
if (periodic_copy) {
res->credit=StrNew(tmpb->credit);
res->debit =StrNew(tmpb->debit);
res->desc =StrNew(tmpb->desc);
}
return res;
}
U0 BgtEntryDel(CBgtEntry *tmpb)
{
BgtEntryDel2(tmpb);
Free(tmpb);
}
U0 BgtIns(CBgtEntry *tmpb)
{
CBgtEntry *tmpb1=b_head.next;
while (tmpb1!=&b_head && tmpb1->date<tmpb->date)
tmpb1=tmpb1->next;
QueIns(tmpb,tmpb1->last);
}
class CBgtEntryForm
{
U8 date[512] fmtstr "$$DA-P,A=\"Date :%s\"$$\n";
F64 amount fmtstr "Amount $$$$$$DA,A=\"%10.2f\"$$\n";
U8 credit[512] fmtstr "$$DA-P,A=\"Credit (from) Acct:%s\"$$\n";
U8 debit [512] fmtstr "$$DA-P,A=\"Debit (to) Acct:%s\"$$\n";
U8 desc [512] fmtstr "$$DA-P,A=\"Desc :%s\"$$\n";
};
CBgtEntry *BgtEntryPmt(CBgtEntry *dft=NULL)
{
CBgtEntryForm b;
CBgtEntry *tmpb;
U8 *st;
MemSet(&b,0,sizeof(CBgtEntryForm));
StrCpy(&b.date,"*");
if (dft) {
StrPrint(b.date,"%D",dft->date);
b.amount=dft->amount;
StrCpy(b.credit,dft->credit);
StrCpy(b.debit ,dft->debit);
StrCpy(b.desc ,dft->desc);
}
while (TRUE)
if (PopUpForm(&b)) {
if (!*b.credit) {
st=BgtPopUpAcct("Credit Acct\n\n");
if (st!=DOCM_CANCEL)
StrCpy(b.credit,st);
} else if (!*b.debit) {
st=BgtPopUpAcct("Debit Acct\n\n");
if (st!=DOCM_CANCEL)
StrCpy(b.debit,st);
} else {
tmpb=CAlloc(sizeof(CBgtEntry));
tmpb->date =Str2Date(b.date);
tmpb->amount=b.amount;
tmpb->credit=StrNew(b.credit);
tmpb->debit =StrNew(b.debit);
tmpb->desc =StrNew(b.desc);
tmpb->type =BE_NORMAL;
StrFileAdd(tmpb->credit,&accts_table_strs,accts_table);
StrFileAdd(tmpb->debit,&accts_table_strs,accts_table);
return tmpb;
}
} else
return NULL;
}
+140
View File
@@ -0,0 +1,140 @@
U0 BgtDataRead()
{
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
I64 i,cnt,size;
U8 *b,*ptr;
I64 max_num;
U8 **s=StrFileRead(BGT_STRINGS_FILE,&max_num);
MemSet(&b_head,0,sizeof(CBgtEntry));
QueInit(&b_head);
b_head.date=Now;
MemSet(&t_head,0,sizeof(CBgtTemplate));
QueInit(&t_head);
t_head.b.date=Now;
if (ptr=b=FileRead(BGT_DATA_FILE,&size)) {
cnt=*ptr(I64 *)++;
for (i=0;i<cnt;i++) {
tmpb=CAlloc(sizeof(CBgtEntry));
MemCpy(&tmpb->start,ptr,BE_SIZE);
tmpb->credit=StrNew(s[tmpb->credit_idx]);
tmpb->debit =StrNew(s[tmpb->debit_idx]);
tmpb->desc =StrNew(s[tmpb->desc_idx]);
QueIns(tmpb,b_head.last);
ptr+=BE_SIZE;
}
cnt=*ptr(I64 *)++;
for (i=0;i<cnt;i++) {
tmpt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tmpt->start,ptr,BT_SIZE);
ptr+=BT_SIZE;
MemCpy(&tmpt->b.start,ptr,BE_SIZE);
ptr+=BE_SIZE;
tmpt->b.credit=StrNew(s[tmpt->b.credit_idx]);
tmpt->b.debit =StrNew(s[tmpt->b.debit_idx]);
tmpt->b.desc =StrNew(s[tmpt->b.desc_idx]);
QueIns(tmpt,t_head.last);
}
}
StrFileArrDel(s,max_num);
Free(b);
BgtAcctsUpdate;
}
U0 BgtDataWrite()
{
I64 i,num=0,size,cnt1,cnt2;
CHashTable *table=HashTableNew(1024);
CBgtEntry *tmpb;
CBgtTemplate *tmpt;
CHashGeneric *tmph;
U8 *buf,*ptr;
for (i=0;i<=accts_table->mask;i++) {
tmph=accts_table->body[i];
while (tmph) {
StrFileAdd(tmph->str,&num,table); //Cosmetics -- make accts appear first.
tmph=tmph->next;
}
}
tmpb=b_head.next;
cnt1=0;
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
tmpb->credit_idx =StrFileAdd(tmpb->credit,&num,table);
tmpb->debit_idx =StrFileAdd(tmpb->debit,&num,table);
tmpb->desc_idx =StrFileAdd(tmpb->desc,&num,table);
cnt1++;
}
tmpb=tmpb->next;
}
tmpt=t_head.next;
cnt2=0;
while (tmpt!=&t_head) {
tmpt->b.credit_idx =StrFileAdd(tmpt->b.credit,&num,table);
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,&num,table);
tmpt->b.desc_idx =StrFileAdd(tmpt->b.desc,&num,table);
cnt2++;
tmpt=tmpt->next;
}
StrFileWrite(BGT_STRINGS_FILE,table);
StrFileDel(table);
size=sizeof(I64)*2+cnt1*BE_SIZE+cnt2*(BT_SIZE+BE_SIZE);
buf=ptr=MAlloc(size);
MemCpy(ptr,&cnt1,sizeof(I64));
ptr+=sizeof(I64);
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb->type!=BE_TEMPLATE_COPY) {
MemCpy(ptr,&tmpb->start,BE_SIZE);
ptr+=BE_SIZE;
}
tmpb=tmpb->next;
}
MemCpy(ptr,&cnt2,sizeof(I64));
ptr+=sizeof(I64);
tmpt=t_head.next;
while (tmpt!=&t_head) {
MemCpy(ptr,&tmpt->start,BT_SIZE);
ptr+=BT_SIZE;
MemCpy(ptr,&tmpt->b.start,BE_SIZE);
ptr+=BE_SIZE;
tmpt=tmpt->next;
}
FileWrite(BGT_DATA_FILE,buf,size);
Free(buf);
}
U0 BgtDel()
{
CBgtEntry *tmpb,*tmpb1;
CBgtTemplate *tmpt,*tmpt1;
tmpb=b_head.next;
while (tmpb!=&b_head) {
tmpb1=tmpb->next;
BgtEntryDel2(tmpb);
Free(tmpb);
tmpb=tmpb1;
}
tmpt=t_head.next;
while (tmpt!=&t_head) {
tmpt1=tmpt->next;
BgtEntryDel2(&tmpt->b);
Free(tmpt);
tmpt=tmpt1;
}
StrFileDel(accts_table);
accts_table=NULL;
accts_table_strs=0;
}
+224
View File
@@ -0,0 +1,224 @@
extern U0 BgtRegen();
Bool BgtPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
{//ch=ASCII; sc=scan_code
no_warn sc;
CBgtEntry *tmpb,*tmpb1;
CBgtTemplate *tmpt,*tmpt1;
CDocEntry *doc_ce;
U8 *st;
switch (ch) {
case '\n':
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL) {
tmpb=doc_ce->user_data;
if (tmpt=tmpb->template) {
if (tmpt1=BgtTemplatePmt(tmpt)) {
QueRem(tmpt);
BgtTemplatePurge(tmpt);
BgtEntryDel2(&tmpt->b);
Free(tmpt);
QueIns(tmpt1,t_head.last);
BgtTemplateExpand(tmpt1);
BgtRegen;
}
} else {
if (tmpb1=BgtEntryPmt(tmpb)) {
QueRem(tmpb);
BgtEntryDel(tmpb);
BgtIns(tmpb1);
BgtRegen;
}
}
}
return TRUE;
case CH_CTRLY:
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL) {
tmpb=doc_ce->user_data;
if (tmpt=tmpb->template) {
QueRem(tmpt);
BgtTemplateDel(tmpt);
} else {
QueRem(tmpb);
BgtEntryDel(tmpb);
}
BgtRegen;
}
return TRUE;
case 'a':
PopUpOk( "Set the name and color of your accounts.\n"
"To delete accounts, manually edit\n"
"$$GREEN$$~/Budget/Accts.DD.Z$$FG$$.");
if (PopUpEd(BGT_ACCTS_FILE,Fs)) {
BgtAcctsRead;
BgtRegen;
}
return TRUE;
case 'v':
if ((st=BgtPopUpAcct("View Acct\n\n",view_acct))>=0) {
StrCpy(view_acct,st);
BgtRegen;
}
return TRUE;
case 'n':
if (tmpb1=BgtEntryPmt) {
BgtIns(tmpb1);
BgtRegen;
}
return TRUE;
case 't':
if (tmpt1=BgtTemplatePmt) {
QueIns(tmpt1,t_head.last);
BgtTemplateExpand(tmpt1);
BgtRegen;
}
return TRUE;
case 'c':
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL)
tmpb=doc_ce->user_data;
else
tmpb=NULL;
if (tmpb1=BgtEntryPmt(tmpb)) {
BgtIns(tmpb1);
BgtRegen;
}
return TRUE;
case 'p':
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
doc_ce->type_u8==DOCT_MENU_VAL) {
tmpb=doc_ce->user_data;
if (tmpt1=BgtTemplatePmt(,tmpb)) {
BgtTemplateExpand(tmpt1,TRUE);
BgtTemplateDel(tmpt1);
BgtRegen;
}
}
return TRUE;
}
return FALSE;
}
U0 BgtRegen()
{
I64 timeout_jiffy,c,color=COLOR_INVALID;
F64 balance=0;
CDoc *doc,*pdoc,*ddoc;
CDocEntry *doc_ce;
CBgtEntry *tmpb=b_head.next,*tmpb_ce;
doc=DocNew;
doc->flags|=DOCF_FORM;
while (tmpb!=&b_head) {
if (!StrCmp(view_acct,tmpb->credit))
balance-=tmpb->amount;
if (!StrCmp(view_acct,tmpb->debit))
balance+=tmpb->amount;
c=BgtAcctColor(tmpb->credit);
if (c!=color) {
color=c;
DocPrint(doc,"$$FG,%d$$",color);
}
tmpb->doc_e=DocPrint(doc,
"$$MU-UL,\"%D %8ts %8ts:%8.2f %8.2f:%$$Q\",U=0x%X$$\n",
tmpb->date,tmpb->credit,tmpb->debit,balance,
tmpb->amount,tmpb->desc,tmpb);
tmpb=tmpb->next;
}
DocRecalc(doc);
if (pdoc=Fs->put_doc) {
DocLock(pdoc);
//Now, we want to preserve old position in doc, using ugly brute force.
//It's tricky -- can't use old line num because of editor filters.
//The price we pay for using the standard document editor is this kludge.
//When I originally wrote my budget program, I did not have separate budget
//and line entries, so we never had to resync.
doc_ce=pdoc->cur_entry;
timeout_jiffy=cnts.jiffies+JIFFY_FREQ; //Max one second.
while (doc_ce!=pdoc && cnts.jiffies<timeout_jiffy) {
while (doc_ce->type_u8!=DOCT_MENU_VAL || !(tmpb_ce=doc_ce->user_data)) {
doc_ce=doc_ce->next;
if (doc_ce==pdoc) goto br_cont;
}
tmpb=b_head.next;
while (tmpb!=&b_head) {
if (tmpb==tmpb_ce) {
doc->cur_entry=tmpb->doc_e;
doc->cur_col=0;
DocCenter(doc);
goto br_cont;
}
tmpb=tmpb->next;
}
doc_ce=doc_ce->next;
}
}
br_cont:
ddoc=Fs->display_doc;
Fs->put_doc =doc;
Fs->display_doc=doc;
DocDel(pdoc);
if (pdoc!=ddoc)
DocDel(ddoc);
doc->user_put_key=&BgtPutKey;
}
U0 Budget()
{
CDoc *pdoc,*ddoc,*old_put,*old_display;
BgtAcctsRead;
BgtDataRead;
CBgtTemplatesExpand;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
AutoComplete;
WinBorder;
WinMax;
MenuPush(
"File {"
" Abort(,CH_SHIFT_ESC);"
" Exit(,CH_ESC);"
"}"
"Edit {"
" NewEntry(,'n');"
" CopyEntry(,'c');"
" PeriodicEntry(,'p');"
" EditEntry(,'\n');"
" DeleteEntry(,CH_CTRLY);"
" NewTemplate(,'t');"
" AcctsFile(,'a');"
"}"
"View {"
" ViewAcct(,'v');"
"}"
);
StrCpy(view_acct,"BANK");
DocMax;
old_put =Fs->put_doc;
old_display =Fs->display_doc;
Fs->put_doc =NULL;
Fs->display_doc=NULL;
BgtRegen;
try
if (View) {
BgtDataWrite;
BgtAcctsWrite;
}
catch
PutExcept;
pdoc=Fs->put_doc;
ddoc=Fs->display_doc;
Fs->put_doc =old_put;
Fs->display_doc=old_display;
DocDel(pdoc);
if (pdoc!=ddoc)
DocDel(ddoc);
SettingsPop;
BgtDel;
MenuPop;
}
+132
View File
@@ -0,0 +1,132 @@
#define SFT_GENERIC 1
public U8 **StrFileRead(U8 *name,I64 *_max_num=NULL,
U8 **_colors=NULL,Bool no_nums=FALSE)
{
CDoc *doc=DocRead(name,DOCF_DBL_DOLLARS|DOCF_NO_CURSOR);
CDocEntry *doc_e=doc->head.next;
I64 i,max_num=0;
U8 *ptr,**res,*colors;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TEXT) {
if (no_nums)
i=++max_num;
else {
i=Str2I64(doc_e->tag,,&ptr);
if (i>max_num) max_num=i;
if (*ptr==',') ptr++;
ptr=StrNew(ptr);
Free(doc_e->tag);
doc_e->tag=ptr;
}
doc_e->user_data=i;
}
doc_e=doc_e->next;
}
res=CAlloc(sizeof(U8 *)*(max_num+1));
colors=CAlloc(sizeof(U8)*(max_num+1));
doc_e=doc->head.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TEXT && 0<=doc_e->user_data<=max_num) {
res[doc_e->user_data]=doc_e->tag;
doc_e->tag=NULL;
colors[doc_e->user_data]=doc_e->type.u8[1]&15;
}
doc_e=doc_e->next;
}
DocDel(doc);
if (_max_num) *_max_num=max_num;
if (_colors)
*_colors=colors;
else
Free(colors);
return res;
}
public U0 StrFileArrDel(U8 **a,I64 max_num)
{
I64 i;
for (i=0;i<=max_num;i++)
Free(a[i]);
Free(a);
}
public I64 StrFileAdd(U8 *st,I64 *_num,
CHashTable *table,I64 color=COLOR_INVALID)
{
CHashGeneric *tmph;
if (!st) return 0;
if (!(tmph=HashFind(st,table,SFT_GENERIC))) {
tmph=CAlloc(sizeof(CHashGeneric));
tmph->type=SFT_GENERIC;
tmph->str=StrNew(st);
tmph->user_data0=(*_num)++;
HashAdd(tmph,table);
}
if (color!=COLOR_INVALID)
tmph->user_data1=color;
return tmph->user_data0;
}
I64 StrEntriesCompare(CHashGeneric *h1,CHashGeneric *h2)
{
return h1->user_data0-h2->user_data0;
}
public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
{
I64 i,j,cnt,color=BLACK;
CDoc *doc=DocNew(name);
CHashGeneric *tmph,**a;
if (table) {
cnt=0; //Count Strings
for (i=0;i<=table->mask;i++)
cnt+=LinkedLstCnt(table->body[i]);
a=MAlloc(cnt*sizeof(CHashGeneric *));
j=0; //Load Strings
for (i=0;i<=table->mask;i++) {
tmph=table->body[i];
while (tmph) {
a[j++]=tmph;
tmph=tmph->next;
}
}
QSortI64(a,cnt,&StrEntriesCompare);
for (i=0;i<cnt;i++) {
tmph=a[i];
if (tmph->user_data1&15!=color) {
DocPrint(doc,"$$FG,%d$$",tmph->user_data1&15);
color=tmph->user_data1&15;
}
if (no_nums)
DocPrint(doc,"%s\n",tmph->str);
else
DocPrint(doc,"%d,%s\n",tmph->user_data0,tmph->str);
}
Free(a);
}
doc->flags|=DOCF_NO_CURSOR;
DocWrite(doc);
DocDel(doc);
}
public U0 StrFileDel(CHashTable *table)
{
I64 i;
CHashGeneric *tmph,*tmph1;
if (!table) return;
for (i=0;i<=table->mask;i++) {
tmph=table->body[i];
while (tmph) {
tmph1=tmph->next;
Free(tmph->str);
Free(tmph);
tmph=tmph1;
}
}
Free(table->body);
Free(table);
}
+182
View File
@@ -0,0 +1,182 @@
U0 BgtTemplatePurge(CBgtTemplate *tmpt)
{
CBgtEntry *tmpb,*tmpb1;
tmpb=b_head.next;
while (tmpb!=&b_head) {
tmpb1=tmpb->next;
if (tmpb->template==tmpt) {
QueRem(tmpb);
BgtEntryDel2(tmpb);
Free(tmpb);
}
tmpb=tmpb1;
}
}
U0 BgtTemplateDel(CBgtTemplate *tmpt)
{
BgtTemplatePurge(tmpt);
BgtEntryDel2(&tmpt->b);
Free(tmpt);
}
U0 BgtTemplateExpand(CBgtTemplate *tmpt,Bool periodic_copy=FALSE)
{
CDate d,start,end;
CDateStruct ds;
CBgtEntry *tmpb;
Bool first=TRUE;
start=MyStr2Date(tmpt->start_date);
end =MyStr2Date(tmpt->end_date);
tmpt->b.template=tmpt;
switch (tmpt->type) {
case BT_INTERVAL:
d=start;
while (d<=end) {
if (!first || !periodic_copy) {
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
tmpb->date=d;
if (periodic_copy)
tmpb->template=NULL;
else
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
}
d+=tmpt->period*0x100000000;
first=FALSE;
}
break;
case BT_MONTHLY:
Date2Struct(&ds,start);
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
if (!first || !periodic_copy) {
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
tmpb->date=d;
if (periodic_copy)
tmpb->template=NULL;
else
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
}
} else
break;
if (++ds.mon>12) {
ds.mon=1;
ds.year++;
}
first=FALSE;
}
break;
case BT_BIMONTHLY:
Date2Struct(&ds,start);
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
if (!first || !periodic_copy) {
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
tmpb->date=d;
if (periodic_copy)
tmpb->template=NULL;
else
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
}
} else
break;
ds.mon+=2;
if (ds.mon>12) {
ds.mon-=12;
ds.year++;
}
first=FALSE;
}
break;
case BT_SEMIANNUAL:
Date2Struct(&ds,start);
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
if (!first || !periodic_copy) {
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
tmpb->date=d;
if (periodic_copy)
tmpb->template=NULL;
else
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
}
} else
break;
ds.mon+=6;
if (ds.mon>12) {
ds.mon-=12;
ds.year++;
}
first=FALSE;
}
break;
case BT_ANNUAL:
Date2Struct(&ds,start);
while (TRUE) {
d=Struct2Date(&ds);
if (d<=end) {
if (!first || !periodic_copy) {
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
tmpb->date=d;
if (periodic_copy)
tmpb->template=NULL;
else
tmpb->type=BE_TEMPLATE_COPY;
BgtIns(tmpb);
}
} else
break;
ds.year++;
first=FALSE;
}
break;
}
}
U0 CBgtTemplatesExpand()
{
CBgtTemplate *tmpt=t_head.next;
while (tmpt!=&t_head) {
BgtTemplateExpand(tmpt);
tmpt=tmpt->next;
}
}
CBgtTemplate *BgtTemplatePmt(CBgtTemplate *dft_t=NULL,CBgtEntry *dft_b=NULL)
{
CBgtTemplate t,*tmpt;
CBgtEntry *tmpb;
MemSet(&t,0,sizeof(CBgtTemplate));
if (dft_t) {
MemCpy(&t.start,&dft_t->start,BT_SIZE);
dft_b=&dft_t->b;
} else {
t.type=BT_INTERVAL;
if (dft_b)
StrPrint(&t.start_date,"%D",dft_b->date);
else
StrCpy(&t.start_date,"[");
StrCpy(&t.end_date,"]");
}
while (TRUE)
if (PopUpForm(&t) && ((t.type==BT_INTERVAL && t.period>0) ||
t.type>BT_INTERVAL)) {
if (tmpb=BgtEntryPmt(dft_b)) {
tmpt=CAlloc(sizeof(CBgtTemplate));
MemCpy(&tmpt->start,&t.start,BT_SIZE);
MemCpy(&tmpt->b,tmpb,sizeof(CBgtEntry));
Free(tmpb);
return tmpt;
}
} else
break;
return NULL;
}
+77
View File
@@ -0,0 +1,77 @@
#define BGT_STRINGS_FILE "~/Budget/Strs.DD.Z"
#define BGT_ACCTS_FILE "~/Budget/Accts.DD.Z"
#define BGT_DATA_FILE "~/Budget/Bgt.DATA.Z"
#define BE_NORMAL 0
#define BE_GAS 1
#define BE_ANNIVERSARY 2
#define BE_PRICE 3
#define BE_TEMPLATE_COPY 4
extern class CBgtTemplate;
class CBgtEntry
{
CBgtEntry *next,*last;
U0 start;
CDate date;
U16 type,flags;
U32 credit_idx,debit_idx,desc_idx;
F64 amount;
U0 end;
U8 *credit,*debit,*desc;
CBgtTemplate *template;
CDocEntry *doc_e;
} b_head;
#define BE_SIZE (offset(CBgtEntry.end)-offset(CBgtEntry.start))
#define BT_NULL 0
#define BT_INTERVAL 1
#define BT_MONTHLY 2
#define BT_BIMONTHLY 3
#define BT_SEMIANNUAL 4
#define BT_ANNUAL 5
DefineLstLoad("ST_BGT_TEMPLATE_TYPES",
"Null\0Interval\0Monthly\0Bimonthly\0Semiannual\0Annual\0");
class CBgtTemplate
{
CBgtTemplate *next,*last;
U0 start;
U16 type fmtstr "$$LS,D=\"ST_BGT_TEMPLATE_TYPES\"$$\n";
U16 flags;
U8 start_date[16] fmtstr "$$DA-P,A=\"Start Date:%s\"$$\n";
U8 end_date[16] fmtstr "$$DA-P,A=\"End Date :%s\"$$\n";
F64 period fmtstr "$$DA,A=\"Period :%8.2f\"$$\n";
U0 end;
CBgtEntry b;
} t_head;
#define BT_SIZE (offset(CBgtTemplate.end)-offset(CBgtTemplate.start))
U8 view_acct[512];
CHashTable *accts_table=NULL;
I64 accts_table_strs=0;
CDate MyStr2Date(U8 *st)
{
CDateStruct ds;
CDate res;
if (st&&*st) {
if (StrOcc(st,'['))
res=b_head.next->date;
else if (StrOcc(st,']'))
res=b_head.last->date;
else
res=Str2Date(st);
} else
res=Now;
Date2Struct(&ds,res);
if (ds.year>2050)
ds.year-=100;
return Struct2Date(&ds);
}
+5
View File
@@ -0,0 +1,5 @@
Cd(__DIR__);;
if (!FileFind("~/Budget",,FUF_JUST_DIRS)) {
MkDir("~/Budget");
Copy("Accts.DD.Z","~/Budget");
}
+12
View File
@@ -0,0 +1,12 @@
#help_index "Finance"
Cd(__DIR__);;
#include "BgtStrs"
#include "Budget"
#include "BgtAccts"
#include "BgtEntry"
#include "BgtTemplate"
#include "BgtFile"
#include "BgtMain"
#help_index ""
+4
View File
@@ -0,0 +1,4 @@
Cd(__DIR__);;
#include "Load"
#include "Install" //Might as well always install
Budget;