home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 19 / AACD19.BIN / AACD / Programming / YAEC / examples / uptime.e < prev    next >
Encoding:
Text File  |  2001-02-23  |  1.8 KB  |  64 lines

  1. -> uptime.e
  2.  
  3. ->>> Header (globals)
  4. ->Eeh-note : not really needed
  5. OPT PREPROCESS
  6.  
  7. MODULE 'dos/dos', 'dos/dosextens',
  8.         'utility/date'
  9.  
  10. EXTERN 'utility'
  11.  
  12. DEF utilitybase
  13.  
  14. ENUM ERR_NONE, ERR_INFO, ERR_LIB, ERR_LOCK
  15.  
  16. RAISE ERR_INFO IF Info()<>TRUE
  17. RAISE ERR_LIB  IF OpenLibrary()=NIL
  18. RAISE ERR_LOCK IF Lock()=NIL
  19. ->>>
  20.  
  21. ->>> PROC main()
  22. PROC main()
  23.   DEF infodata=NIL:PTR TO infodata, ramdevice:PTR TO devlist
  24.   DEF now=NIL:PTR TO datestamp, currenttime:LONG, boottime:LONG
  25.   DEF lock=NIL, d:LONG, h:LONG, m:LONG
  26.   utilitybase:=OpenLibrary('utility.library', 37)
  27.   NEW infodata
  28.   NEW now
  29.   lock:=Lock('RAM:', SHARED_LOCK)
  30.   Info(lock, infodata)
  31.   -> E-Note: convert BCPL pointer
  32.   ramdevice:=BADDR(infodata.volumenode)
  33.   -> Eeh-note : operators are 32bit! we can use *
  34.   boottime:=(ramdevice.volumedate.days * 86400) +
  35.             (ramdevice.volumedate.minute * 60) +
  36.             Mod(ramdevice.volumedate.tick, TICKS_PER_SECOND)
  37.   DateStamp(now)
  38.   currenttime:=(now.days * 86400) +
  39.                (now.minute * 60) +
  40.                Mod(now.tick, TICKS_PER_SECOND)
  41.   currenttime:=currenttime-boottime
  42.   IF currenttime > 0
  43.     -> E-Note: a multiple assignment gets the two UdivMod32() results
  44.     d:=UDivMod32(currenttime, 86400)
  45.     h := D1 -> Eeh-note : multiple returnvals-workaround for now
  46.     h:=UDivMod32(h, 3600)
  47.     m := D1
  48.     m:=UDivMod32(m, 60)
  49.     WriteF('Up for \d days, \d hours, \d minutes\n', d, h, m)
  50.   ENDIF
  51. EXCEPT DO
  52.   IF lock THEN UnLock(lock)
  53.   END now
  54.   END infodata
  55.   IF utilitybase THEN CloseLibrary(utilitybase)
  56.   SELECT exception
  57.   CASE ERR_INFO;  WriteF('Error: could not get info on lock\n')
  58.   CASE ERR_LIB;   WriteF('Error: could not open utility library\n')
  59.   CASE ERR_LOCK;  WriteF('Error: could not lock RAM:\n')
  60.   CASE "MEM";     WriteF('Error: ran out of memory\n')
  61.   ENDSELECT
  62. ENDPROC
  63. ->>>
  64.