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 % 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.
29 block_libs = rpp_get_blocks();
31 for i=1:length(block_libs),
32 block_lib = block_libs{i};
33 last_updated = updated;
34 load_system(block_lib);
35 set_param(block_lib, 'Lock', 'off');
36 blocks = find_system(block_lib, 'Type', 'block');
37 for j=1:length(blocks),
39 params = get_param(block, 'ObjectParameters');
40 fields = fieldnames(params);
42 disp(['Processing ' blocks{j}]);
43 updated = updated + process_param(op, block, 'MaskType', '--masktype');
44 updated = updated + process_param(op, block, 'MaskDescription', '--html --printdesc');
45 updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
46 updated = updated + process_param(op, block, 'MaskHelp', '--html --printhelp');
47 updated = updated + process_param(op, block, 'Name', '--name'); % Name must be changed last!!!
49 set_param(block_lib, 'Lock', 'on');
50 if strcmp(op, 'update') && updated ~= last_updated,
51 save_system(block_lib);
53 close_system(block_lib);
56 function output = run_doc_parse(fn, opts)
57 % We have to unset Matlab's library path in order to run pandoc - it
58 % needs newer libc than the one shipped with Matlab
59 [rc, output] = system(['unset LD_LIBRARY_PATH; scripts/doc_parse.py ' opts ' ' fn '.c']);
62 throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
65 function print_diff(fn, param, old, new, diffopts)
66 fnold = [fn '.' param '.old'];
67 f = fopen(fnold, 'w');
68 fprintf(f, '%s', old);
71 fnnew = [fn '.' param '.new'];
72 f = fopen(fnnew, 'w');
73 fprintf(f, '%s', new);
76 [rc, diff] = system(['git --no-pager diff --no-index ' diffopts ' --word-diff=plain ' fnold ' ' fnnew]);
81 function updated = process_param(op, block, param, opts)
82 fn = get_param(block, 'FunctionName');
83 new_content = run_doc_parse(fn, opts);
84 old_content = get_param(block, param);
86 if strcmp(param, 'MaskType') || ...
87 strcmp(param, 'MaskPromptString') || ...
88 strcmp(param, 'Name'),
89 new_content = deblank(new_content);
92 if ~strcmp(old_content, new_content),
93 if strcmp(op, 'diff'),
94 disp([block ': ' param ' not up-to-date'])
95 print_diff(fn, param, old_content, new_content, '')
97 set_param(block, param, new_content)
98 print_diff(fn, param, old_content, new_content, '--no-color')