%
% Author: Stanislaw Adaszewski, 2014
% http://algoholic.eu
%
% Fixes subs for use with Octave's builtin('subsref', ...'), builtin('subsasgn', ...)
%

function out = oct_fixsubs(obj, subs)
    %for i=1:numel(subs)
%	disp(i);
%	disp(subs(i));
%    end
    val = obj;
    out = struct('type', '', 'subs', {1});
    out(1) = [];
    for i=1:numel(subs)
	if subs(i).type == '.'
	    ret = oct_findfield(val, subs(i).subs);
	    try
		val = builtin('subsref', val, ret);
	    catch
	    end
	    out = [out ret];
	else
	    out(end+1) = subs(i);
	    try
		val = builtin('subsref', val, subs(i));
	    catch
	    end
	end
    end
end
