1 % Copyright (C) 2013-2015 Czech Technical University in Prague
4 % - Carlos Jenkins <carlos@jenkins.co.cr>
5 % - Michal Sojka <sojkam1@fel.cvut.cz>
7 % Permission is hereby granted, free of charge, to any person
8 % obtaining a copy of this software and associated documentation
9 % files (the "Software"), to deal in the Software without
10 % restriction, including without limitation the rights to use,
11 % copy, modify, merge, publish, distribute, sublicense, and/or sell
12 % copies of the Software, and to permit persons to whom the
13 % Software is furnished to do so, subject to the following
16 % The above copyright notice and this permission notice shall be
17 % included in all copies or substantial portions of the Software.
19 % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 % EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 % OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 % NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 % HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 % WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 % FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 % OTHER DEALINGS IN THE SOFTWARE.
28 % File : compile_blocks.m
30 % Compile all the C-MEX S-Function in current folder.
33 % http://www.mathworks.com/help/matlab/ref/mex.html
34 % http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
36 function updated = rpp_update_doc(varargin)
37 % RPP_UPDATE_DOC Update built-in S-functions documentation.
38 % The documentation is updated based on the YAML comment in .c files.
39 % The number of updated blocks is returned.
45 block_libs = rpp_get_blocks();
47 for i=1:length(block_libs),
48 block_lib = block_libs{i};
49 last_updated = updated;
50 load_system(block_lib);
51 set_param(block_lib, 'Lock', 'off');
52 blocks = find_system(block_lib, 'Type', 'block');
53 for j=1:length(blocks),
55 params = get_param(block, 'ObjectParameters');
56 fields = fieldnames(params);
58 disp(['Processing ' blocks{j}]);
59 updated = updated + process_param(op, block, 'MaskType', '--masktype');
60 updated = updated + process_param(op, block, 'MaskDescription', '--html --printdesc');
61 updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
62 updated = updated + process_param(op, block, 'MaskHelp', '--html --printhelp');
63 updated = updated + process_param(op, block, 'Name', '--name'); % Name must be changed last!!!
65 set_param(block_lib, 'Lock', 'on');
66 if strcmp(op, 'update') && updated ~= last_updated,
67 save_system(block_lib);
69 close_system(block_lib);
72 function output = run_doc_parse(fn, opts)
73 % We have to unset Matlab's library path in order to run pandoc - it
74 % needs newer libc than the one shipped with Matlab
75 [rc, output] = system(['unset LD_LIBRARY_PATH; scripts/doc_parse.py ' opts ' ' fn '.c']);
78 throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
81 function print_diff(fn, param, old, new, diffopts)
82 fnold = [fn '.' param '.old'];
83 f = fopen(fnold, 'w');
84 fprintf(f, '%s', old);
87 fnnew = [fn '.' param '.new'];
88 f = fopen(fnnew, 'w');
89 fprintf(f, '%s', new);
92 [rc, diff] = system(['git --no-pager diff --no-index ' diffopts ' --word-diff=plain ' fnold ' ' fnnew]);
97 function updated = process_param(op, block, param, opts)
98 fn = get_param(block, 'FunctionName');
99 new_content = run_doc_parse(fn, opts);
100 old_content = get_param(block, param);
102 if strcmp(param, 'MaskType') || ...
103 strcmp(param, 'MaskPromptString') || ...
104 strcmp(param, 'Name'),
105 new_content = deblank(new_content);
108 if ~strcmp(old_content, new_content),
109 if strcmp(op, 'diff'),
110 disp([block ': ' param ' not up-to-date'])
111 print_diff(fn, param, old_content, new_content, '')
113 set_param(block, param, new_content)
114 print_diff(fn, param, old_content, new_content, '--no-color')