home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource4
/
207_01
/
checks.c
< prev
next >
Wrap
Text File
|
1979-12-31
|
29KB
|
766 lines
/* checks.c -- main source file for check register program */
/* copyright (c) 1986 by Jim Woolley and WoolleyWare, San Jose, CA */
/* vers. 1.0, 12/85 thru 5/86
*/
/* this file contains:
* main()
* startup()
* getval( q)
* getentry()
* getinfo()
* getyesno( def)
* struct nlist *install( name, def)
* struct nlist *lookup( s)
* hash( s)
* char *strsave( s)
* compdate( e1, e2)
* datecomp( d1, d2)
* comppayee( e1, e2)
* compcateg( e1, e2)
* categcomp( e1, e2)
* compamount( e1, e2)
* compbbf( e1, e2)
* compabrev( p1, p2)
* isebbf( e)
* isibbf( i)
* char *index( s, c)
* char *skipspace( s)
* typcat( f, t)
* openerr()
* readerr()
* writerr( s)
* createrr( s)
* baddisk()
*/
#include "a:checks.h"
main( argc, argv) /* check register program */
int argc;
char *argv[];
{
char *p, *copyright, *allrights;
int i, length;
copyright = "Check Register Program, v.1.0 (c) 1986 by WoolleyWare";
/* copyright must be < (COLS - FNAMSIZE - 3) chars */
allrights = "All Rights Reserved";
_Outdev = CONOUT; /* direct putchar() to screen */
_Lastch = 0; /* used by getchar()/ungetch() */
Speed = 5; /* initial Speed for ^QW and ^QZ */
Today.yy = 0; /* initialize other globals */
Savrecno = Oldfield = -1;
Modified = Printing = Ctrlyundo = FALSE;
for ( i = 0; i < HASHSIZE; ++i)
Hashtab[ i] = 0;
strcpy( Title, copyright);
Ftoc[ MMFIELD] = 1; /* Ftoc[ f] = c */
Ftoc[ DDFIELD] = 4; /* locates cursor for Field f */
Ftoc[ YYFIELD] = 7; /* at column c, where c = 0 */
Ftoc[ PAYFIELD] = 9; /* corresponds to left edge */
Ftoc[ CATFIELD] = 52; /* of screen */
Ftoc[ AMTFIELD] = 61;
Ftoc[ DEPFIELD] = 63;
Ftoc[ CLRFIELD] = 67;
if ( argc > 1) /* get Filename root */
p = argv[ 1];
else p = DEFNAM;
length = strlen( p);
if ( !index( p, ':')) /* if no drive designated */
{
Filename[ 0] = 'A' + defdsk();
Filename[ 1] = ':';
i = 2;
}
else /* drive was designated */
{
if ( length == 2) /* if just d: without filename */
{
strcpy( Filename, p);
p = DEFNAM; /* use default */
i = 2;
}
else i = 0;
}
if ( length > ( FNAMSIZE - 5 - i)) /* should be FALSE if p = DEFNAM */
*( p + FNAMSIZE - 5 - i) = '\0';
strcpy(( Filename + i), p);
if ( !( p = index( Filename, '.'))) /* add dot if none */
*( p = Filename + strlen( Filename)) = '.';
*( p + 1) = '\0'; /* truncate after dot */
startup();
getentry(); /* read entry data */
disheading(); /* initialize display */
Recno = Maxentry + ( 1 - PAGE); /* initialize gobottom() */
First = Recno - PAGE;
Last = First - 1;
Field = 0;
gobottom();
getinfo(); /* read title, abrev, auto entries */
control(); /* never returns */
}
startup() /* startup check register program */
{
char line, *p, *q, s[ MAXLINE], f[ FNAMSIZE], buf[ BUFSIZ], *fgets();
int i;
strcpy( f, DEFNAM);
typcat( f, SCRTYP);
if ( fopen( f, buf) == ERROR)
abort( "Cannot open ", f); /* never returns */
for ( line = 6; line; --line) /* skip 6 lines */
if ( !fgets( s, buf))
readerr( f); /* never returns */
for ( line = 0; line < 11; ++line) /* get cursor/screen controls */
{
if ( !fgets(( q = s), buf))
readerr( f); /* never returns */
switch ( line)
{
case 0:
p = Clead1;
break;
case 1:
p = Clead2;
break;
case 2:
p = Ctrail;
break;
case 3:
Cb4flg = getval( &q);
Linoff = getval( &q);
Coloff = getval( &q);
if ( Ascur = getval( &q)) /* Ascur must be 0, 2, or 3 */
Ascur = min( 3, max( 2, Ascur));
break;
case 4:
p = Eraeol;
break;
case 5:
p = Lindel;
break;
case 6:
p = Linins;
break;
case 7:
p = Ivon;
break;
case 8:
p = Ivoff;
break;
case 9:
p = Trmini;
break;
case 10:
Dloop = (( DLOOP/10)*max( 1, min( 1000, getval( &q))))/10;
Inserton = getval( &q);
break;
default:
break;
}
if ( line != 3) /* note that i may be negative */
for ( *p++ = i = getval( &q); i > 0; --i)
*p++ = getval( &q);
}
if ( fgets( s, buf)) /* if more than 17 lines */
{
clrscr();
while (( i = getc( buf)) != CPMEOF && i != ERROR)
putchar( i - 1);
if ( getchar() == CTRLC)
exit(); /* never returns */
}
fclose( buf);
clrscr();
}
/* getval( q) returns next int value from string of decimal numbers separated
* by white space; string must be pointed to by *q; each decimal number in
* string may be headed by white space with optional minus sign followed by
* consecutive decimal digits; first non-digit terminates the scan; zero is
* returned if no legal value is found; *q will be updated to point to first
* white space char following the current decimal number; *q will not point
* beyond end of string
*
* sample calling program segment:
*
* char *p; string pointer
* p = " 1 -32 123 9"; point to typical space separated string
* printf( "%d", getval( &p)); pass pointer to string pointer
*/
getval( q) /* return int value and update *q */
char **q; /* pointer to string pointer */
{
int i;
i = atoi( *q = skipspace( *q));
while ( !isspace( **q) && **q)
++( *q);
return ( i);
}
getentry() /* get check register entries */
{
char *p, buf[ BUFSIZ];
int g, imax;
typcat( Filename, DATTYP);
if ( fopen( Filename, buf) == ERROR)
{
openerr( Filename);
Maxentry = -1; /* initialize */
Memory.dollar = Memory.cent = 0;
return;
}
if (( g = getw( buf)) == ERROR)
readerr( Filename); /* never returns */
imax = RECSIZ*g;
Maxentry = g - 1;
Memory.dollar = getw( buf); /* assume no read error */
Memory.cent = getw( buf);
p = Entry;
while ( imax--)
{
if (( g = getc( buf)) == ERROR)
readerr( Filename); /* never returns */
*p++ = g;
}
fclose( buf);
for ( g = 0; g <= Maxentry; ++g)
newbalance( g);
}