function opt = svn_options(varargin)

% svn_options - get and set svn options
% -------------------------------------
%
% opt = svn_options
%
% svn_options('field', value, ...)
%
% Input:
% ------
%  field - svn option field name
%  value - svn option field value
%
% Output:
% -------
%  opt - svn options structure

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 1180 $
% $Date: 2005-07-15 17:22:21 -0400 (Fri, 15 Jul 2005) $
%--------------------------------

% NOTE: there is some interesting dynamic code in this function

%--
% set prototype structure and defaults
%--

persistent SVN_OPTION;

if isempty(SVN_OPTION)
		
	SVN_OPTION.block = 0;
	
	SVN_OPTION.close = 0;
	
end

%--
% call set or get depending on number of inputs
%--

% NOTE: the exception creates an independent get of defaults

try
	if ~nargin
		opt = get_svn_options(SVN_OPTION);
	else
		opt = set_svn_options(SVN_OPTION, varargin{:});
	end
catch	
	opt = SVN_OPTION;
end


%----------------------------------------------------------
% GET_SVN_OPTIONS
%----------------------------------------------------------

function opt = get_svn_options(opt)

fields = fieldnames(opt);

for k = 1:length(fields)

	%--
	% build option enviroment name
	%--
	
	var = ['svn_', fields{k}];

	%--
	% get value for options field from environment variable
	%--
	
	value = get_env(var);

	if ~isempty(value)
		opt.(fields{k}) = value;
	end

end


%----------------------------------------------------------
% SET_SVN_OPTIONS
%----------------------------------------------------------

function opt = set_svn_options(opt, varargin)

%--
% get and update options structure
%--

opt = get_svn_options(opt);

opt = parse_inputs(opt, varargin{:});

%--
% set environment variables
%--

fields = fieldnames(opt);

for k = 1:length(fields)

	%--
	% build option enviroment name
	%--
	
	var = ['svn_', fields{k}];

	%--
	% set value of environment variables from option fields
	%--
	
	set_env(var, opt.(fields{k}));
	
end

