home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / envsof20 / eiffel / rexx / update_short.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1999-08-27  |  3.9 KB  |  155 lines

  1. /*
  2.  * update_short.rexx -- Create short form of a class.
  3.  *
  4.  * The short form is written to a file with the same name, but to the
  5.  * directory "sofa/short/" relative to the original class directory.
  6.  * For example "toy:source/hugo.e" is written to
  7.  * "toy:source/sofa/short/hugo.e". If the short form already exists,
  8.  * it is only written if the class file is newer than the short form.
  9.  *
  10.  * Copyright (C) 1999 Thomas Aglassiner <agi@sbox.tu-graz.ac.at>
  11.  * Freeware. Use at your own risk.
  12.  */
  13. version_info = "$VER: update_short.rexx 1.1 (26.8.99)"
  14.  
  15. /* update_guide.rexx -- Update SmallEiffel class short form */
  16. Call AddLib('rexxsupport.library', 0, -30, 0)
  17. Call AddLib('rexxdossupport.library', 0, -30, 0)
  18.  
  19. /* Set default options */
  20. template = 'File/A,Force/S,Quiet/S,Debug/S,Port/K,ShortOptions/F'
  21. file = ''
  22. port = Address()
  23. ShortOptions = ''
  24. force = 0
  25. quiet = 0
  26. debug = 0
  27. host  = ''
  28.  
  29. /* Some constants */
  30. linefeed = '0a'x
  31. tab = '9'x
  32.  
  33. /* Check Arguments */
  34. Parse Arg arguments
  35.  
  36. if Strip(arguments, 'B', ' "') = '?' then do
  37.    Call WriteCh('STDOUT', template || ': ')
  38.    Pull arguments
  39. end
  40.  
  41. if ~ReadArgs(arguments, template) then do
  42.    Say "Error in arguments: " || Fault(RC)
  43.    Exit 10
  44. end
  45.  
  46. /* Send status message commands to `port' */
  47. Address Value port
  48.  
  49. separator_index = Max(LastPos(':', file), LastPos('/', file))
  50.  
  51. class_file = file
  52. sofa_directory = Left(file, separator_index) || 'sofa'
  53. short_directory = sofa_directory || '/short'
  54. short_file = short_directory || '/' || SubStr(file, separator_index + 1)
  55.  
  56. Call debug_message('class = "' || class_file || '"')
  57. Call debug_message('short = "' || short_file || '"')
  58.  
  59. /* Create short directory if necessary */
  60. if ~Exists(sofa_directory) then do
  61.    Call debug_message('create "' || sofa_directory || '"')
  62.    MakeDir(sofa_directory)
  63. end
  64. if ~Exists(short_directory) then do
  65.    Call debug_message('create "' || short_directory || '"')
  66.    MakeDir(short_directory)
  67. end
  68.  
  69. /* Compare datestamp of `class_file' and `short_file' */
  70. if ~force then do
  71.    class_time = file_time(class_file)
  72.    if class_time = 0 then do
  73.       Say 'Cannot find "' || class_file || '"'
  74.       Exit 10
  75.    end
  76.    short_time = file_time(short_file)
  77.    if class_time > short_time then do
  78.       force = 1
  79.    end
  80. end
  81.  
  82. if force then do
  83.    if exists(short_file) then do
  84.       Call set_file_protection(short_file, 'rwed')
  85.    end
  86.    short_command = 'short '|| ShortOptions || ' "' || class_file || '" >"' || short_file || '"'
  87.    Call progress_message('Updating short form...')
  88.    Call debug_message(short_command)
  89.    Address Command short_command
  90.    Call set_file_protection(short_file, 'r') /* Make cached short form read only */
  91.    Call progress_message('')
  92. end
  93. else do
  94.    Call status_message('"' || short_file || '" is up to date')
  95. end
  96.  
  97. Exit 0
  98.  
  99. /* Date and time of file in seconds till 1-Jan-1978 */
  100. file_time: procedure
  101.    Parse Arg filename
  102.  
  103.    info = StateF(filename)
  104.    if info ~= '' then do
  105.       Parse Var info . . . . days minutes ticks
  106.       time = days * 24 * 60 * 60 + minutes * 60 + ticks / 50
  107.    end
  108.    else do
  109.       time = 0 /* Assume 1-Jan-1978 if file does not exist */
  110.    end
  111.  
  112.    Return time
  113.  
  114. /* Display progress message. Depending on current host, this can be in the console or
  115.    the status line of the application. */
  116. progress_message:
  117.    Parse Arg message
  118.  
  119.    if Left(port, 6) = "GOLDED" then do
  120.       'REQUEST STATUS="' || message || '"'
  121.    end
  122.    else if message ~= '' then do
  123.       Say message
  124.    end
  125.  
  126.    Return
  127.  
  128. /* Display status message if not `quiet' */
  129. status_message:
  130.    if ~quiet then do
  131.       Parse Arg message
  132.       Say message
  133.    end
  134.  
  135.    Return
  136.  
  137. set_file_protection: procedure
  138.    Parse Arg filename, mask
  139.    Address Command 'protect "' || filename || '" ' || mask
  140.    if RC ~= 0 then do
  141.       Say 'Cannot change protection of "' || filename || '" to "' || mask || '"'
  142.       Exit 10
  143.    end
  144.    Return
  145.  
  146. /* Display debug message if `debug' */
  147. debug_message:
  148.    if debug then do
  149.       Parse Arg message
  150.       Say message
  151.    end
  152.  
  153.    Return
  154.  
  155.