function str=buildUsage(S)
% buildUsage <Build usage line from parseUsage stucture.>
% Usage:: str=buildUsage(S)
%

% revision history:
% 04/24/16 Mark D. Shattuck <mds> buildUsage.m

%% Main

cap=find(lower(S.fn)-S.fn);
Ncap=length(cap);
name=[strSplit(S.fn,cap);num2cell(repmat(' ',1,Ncap+1))];
name=strtrim([name{:}]);
vars=S.iarg;
defs=S.iopt;
ovars=S.oarg;
isdefs=~cellfun('isempty',defs);

base=camelcase(name,true,false);  % compress camelcase first word lower

Nv=length(vars);
No=length(ovars);

str=sprintf('%% Usage:: ');
switch No
  case 0
    str=sprintf('%s%s(',str,base);
  case 1
    str=sprintf('%s%s=%s(',str,ovars{1},base);
  otherwise
    str=sprintf('%s[',str);
    for no=1:No
      str=sprintf('%s%s',str,ovars{no});
      if(S.oopt(no));
        str=sprintf('%s*',str);
      end
      if(no~=No);
        str=sprintf('%s,',str);
      end
    end
    str=sprintf('%s]=%s(',str,base);
end
for nv=1:Nv
  str=sprintf('%s%s',str,vars{nv});
  if(isdefs(nv))
    str=sprintf('%s[%s]',str,defs{nv});
  end
  if(nv~=Nv);
    str=sprintf('%s,',str);
  end
end
str=sprintf('%s)\n%%\n',str);


