/* PAY.C - This program demonstrates some of the capabilities of the SCREEN DOOR Screen Management System. Copyright (c) 1986, By T.A. Daneliuk Last Modified: 06/30/86 */ #include <stdio.h> #include <system.h> #include <vstruct.h> #include <math.h> /* Macro Color Definitions */ #define ICOLOR color(BLACK,WHITE) /* Input Color */ #define PCOLOR color(YELLOW,BLUE) /* Prompt Color */ #define RCOLOR color(GREEN,BLACK) /* Response Color */ #define BCOLOR color(LCYAN,BLACK) /* Border Color */ #define RBCOLOR color(BLACK,CYAN) /* Reverse Border Color */ #define HCOLOR color(YELLOW,BLUE) /* Help Colors */ #define HCOLOR2 color(YELLOW,BLACK) #define HCOLOR3 color(LGREEN,BLACK) #define HCOLOR4 color(HWHITE,BLACK) #define HCOLOR5 color(LMAGENTA,BLACK) #define HCOLOR6 color(LCYAN,BLACK) #define SAMEPG FALSE /* If TRUE, Both Help And Input On Same Video Page */ #if !SAMEPG #define HELPLOC 11 #define HELP1 help_screen1 #define VPAGE 3 #define HCLEAR TRUE #define HMCLEAR FALSE #endif #if SAMEPG #define HELPLOC 20 #define HELP1 NULL #define VPAGE 0 #define HCLEAR FALSE #define HMCLEAR TRUE #endif extern char *errmsg_rval,vpg_help; extern int help_cls,help_msg_cls; extern int recalc(); /* These Functions Will Show Up Later In The File */ extern void hbord1(),hbord2(); main() { vpg_help=VPAGE; help_cls=HCLEAR; help_msg_cls=HMCLEAR; /* Prompt, Response, And Help Strings These Must Precede The Control Tables Below Which Reference The Arrays Because Some One-Pass Compilers (Such As DeSmet) Cannot Resolve A Reference To A Variable Which Is Declared Later In The File. Note That The Response Fields Are Dimensioned To A Size Equal To rlen+1 To Make Room For The '\0' String Terminator Byte. Notice Also That The Response Strings Are Initialized To Provide Default Responses For The Response Fields On Screen. */ static char prompt1[]={"Principal Amount:"}; static char prompt2[]={"Annual Interest Rate (%):"}; static char prompt3[]={"Number Of Months To Payoff:"}; static char prompt4[]={"Monthly Payment:"}; static char prompt5[]={"[ SCREEN DOOR Demonstration ]"}; static char prompt6[]={"[ Copyright (c) 1986, T&R Communications Associates ]"}; static char prompt7[]={"[ F3 To QUIT, F1 For HELP ]"}; static char resp1[11]={"10000"}; static char resp2[6]={"10"}; static char resp3[5]={"24"}; static char resp4[14]={""}; static char h1[]={"This is a demonstration of the SCREEN DOOR Screen Management System."}; static char h2[]={"SCREEN DOOR is a 'C' Language programming tool designed to speedup"}; static char h3[]={"the creation and maintenance of data entry screens via simple tables."}; static char h4[]={"SCREEN DOOR supports unlimited keyin-time full field data validations"}; static char h5[]={"as well as a host of built in character-by-character validations."}; static char h6[]={"The latter include Alpha-Only, Numeric-Only, Alphanumeric, Forced Case,"}; static char h7[]={"Floating Point Format, Hexadecimal Format, Binary Format, and many others."}; static char h8[]={"The programmer can manage any number of Prompt and Response fields."}; static char h9[]={"Any Prompt field may be displayed or not, and any Response field may"}; static char h10[]={"be protected from User modification. The programmer can also define"}; static char h11[]={"fields which require User input at runtime (i.e., Disallow empty fields)."}; static char h12[]={"Of course, context sensitive Help is available for any Response field"}; static char h13[]={"the User is editing. In this example, a different Help screen is"}; static char h14[]={"displayed for each Response field. SCREEN DOOR is also capable of"}; static char h15[]={"displaying the same Help screen for each Response field being edited."}; static char h16[]={"All of SCREEN DOOR's parameters can be dynamically varied, allowing"}; static char h17[]={"the programmer to control screen and input behavior as the program runs."}; static char h18[]={""}; static char h19[]={"For more information on SCREEN DOOR contact:"}; static char h21[]={"T&R Communications Associates"}; static char h22[]={"4927 North Rockwell Street"}; static char h23[]={"Chicago, IL 60625"}; static char h24[]={"Enter Yearly Interest Rate In This Field."}; static char h25[]={"Enter The Length Of The Loan (In Months) In This Field."}; /* Screen Control Tables - One For Help Screen, One For Input Screen As Before, The Help Table Must Precede Its Reference In The Actual Screen Table To Accommodate One-Pass Compilers. */ static struct VSTRUCT help_screen1[]={ 0,HCOLOR2,1,5,TRUE,h1,HCOLOR2,2,5,FALSE,h2,0,0,0,0,hbord1,0,0,0,NULL,FALSE, 0,HCOLOR2,3,5,TRUE,h3,HCOLOR3,4,5,FALSE,h4,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR3,5,5,TRUE,h5,HCOLOR3,6,5,FALSE,h6,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR3,7,5,TRUE,h7,HCOLOR4,8,5,FALSE,h8,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR4,9,5,TRUE,h9,HCOLOR4,10,5,FALSE,h10,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR4,11,5,TRUE,h11,HCOLOR5,12,5,FALSE,h12,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR5,13,5,TRUE,h13,HCOLOR5,14,5,FALSE,h14,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR5,15,5,TRUE,h15,HCOLOR6,16,5,FALSE,h16,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR6,17,5,TRUE,h17,HCOLOR,18,5,FALSE,h18,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR|BLINK,19,5,TRUE,h19,HCOLOR,21,23,FALSE,h21,0,0,0,0,NULL,0,0,0,NULL,FALSE, 0,HCOLOR,22,26,TRUE,h22,HCOLOR,23,30,FALSE,h23,0,0,0,0,NULL,0,0,0,NULL,TRUE }; static struct VSTRUCT help_screen2[]={ 0,HCOLOR6,HELPLOC+1,10,TRUE,h24,0,0,0,FALSE,NULL,0,0,FALSE,0,hbord2,FALSE,TRUE,TRUE,NULL,TRUE }; static struct VSTRUCT help_screen3[]={ 0,HCOLOR5,HELPLOC+1,10,TRUE,h25,0,0,0,FALSE,NULL,0,0,FALSE,0,hbord2,FALSE,TRUE,TRUE,NULL,TRUE }; static struct VSTRUCT input_screen[]={ ICOLOR,PCOLOR,10,25,TRUE,prompt1,RCOLOR,10,53,TRUE,resp1,10,'.',FALSE,15,recalc,FALSE,TRUE,FALSE,HELP1,FALSE, ICOLOR,PCOLOR,11,25,TRUE,prompt2,RCOLOR,11,53,TRUE,resp2,5,'.',FALSE,15,recalc,FALSE,TRUE,FALSE,help_screen2,FALSE, ICOLOR,PCOLOR,12,25,TRUE,prompt3,RCOLOR,12,53,TRUE,resp3,4,'.',FALSE,15,recalc,FALSE,TRUE,FALSE,help_screen3,FALSE, ICOLOR,RBCOLOR,6,12,TRUE,prompt5,RCOLOR,15,55,FALSE,NULL,7,'.',FALSE,11,NULL,FALSE,TRUE,TRUE,NULL,FALSE, ICOLOR,RBCOLOR,19,16,TRUE,prompt6,RCOLOR,15,55,FALSE,NULL,7,'.',FALSE,11,NULL,FALSE,TRUE,TRUE,NULL,FALSE, ICOLOR,RBCOLOR,8,29,TRUE,prompt7,RCOLOR,15,55,FALSE,NULL,7,'.',FALSE,11,NULL,FALSE,TRUE,TRUE,NULL,FALSE, ICOLOR,PCOLOR,15,25,TRUE,prompt4,RCOLOR,15,49,FALSE,resp4,13,'.',FALSE,11,NULL,FALSE,TRUE,TRUE,NULL,TRUE }; /****************************** END-OF-DATA-TABLES **************************/ /* Actual Control Code Which Invokes Screen */ int ctr=0; struct VSTRUCT *vptr; /* Declare A Pointer To A Screen Control Table */ vptr=help_screen1; /* Center All Lines On Help Screen For Grins */ while (ctr<11) /* This Also Demonstrates Runtime Table Modification */ { ((vptr+ctr)->phoriz)=center((vptr+ctr)->parray); ((vptr+ctr)->rhoriz)=center((vptr+ctr)->rarray); ctr++; } vptr=help_screen2; (vptr->phoriz)=center(vptr->parray); vptr=help_screen3; (vptr->phoriz)=center(vptr->parray); scr_setup(); /* Initialize PCIO Screen Constants */ scr_clr(); /* Clear Screen */ border(8,20,45,10,BCOLOR); /* Draw Borders */ border(6,10,65,14,BCOLOR); vptr=input_screen; /* Point To The Input Screen */ vdsply(vptr); /* Display It */ recalc(vptr,0); /* So We Have An Answer 1st Time Through */ vkeyin(vptr,0,FALSE); /* Accept User Input */ scr_clr(); /* Clear Screen And Back To Dos */ } /****************************************************************************/ static void hbord1(vptr,fld) /* Draw A Border For The Help Screen */ struct VSTRUCT *vptr; /* These Are Always Passed By The Help Feature */ int fld; /* But We Don't Use Them In This Case */ { border(0,0,79,25,HCOLOR); } /****************************************************************************/ static void hbord2(vptr,fld) /* Draw A Border For The Help Screen */ struct VSTRUCT *vptr; /* These Are Always Passed By The Help Feature */ int fld; /* But We Don't Use Them In This Case */ { border(HELPLOC,0,79,3,HCOLOR3); } /****************************************************************************/ static void border(startv,starth,width,height,vattrib) char vattrib; int startv,starth,width,height; { int x; v_rowcol(startv,starth); scr_aputs(mkstr(BORDERNW,1),vattrib); scr_aputs(mkstr(BORDERH,width-2),vattrib); scr_aputs(mkstr(BORDERNE,1),vattrib); v_rowcol(startv+height-1,starth); scr_aputs(mkstr(BORDERSW,1),vattrib); scr_aputs(mkstr(BORDERH,width-2),vattrib); scr_aputs(mkstr(BORDERSE,1),vattrib); for (x=startv+1;x<=(startv+height-2);x++) { v_rowcol(x,starth); scr_aputs(mkstr(BORDERV,1),vattrib); v_rowcol(x,starth+width-1); scr_aputs(mkstr(BORDERV,1),vattrib); } } /****************************************************************************/ /* This Is Our "Validation" Routine That's Really Being Used To Recalculate The Monthly Payment */ static int recalc(vptr,fld) struct VSTRUCT *vptr; int fld; { int x,z,answlen,error,inrange; inrange=error=FALSE; answlen=((vptr+6)->rlen); double pay,princ,interest,period,y; char *answer; static char msg[]={"Calculation Cannot Be Done Because Of Invalid Input Data!"}; errmsg_rval=msg; /* This points SCREEN DOOR's global to our own error message */ answer=(vptr+6)->rarray; /* This is where we'll put our answer */ princ=atof(vptr->rarray); /* Convert input strings to floating point */ interest=(atof((vptr+1)->rarray))/1200.0; period=atof((vptr+2)->rarray); for(x=0;x < answlen;x++) /* Initialize answer display to zeros */ *(answer+x)='0'; *(answer+(answlen-3))='.'; /* Stick In The Decimal Point */ if (princ==0 || interest==0 || period==0) /* Make sure we have valid input */ error=TRUE; if (!error) pay=princ*(interest/(1.0-(pow((1.0/(1.0+interest)),period)))); /* Do the calculation */ if (pay >= exp10((double)(answlen-4))) /* Make sure answer can fit in the room alloted to it */ error=TRUE; if (errno==EDOM || errno==ERANGE) /* Make sure the math routines didn't choke */ error=TRUE; if (!error) /* Convert answer back to a string */ { for (x=answlen-4;x>-3;x--) /* Do it by powers of 10 */ { y=exp10((double)x); z=(x<0 ? (answlen-x-3) : (answlen-x-4)); /* Remember the decimal pt.! */ if ((pay < y) && !inrange) *(((vptr+6)->rarray)+z)=' '; /* Don't want leading zeros */ else { inrange=TRUE; while (pay >= y) { pay=pay-y; (*(((vptr+6)->rarray)+z))++; } } } } vdsply(vptr); /* Make sure answer gets displayed */ return(error); } /****************************************************************************/