forked from lmendo/MATL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matl_help.m
79 lines (74 loc) · 2.72 KB
/
matl_help.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function matl_help(H, strHelp, verbose, useTags)
%
% MATL help.
%
% Search for input string and show corresponding help.
%
% Luis Mendo
if verbose
disp('MATL help:')
end
if useTags
strongBegin = '<strong>';
strongEnd = '</strong>';
else
strongBegin = '';
strongEnd = '';
end
if isempty(strHelp) || strcmp(strHelp,'help') % empty string: show help usage and return
if verbose
fprintf(' General help\n')
fprintf('\n')
end
fprintf('%smatl%s usage:\n', strongBegin, strongEnd)
fprintf('First input: options:\n')
fprintf(' %s-p%s: parse\n', strongBegin, strongEnd)
fprintf(' %s-l%s: listing. Numeric options specify format\n', strongBegin, strongEnd)
fprintf(' %s-e%s: listing with comments. Numeric options specify format\n', strongBegin, strongEnd)
fprintf(' %s-c%s: compile\n', strongBegin, strongEnd)
fprintf(' %s-r%s: run (default)\n', strongBegin, strongEnd)
fprintf(' %s-d%s: debug\n', strongBegin, strongEnd)
fprintf(' %s-f%s: use file\n', strongBegin, strongEnd)
fprintf(' %s-v%s: verbose\n', strongBegin, strongEnd)
fprintf(' %s-h%s: help\n', strongBegin, strongEnd)
fprintf(' %s-o%s: online mode\n', strongBegin, strongEnd)
fprintf('Second input: string:\n')
fprintf(' Contains source code, file name or search text\n')
fprintf(' Source code or file name can be omitted, to be introduced later\n')
fprintf(' Search text can be a name of function or statement, or a word.\n')
return
elseif numel(strHelp)==1 || (numel(strHelp)==2 && any(strHelp(1)=='XYZ')) % search in source
if verbose
fprintf(' Searching for statement with exact matching\n')
end
ind = find(strcmp(H.sourcePlain, strHelp)); % exact search in source
elseif ~isempty(strHelp) % search in comment or description
if verbose
fprintf(' Searching for text, case-insensitive, partial matching\n')
end
ind = find(~cellfun(@isempty, strfind(lower(H.comm), lower(strHelp))) |...
~cellfun(@isempty, strfind(lower(H.descrPlain), lower(strHelp)))); % partial, case-insentive search in comment and description
end
if verbose && ~isempty(ind)
disp(' ')
end
if useTags
descrFieldName = 'descr';
sourceFieldName = 'source';
else
descrFieldName = 'descrNoTags';
sourceFieldName = 'sourcePlain';
end
for n = ind
disp([H.(sourceFieldName){n} repmat(' ',1,4-numel(H.sourcePlain{n})) H.comm{n}]) % one or two spaces for left margin, total four characters
if H.inOutTogether{n}
disp([' ' H.in{n}, '; ' H.out{n}]) % four spaces for left margin
else
disp([' ' H.in{n}, ';'])
disp([' ' H.out{n}])
end
disp(H.(descrFieldName){n})
end
if verbose && ~isempty(ind)
disp(' ')
end