home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 September / Simtel20_Sept92.cdr / msdos / telix / tset31.arc / TSET31.SLT < prev   
Text File  |  1988-11-01  |  5KB  |  213 lines

  1. main()
  2. {
  3.     int count,hi_hour,lo_hour,hi_min,lo_min,hi_sec,lo_sec,local_hr,t;
  4.     int error,err_test,cfg=0,time_adj,old_b_color,old_f_color;
  5.     str utc_hour[3],slocal_hr[3],set_dos_time[20]="time ",
  6.     dial_str[26],time_adj_str[3],script_path[78];
  7.  
  8.     // Initialize variables
  9.     error=1;        //Indicates that time info is yet to be decoded properly
  10.     err_test=-1;    //Used to detect if time info is properly recieved
  11.     hi_hour=-1;     //Receives hi byte of hour time info
  12.     lo_hour=-1;     //Receives lo byte of hour time info
  13.     hi_min=-1;        //Recieves hi byte of minute time info
  14.     lo_min=-1;        //Receives lo byte of minute time info
  15.     hi_sec=-1;        //Receives hi byte of second time info
  16.     lo_sec=-1;        //Recieves lo byte of second time info
  17.  
  18.     //Show opening TIMESET display
  19.     clear_scr();
  20.     prints("Welcome to Timeset!!!");
  21.  
  22.     copystr(_script_dir,script_path,0,65);
  23.     strcat(script_path,"timeset.cfg");
  24.  
  25.     while(!cfg)
  26.     {
  27.     cfg=fopen(script_path,"r");
  28.     if(!cfg)
  29.     {
  30.         prints(" ");
  31.         alarm(1);
  32.         prints("Can't find the configuration file!");
  33.         prints("Run the Timeset configuration script? <Y=yes>");
  34.         _scr_chk_key=0;
  35.         t=inkeyw();
  36.         if(t=="Y"|t=="y")
  37.         {
  38.         status_wind("Executing configuration script!",30);
  39.         call("timecfg.slc");
  40.         }
  41.         else
  42.         {
  43.         status_wind("Aborting Timeset!",30);
  44.         prints(" ");
  45.         prints("+++ Timeset Aborted +++");
  46.         return();
  47.         }
  48.     }
  49.     }
  50.     fgets(dial_str,25,cfg);
  51.     fgets(time_adj_str,3,cfg);
  52.     time_adj=stoi(time_adj_str);
  53.     fclose(cfg);
  54.  
  55.     inschrs("m",dial_str,0,1);
  56.  
  57.     prints(" ");
  58.     prints("Now dialing for the time...");
  59.  
  60.     //Dial for the time
  61.  
  62.     set_cparams(1200,0,8,1);
  63.     if(!(dial(dial_str,0,1)))
  64.     {
  65.     status_wind("Can not contact the Naval Observatory!  Aborting.",30);
  66.     alarm(1);
  67.     prints("+++  Timeset Aborted  +++");
  68.     return;        //User pressed the Esc key.  Abort.
  69.     }
  70.  
  71.     flushbuf();
  72.     //Decode the time info received
  73.     while(error)
  74.     {
  75.     count=15;    //Amount of bytes to wait until time data should start
  76.  
  77.     if(!waitfor("UTC",10))
  78.     {
  79.         status_wind("Timeout error, aborting!",30);
  80.         prints("+++  Timeset Aborted  +++");
  81.         hangup();
  82.         return;    //Time info is not flowing right.  Abort.
  83.     }
  84.  
  85.     //Let the calander bytes flow past
  86.     while(count)
  87.     {
  88.         while(cgetc()==-1)
  89.         {
  90.         }
  91.         count=count-1;
  92.     }
  93.     //Receive the time data
  94.     while(hi_hour==-1)
  95.     {
  96.         hi_hour=cgetc();
  97.     }
  98.     while(lo_hour==-1)
  99.     {
  100.         lo_hour=cgetc();
  101.     }
  102.     while(hi_min==-1)
  103.     {
  104.         hi_min=cgetc();
  105.     }
  106.     while(lo_min==-1)
  107.     {
  108.         lo_min=cgetc();
  109.     }
  110.     while(hi_sec==-1)
  111.     {
  112.         hi_sec=cgetc();
  113.     }
  114.     while(lo_sec==-1)
  115.     {
  116.         lo_sec=cgetc();
  117.     }
  118.  
  119.     //Check to see if the data flowed as expected
  120.     while(err_test==-1)
  121.     {
  122.         err_test=cgetc();
  123.     }
  124.     if(err_test==32)
  125.     {
  126.         error=0;    //Everything is ok.  Set error to end the loop.
  127.     }
  128.     }
  129.  
  130.     //Start building the DOS set time command
  131.     strcat(utc_hour,hi_hour);
  132.     strcat(utc_hour,lo_hour);
  133.     local_hr=stoi(utc_hour);
  134.  
  135.     //Adjust UTC time to local time here
  136.     local_hr=local_hr-time_adj;
  137.     if(local_hr<0)
  138.     {
  139.     local_hr=local_hr+24;
  140.     }
  141.     itos(local_hr,slocal_hr);
  142.  
  143.     //Set DOS time
  144.     strcat(set_dos_time,slocal_hr);
  145.     strcat(set_dos_time,":");
  146.     strcat(set_dos_time,hi_min);
  147.     strcat(set_dos_time,lo_min);
  148.     strcat(set_dos_time,":");
  149.     strcat(set_dos_time,hi_sec);
  150.     strcat(set_dos_time,lo_sec);
  151.     dos(set_dos_time,0);
  152.  
  153.     //Hangup the modem and clear extra received data
  154.     hangup();
  155.     flushbuf();
  156.  
  157.     //Display current time continuosly
  158.     old_b_color=_back_color;
  159.     old_f_color=_fore_color;
  160.     _back_color=0;
  161.     _fore_color=15;
  162.     clear_scr();
  163.     cursor_onoff(0);     //Disable the cursor because it is annoying
  164.     box(32,11,46,14,4,1,9);
  165.     gotoxy(34,12);
  166.  
  167.     prints("The time is");
  168.  
  169.     t=curtime();
  170.     _scr_chk_key=0;
  171.  
  172.     while(1)
  173.     {
  174.     gotoxy(36,13);
  175.     while(curtime()==t)   //Wait for time to change!
  176.     {
  177.     }
  178.     t=curtime();
  179.     if(thour(t)<10)
  180.     {
  181.         printsc("0");
  182.     }
  183.     printn(thour(t));
  184.     if(tmin(t)<10)
  185.     {
  186.         printsc("0");
  187.     }
  188.     printn(tmin(t));
  189.     printsc(".");
  190.     if(tsec(t)<10)
  191.     {
  192.         printsc("0");
  193.     }
  194.     printn(tsec(t));
  195.     if(!(tsec(t)))
  196.     {
  197.         tone(1000,10);
  198.     }
  199.     else
  200.     {
  201.         tone(300,5);
  202.     }
  203.     if(inkey()==32)
  204.     {
  205.         break;    //Exit if the space bar is pressed
  206.     }
  207.     }
  208.     _fore_color=old_f_color;
  209.     _back_color=old_b_color;
  210.     clear_scr();
  211.     prints("Thank you for using TIMESET!");
  212. }
  213.