source: ResearchApps/PHY/WARPLAB/WARPLab7/M_Code_Reference/util/wl_cmd_list.m

Last change on this file was 5618, checked in by murphpo, 8 years ago

Updated wl_cmd_list to use 'unknown command' to detect the end of the command list switch. This allows command doc strings to use switch/case/otherwise without breaking the documentation generation script for later commands

File size: 4.5 KB
Line 
1function out = wl_cmd_list(class_name, varargin)
2%WL_CMD_LIST WARPLab command lister - lists available commands and their associated
3%help text.
4%
5% Example:
6% Input argument can be:
7% String:
8% wl_cmd_list('wl_node')
9%  Prints all commands/help for 'wl_node' class
10%
11% Class:
12% wl_cmd_list(wl_node)
13%  Prints all commands/help for 'wl_node' class
14%
15% Instance:
16% n = wl_node;
17% wl_cmd_list(n)
18%  Prints all commands/help for 'wl_node' class
19%
20% wl_cmd_list(n.baseband)
21%  Prints all commands/help for the node's baseband object
22
23%Use the first element if the user passes in a cell
24% Handles the case of wl_cmd_list(node.interfaceGroups)
25if(iscell(class_name))
26    class_name = class_name{1};
27end
28   
29if(ischar(class_name))
30    %wl_cmd_list('wl_node')
31    wl_file = which(class_name);
32elseif(isobject(class_name))
33    %wl_cmd_list(wl_node)
34    % OR
35    %node=wl_node;
36    %wl_cmd_list(node)
37    %wl_cmd_list(node.baseband)
38    wl_file = which(class(class_name));
39else
40    fprintf('\nError: input argument must be string or object');
41end
42
43if(~isempty(varargin) && strcmp(varargin{1}, 'wiki'))
44    do_wiki = 1;
45else
46    do_wiki = 0;
47end
48
49if(isempty(wl_file))
50    fprintf('\nError: class %s not found\n', class_name);
51    return;
52end
53
54CR = char(10);
55TAB = char(9);
56SEP = '--------------------';
57
58procCmd_line = 0;
59fid = fopen(wl_file);
60
61lnum = 0;
62res = [];
63
64%Find the 'function out=procCmd' section of the class
65while (procCmd_line == 0)
66    line = fgetl(fid);
67    lnum = lnum + 1;
68    if(line == -1)
69        %EOF - punt
70        fprintf('\nError: class %s does not contain a procCmd method\n', class_name);
71        return;
72    end
73
74    procCmd_ind = regexp(line, '^[ \t]*function.*procCmd', 'once');
75    if(~isempty(procCmd_ind))
76        %Found the procCmd function
77        procCmd_line = lnum;
78    end
79end
80
81%Check for a case block for the requested command
82% This loop is skipped if no procCmd function was found
83while (procCmd_line > 0)
84    line = fgetl(fid);
85    lnum = lnum + 1;
86
87    if(line == -1)
88        %EOF - punt
89        break;
90    end
91       
92    %Check if we've reached the end of the procCmd switch/case
93%    endcase_ind = regexp(line, '^[ \t]*otherwise', 'once');
94    endcase_ind = regexp(line, 'error(''unknown command', 'once');
95    if(~isempty(endcase_ind))
96        %End of procCmd; punt
97        break;
98    end
99       
100    %Check if this has a "case 'some_cmd'" string
101     match = regexpi(line,'^[ \t]*case[ \t]+''(?<cmd_str>\S+)''','names');
102   
103    if(~isempty(match))
104        if(~do_wiki)
105            %Found a command; retrieve all following lines until a non-comment is found
106            res = [res CR match.cmd_str ':' CR];
107            while 1
108                line = fgetl(fid);
109                txt_ind = regexp(line, '^[ \t]*%', 'end', 'once');
110                if(~isempty(txt_ind))
111                    res = [res CR TAB line(txt_ind+1:end)];
112                else
113                    res = [res CR CR SEP CR];
114                    break;
115                end
116            end
117        else
118            res = [res CR '=== {{{' match.cmd_str '}}} ==='];
119            while 1
120                line = fgetl(fid);
121                line = strrep(line, '[', '![');
122                txt_ind = regexp(line, '^[ \t]*%\s*', 'end', 'once');
123                args_ind = regexp(line, '^[ \t]*%\s* Arguments:', 'end', 'once');
124                rets_ind = regexp(line, '^[ \t]*%\s* Returns:', 'end', 'once');
125                buffsel_ind = regexp(line, '^[ \t]*%\s* Requires BUFF_SEL:', 'end', 'once');
126                anytext_ind = regexp(line,'^[ \t]*%\s*\w+', 'end', 'once');
127               
128                if(~isempty(txt_ind))
129                    %Got another documentation line
130                    if(~isempty(args_ind))
131                        res = [res CR CR '''''''Arguments:''''''' line(args_ind+1:end)];
132                    elseif(~isempty(rets_ind))
133                        res = [res CR CR '''''''Returns:''''''' line(rets_ind+1:end)];
134                    elseif(~isempty(buffsel_ind))
135                        res = [res CR CR '''''''Requires BUFF_SEL:''''''' line(buffsel_ind+1:end)];
136                    elseif(~isempty(anytext_ind))
137                        res = [res CR line(txt_ind+1:end) '[[BR]]'];
138                    else
139                        res = [res CR line(txt_ind+1:end)];
140                    end
141                else
142                    res = [res CR CR];
143                    break;
144                end
145            end
146        end
147    end
148end
149
150fclose(fid);
151
152out = res;
Note: See TracBrowser for help on using the repository browser.