1 % Copyright (C) 2013-2014 Czech Technical University in Prague
4 % - Carlos Jenkins <carlos@jenkins.co.cr>
5 % - Michal Sojka <sojkam1@fel.cvut.cz>
7 % This document contains proprietary information belonging to Czech
8 % Technical University in Prague. Passing on and copying of this
9 % document, and communication of its contents is not permitted
10 % without prior written authorization.
12 % File : compile_blocks.m
14 % Compile all the C-MEX S-Function in current folder.
17 % http://www.mathworks.com/help/matlab/ref/mex.html
18 % http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
20 function updated = rpp_update_doc(varargin)
21 % RPP_UPDATE_DOC Update built-in S-functions documentation.
22 % The documentation is updated based on the YAML comment in .c files.
23 % The number of updated blocks is returned.
30 set_param('rpp_lib', 'Lock', 'off');
31 blocks = find_system('rpp_lib', 'Type', 'block');
33 for i=1:length(blocks),
35 params = get_param(block, 'ObjectParameters');
36 fields = fieldnames(params);
38 disp(['Processing ' blocks{i}]);
40 updated = updated + process_param(op, block, 'MaskType', '--masktype');
41 updated = updated + process_param(op, block, 'MaskDescription', '--html --printdesc');
42 updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
43 updated = updated + process_param(op, block, 'MaskHelp', '--html --printhelp');
44 updated = updated + process_param(op, block, 'Name', '--name'); % Name must be changed last!!!
46 set_param('rpp_lib', 'Lock', 'on');
48 function output = run_doc_parse(fn, opts)
49 % We have to unset Matlab's library path in order to run pandoc - it
50 % needs newer libc than the one shipped with Matlab
51 [rc, output] = system(['unset LD_LIBRARY_PATH; scripts/doc_parse.py ' opts ' ' fn '.c']);
54 throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
57 function print_diff(fn, param, old, new)
58 fnold = [fn '.' param '.old'];
59 f = fopen(fnold, 'w');
60 fprintf(f, '%s', old);
63 fnnew = [fn '.' param '.new'];
64 f = fopen(fnnew, 'w');
65 fprintf(f, '%s', new);
68 [rc, diff] = system(['diff -u ' fnold ' ' fnnew]);
73 function updated = process_param(op, block, param, opts)
74 fn = get_param(block, 'FunctionName');
75 new_content = run_doc_parse(fn, opts);
76 old_content = get_param(block, param);
78 if strcmp(param, 'MaskType') || ...
79 strcmp(param, 'MaskPromptString') || ...
80 strcmp(param, 'Name'),
81 new_content = deblank(new_content);
84 if ~strcmp(old_content, new_content),
85 if strcmp(op, 'diff'),
86 disp([block ': ' param ' not up-to-date'])
87 print_diff(fn, param, old_content, new_content)
89 set_param(block, param, new_content)