home *** CD-ROM | disk | FTP | other *** search
/ AMIGA PD 1 / AMIGA-PD-1.iso / Programme_zum_Heft / Programmieren / Kurztests / ACE / Prgs / ShellUtils / older.b < prev   
Text File  |  1994-01-10  |  2KB  |  102 lines

  1. { An example of structures and library functions at work
  2.   to compare the datestamps of two files.
  3.  
  4.   Author: David Benn
  5.     Date: 31st December 1993,
  6.       5th January 1994 }
  7.  
  8. DEFLNG a-z
  9.  
  10. CONST NOT_OLDER=0,OLDER=5     '..WARN=5 in a shell script
  11.  
  12. '..structure definitions
  13. STRUCT DateStamp
  14.   LONGINT days
  15.   LONGINT mins
  16.   LONGINT ticks
  17. END STRUCT
  18.  
  19. STRUCT FileInfoBlock
  20.   longint fib_DiskKey
  21.   longint fib_DirEntryType
  22.   string  fib_FileName size 108
  23.   longint fib_Protection
  24.   longint fib_EntryType
  25.   longint fib_Size
  26.   longint fib_NumBlocks
  27.   string  fib_Date size 12
  28.   string  fib_Comment size 80
  29.   string  fib_Reserved size 36
  30. END STRUCT
  31.  
  32. '..subprograms
  33. SUB get_file_datestamp(STRING fname,ADDRESS ds_addr)
  34. CONST ACCESS_READ = -2&
  35. CONST NULL = 0&
  36.  
  37. LONGINT mylock
  38.  
  39. DECLARE STRUCT DateStamp ds,Date
  40. DECLARE STRUCT FileInfoBlock file_info
  41.  
  42. DECLARE FUNCTION Lock& library dos
  43. DECLARE FUNCTION UnLock library dos
  44. DECLARE FUNCTION Examine library dos
  45.  
  46.   ds = ds_addr
  47.   mylock = Lock(fname,ACCESS_READ) 
  48.  
  49.   if mylock <> NULL then
  50.     Examine(mylock,file_info)
  51.     Date = @file_info->fib_Date
  52.     ds->days  = Date->days
  53.     ds->mins  = Date->mins
  54.     ds->ticks = Date->ticks
  55.     UnLock(mylock)
  56.   end if
  57. END SUB
  58.  
  59. SUB usage
  60.   print 
  61.   print "usage: ";arg$(0);" file1 file2"
  62.   print
  63.   print "Typical usage in a shell script is:"
  64.   print
  65.   print "     FAILAT 11" 
  66.   print
  67.   print "     ";arg$(0);" >NIL: file1 file2"
  68.   print
  69.   print "     IF WARN"
  70.   print "       ."
  71.   print "       ."
  72.   print "     ENDIF"
  73.   print
  74. END SUB
  75.  
  76. '..main
  77. DECLARE STRUCT DateStamp stamp1,stamp2
  78.  
  79. if argcount=2 then
  80.   get_file_datestamp(arg$(1),stamp1)
  81.   get_file_datestamp(arg$(2),stamp2)
  82.  
  83.   d1=stamp1->days
  84.   d2=stamp2->days
  85.   m1=stamp1->mins
  86.   m2=stamp2->mins
  87.   t1=stamp1->ticks
  88.   t2=stamp2->ticks
  89.  
  90.   if (d2>d1) or (d2=d1 and m2>m1) or (d2=d1 and m2=m1 and t2>t1) then 
  91.     print arg$(1);" is older than ";arg$(2);"."
  92.     SYSTEM OLDER
  93.   else
  94.     print arg$(1);" is not older than ";arg$(2);"."
  95.     SYSTEM NOT_OLDER
  96.   end if
  97. else
  98.   usage
  99. end if
  100.  
  101. END
  102.