home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * ut_test1.c - utilities test program.
- *
- * Purpose: This file contains functions to test the the utility
- * functions. See also ut_test2.c
- *
- * Blackstar C Function Library
- * (c) Copyright 1985 Sterling Castle Software
- *
- *******/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "blackstr.h"
- #include "ut_head.h"
- #include "co_head.h"
-
- void main()
- {
- int i,j;
- char timestr[64],datestr[128];
- struct DATE adate,adate1;
- struct TIME atime,atime1;
- extern int hour_,minute_,sec_,hsec_,year_,month_,day_;
- extern char timeoptf_,dateoptf_;
- long ldate,ltime;
-
- co_init(0);
- co_mode(BW80,FWHITE,BBLACK);
- co_clr(); /* clear screen */
-
- printf("Hello from utilities test 1");
- printf("\n\n\rPhase 1 - Get date & time, output in various formats");
-
- ut_gtod();
-
- printf("\n\rCurrent date is %02d/%02d/%d",month_,day_,year_);
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",hour_,minute_,sec_,hsec_);
- printf("\n\r");
-
- ldate = ut_datel();
- printf("\n\n\rDate in a long integer is %ld", ldate);
- ltime = ut_timel();
- printf("\n\rTime in a long integer is %ld", ltime);
- printf("\n\r");
-
- ut_dates(&adate); /* Get date into DATE structure */
-
- dateoptf_=0; /* Clear option flag bits */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (4 digit year) in a string is %s", datestr);
- dateoptf_|=DYR2F; /* Turn on 2 digit years flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (2 digit year) in a string is %s", datestr);
-
- dateoptf_=0; /* Clear option flag bits */
- dateoptf_|= DYR2F; /* Turn on 2 digit years flag */
- dateoptf_|= DTNDF; /* Turn on name of day flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with name of day) in a string is %s", datestr);
- dateoptf_|= DDY3F; /* Turn on 3 char day name flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with 3 char name of day) in a string is %s", datestr);
-
- dateoptf_=0; /* Clear option flag bits */
- dateoptf_|= DTNMF; /* Turn on name of month flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with name of month) in a string is %s", datestr);
- dateoptf_|= DMO3F; /* Turn on 3 char month name flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with 3 char name of month) in a string is %s", datestr);
-
- dateoptf_=0; /* Clear option flag bits */
- dateoptf_|= DTNDF; /* Turn on name of day flag */
- dateoptf_|= DTNMF; /* Turn on name of month flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with name of day & month) in a string is %s", datestr);
- dateoptf_|= DDY3F; /* Turn on 3 char day name flag */
- dateoptf_|= DMO3F; /* Turn on 3 char month name flag */
- ut_sdatestr(datestr,&adate);/* Convert date to a string */
- printf("\n\rDate (with 3 char name of day & month) in a string is %s", datestr);
- printf("\n\r");
-
- ut_times(&atime); /* Get time into TIME structure */
-
- timeoptf_=0; /* Clear option flag bits */
- ut_stimestr(timestr,&atime);/* Convert time to a string */
- printf("\n\rTime (without seconds) in a string is %s", timestr);
- timeoptf_|= TSECF; /* Turn on sec/hsec flag */
- ut_stimestr(timestr,&atime);/* Convert time to a string */
- printf("\n\rTime (with seconds) in a string is %s", timestr);
- timeoptf_=0; /* Clear option flag bits */
- timeoptf_|= T24HF;
- ut_stimestr(timestr,&atime);/* Convert time to a string */
- printf("\n\rTime (24 hr without seconds) in a string is %s", timestr);
- timeoptf_|= TSECF; /* Turn on sec/hsec flag */
- ut_stimestr(timestr,&atime);/* Convert time to a string */
- printf("\n\rTime (24 hr with seconds) in a string is %s", timestr);
-
- printf("\n\n\rPress <CR> to continue with next phase");
- fgetchar();
-
-
- printf("\n\n\rPhase 2 - Date & time comparisons");
-
- ut_dates(&adate); /* Get date into DATE structure */
- adate1.yr = adate.yr;
- adate1.mo = adate.mo;
- adate1.dy = adate.dy;
- printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
- printf("\n\rCurrent date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
- i = ut_datecmp(&adate,&adate1);
- printf("\n\r Result of comparison = %d", i);
-
- adate1.yr = 1901;
- adate1.mo = 8;
- adate1.dy = 29;
- printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
- printf("\n\rCurrent date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
- i = ut_datecmp(&adate,&adate1);
- printf("\n\r Result of comparison = %d", i);
-
- adate1.yr = 2099;
- adate1.mo = 6;
- adate1.dy = 13;
- printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
- printf("\n\rCurrent date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
- i = ut_datecmp(&adate,&adate1);
- printf("\n\r Result of comparison = %d", i);
-
- ut_times(&atime); /* Get time into TIME structure */
- atime1.hr = atime.hr;
- atime1.mn = atime.mn;
- atime1.sec = atime.sec;
- atime1.hsec = atime.hsec;
- printf("\n\rComparison time is %02d:%02d:%02d.%02d",
- atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
- j = ut_timecmp(&atime,&atime1);
- printf("\n\r Result of comparison = %d", j);
-
- atime1.hr = atime.hr - 1;
- atime1.mn = 58;
- atime1.sec = 58;
- atime1.hsec = 98;
- printf("\n\rComparison time is %02d:%02d:%02d.%02d",
- atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
- j = ut_timecmp(&atime,&atime1);
- printf("\n\r Result of comparison = %d", j);
-
- atime1.hr = atime.hr + 1;
- atime1.mn = 26;
- atime1.sec = 43;
- atime1.hsec = 39;
- printf("\n\rComparison time is %02d:%02d:%02d.%02d",
- atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
- j = ut_timecmp(&atime,&atime1);
- printf("\n\r Result of comparison = %d", j);
-
- printf("\n\n\rPress <CR> to continue with next phase");
- fgetchar();
-
- printf("\n\n\rPhase 3 - Date & time (in structure) arithmetic");
-
- ut_dates(&adate); /* Get date into DATE structure */
- adate1.yr = 2;
- adate1.mo = 11;
- adate1.dy = 3;
- printf("\n\rCurrent date is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
- printf("\n\rAmount to add is %02d/%02d/%4d",adate1.mo,adate1.dy,adate1.yr);
- ut_dateadd(&adate,&adate1);
- printf("\n\rResult of add is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
-
- ut_dates(&adate); /* Get date into DATE structure */
- adate1.yr = 3;
- adate1.mo = 10;
- adate1.dy = 7;
- printf("\n\rCurrent date is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
- printf("\n\rAmount to subtract is %02d/%02d/%4d",adate1.mo,adate1.dy,adate1.yr);
- ut_datesub(&adate,&adate1);
- printf("\n\rResult of subtract is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
-
- printf("\n\rResult of difference from 9/7/86 is %06d",ut_ldatedif(ldate,860907) );
- ut_times(&atime); /* Get time into TIME structure */
- atime1.hr = 3;
- atime1.mn = 17;
- atime1.sec = 23;
- atime1.hsec = 54;
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
- printf("\n\rAmount to add is %02d:%02d:%02d.%02d",
- atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
- ut_timeadd(&atime,&atime1);
- printf("\n\rResult of add is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
-
- ut_times(&atime); /* Get time into TIME structure */
- atime1.hr = 1;
- atime1.mn = 27;
- atime1.sec = 53;
- atime1.hsec = 14;
- printf("\n\rCurrent time is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
- printf("\n\rAmount to subtract is %02d:%02d:%02d.%02d",
- atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
- ut_timesub(&atime,&atime1);
- printf("\n\rResult of subtract is %02d:%02d:%02d.%02d",
- atime.hr,atime.mn,atime.sec,atime.hsec);
-
- printf("\n\n\rPress <CR> to continue with next phase");
- fgetchar();
-
- printf("\n\n\rPhase 4 - Date & time (in long integer) arithmetic");
-
- ldate = ut_datel(); /* Get date in a long integer */
- printf("\n\rCurrent date is %8ld", ldate);
- printf("\n\rAmount to add is 10929");
- ldate = ut_ldateadd(ldate,10929L);
- printf("\n\rResult of add is %8ld", ldate);
-
- ldate = ut_datel(); /* Get date in a long integer */
- printf("\n\rCurrent date is %8ld", ldate);
- printf("\n\rAmount to subtract is 20109");
- ldate = ut_ldatesub(ldate,20109L);
- printf("\n\rResult of subtract is %8ld", ldate);
-
- ltime = ut_timel(); /* Get time in a long integer */
- printf("\n\rCurrent time is %8ld", ltime);
- printf("\n\rAmount to add is 111726");
- ltime = ut_ltimeadd(ltime,111726L);
- printf("\n\rResult of add is %8ld", ltime);
-
- ltime = ut_timel(); /* Get time in a long integer */
- printf("\n\rCurrent time is %8ld", ltime);
- printf("\n\rAmount to subtract is 31624");
- ltime = ut_ltimesub(ltime, 31624L);
- printf("\n\rResult of subtract is %8ld", ltime);
-
- printf("\n\n\rPress <CR> to continue with next phase");
- fgetchar();
-
- printf("\n\n\rPhase 5 - Date & time string conversions");
-
- printf("\n\rConversion of date & time strings to long integers");
- ldate = ut_stdatel("2/3/85");
- printf("\n\rDate string \"2/3/85\" converted to long = %8ld",ldate);
- ltime = ut_sttimel("1:05p");
- printf("\n\rTime string \"1:05p\" converted to long = %8ld",ltime);
- ldate = ut_stdatel("12/24/85");
- printf("\n\rDate string \"12/24/85\" converted to long = %8ld",ldate);
- ltime=ut_sttimel("10:05");
- printf("\n\rTime string \"10:05\" converted to long = %8ld",ltime);
- ldate = ut_stdatel("1/24/05");
- printf("\n\rDate string \"1/24/05\" converted to long = %8ld",ldate);
- ltime = ut_sttimel("1300");
- printf("\n\rTime string \"1300\" converted to long = %8ld",ltime);
-
- printf("\n\nEND OF TEST - Press any key to exit...");
- kb_getc();
- co_clr(); /* clear screen */
- }
-