Skip to content

Commit

Permalink
external/toolboxUpdateHeader.m: generalizing to update c headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pdollar committed Oct 26, 2014
1 parent 70e23ea commit 39c63c2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
3 changes: 2 additions & 1 deletion external/history.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Version NEW
-changed toolbox name to "Piotr's Computer Vision Matlab Toolbox"
-added Mac binaries (mexmaci64)
-added Mac 64 bit binaries (mexmaci64)
-gradientMex, rgbConvertMex, imtransform2_c: fixed compiler warnings on Mac
-toolboxCompile: disable OMP on Mac by default (OMP is tricky to setup on Mac)
-toolboxUpdateHeader.m: generalizing to update c headers
-bbApply.m>draw(): minor fix (thanks Michele Pratusevich)

Version 3.26 (15-July-2014)
Expand Down
58 changes: 31 additions & 27 deletions external/toolboxUpdateHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,49 @@
% Licensed under the Simplified BSD License [see external/bsd.txt]

header={
'% Piotr''s Computer Vision Matlab Toolbox Version 3.26'; ...
'% Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]'; ...
'% Licensed under the Simplified BSD License [see external/bsd.txt]'};
'Piotr''s Computer Vision Matlab Toolbox Version 3.26'; ...
'Copyright 2014 Piotr Dollar. [pdollar-at-gmail.com]'; ...
'Licensed under the Simplified BSD License [see external/bsd.txt]'};

% must start in /toolbox base directory
cd(fileparts(mfilename('fullpath'))); cd('../');
dirs={ 'channels', 'classify', 'classify/private', 'detector', ...
'filters', 'images', 'images/private', 'matlab', 'external', 'videos' };
root=fileparts(fileparts(mfilename('fullpath')));
ds=dir(root); ds=ds([ds.isdir]); ds={ds.name};
ds=ds(3:end); ds=setdiff(ds,{'.git','doc'});
subds = { '/', '/private/' };
exts = {'m','c','cpp','h','hpp'};
omit = {'Contents.m','fibheap.h','fibheap.cpp'};

% update the headers
for i=1:length(dirs)
mFiles = dir([ dirs{i}, '/*.m' ]);
disp( ['--------------------------------->' dirs{i}] );
for j=1:length(mFiles);
fName = [dirs{i} '/' mFiles(j).name]; disp( fName );
toolboxUpdateHeader1( fName, header );
for i=1:length(ds)
for j=1:length(subds)
for k=1:length(exts)
d=[root '/' ds{i} subds{j}];
if(k==1), comment='%'; else comment='*'; end
fs=dir([d '*.' exts{k}]); fs={fs.name}; fs=setdiff(fs,omit);
n=length(fs); for f=1:n, fs{f}=[d fs{f}]; end
for f=1:n, toolboxUpdateHeader1(fs{f},header,comment); end
end
end
end

end

function toolboxUpdateHeader1( fName, header )
lines=readFile(fName); n=length(lines);
function toolboxUpdateHeader1( fName, header, comment )

% find first part of first lines of header in file
loc = strfind(lines,header{1}(1:30));
for i=1:n, if(~isempty(loc{i})), break; end; end; loc=i;
% set appropriate comment symbol in header
m=length(header); for i=1:m, header{i}=[comment ' ' header{i}]; end

% if not found nothing to do, ow assert nHeader lines exist
nHeader = length(header);
if(loc>n-nHeader+1), warning([fName ' no header']); return; end %#ok<WNTAG>
for i=1:nHeader; assert( strfind(lines{loc+i-1},header{i}(1:10))>0 ); end
% read in file and find header
disp(fName); lines=readFile(fName);
loc = find(not(cellfun('isempty',strfind(lines,header{1}(1:40)))));
if(isempty(loc)), error('NO HEADER: %s\n',fName); end; loc=loc(1);

% check if first lines changed, if so update; optionally update rest
% check that header is properly formed, return if up to date
for i=1:m; assert(isequal(lines{loc+i-1}(1:10),header{i}(1:10))); end
if(~any(strfind(lines{loc},'NEW'))); return; end

% update copyright year and overwrite rest of header
lines{loc+1}(13:16)=header{2}(13:16);
for i=[1 3:nHeader]; lines{loc+i-1}=header{i}; end
assert(isempty(lines{loc-1}) || strcmp(lines{loc-1},'%'));
lines{loc-1} = '%'; writeFile( fName, lines );
for i=[1 3:m]; lines{loc+i-1}=header{i}; end
writeFile( fName, lines );

end

Expand Down

0 comments on commit 39c63c2

Please sign in to comment.