home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
telix
/
tset31.arc
/
TSET31.SLT
< prev
Wrap
Text File
|
1988-11-01
|
5KB
|
213 lines
main()
{
int count,hi_hour,lo_hour,hi_min,lo_min,hi_sec,lo_sec,local_hr,t;
int error,err_test,cfg=0,time_adj,old_b_color,old_f_color;
str utc_hour[3],slocal_hr[3],set_dos_time[20]="time ",
dial_str[26],time_adj_str[3],script_path[78];
// Initialize variables
error=1; //Indicates that time info is yet to be decoded properly
err_test=-1; //Used to detect if time info is properly recieved
hi_hour=-1; //Receives hi byte of hour time info
lo_hour=-1; //Receives lo byte of hour time info
hi_min=-1; //Recieves hi byte of minute time info
lo_min=-1; //Receives lo byte of minute time info
hi_sec=-1; //Receives hi byte of second time info
lo_sec=-1; //Recieves lo byte of second time info
//Show opening TIMESET display
clear_scr();
prints("Welcome to Timeset!!!");
copystr(_script_dir,script_path,0,65);
strcat(script_path,"timeset.cfg");
while(!cfg)
{
cfg=fopen(script_path,"r");
if(!cfg)
{
prints(" ");
alarm(1);
prints("Can't find the configuration file!");
prints("Run the Timeset configuration script? <Y=yes>");
_scr_chk_key=0;
t=inkeyw();
if(t=="Y"|t=="y")
{
status_wind("Executing configuration script!",30);
call("timecfg.slc");
}
else
{
status_wind("Aborting Timeset!",30);
prints(" ");
prints("+++ Timeset Aborted +++");
return();
}
}
}
fgets(dial_str,25,cfg);
fgets(time_adj_str,3,cfg);
time_adj=stoi(time_adj_str);
fclose(cfg);
inschrs("m",dial_str,0,1);
prints(" ");
prints("Now dialing for the time...");
//Dial for the time
set_cparams(1200,0,8,1);
if(!(dial(dial_str,0,1)))
{
status_wind("Can not contact the Naval Observatory! Aborting.",30);
alarm(1);
prints("+++ Timeset Aborted +++");
return; //User pressed the Esc key. Abort.
}
flushbuf();
//Decode the time info received
while(error)
{
count=15; //Amount of bytes to wait until time data should start
if(!waitfor("UTC",10))
{
status_wind("Timeout error, aborting!",30);
prints("+++ Timeset Aborted +++");
hangup();
return; //Time info is not flowing right. Abort.
}
//Let the calander bytes flow past
while(count)
{
while(cgetc()==-1)
{
}
count=count-1;
}
//Receive the time data
while(hi_hour==-1)
{
hi_hour=cgetc();
}
while(lo_hour==-1)
{
lo_hour=cgetc();
}
while(hi_min==-1)
{
hi_min=cgetc();
}
while(lo_min==-1)
{
lo_min=cgetc();
}
while(hi_sec==-1)
{
hi_sec=cgetc();
}
while(lo_sec==-1)
{
lo_sec=cgetc();
}
//Check to see if the data flowed as expected
while(err_test==-1)
{
err_test=cgetc();
}
if(err_test==32)
{
error=0; //Everything is ok. Set error to end the loop.
}
}
//Start building the DOS set time command
strcat(utc_hour,hi_hour);
strcat(utc_hour,lo_hour);
local_hr=stoi(utc_hour);
//Adjust UTC time to local time here
local_hr=local_hr-time_adj;
if(local_hr<0)
{
local_hr=local_hr+24;
}
itos(local_hr,slocal_hr);
//Set DOS time
strcat(set_dos_time,slocal_hr);
strcat(set_dos_time,":");
strcat(set_dos_time,hi_min);
strcat(set_dos_time,lo_min);
strcat(set_dos_time,":");
strcat(set_dos_time,hi_sec);
strcat(set_dos_time,lo_sec);
dos(set_dos_time,0);
//Hangup the modem and clear extra received data
hangup();
flushbuf();
//Display current time continuosly
old_b_color=_back_color;
old_f_color=_fore_color;
_back_color=0;
_fore_color=15;
clear_scr();
cursor_onoff(0); //Disable the cursor because it is annoying
box(32,11,46,14,4,1,9);
gotoxy(34,12);
prints("The time is");
t=curtime();
_scr_chk_key=0;
while(1)
{
gotoxy(36,13);
while(curtime()==t) //Wait for time to change!
{
}
t=curtime();
if(thour(t)<10)
{
printsc("0");
}
printn(thour(t));
if(tmin(t)<10)
{
printsc("0");
}
printn(tmin(t));
printsc(".");
if(tsec(t)<10)
{
printsc("0");
}
printn(tsec(t));
if(!(tsec(t)))
{
tone(1000,10);
}
else
{
tone(300,5);
}
if(inkey()==32)
{
break; //Exit if the space bar is pressed
}
}
_fore_color=old_f_color;
_back_color=old_b_color;
clear_scr();
prints("Thank you for using TIMESET!");
}