/****************************************************************
*                                                               *
* etb.h                                                         *
*                                                               *
* header file for the extended trial balance program            *
*                                                               *
****************************************************************/



#ifndef ETB_H
#define ETB_H


#define VERSION "etb 1.00 (26.2.95)"



/* include */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifdef DEBUG
   #include <assert.h>
#endif

#include "mcstd.h"
#include "mcstring.c"



/* DICE-specific option to make a long data model in the struct's */
#ifdef _DCC /* defined automatically in the DICE compiler */
   #define FAR __far  /* this does it                     */
#else
   #define FAR       /* otherwise, just leave it blank   */
#endif



/* ledger file formats */

#define MAX_ACCTS   100  /* the max num of ledger accounts   */
#define ABBREV_SIZE   5  /* num of chars in the abbreviation */
#define HEAD_SIZE    41  /* num of chars in the heading      */

FAR   struct etb_line     /* an individual ledger account     */
{
   char abbrev[ABBREV_SIZE+1] ; /* the abbreviation code      */
   char heading[HEAD_SIZE+1]  ; /* description of etb heading */
   long amount                ; /* in pence - cum figure      */
   long value                 ; /* maybe pennies, maybe pounds*/
   int line                   ; /* the line in transact file  */
   BOOL tag                   ; /* determines if etb line prts*/
} etb[MAX_ACCTS]              ; /* full etb                   */

/* NB : normally a loop i over etb[] would run from 0 to
MAX_ACCTS-1. However, etb[0] is reserved for unallocated
items, so one would normally allocate etb[] lines from i=1.  */



/* transaction file formats */

#define MAX_TRANS 1000 /* maximum number of transactions          */
#define DESC_SIZE   47 /* number of characters in the description */


FAR   struct trans_line    /* an individual transaction           */
{
   char abbrev[ABBREV_SIZE+1]  ; /* the abbreviation code         */
   char desc[DESC_SIZE+1]      ; /* transaction description       */
   long amount                 ; /* the size of the transaction   */
   int  line                   ; /* transaction line number       */
   int  etb                    ; /* allocate transact to etb line */
}  trans[MAX_TRANS]            ; /* full transaction record       */




/* prototypes */
int   accumulate(int,int) ; /* accumulate the transactions into the ledger */
BOOL  abbrevcmp(int i, int j) ; /* compare trans abbrev with ledger abbrev */
int   amount2value(BOOL,int) ; /* transfer 'amount' to 'value'             */
void  etbdrcrtotalxunall(long*,long*); /* cumulate dr and cr col exc unal  */
void  exitifcantopenfile(FILE *fp,char *name) ; /* self-explanatory        */
void  initialise(void) ; /* initialise the etb                             */
void  mainCLI(int, char **) ; /* the main CLI processing routine           */
void  matchabbrevs(INT,INT, FILE *) ; /* allocate all trans to ledger accts*/
void  printalletblines(BOOL) ; /* print all the etb lines                  */
void  printdrcr(FILE*,BOOL); /* print the ' ... LINE Dr Cr' heading        */
void  printdrcrbalance(FILE*,long,BOOL); /* print balance in correct col   */
void  printdrcrtotals(FILE*,long,long,BOOL); /* print dr and cr totals     */
void  printoneetbline(int,int,long,BOOL,FILE *) ; /* just one etb line     */
void  printonenomledgeracct(FILE *, BOOL, int, int) ; /* 1 nom ledge acct  */
void  printwholeetb(FILE *, BOOL) ; /* print the whole of the etb          */
void  printwholenomledger(FILE *,int,int,BOOL) ; /* print the nom ledger   */
void  pushetbdesc(int,char *, char *) ; /* simple setup of abbrev & head   */
int   readledgerformat(FILE *,FILE *) ; /* read in the ledger format lines */
BOOL  readtransabbrev(FILE *, int) ;/* read just the abbreviation          */
int   readtransfile(FILE *, FILE *, BOOL) ;   /* read transaction file     */
void  twosumbars(char); /* print the totalling-up bars                     */

#endif  /* ETB_H */
