Clock

This is a C time library wrapper for getting system time to support Dates.Mod. The procedures are read only as setting time is non-standard on many Unix-like systems1. The two procedures follow the A2 style procedure signatures adjusted for Oberon-07.

Source code for Clock.Mod

  1. MODULE Clock;
  2. PROCEDURE GetRtcTime*(VAR second, minute, hour, day, month, year : INTEGER);
  3. BEGIN
  4. END GetRtcTime;
  5. PROCEDURE Get*(VAR time, date : INTEGER);
  6. BEGIN
  7. END Get;
  8. END Clock.

The C Source generated by OBNC then modified for this module.

  1. /*GENERATED BY OBNC 0.16.1*/
  2. #include ".obnc/Clock.h"
  3. #include <obnc/OBNC.h>
  4. #include <time.h>
  5. #define OBERON_SOURCE_FILENAME "Clock.Mod"
  6. void Clock__GetRtcTime_(OBNC_INTEGER *second_, OBNC_INTEGER *minute_, OBNC_INTEGER *hour_, OBNC_INTEGER *day_, OBNC_INTEGER *month_, OBNC_INTEGER *year_)
  7. {
  8. time_t now;
  9. struct tm *time_info;
  10. now = time(NULL);
  11. time_info = localtime(&now);
  12. *second_ = time_info->tm_sec;
  13. *minute_ = time_info->tm_min;
  14. *hour_ = time_info->tm_hour;
  15. *day_ = time_info->tm_mday;
  16. *month_ = time_info->tm_mon;
  17. *year_ = (time_info->tm_year) + 1900;
  18. }
  19. void Clock__Get_(OBNC_INTEGER *time_, OBNC_INTEGER *date_)
  20. {
  21. OBNC_INTEGER second_, minute_, hour_, day_, month_, year_;
  22. Clock__GetRtcTime_(&second_, &minute_, &hour_, &day_, &month_, &year_);
  23. (*time_) = ((hour_ * 4096) + (minute_ * 64)) + second_;
  24. (*date_) = ((year_ * 512) + (month_ * 32)) + day_;
  25. }
  26. void Clock__Init(void)
  27. {
  28. }

  1. Eric Raymond discusses time functions, http://www.catb.org/esr/time-programming/↩︎