-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyahelp.m
134 lines (116 loc) · 3.37 KB
/
yahelp.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
function out = yahelp(yafile, section)
% YAHELP - Display the help associated with a YAWTB file.
%
% This function displays a user-friendly help section of any YAWTB function.
%
% Syntax:
% yahelp yafile
% yahelp(yafile [, section])
%
% Inputs:
% yafile - STRING: The name of the file.
% section - SET OF STRING (optional): Specifies which part of the help must be displayed.
% Type yahelp([]) to obtain a complete list of available sections.
%
% Example:
% yahelp yashow
% yahelp yashow syntax
%
%% Input manipulations
if ~exist('yafile', 'var')
yafile = 'yahelp';
end
if ~exist('section', 'var')
section = '';
else
section = upper(section);
end
%% Elements to replace
actions = {
'\manchap', upper(yafile), ...
'\mansecSyntax', 'SYNTAX', ...
'\mansecDescription', 'DESCRIPTION', ...
'\mansubsecInputData', 'INPUTS', ...
'\mansubsecOutputData', 'OUTPUTS', ...
'\mansecExample', 'EXAMPLE', ...
'\mansecReference', 'REFERENCE', ...
'\mansecSeeAlso', 'SEE ALSO', ...
'\mansecLicense', 'LICENSE:', ...
'\begin{description}', '', ...
'\end{description}', '', ...
'\item[', '* [', ...
'\begin{itemize}', '', ...
'\end{itemize}', '', ...
'\item', '- ', ...
'\begin{code}', '', ...
'\end{code}', '', ...
'\url{"', '"', ...
'\libfun{', '''', ...
'\libvar{', '''', ...
'\', '', ...
'$', '' };
%% Possible marks. Order is important.
marks = { 'USAGE', 'SYNTAX', 'DESCRIPTION', ...
'INPUTS', 'OUTPUTS', 'CODE', 'EXAMPLE', ...
'REFERENCE', 'SEE ALSO', 'LICENSE' };
if mod(length(actions), 2) ~= 0
error('Check your actions of replacement');
end
%% Recording standard help
helpfun = help(yafile);
%% Additional pattern replacements for sections other than 'CODE' and 'EXAMPLE'
if ~strcmp(section, 'CODE') && ~strcmp(section, 'EXAMPLE')
actions = [actions, ...
'{"', '"', ...
'{', '''', ...
'"}', '"', ...
'}', ''''];
end
%% Processing replacements
for k = 1:2:length(actions)
helpfun = strrep(helpfun, actions{k}, actions{k+1});
end
%% Handle section extraction
if isempty(section)
%% Removing License specification
helpfun(strfind(helpfun, 'LICENSE'):end) = '';
else
if ~any(strcmp(marks, section))
error('This section is not valid');
end
%% Possible synonyms
switch section
case 'USAGE'
section = 'SYNTAX';
case 'CODE'
section = 'EXAMPLE';
end
first = strfind(helpfun, section);
if isempty(first)
if nargout == 1
out = '';
end
return;
end
section_id = find(strcmp(marks, section));
section_id = section_id(1);
nb_sections = length(marks);
last = [];
k = 1;
while isempty(last) && ((section_id + k) < nb_sections)
next_section = marks{section_id + k};
last = strfind(helpfun, next_section);
k = k + 1;
end
if isempty(last)
helpfun = helpfun(first:end);
else
helpfun = helpfun(first:last-1);
end
end
if nargout == 1
out = helpfun;
else
disp(helpfun);
end
end