📄 mfpdemo.c
字号:
"This is a twenty character",
"field.",
0
};
char *state_txt[] = {
"Please enter the last name.",
"",
"The entry will be capital-",
"ized for you.",
"",
"This is a two character",
"field.",
"",
"Your entry will be tested",
"for a proper state",
"abbreviation",
0
};
char *zip_txt[] = {
"Please enter the zip code.",
"",
"Only numeric zip codes will",
"be accepted for input.",
"",
"This is a ten character",
"field.",
0
};
char *phon1_txt[] = {
"Please enter the home phone.",
"",
"The commas and dashes will",
"be entered for you.",
"",
"You just enter the numbers.",
0
};
char *phon2_txt[] = {
"Please enter the work phone.",
"",
"The commas and dashes will",
"be entered for you.",
"",
"You just enter the numbers.",
0
};
char *ssn_txt[] = {
"Please enter the social",
"security number",
"",
"The dashes will be entered",
"for you.",
"",
"You just enter the numbers.",
0
};
char *dob_txt[] = {
"Please enter the date",
"of birth for this person.",
"",
"The date entered will be",
"checked for validity.",
0
};
char **char_txt[] = {
fname_txt,
lname_txt,
strt_txt,
city_txt,
state_txt,
zip_txt,
phon1_txt,
phon2_txt,
ssn_txt,
dob_txt
};
/*============================== Executable code ===========================*/
void main()
{
int yorn;
/*
The scrsave() function requires an integer value representing
the time in tenths of a second, to wait before blanking the
display. The purpose for this function is to increase the
amount of time before your main menu makes a permanent im-
pression on the phosphors of the users monitor. It accomplishes
this task by waiting the required time after each keypress
until the time expires. It then stores the attribute bytes in
screen memory to a 2k buffer and then writes out a BLACK on
BLACK attribute in the originals place. This makes the screen
look like it has been turned off and it effectively will pre-
vent screen burn. When a subsequent keypress occurs, this func-
tion will write the stored attributes back out into screen
memory effectively restoring the original screen.
The nosave() function is used to disengage the scrsave()
function. THIS FUNCTION MUST BE CALLED PRIOR TO RETURNING TO
DOS IF scrsave() IS USED.
The scrsave() function intercepts interrupt vectors 9 and 1CH.
*/
scrsave( 3000 );
/*
The showclok() function requires the row, column, foreground
attribute, and background attribute. It will display the
time continuously until you disengage it. It is a background
task that will not interfere or measurably affect your app-
lication. It provides a nice eight character digital presen-
tation, HH:MM:SS.
The noclok() function is used to disengage the showclok()
function. THIS FUNCTION MUST BE CALLED PRIOR TO RETURNING TO
DOS IF showclok() IS USED.
The showclok() function intercepts interrupt vector 1CH.
*/
showclok( 1, 71, RED, WHITE );
do
{
drawscrn("MFP1 Demonstration Software -- Main Menu");
MENNORMFG = WHITE; /* Menu normal foreground color */
MENNORMBG = BLUE; /* Menu normal background color */
MENLITEFG = BLUE; /* Menu highlighted foreground color */
MENLITEBG = WHITE; /* Menu highlighted background color */
MENHLPFG = WHITE; /* Menu help text foreground color */
MENHLPBG = BLUE; /* Menu help text background color */
/*
Execute the menu defined by the menu list -- mmlist
*/
yorn = menu( mmlist, 0 );
switch( yorn )
{
case 0:
character();
break;
case 1:
numeric();
break;
default:
break;
}
} while( yorn != 2 );
/*
Turn off the clock display and driver...
*/
noclok();
/*
Turn off the screen saver...
*/
nosave();
/*
Make the color normal white on black..
*/
color( LIGHTGRAY, BLACK );
/*
Clear the screen...
*/
clrscr();
color( REMOVE );
/*
Display our going-away message...
*/
signoff();
}
/*
This is the numeric entry module.
Numeric entry is demonstrated here...
*/
void numeric()
{
int yorn;
MENNORMFG = RED; /* Red menu foreground */
MENNORMBG = WHITE; /* White menu background */
MENLITEFG = WHITE; /* White menu highlight foreground */
MENLITEBG = BLUE; /* Blue menu highlight background */
MENHLPFG = WHITE; /* White help text foreground */
MENHLPBG = BLUE; /* Blue help text background */
/*
Clear the numeric entry variables...
*/
clearnio();
/*
Perform the data entry loop...
*/
do
{
drawscrn("MFP1 Numeric Entry Demonstration");
/*
Display the entry prompts...
*/
nprompts();
mess24("Please enter above data...");
/*
Setup the FAST() edit list to be the same as the MFP entry list...
*/
ed_list = nlst;
/*
Perform the data entry now using the numeric entry list and a
procedure list.
*/
mfp( nlst, plist );
mess24("");
/*
Provide a menu of options for the user, the menu is defined
with the mnlist, also a procedure list is provided for HOT key
support...
*/
yorn = menu( mnlist, plist );
switch( yorn )
{
case 1:
mess24("Please standby, Saving data to disk...");
fp = fopen("MFPNDEMO.DAT","wb");
if( fp != NULL )
{
if( !fwrite((char *)&nio,sizeof(struct NUM_BLK),1,fp) )
{
mess24("Write error, press any key...");
pause();
}
fclose( fp );
}
else
{
mess24("Error opening MFPNDEMO.DAT, press any key");
pause();
}
break;
case 2:
if( unlink("MFPNDEMO.DAT") )
{
mess24("Error deleting MFPNDEMO.DAT, press any key");
pause();
}
else
clearnio();
break;
case 3:
clearnio();
break;
case 4:
mess24("Please standby, retrieving data from disk...");
fp = fopen("MFPNDEMO.DAT","rb");
if( fp != NULL )
{
if( !fread((char *)&nio,sizeof(struct NUM_BLK),1,fp) )
{
clearnio();
mess24("Read error, press any key...");
pause();
}
fclose( fp );
}
else
{
mess24("Error opening MFPNDEMO.DAT, press any key");
pause();
}
break;
default:
break;
}
} while( yorn != 5 );
}
/*
Here we perform a character entry demonstration for the user...
*/
void character()
{
int yorn;
MENNORMFG = RED;
MENNORMBG = WHITE;
MENLITEFG = WHITE;
MENLITEBG = BLUE;
MENHLPFG = WHITE;
MENHLPBG = BLUE;
clearcio();
do
{
drawscrn("MFP1 Character Entry Demonstration");
cprompts();
mess24("Please enter above data...");
ed_list = clst;
mfp( clst, plist );
mess24("");
yorn = menu( mnlist, plist );
switch( yorn )
{
case 1:
mess24("Please standby, Saving data to disk...");
fp = fopen("MFPCDEMO.DAT","wb");
if( fp != NULL )
{
if( !fwrite((char *)&cio,sizeof(struct CHR_BLK),1,fp) )
{
mess24("Write error, press any key...");
pause();
}
fclose( fp );
}
else
{
mess24("Error opening MFPCDEMO.DAT, press any key");
pause();
}
break;
case 2:
if( unlink("MFPCDEMO.DAT") )
{
mess24("Error deleting MFPCDEMO.DAT, press any key");
pause();
}
else
clearcio();
break;
case 3:
clearcio();
break;
case 4:
mess24("Please standby, retrieving data from disk...");
fp = fopen("MFPCDEMO.DAT","rb");
if( fp != NULL )
{
if( !fread((char *)&cio,sizeof(struct CHR_BLK),1,fp) )
{
clearcio();
mess24("Read error, press any key...");
pause();
}
fclose( fp );
}
else
{
mess24("Error opening MFPCDEMO.DAT, press any key");
pause();
}
break;
default:
break;
}
} while( yorn != 5 );
}
void drawscrn( header )
char *header;
{
static char buf[ 11 ];
int x;
color( WHITE, BLUE );
clrscr();
color( RED, WHITE );
/*
Clear an area defined by the upper left and lower right
corners. Handy for simple windows or clearing screen
sections.
*/
wcls( 1,1, 2,80 );
color( LIGHTGRAY, BLUE );
for( x = 3 ; x < 25 ; x++ )
{
cup( x,1 ); /* Cursur position, Row, Column */
bioputc((unsigned char)186); /* High performance character output */
cup( x,48 );
bioputc((unsigned char)179);
cup( x,80 );
bioputc((unsigned char)186);
}
color( RED, WHITE );
wcls( 24,1, 24,80 );
cup( 1, 2 );
print( ldate( buf ) ); /* High performance string output */
x = strlen( header );
cup( 2, (80-x)/2 );
print(header);
color( WHITE, BLUE );
wcls( 25,1, 25,80 );
cup( 25,2 );
print(
"F1 Help | F2 Jump | F3 | F4 | F5 | F6 | F7 | F8"
);
}
void nprompts()
{
color( WHITE, BLUE );
cup( 5,4 );
print("Stellar Ident:");
cup( 7,4 );
print(" System Size:");
cup( 9,4);
print(" Relative Lux:");
cup( 11,4 );
print(" Absolute Lux:");
cup( 13,4 );
print(" Surface Temp:");
cup( 15,4 );
print(" Stellar Age:");
cup( 17,4 );
print(" Magnitude:");
cup( 19,4 );
print(" Light Years:");
}
void cprompts()
{
color( WHITE, BLUE );
cup( 5,4 );
print(" First Name:");
cup( 7,4 );
print(" Last Name:");
cup( 9,4);
print(" Street:");
cup( 11,4 );
print(" City:");
cup( 13,4 );
print(" State / Zip:");
cup( 15,4 );
print(" Home Phone:");
cup( 17,4 );
print(" Work Phone:");
cup( 19,4 );
print(" SSN #:");
cup( 21,4 );
print(" Birthdate:");
}
void clearnio()
{
zero(nio.name,21);
nio.binarys = 0;
nio.rel_lum = 0;
nio.sfc_temp = 0L;
nio.abs_lum = 0;
nio.age_yrs = 0L;
nio.magnitd = 0.0;
nio.distance = 0.0;
}
void clearcio()
{
/*
zero( char *buf, int length );
Handy function to initialize a buffer before or after use.
Be careful with the length parameter - if it's too long,
it may wipe out other data because you will make it initial-
ize data after the array.
*/
zero( cio.fname, sizeof( struct CHR_BLK ) );
}
void mess24( mess )
char *mess;
{
color( RED, WHITE );
wcls( 24,2,24,76 );
cup( 24,2 );
print( mess );
}
void ninst()
{
/*
This function is called in the prevalidation test of each entry field.
Instead of prevalidation this function displays text on the right hand
side of the display.
*/
auto int x = 0;
/*
The instructional text will be white on blue...
*/
color( WHITE, BLUE );
/*
Clear the right hand side of the screen for a new display of text...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -