]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/blocks/rpp_update_doc.m
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / blocks / rpp_update_doc.m
index 85daa9a8f4b5b9995d1099d944edcb13a1042263..cf6f102a541252572cf588aa0d5ff4ea85ac0ac8 100644 (file)
@@ -1,3 +1,38 @@
+% Copyright (C) 2013-2015 Czech Technical University in Prague
+%
+% Authors:
+%     - Carlos Jenkins <carlos@jenkins.co.cr>
+%     - Michal Sojka <sojkam1@fel.cvut.cz>
+%
+% Permission is hereby granted, free of charge, to any person
+% obtaining a copy of this software and associated documentation
+% files (the "Software"), to deal in the Software without
+% restriction, including without limitation the rights to use,
+% copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the
+% Software is furnished to do so, subject to the following
+% conditions:
+
+% The above copyright notice and this permission notice shall be
+% included in all copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+% OTHER DEALINGS IN THE SOFTWARE.
+%
+% File : compile_blocks.m
+% Abstract:
+%     Compile all the C-MEX S-Function in current folder.
+%
+% References:
+%     http://www.mathworks.com/help/matlab/ref/mex.html
+%     http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
+
 function updated = rpp_update_doc(varargin)
 % RPP_UPDATE_DOC Update built-in S-functions documentation.
 %    The documentation is updated based on the YAML comment in .c files.
@@ -7,23 +42,32 @@ if nargin > 0,
 else
     op = 'update';
 end
-open('rpp_lib');
-set_param('rpp_lib', 'Lock', 'off');
-blocks = find_system('rpp_lib', 'Type', 'block');
+block_libs = rpp_get_blocks();
 updated = 0;
-for i=1:length(blocks),
-    block = blocks{i};
-    params = get_param(block, 'ObjectParameters');
-    fields = fieldnames(params);
+for i=1:length(block_libs),
+    block_lib = block_libs{i};
+    last_updated = updated;
+    load_system(block_lib);
+    set_param(block_lib, 'Lock', 'off');
+    blocks = find_system(block_lib, 'Type', 'block');
+    for j=1:length(blocks),
+        block = blocks{j};
+        params = get_param(block, 'ObjectParameters');
+        fields = fieldnames(params);
 
-    disp(['Processing ' blocks{i}]);
-
-    updated = updated + process_param(op, block, 'MaskType', '--masktype');
-    updated = updated + process_param(op, block, 'MaskDescription', '--html --printdesc');
-    updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
-    updated = updated + process_param(op, block, 'MaskHelp', '--html --printhelp');
+        disp(['Processing ' blocks{j}]);
+        updated = updated + process_param(op, block, 'MaskType', '--masktype');
+        updated = updated + process_param(op, block, 'MaskDescription', '--html --printdesc');
+        updated = updated + process_param(op, block, 'MaskPromptString', '--maskpromptstring');
+        updated = updated + process_param(op, block, 'MaskHelp', '--html --printhelp');
+        updated = updated + process_param(op, block, 'Name', '--name'); % Name must be changed last!!!
+    end
+    set_param(block_lib, 'Lock', 'on');
+    if strcmp(op, 'update') && updated ~= last_updated,
+        save_system(block_lib);
+    end
+    close_system(block_lib);
 end
-set_param('rpp_lib', 'Lock', 'on');
 
 function output = run_doc_parse(fn, opts)
     % We have to unset Matlab's library path in order to run pandoc - it
@@ -34,7 +78,7 @@ function output = run_doc_parse(fn, opts)
         throw(MException('rpp:pandoc_failure', ['Failed to extract doc from ' fn '.c']))
     end
 
-function print_diff(fn, param, old, new)
+function print_diff(fn, param, old, new, diffopts)
     fnold = [fn '.' param '.old'];
     f = fopen(fnold, 'w');
     fprintf(f, '%s', old);
@@ -45,7 +89,7 @@ function print_diff(fn, param, old, new)
     fprintf(f, '%s', new);
     fclose(f);
 
-    [rc, diff] = system(['diff -u ' fnold ' ' fnnew]);
+    [rc, diff] = system(['git --no-pager diff --no-index ' diffopts ' --word-diff=plain ' fnold ' ' fnnew]);
     disp(diff);
     delete(fnold);
     delete(fnnew);
@@ -56,16 +100,18 @@ function updated = process_param(op, block, param, opts)
     old_content = get_param(block, param);
 
     if strcmp(param, 'MaskType') || ...
-       strcmp(param, 'MaskPromptString'),
+       strcmp(param, 'MaskPromptString') || ...
+       strcmp(param, 'Name'),
         new_content = deblank(new_content);
     end
 
     if ~strcmp(old_content, new_content),
         if strcmp(op, 'diff'),
             disp([block ': ' param ' not up-to-date'])
-            print_diff(fn, param, old_content, new_content)
+            print_diff(fn, param, old_content, new_content, '')
         else
             set_param(block, param, new_content)
+            print_diff(fn, param, old_content, new_content, '--no-color')
         end
         updated = 1;
     else