1 | function wl_cmd_doc(cmd_str) |
---|
2 | %WL_CMD_DOC WARPLab Command Documentation Printer |
---|
3 | %This function prints documentation for individual commands based on the |
---|
4 | %command string provided as the argument. |
---|
5 | % |
---|
6 | % Example: |
---|
7 | % wl_cmd_doc('write_IQ') |
---|
8 | |
---|
9 | [wl_path, dummy_var0, dummy_var1] = fileparts(which('wl_node')); |
---|
10 | |
---|
11 | file_list = what(wl_path); |
---|
12 | files = {file_list.m{:}, file_list.classes{:}}; |
---|
13 | |
---|
14 | found_cmd_glbl = 0; |
---|
15 | CR = char(10); |
---|
16 | TAB = char(9); |
---|
17 | for n = 1:length(files) |
---|
18 | procCmd_line = 0; |
---|
19 | cmd_line = 0; |
---|
20 | found_cmd = 0; |
---|
21 | cur_file = files{n}; |
---|
22 | fid = fopen(cur_file); |
---|
23 | |
---|
24 | lnum = 0; |
---|
25 | res = []; |
---|
26 | |
---|
27 | %Find the 'function out=procCmd' section of the class |
---|
28 | while (procCmd_line == 0) |
---|
29 | line = fgetl(fid); |
---|
30 | lnum = lnum + 1; |
---|
31 | if(line == -1) |
---|
32 | %EOF - punt |
---|
33 | break; |
---|
34 | end |
---|
35 | |
---|
36 | procCmd_ind = regexp(line, '^[ \t]*function.*procCmd', 'once'); |
---|
37 | if(~isempty(procCmd_ind)) |
---|
38 | %Found the procCmd function |
---|
39 | procCmd_line = lnum; |
---|
40 | end |
---|
41 | end |
---|
42 | |
---|
43 | %Check for a case block for the requested command |
---|
44 | % This loop is skipped if no procCmd function was found |
---|
45 | while (procCmd_line > 0 && cmd_line == 0) |
---|
46 | line = fgetl(fid); |
---|
47 | lnum = lnum + 1; |
---|
48 | |
---|
49 | if(line == -1) |
---|
50 | %EOF - punt |
---|
51 | break; |
---|
52 | end |
---|
53 | |
---|
54 | %Check if we've reached the end of the procCmd switch/case |
---|
55 | endcase_ind = regexp(line, '^[ \t]*otherwise', 'once'); |
---|
56 | if(~isempty(endcase_ind)) |
---|
57 | %End of procCmd; punt |
---|
58 | break; |
---|
59 | end |
---|
60 | |
---|
61 | %Check if this line matches the requested command string |
---|
62 | cmd_ind = regexpi(line, ['^[ \t]*case[ \t]+''' cmd_str ''], 'once'); |
---|
63 | |
---|
64 | if(~isempty(cmd_ind)) |
---|
65 | %Found the command; retrieve all following lines until a non-comment is found |
---|
66 | found_cmd = 1; |
---|
67 | cmd_line = lnum; |
---|
68 | while 1 |
---|
69 | line = fgetl(fid); |
---|
70 | txt_ind = regexp(line, '^[ \t]*%', 'end', 'once'); |
---|
71 | if(~isempty(txt_ind)) |
---|
72 | res = [res CR TAB line(txt_ind+1:end)]; |
---|
73 | else |
---|
74 | break; |
---|
75 | end |
---|
76 | end |
---|
77 | end |
---|
78 | end |
---|
79 | |
---|
80 | if(found_cmd) |
---|
81 | fprintf('\rCommand ''%s'' found in %s (line %d):', lower(cmd_str), cur_file, cmd_line) |
---|
82 | fprintf('%s\r\r', res) |
---|
83 | end |
---|
84 | |
---|
85 | fclose(fid); |
---|
86 | found_cmd_glbl = found_cmd_glbl || found_cmd; |
---|
87 | end |
---|
88 | |
---|
89 | if(~found_cmd_glbl) |
---|
90 | fprintf('\r\tCommand %s not found\r\r', cmd_str) |
---|
91 | end |
---|