% Copyright (C) 1993, Digital Equipment Corporation
% All rights reserved.
% See the file COPYRIGHT for a full description.
%
% Last modified on Fri Feb 10 08:05:06 PST 1995 by kalsow 
%      modified on Fri Jun  3 09:57:46 PDT 1994 by heydon 
%      modified on Thu Jun  2 00:12:29 PDT 1994 by mhb    
%      modified on Mon Jan 24 13:14:09 PST 1994 by najork 
%      modified on Thu Jul  8 11:26:51 PDT 1993 by steveg
%      modified on Wed Jul  7 15:11:23 PDT 1993 by harrison

if defined ("M3ZUME")
  % take the version of m3zume specified by the user
  _ZUME_EXEC = M3ZUME
else
  _ZUME_EXEC = format ("%s%s%s", BIN_USE, SL, "m3zume")  %% - full path
  %% _ZUME_EXEC = "m3zume"
end

%------------------------------------------------------------- vanilla zume ---

readonly _ZUME_FV_FILES = [ "EventData", "TranscriptView" ]
readonly _ZUME_M3_FILES = [ "AlgClass", "ViewClass", "IE",
                            "DataView", "TranscriptView" ]

readonly proc zume(x) is
  local any_stale = ""
  local evt_file = path_of(x & ".evt")

  foreach p in _ZUME_M3_FILES
    local fn = x & p

    if not any_stale
      any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
    end
    derived_interface(fn, VISIBLE)
    derived_implementation(fn)
  end

  if defined("_all") and any_stale
    local cmd = [ _ZUME_EXEC, path_of(x) ]
    write(cmd, CR)
    local ret = exec(cmd)
    if not equal(ret, 0) error("command failed with error code: ", ret) end
  end

  foreach r in _ZUME_FV_FILES
    derived_resource(format ("%s%s.fv", x, r))
  end
end

%------------------------------------------------------------- 3D zume --------

readonly _ZUME3D_M3_FILES = [ "AlgClass", "ViewClass", "3DViewClass", "IE",
                            "DataView", "TranscriptView" ]

readonly proc zume3D(x) is
  local any_stale = ""
  local evt_file = path_of(x & ".evt")

  foreach p in _ZUME3D_M3_FILES
    local fn = x & p

    if not any_stale
      any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
    end
    derived_interface(fn, VISIBLE)
    derived_implementation(fn)
  end

  if defined("_all") and any_stale
    local cmd = [ _ZUME_EXEC, "-3D", path_of(x) ]
    write(cmd, CR)
    local ret = exec(cmd)
    if not equal(ret, 0) error("command failed with error code: ", ret) end
  end

  foreach r in _ZUME_FV_FILES
    derived_resource(format ("%s%s.fv", x, r))
  end
end

%------------------------------------------------------------------ Obliq -----

readonly _OBLUME_FILES = ["ObliqView"]

readonly proc oblume(x, obl) is
  local any_stale = ""
  local evt_file = path_of(x & ".evt")

  import ("obliqparse")
  import ("obliqlibm3")
  import ("obliqlibanim")

  foreach p in _OBLUME_FILES
    local fn = format("%s%s%s", x, obl, p)

    if not any_stale
      any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
    end
    derived_interface(fn, VISIBLE)
    derived_implementation(fn)
  end

  if defined ("_all") and any_stale
    local cmd = [ _ZUME_EXEC, "-Obliq", path_of(obl), path_of(x) ]
    write(cmd, CR)
    local ret = exec(cmd)
    if not equal(ret, 0) error("command failed with error code: ", ret) end
  end

  resource(obl & ".obl")
end

%---------------------------------------------------------------- Obliq3D -----

readonly _OBLUME3D_FILES = ["Obliq3DView"]

readonly proc oblume3D(x, obl) is
  local any_stale = ""
  local evt_file = path_of(x & ".evt")

  import ("obliqparse")
  import ("obliqlibm3")
  import ("obliqlib3D")

  foreach p in _OBLUME3D_FILES
    local fn = format("%s%s%s", x, obl, p)

    if not any_stale
      any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
    end
    derived_interface(fn, VISIBLE)
    derived_implementation(fn)
  end

  if defined ("_all") and any_stale
    local cmd = [ _ZUME_EXEC, "-Obliq3D", path_of(obl), path_of(x) ]
    write(cmd, CR)
    local ret = exec(cmd)
    if not equal(ret, 0) error("command failed with error code: ", ret) end
  end

  resource(obl & ".obl")
end

%------------------------------------------------------------------ Juno -----

readonly _JUNOZUME_FILES = ["JunoView"]

readonly proc junozume(x, viewName) is
  local any_stale = ""
  local evt_file = path_of(x & ".evt")

  foreach p in _JUNOZUME_FILES
    local fn = format("%s%s%s", x, viewName, p)

    if not any_stale
      any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
    end
    derived_interface(fn, VISIBLE)
    derived_implementation(fn)
  end

  if defined ("_all") and any_stale
    local cmd = [ _ZUME_EXEC, "-Juno", viewName, path_of(x) ]
    write(cmd, CR)
    local ret = exec(cmd)
    if not equal(ret, 0) error("command failed with error code: ", ret) end
  end
end

%---------------------------------------------------------------------- gef ---
%  
%  readonly _GEFLUME_FILES = ["GEFView"]
%  
%  readonly proc geflume(x, gef) is
%    local any_stale = ""
%    local evt_file = path_of(x & ".evt")
%  
%    import ("gef")
%  
%    foreach p in _GEFLUME_FILES
%      local fn = format("%s%s%s", x, gef, p)
%  
%      if not any_stale
%        any_stale = stale(fn & ".i3", evt_file) or stale(fn & ".m3", evt_file)
%      end
%      derived_interface(fn, VISIBLE)
%      derived_implementation(fn)
%    end
%  
%    if defined ("_all") and any_stale
%      exec(_ZUME_EXEC, "-GEF", path_of(gef), path_of(x))
%    end
%  
%    resource(gef & ".gef")
%  end

