home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / DEMOS / UT_TEST1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  11.0 KB  |  268 lines

  1. /*********************
  2.  *
  3.  *  ut_test1.c - utilities test program.
  4.  *
  5.  *  Purpose: This file contains functions to test the the utility
  6.  *           functions. See also ut_test2.c
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include "blackstr.h"
  16. #include "ut_head.h"
  17. #include "co_head.h"
  18.  
  19. void main()
  20. {
  21.     int          i,j;
  22.     char         timestr[64],datestr[128];
  23.     struct DATE  adate,adate1;
  24.     struct TIME  atime,atime1;
  25.     extern int   hour_,minute_,sec_,hsec_,year_,month_,day_;
  26.     extern char  timeoptf_,dateoptf_;
  27.     long         ldate,ltime;
  28.  
  29.     co_init(0);
  30.     co_mode(BW80,FWHITE,BBLACK);
  31.     co_clr();               /* clear screen */
  32.  
  33.     printf("Hello from utilities test 1");
  34.     printf("\n\n\rPhase 1 - Get date & time, output in various formats");
  35.  
  36.     ut_gtod();
  37.  
  38.     printf("\n\rCurrent date is %02d/%02d/%d",month_,day_,year_);
  39.     printf("\n\rCurrent time is %02d:%02d:%02d.%02d",hour_,minute_,sec_,hsec_);
  40.     printf("\n\r");
  41.  
  42.     ldate = ut_datel();
  43.     printf("\n\n\rDate in a long integer is %ld", ldate);
  44.     ltime = ut_timel();
  45.     printf("\n\rTime in a long integer is %ld", ltime);
  46.     printf("\n\r");
  47.  
  48.     ut_dates(&adate);            /* Get date into DATE structure */
  49.  
  50.     dateoptf_=0;                /* Clear option flag bits       */
  51.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  52.     printf("\n\rDate (4 digit year) in a string is %s", datestr);
  53.     dateoptf_|=DYR2F;           /* Turn on 2 digit years flag   */
  54.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  55.     printf("\n\rDate (2 digit year) in a string is %s", datestr);
  56.  
  57.     dateoptf_=0;                /* Clear option flag bits       */
  58.     dateoptf_|= DYR2F;          /* Turn on 2 digit years flag   */
  59.     dateoptf_|= DTNDF;          /* Turn on name of day flag     */
  60.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  61.     printf("\n\rDate (with name of day) in a string is %s", datestr);
  62.     dateoptf_|= DDY3F;          /* Turn on 3 char day name flag */
  63.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  64.     printf("\n\rDate (with 3 char name of day) in a string is %s", datestr);
  65.  
  66.     dateoptf_=0;                /* Clear option flag bits       */
  67.     dateoptf_|= DTNMF;          /* Turn on name of month flag   */
  68.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  69.     printf("\n\rDate (with name of month) in a string is %s", datestr);
  70.     dateoptf_|= DMO3F;          /* Turn on 3 char month name flag */
  71.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  72.     printf("\n\rDate (with 3 char name of month) in a string is %s", datestr);
  73.  
  74.     dateoptf_=0;                /* Clear option flag bits       */
  75.     dateoptf_|= DTNDF;          /* Turn on name of day flag     */
  76.     dateoptf_|= DTNMF;          /* Turn on name of month flag   */
  77.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  78.     printf("\n\rDate (with name of day & month) in a string is %s", datestr);
  79.     dateoptf_|= DDY3F;          /* Turn on 3 char day name flag */
  80.     dateoptf_|= DMO3F;          /* Turn on 3 char month name flag */
  81.     ut_sdatestr(datestr,&adate);/* Convert date to a string     */
  82.     printf("\n\rDate (with 3 char name of day & month) in a string is %s", datestr);
  83.     printf("\n\r");
  84.  
  85.     ut_times(&atime);           /* Get time into TIME structure */
  86.  
  87.     timeoptf_=0;                /* Clear option flag bits       */
  88.     ut_stimestr(timestr,&atime);/* Convert time to a string     */
  89.     printf("\n\rTime (without seconds) in a string is %s", timestr);
  90.     timeoptf_|= TSECF;          /* Turn on sec/hsec flag        */
  91.     ut_stimestr(timestr,&atime);/* Convert time to a string     */
  92.     printf("\n\rTime (with seconds) in a string is %s", timestr);
  93.     timeoptf_=0;                /* Clear option flag bits       */
  94.     timeoptf_|= T24HF;
  95.     ut_stimestr(timestr,&atime);/* Convert time to a string     */
  96.     printf("\n\rTime (24 hr without seconds) in a string is %s", timestr);
  97.     timeoptf_|= TSECF;          /* Turn on sec/hsec flag        */
  98.     ut_stimestr(timestr,&atime);/* Convert time to a string     */
  99.     printf("\n\rTime (24 hr with seconds) in a string is %s", timestr);
  100.  
  101.     printf("\n\n\rPress <CR> to continue with next phase");
  102.     fgetchar();
  103.  
  104.  
  105.     printf("\n\n\rPhase 2 - Date & time comparisons");
  106.  
  107.     ut_dates(&adate);            /* Get date into DATE structure */
  108.     adate1.yr = adate.yr;
  109.     adate1.mo = adate.mo;
  110.     adate1.dy = adate.dy;
  111.     printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
  112.     printf("\n\rCurrent    date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
  113.     i = ut_datecmp(&adate,&adate1);
  114.     printf("\n\r Result of comparison = %d", i);
  115.  
  116.     adate1.yr = 1901;
  117.     adate1.mo = 8;
  118.     adate1.dy = 29;
  119.     printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
  120.     printf("\n\rCurrent    date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
  121.     i = ut_datecmp(&adate,&adate1);
  122.     printf("\n\r Result of comparison = %d", i);
  123.  
  124.     adate1.yr = 2099;
  125.     adate1.mo = 6;
  126.     adate1.dy = 13;
  127.     printf("\n\rComparison date is %02d/%02d/%d",adate1.mo,adate1.dy,adate1.yr);
  128.     printf("\n\rCurrent    date is %02d/%02d/%d",adate.mo,adate.dy,adate.yr);
  129.     i = ut_datecmp(&adate,&adate1);
  130.     printf("\n\r Result of comparison = %d", i);
  131.  
  132.     ut_times(&atime);            /* Get time into TIME structure */
  133.     atime1.hr = atime.hr;
  134.     atime1.mn = atime.mn;
  135.     atime1.sec = atime.sec;
  136.     atime1.hsec = atime.hsec;
  137.     printf("\n\rComparison time is %02d:%02d:%02d.%02d",
  138.                     atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
  139.     printf("\n\rCurrent    time is %02d:%02d:%02d.%02d",
  140.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  141.     j = ut_timecmp(&atime,&atime1);
  142.     printf("\n\r Result of comparison = %d", j);
  143.  
  144.     atime1.hr = atime.hr - 1;
  145.     atime1.mn = 58;
  146.     atime1.sec = 58;
  147.     atime1.hsec = 98;
  148.     printf("\n\rComparison time is %02d:%02d:%02d.%02d",
  149.                     atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
  150.     printf("\n\rCurrent    time is %02d:%02d:%02d.%02d",
  151.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  152.     j = ut_timecmp(&atime,&atime1);
  153.     printf("\n\r Result of comparison = %d", j);
  154.  
  155.     atime1.hr = atime.hr + 1;
  156.     atime1.mn = 26;
  157.     atime1.sec = 43;
  158.     atime1.hsec = 39;
  159.     printf("\n\rComparison time is %02d:%02d:%02d.%02d",
  160.                     atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
  161.     printf("\n\rCurrent    time is %02d:%02d:%02d.%02d",
  162.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  163.     j = ut_timecmp(&atime,&atime1);
  164.     printf("\n\r Result of comparison = %d", j);
  165.  
  166.     printf("\n\n\rPress <CR> to continue with next phase");
  167.     fgetchar();
  168.  
  169.     printf("\n\n\rPhase 3 - Date & time (in structure) arithmetic");
  170.  
  171.     ut_dates(&adate);            /* Get date into DATE structure */
  172.     adate1.yr = 2;
  173.     adate1.mo = 11;
  174.     adate1.dy = 3;
  175.     printf("\n\rCurrent  date is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
  176.     printf("\n\rAmount to add is %02d/%02d/%4d",adate1.mo,adate1.dy,adate1.yr);
  177.     ut_dateadd(&adate,&adate1);
  178.     printf("\n\rResult of add is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
  179.  
  180.     ut_dates(&adate);            /* Get date into DATE structure */
  181.     adate1.yr = 3;
  182.     adate1.mo = 10;
  183.     adate1.dy = 7;
  184.     printf("\n\rCurrent       date is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
  185.     printf("\n\rAmount to subtract is %02d/%02d/%4d",adate1.mo,adate1.dy,adate1.yr);
  186.     ut_datesub(&adate,&adate1);
  187.     printf("\n\rResult of subtract is %02d/%02d/%4d",adate.mo,adate.dy,adate.yr);
  188.  
  189.     printf("\n\rResult of difference from 9/7/86 is %06d",ut_ldatedif(ldate,860907) );
  190.     ut_times(&atime);            /* Get time into TIME structure */
  191.     atime1.hr = 3;
  192.     atime1.mn = 17;
  193.     atime1.sec = 23;
  194.     atime1.hsec = 54;
  195.     printf("\n\rCurrent  time is %02d:%02d:%02d.%02d",
  196.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  197.     printf("\n\rAmount to add is %02d:%02d:%02d.%02d",
  198.             atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
  199.     ut_timeadd(&atime,&atime1);
  200.     printf("\n\rResult of add is %02d:%02d:%02d.%02d",
  201.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  202.  
  203.     ut_times(&atime);            /* Get time into TIME structure */
  204.     atime1.hr = 1;
  205.     atime1.mn = 27;
  206.     atime1.sec = 53;
  207.     atime1.hsec = 14;
  208.     printf("\n\rCurrent       time is %02d:%02d:%02d.%02d",
  209.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  210.     printf("\n\rAmount to subtract is %02d:%02d:%02d.%02d",
  211.                     atime1.hr,atime1.mn,atime1.sec,atime1.hsec);
  212.     ut_timesub(&atime,&atime1);
  213.     printf("\n\rResult of subtract is %02d:%02d:%02d.%02d",
  214.                     atime.hr,atime.mn,atime.sec,atime.hsec);
  215.  
  216.     printf("\n\n\rPress <CR> to continue with next phase");
  217.     fgetchar();
  218.  
  219.     printf("\n\n\rPhase 4 - Date & time (in long integer) arithmetic");
  220.  
  221.     ldate = ut_datel();         /* Get date in a long integer */
  222.     printf("\n\rCurrent  date is %8ld", ldate);
  223.     printf("\n\rAmount to add is    10929");
  224.     ldate = ut_ldateadd(ldate,10929L);
  225.     printf("\n\rResult of add is %8ld", ldate);
  226.  
  227.     ldate = ut_datel();         /* Get date in a long integer */
  228.     printf("\n\rCurrent       date is %8ld", ldate);
  229.     printf("\n\rAmount to subtract is    20109");
  230.     ldate = ut_ldatesub(ldate,20109L);
  231.     printf("\n\rResult of subtract is %8ld", ldate);
  232.  
  233.     ltime = ut_timel();         /* Get time in a long integer */
  234.     printf("\n\rCurrent  time is %8ld", ltime);
  235.     printf("\n\rAmount to add is   111726");
  236.     ltime = ut_ltimeadd(ltime,111726L);
  237.     printf("\n\rResult of add is %8ld", ltime);
  238.  
  239.     ltime = ut_timel();         /* Get time in a long integer */
  240.     printf("\n\rCurrent       time is %8ld", ltime);
  241.     printf("\n\rAmount to subtract is    31624");
  242.     ltime = ut_ltimesub(ltime, 31624L);
  243.     printf("\n\rResult of subtract is %8ld", ltime);
  244.  
  245.     printf("\n\n\rPress <CR> to continue with next phase");
  246.     fgetchar();
  247.  
  248.     printf("\n\n\rPhase 5 - Date & time string conversions");
  249.  
  250.     printf("\n\rConversion of date & time strings to long integers");
  251.     ldate = ut_stdatel("2/3/85");
  252.     printf("\n\rDate string \"2/3/85\"   converted to long = %8ld",ldate);
  253.     ltime = ut_sttimel("1:05p");
  254.     printf("\n\rTime string \"1:05p\"    converted to long = %8ld",ltime);
  255.     ldate = ut_stdatel("12/24/85");
  256.     printf("\n\rDate string \"12/24/85\" converted to long = %8ld",ldate);
  257.     ltime=ut_sttimel("10:05");
  258.     printf("\n\rTime string \"10:05\"    converted to long = %8ld",ltime);
  259.     ldate = ut_stdatel("1/24/05");
  260.     printf("\n\rDate string \"1/24/05\"  converted to long = %8ld",ldate);
  261.     ltime = ut_sttimel("1300");
  262.     printf("\n\rTime string \"1300\"     converted to long = %8ld",ltime);
  263.  
  264.     printf("\n\nEND OF TEST - Press any key to exit...");
  265.     kb_getc();
  266.     co_clr();               /* clear screen */
  267. }
  268.