function [args,argstring] = getrargof(string,line,type)
%   This software is protected by german copyright and international treaties.             
%   Copyright 2004 Markus Junghöfer & Peter Peyk. All Rights Reserved.                     
%                                                                                          
%   THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE        
%   NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO,    
%   WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE    
%   OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS,
%   TRADEMARKS OR OTHER RIGHTS. COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT,       
%   INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE      
%   OR DOCUMENTATION.                                                                      

if nargin<3
    type = 0;
end


%normal brackets
%==================
if type == 0
        
	firstbracket = findstr(line,string)+length(string);
	if length(firstbracket)==1
		if strcmp(line(firstbracket),'(')
			restline = line(firstbracket+1:end);
			secondbracket = firstbracket + findstr(restline,')');
            if length(secondbracket)>1
                openbracks = firstbracket + findstr(restline,'(');
                allbr = [openbracks,secondbracket];
                allbr = sort(allbr);
                open = 1;
                for r=1:length(allbr)
                    if strcmp(line(allbr(r)),')')
                        open = open-1;
                    elseif strcmp(line(allbr(r)),'(')
                        open = open+1;
                    end
                    if open == 0
                        break
                    end
                end
                secondbracket = allbr(r);
                argstring = line(firstbracket+1:secondbracket-1);   
                kommata = findstr(argstring,',');
				nrofargs = length(kommata)+1;
				args = cell(1);
				if nrofargs ==1
                    args=[];
                    args= argstring;
				else
                    args{1}= argstring(1:kommata(1)-1);
					for t=2:nrofargs-1
                        args{t}=argstring(kommata(t-1)+1:kommata(t)-1);
                    end
                    args{nrofargs}=argstring(kommata(nrofargs-1)+1:end);
				end
                    
            else
				argstring = line(firstbracket+1:secondbracket-1);
				kommata = findstr(argstring,',');
				nrofargs = length(kommata)+1;
				args = cell(1);
				if nrofargs ==1
                    args=[];
                    args= argstring;
				else
                    args{1}= argstring(1:kommata(1)-1);
					for t=2:nrofargs-1
                        args{t}=argstring(kommata(t-1)+1:kommata(t)-1);
                    end
                    args{nrofargs}=argstring(kommata(nrofargs-1)+1:end);
				end
            end
		else
			argstring = line(firstbracket:end);
            firstbreak =min( [findstr(argstring,' '),findstr(argstring,';'),findstr(argstring,'*'),findstr(argstring,'+'),findstr(argstring,'-'),findstr(argstring,'.'),...
                    findstr(argstring,'/'),findstr(argstring,'\')])-1;
            if isempty(firstbreak)
                firstbreak = length(argstring);
            end
            args=argstring(1:firstbreak);
		end
	else
        for e=1:length(firstbracket)
            if strcmp(line(firstbracket(e)),'(')
				restline = line(firstbracket(e)+1:end);
				secondbracket = firstbracket(e) + findstr(restline,')');
				argstring = line(firstbracket(e)+1:secondbracket-1);
				kommata = findstr(argstring,',');
				nrofargs = length(kommata)+1;
				args = cell(1);
				if nrofargs ==1
                    args=[];
                    args= argstring;
				else
                    args{1}= argstring(1:kommata(1)-1);
					for t=2:nrofargs-1
                        args{t}=argstring(kommata(t-1)+1:kommata(t)-1);
                    end
                    args{nrofargs}=argstring(kommata(nrofargs-1)+1:end);
				end
			else
				argstring = line(firstbracket(e):end);
                firstbreak =min( [findstr(argstring,' '),findstr(argstring,';'),findstr(argstring,'*'),findstr(argstring,'+'),findstr(argstring,'-'),findstr(argstring,'.'),...
                        findstr(argstring,'/'),findstr(argstring,'\')])-1;
                if isempty(firstbreak)
                    firstbreak = length(argstring);
                end
                args=argstring(1:firstbreak);
			end
        end
	end
    
%cell
%==============
else
    firstbracket = findstr(line,string)+length(string);
	if length(firstbracket)==1
		if strcmp(line(firstbracket),'{')
			restline = line(firstbracket+1:end);
			secondbracket = firstbracket + findstr(restline,'}');
			argstring = line(firstbracket+1:secondbracket-1);
			kommata = findstr(argstring,',');
			nrofargs = length(kommata)+1;
			args = cell(1);
			if nrofargs ==1
                args=[];
                args= argstring;
			else
                args{1}= argstring(1:kommata(1)-1);
				for t=2:nrofargs-1
                    args{t}=argstring(kommata(t-1)+1:kommata(t)-1);
                end
                args{nrofargs}=argstring(kommata(nrofargs-1)+1:end);
			end
		else
			argstring = line(firstbracket:end);
            firstbreak =min( [findstr(argstring,' '),findstr(argstring,';'),findstr(argstring,'*'),findstr(argstring,'+'),findstr(argstring,'-'),findstr(argstring,'.'),...
                    findstr(argstring,'/'),findstr(argstring,'\')])-1;
            if isempty(firstbreak)
                firstbreak = length(argstring);
            end
            args=argstring(1:firstbreak);
		end
	else
        for e=1:length(firstbracket)
            if strcmp(line(firstbracket(e)),'{')
				restline = line(firstbracket(e)+1:end);
				secondbracket = firstbracket(e) + findstr(restline,'}');
				argstring = line(firstbracket(e)+1:secondbracket-1);
				kommata = findstr(argstring,',');
				nrofargs = length(kommata)+1;
				args = cell(1);
				if nrofargs ==1
                    args=[];
                    args= argstring;
				else
                    args{1}= argstring(1:kommata(1)-1);
					for t=2:nrofargs-1
                        args{t}=argstring(kommata(t-1)+1:kommata(t)-1);
                    end
                    args{nrofargs}=argstring(kommata(nrofargs-1)+1:end);
				end
			else
				argstring = line(firstbracket(e):end);
                firstbreak =min( [findstr(argstring,' '),findstr(argstring,';'),findstr(argstring,'*'),findstr(argstring,'+'),findstr(argstring,'-'),findstr(argstring,'.'),...
                        findstr(argstring,'/'),findstr(argstring,'\')])-1;
                if isempty(firstbreak)
                    firstbreak = length(argstring);
                end
                args=argstring(1:firstbreak);
			end
        end
	end
end

return