0001 function s = mfileparse(mfile, mdirs, names, options)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 error(nargchk(3,4,nargin));
0022 if nargin == 3,
0023 options = struct('verbose',1, 'globalHypertextLinks',0, 'todo',0);
0024 end
0025
0026
0027 strtok_delim = sprintf(' \t\n\r(){}[]<>+-*~!|\\@&/,:;="''%%');
0028
0029
0030 fid = openfile(mfile,'r');
0031 it = 0;
0032
0033
0034 s = struct('synopsis', '', ...
0035 'h1line', '', ...
0036 'subroutine', {{}}, ...
0037 'hrefs', sparse(1,length(names)), ...
0038 'todo', struct('line',[],'comment',{{}}), ...
0039 'ismex', zeros(size(mexexts)));
0040
0041
0042 flagsynopcont = 0;
0043
0044
0045
0046 while 1
0047 tline = fgetl(fid);
0048 if ~ischar(tline), break, end
0049 it = it + 1;
0050 tline = deblank(fliplr(deblank(fliplr(tline))));
0051
0052 if ~isempty(strmatch('function',tline))
0053 s.synopsis = tline;
0054 if ~isempty(strmatch('...',fliplr(tline)))
0055 flagsynopcont = 1;
0056 s.synopsis = deblank(s.synopsis(1:end-3));
0057 end
0058
0059 elseif ~isempty(strmatch('%',tline))
0060
0061 if isempty(s.h1line)
0062 s.h1line = fliplr(deblank(tline(end:-1:2)));
0063 end
0064 if ~isempty(s.synopsis), break, end
0065
0066 elseif isempty(tline)
0067
0068
0069 else
0070 if flagsynopcont
0071 if isempty(strmatch('...',fliplr(tline)))
0072 s.synopsis = [s.synopsis tline];
0073 flagsynopcont = 0;
0074 else
0075 s.synopsis = [s.synopsis deblank(tline(1:end-3))];
0076 end
0077 else
0078 break;
0079 end
0080 end
0081 end
0082
0083
0084
0085
0086 if options.globalHypertextLinks
0087 hrefnames = names;
0088 else
0089 indhref = find(strcmp(fileparts(mfile),mdirs));
0090 hrefnames = {names{indhref}};
0091 end
0092
0093
0094
0095 while ischar(tline)
0096
0097 tline = deblank(fliplr(deblank(fliplr(tline))));
0098
0099
0100 splitc = splitcode(tline);
0101 for j=1:length(splitc)
0102 if isempty(splitc{j}) | ...
0103 splitc{j}(1) == '''' | ...
0104 ~isempty(strmatch('...',splitc{j}))
0105
0106 elseif splitc{j}(1) == '%'
0107
0108
0109 if options.todo
0110 if ~isempty(strmatch('% TODO',splitc{j})) | ...
0111 ~isempty(strmatch('% FIXME',splitc{j}))
0112 s.todo.line = [s.todo.line it];
0113 s.todo.comment{end+1} = splitc{j}(9:end);
0114 end
0115 end
0116 else
0117
0118 if ~isempty(strmatch('function',splitc{j}))
0119 s.subroutine{end+1} = splitc{j};
0120 else
0121
0122 symbol = {};
0123 while 1
0124 [t,splitc{j}] = strtok(splitc{j},strtok_delim);
0125 if isempty(t), break, end;
0126 symbol{end+1} = t;
0127 end
0128 if options.globalHypertextLinks
0129 s.hrefs = s.hrefs + ismember(hrefnames,symbol);
0130 else
0131 if ~isempty(indhref)
0132 s.hrefs(indhref) = s.hrefs(1,indhref) + ...
0133 ismember(hrefnames,symbol);
0134 end
0135 end
0136 end
0137 end
0138 end
0139 tline = fgetl(fid);
0140 it = it + 1;
0141 end
0142
0143 fclose(fid);
0144
0145
0146 [pathstr,name] = fileparts(mfile);
0147 samename = dir(fullfile(pathstr,[name '.*']));
0148 samename = {samename.name};
0149 ext = {};
0150 for i=1:length(samename)
0151 [dummy, dummy, ext{i}] = fileparts(samename{i});
0152 end
0153 s.ismex = ismember(mexexts,ext);