#ifdef AIX_PROD
/* @(#)10    1.4  src/examples/pubsex/dtsex/dtssamp.c, examples.src, os2dce21.dss, 960602a.1 1/11/96 10:43:57 */
/*
 *   COMPONENT_NAME: examples.src
 *
 *   FUNCTIONS: PrintTime
 *              ReadTime
 *              main
 *
 *   ORIGINS: 72
 *
 */
#endif /* AIX_PROD */

#include <time.h>           /* time data structures    */
#include <dce/utc.h>        /* utc structure definitions  */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

extern void ReadTime(struct utc *utcTime);
extern void PrintTime(struct utc *utcTime);

 /* This program requests user input about events, then prints out
  * information about those events.
  */

void main(void)
{
    struct utc event1,event2;
    enum utc_cmptype relation;

    setbuf(stdout,NULL);
    setbuf(stderr,NULL);

     /* Read in the two events.
      */

    ReadTime(&event1);
    ReadTime(&event2);


     /* Print out the two events.
      */

    printf("The first event is : ");
    PrintTime(&event1);
    printf("\nThe second event is : ");
    PrintTime(&event2);
    printf("\n");


     /* Determine which event occurred first.
      */

    if (utc_cmpmidtime(&relation,&event1,&event2))
        exit(1);

    switch( relation )
    {
        case utc_lessThan:
        printf("comparing midpoints: Event1 < Event2\n");
        break;
        case utc_greaterThan:
        printf("comparing midpoints: Event1 > Event2\n");
        break;
        case utc_equalTo:
        printf("comparing midpoints: Event1 = Event2\n");
        break;

        default:
        exit(1);
        break;
    }

     /* Could Event 1 have caused Event 2?  Compare the intervals.
      */

    if (utc_cmpintervaltime(&relation,&event1,&event2))
        exit(1);

    switch( relation )
    {
        case utc_lessThan:
        printf("comparing intervals: Event1 < Event2\n");
        break;
        case utc_greaterThan:
        printf("comparing intervals: Event1 > Event2\n");
        break;
        case utc_equalTo:
        printf("comparing intervals: Event1 = Event2\n");
        break;
        case utc_indeterminate:
        printf("comparing intervals: Event1 ? Event2\n");
        default:
        exit(1);
        break;
    }

}


 /* Print out a utc structure in ISO text format.
  */

void PrintTime(utcTime)
struct utc *utcTime;
{

    char   string[50];


     /* Break up the time string.
      */

    if (utc_ascgmtime(string,      /* Out: Converted time    */
                      50,          /* In:  String length     */
                      utcTime))    /* In:  Time to convert   */
        exit(1);
    printf("%s\n",string);

}


 /* Prompt the user to enter time coordinates.  Store the coordinates
  * in a tm structure and then convert the tm structure to a utc structure.
  */


void ReadTime(utcTime)
struct utc *utcTime;
{
struct tm tmTime,tmInacc;

    (void)memset((void *)&tmTime,  0, sizeof(tmTime));
    (void)memset((void *)&tmInacc, 0, sizeof(tmInacc));
    (void)printf("Year? ");
    (void)scanf("%d",&tmTime.tm_year);
    tmTime.tm_year -= 1900;
    (void)printf("Month? ");
    (void)scanf("%d",&tmTime.tm_mon);
    tmTime.tm_mon -= 1;
    (void)printf("Day? ");
    (void)scanf("%d",&tmTime.tm_mday);
    (void)printf("Hour? ");
    (void)scanf("%d",&tmTime.tm_hour);
    (void)printf("Minute? ");
    (void)scanf("%d",&tmTime.tm_min);
    (void)printf("Inacc Secs? ");
    (void)scanf("%d",&tmInacc.tm_sec);

    if (utc_mkanytime(utcTime,
                      &tmTime,
                      (long)0,
                      &tmInacc,
                      (long)0,
                      (long)0))
        exit(1);

}

