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

MODULE Clock;
      
      PROCEDURE GetRtcTime*(VAR second, minute, hour, day, month, year : INTEGER);
      BEGIN
      END GetRtcTime;
      
      PROCEDURE Get*(VAR time, date : INTEGER);
      BEGIN
      END Get;
      
      END Clock.
      
      

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

/*GENERATED BY OBNC 0.16.1*/
      
      #include ".obnc/Clock.h"
      #include <obnc/OBNC.h>
      #include <time.h>
      
      #define OBERON_SOURCE_FILENAME "Clock.Mod"
      
      void Clock__GetRtcTime_(OBNC_INTEGER *second_, OBNC_INTEGER *minute_, OBNC_INTEGER *hour_, OBNC_INTEGER *day_, OBNC_INTEGER *month_, OBNC_INTEGER *year_)
      {
          time_t now;
          struct tm *time_info;
          now = time(NULL);
          time_info = localtime(&now);
          *second_ = time_info->tm_sec;
          *minute_ = time_info->tm_min;
          *hour_ = time_info->tm_hour;
          *day_ = time_info->tm_mday;
          *month_ = time_info->tm_mon;
          *year_ = (time_info->tm_year) + 1900;
      }
      
      
      void Clock__Get_(OBNC_INTEGER *time_, OBNC_INTEGER *date_)
      {
      	OBNC_INTEGER second_, minute_, hour_, day_, month_, year_;
      
      	Clock__GetRtcTime_(&second_, &minute_, &hour_, &day_, &month_, &year_);
      	(*time_) = ((hour_ * 4096) + (minute_ * 64)) + second_;
      	(*date_) = ((year_ * 512) + (month_ * 32)) + day_;
      }
      
      
      void Clock__Init(void)
      {
      }
      

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