home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / read_battclock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  2.4 KB  |  86 lines

  1. /*
  2.  * Read_BattClock.c
  3.  *
  4.  * Example of reading the BattClock and converting its output to
  5.  * a useful measure of time by calling the Amiga2Date() utility function.
  6.  *
  7.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  8.  *
  9.  * Run from CLI only
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <dos/dos.h>
  14. #include <utility/date.h>
  15. #include <resources/battclock.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. #include <clib/alib_protos.h>
  19. #include <clib/battclock_protos.h>
  20. #include <clib/utility_protos.h>
  21.  
  22. #include <stdio.h>
  23.  
  24. #ifdef LATTICE
  25. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  26. int chkabort(void) { return(0); }  /* really */
  27. #endif
  28.  
  29. VOID main(VOID);
  30.  
  31. struct Library *UtilityBase = NULL;
  32. struct Library *BattClockBase;
  33.  
  34. VOID main(VOID)
  35. {
  36. UBYTE *Days[] ={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
  37. UBYTE *Months[] = {"January","February","March","April","May","June",
  38.                    "July","August","September","October","November","December"};
  39. UBYTE *ampm;
  40. ULONG AmigaTime;
  41. struct ClockData MyClock;
  42.  
  43. if (UtilityBase = (struct Library *)OpenLibrary("utility.library",33))
  44.     {
  45.     if (BattClockBase= OpenResource(BATTCLOCKNAME))
  46.         {
  47.         /* Get number of seconds till now */
  48.         AmigaTime = ReadBattClock();
  49.  
  50.         /* Convert to a ClockData structure */
  51.         Amiga2Date(AmigaTime,&MyClock);
  52.  
  53.         printf("\nRobin, tell everyone the BatDate and BatTime");
  54.  
  55.         /* Print the Date */
  56.         printf("\n\nOkay Batman, the BatDate is ");
  57.         printf("%s, %s %d, %d",Days[MyClock.wday],Months[MyClock.month-1],
  58.                                MyClock.mday,MyClock.year);
  59.  
  60.         /* Convert military time to normal time and set AM/PM */
  61.         if (MyClock.hour < 12)
  62.             ampm = "AM";        /* hour less than 12, must be morning */
  63.         else
  64.             {
  65.             ampm = "PM";         /* hour greater than 12,must be night */
  66.             MyClock.hour -= 12;  /* subtract the extra 12 of military */
  67.             };
  68.  
  69.         if (MyClock.hour == 0)
  70.             MyClock.hour = 12;   /* don't forget the 12s */
  71.  
  72.         /* Print the time */
  73.         printf("\n             the BatTime is ");
  74.         printf("%d:%02d:%02d %s\n\n",MyClock.hour,MyClock.min,MyClock.sec,ampm);
  75.         }
  76.     else
  77.        printf("Error: Unable to open the %s\n",BATTCLOCKNAME);
  78.  
  79.     /* Close the utility library */
  80.     CloseLibrary(UtilityBase);
  81.     }
  82.  
  83. else
  84.     printf("Error: Unable to open utility.library\n");
  85. }
  86.