home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / utility / uptime.e < prev   
Text File  |  1977-12-31  |  2KB  |  55 lines

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