]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/blocks/rpp_update_doc.m
Merge branch 'master' of rtime.felk.cvut.cz:jenkicar/rpp-simulink
[pes-rpp/rpp-simulink.git] / rpp / blocks / rpp_update_doc.m
1 function updated = rpp_update_doc(varargin)
2 % RPP_UPDATE_DOC Update built-in S-functions documentation.
3 %    The documentation is updated based on the YAML comment in .c files.
4 %    The number of updated blocks is returned.
5 if nargin > 0,
6     op = varargin{1};
7 else
8     op = 'update';
9 end
10 open('rpp_lib');
11 set_param('rpp_lib', 'Lock', 'off');
12 blocks = find_system('rpp_lib', 'Type', 'block');
13 updated = 0;
14 for i=1:length(blocks),
15     block = blocks{i};
16     params = get_param(block, 'ObjectParameters');
17     fields = fieldnames(params);
18
19     disp(['Processing ' blocks{i}]);
20
21     updated = updated + process_param(op, block, 'MaskHelp', '--html');
22     updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
23     updated = updated + process_param(op, block, 'MaskType', '--masktype');
24     %updated = updated + process_param(op, block, 'MaskDescription', '--maskdesc');
25 end
26 set_param('rpp_lib', 'Lock', 'on');
27
28 function output = run_doc_parse(fn, opts)
29     % We have to unset Matlab's library path in order to run pandoc - it
30     % needs newer libc than the one shipped with Matlab
31     [rc, output] = system(['unset LD_LIBRARY_PATH; scripts/doc_parse.py ' opts ' ' fn '.c']);
32     if rc ~= 0,
33         disp(output)
34         throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
35     end
36
37 function print_diff(fn, param, old, new)
38     fnold = [fn '.' param '.old'];
39     f = fopen(fnold, 'w');
40     fprintf(f, '%s', old);
41     fclose(f);
42
43     fnnew = [fn '.' param '.new'];
44     f = fopen(fnnew, 'w');
45     fprintf(f, '%s', new);
46     fclose(f);
47
48     [rc, diff] = system(['diff -u ' fnold ' ' fnnew]);
49     disp(diff);
50     delete(fnold);
51     delete(fnnew);
52
53 function updated = process_param(op, block, param, opts)
54     fn = get_param(block, 'FunctionName');
55     new_content = run_doc_parse(fn, opts);
56     old_content = get_param(block, param);
57
58     if strcmp(param, 'MaskType') || ...
59        strcmp(param, 'MaskPromptString'),
60         new_content = deblank(new_content);
61     end
62
63     if ~strcmp(old_content, new_content),
64         if strcmp(op, 'diff'),
65             disp([block ': ' param ' not up-to-date'])
66             print_diff(fn, param, old_content, new_content)
67         else
68             set_param(block, param, new_content)
69         end
70         updated = 1;
71     else
72         updated = 0;
73     end