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.
11 set_param('rpp_lib', 'Lock', 'off');
12 blocks = find_system('rpp_lib', 'Type', 'block');
14 for i=1:length(blocks),
16 params = get_param(block, 'ObjectParameters');
17 fields = fieldnames(params);
19 disp(['Processing ' blocks{i}]);
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');
26 set_param('rpp_lib', 'Lock', 'on');
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']);
34 throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
37 function print_diff(fn, param, old, new)
38 fnold = [fn '.' param '.old'];
39 f = fopen(fnold, 'w');
40 fprintf(f, '%s', old);
43 fnnew = [fn '.' param '.new'];
44 f = fopen(fnnew, 'w');
45 fprintf(f, '%s', new);
48 [rc, diff] = system(['diff -u ' fnold ' ' fnnew]);
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);
58 if strcmp(param, 'MaskType') || ...
59 strcmp(param, 'MaskPromptString'),
60 new_content = deblank(new_content);
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)
68 set_param(block, param, new_content)