]> 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 9d277a87328ae2c2b80e9ba2ce4f8569849d38ac..cf6f102a541252572cf588aa0d5ff4ea85ac0ac8 100644 (file)
@@ -1,13 +1,29 @@
-% Copyright (C) 2013-2014 Czech Technical University in Prague
+% Copyright (C) 2013-2015 Czech Technical University in Prague
 %
 % Authors:
 %     - Carlos Jenkins <carlos@jenkins.co.cr>
 %     - Michal Sojka <sojkam1@fel.cvut.cz>
 %
-% This document contains proprietary information belonging to Czech
-% Technical University in Prague. Passing on and copying of this
-% document, and communication of its contents is not permitted
-% without prior written authorization.
+% 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:
@@ -26,24 +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);
-
-    disp(['Processing ' blocks{i}]);
+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);
 
-    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!!!
+        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
@@ -54,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);
@@ -65,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);
@@ -84,9 +108,10 @@ function updated = process_param(op, block, param, opts)
     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