[1988] | 1 | function out = wl_cmd_list(class_name, varargin) |
---|
[1971] | 2 | %WL_CMD_LIST WARPLab command lister - lists available commands and their associated |
---|
| 3 | %help text. |
---|
| 4 | % |
---|
| 5 | % Example: |
---|
| 6 | % Input argument can be: |
---|
[1915] | 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 |
---|
[1960] | 24 | % Handles the case of wl_cmd_list(node.interfaceGroups) |
---|
[1915] | 25 | if(iscell(class_name)) |
---|
| 26 | class_name = class_name{1}; |
---|
| 27 | end |
---|
| 28 | |
---|
| 29 | if(ischar(class_name)) |
---|
| 30 | %wl_cmd_list('wl_node') |
---|
| 31 | wl_file = which(class_name); |
---|
| 32 | elseif(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)); |
---|
| 39 | else |
---|
| 40 | fprintf('\nError: input argument must be string or object'); |
---|
| 41 | end |
---|
| 42 | |
---|
[1988] | 43 | if(~isempty(varargin) && strcmp(varargin{1}, 'wiki')) |
---|
| 44 | do_wiki = 1; |
---|
| 45 | else |
---|
| 46 | do_wiki = 0; |
---|
| 47 | end |
---|
| 48 | |
---|
[1915] | 49 | if(isempty(wl_file)) |
---|
| 50 | fprintf('\nError: class %s not found\n', class_name); |
---|
| 51 | return; |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | CR = char(10); |
---|
| 55 | TAB = char(9); |
---|
| 56 | SEP = '--------------------'; |
---|
| 57 | |
---|
| 58 | procCmd_line = 0; |
---|
| 59 | fid = fopen(wl_file); |
---|
| 60 | |
---|
| 61 | lnum = 0; |
---|
| 62 | res = []; |
---|
| 63 | |
---|
| 64 | %Find the 'function out=procCmd' section of the class |
---|
| 65 | while (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 |
---|
| 79 | end |
---|
| 80 | |
---|
| 81 | %Check for a case block for the requested command |
---|
| 82 | % This loop is skipped if no procCmd function was found |
---|
| 83 | while (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 |
---|
[5618] | 93 | % endcase_ind = regexp(line, '^[ \t]*otherwise', 'once'); |
---|
| 94 | endcase_ind = regexp(line, 'error(''unknown command', 'once'); |
---|
[1915] | 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)) |
---|
[1988] | 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 |
---|
[1915] | 116 | end |
---|
[1988] | 117 | else |
---|
| 118 | res = [res CR '=== {{{' match.cmd_str '}}} ===']; |
---|
| 119 | while 1 |
---|
| 120 | line = fgetl(fid); |
---|
[1989] | 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 | |
---|
[1988] | 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)]; |
---|
[1989] | 136 | elseif(~isempty(anytext_ind)) |
---|
| 137 | res = [res CR line(txt_ind+1:end) '[[BR]]']; |
---|
[1988] | 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 |
---|
[1915] | 146 | end |
---|
| 147 | end |
---|
| 148 | end |
---|
| 149 | |
---|
| 150 | fclose(fid); |
---|
| 151 | |
---|
| 152 | out = res; |
---|