function bSuccess = fCleanAllFileAlignment(vPath, varargin)
%fCleanAllFileAlignment clean m-file alignments in vPath
%
% bSuccess = fCleanAllFileAlignment(vPath, varargin)
%
% varargin = {bCreateIndexFile} : create index file after cleaning process
%
% Function for cleaning m-file alignments in vPath.
%
% Example: bSuccess = fCleanAllFileAlignment(pwd);
%
% Author: Dipl.-Ing. Andr Manfred Strobel
% Copyright: 1999-2001 by DaimlerChrysler AG, FT1/AK
% Matlab: 6.1, R12.1 (Win)
% Date: 2001/09/26 11:00
% Version: 001.12 * Released * / beta / alpha
% Release: 01.00
if isequal(computer, ['PCWIN'])
% computer system is Microsoft Windows
cbWinSystem = -1; % system is windows
cStandardSlash = ['\']; % define the standard slash
else
% computer system is not Microsoft Windows
cbWinSystem = 0; % system is not windows (probably unix type)
% error(['Vecmo only works with Microsoft Windows'])
% break; % break install procedure
cStandardSlash = ['/']; % define the standard slash
end % of if
% initialize outputs
bSuccess = -1; % init success variable with true
% get variable inputs
if ((size(varargin, 1) > 0) | (size(varargin, 2) > 0))
% there is an additional input
if isnumeric(varargin{1})
% additional input is a numeric value
bCreateIndexFile = varargin{1}(1); % only take first value (no matter what dimension)
else
% additional input is not a numeric value
error(['Additional input has wrong data type (must be a numeric value interpreted as boolean).'])
end % of if
else
% there is no additional input
bCreateIndexFile = 0; % don't create an index file
end % of if
% get all subdirectories
vSubs = fAllSubDirectories(vPath); % get cell array of all subdirectories in vPath
vSubs{size(vSubs, 1) + 1} = vPath; % add the path itself as last subdirectory
vSubs = fVectorOrientation(vSubs, 'column'); % ensure column vector orientation
% cleaning file alignment
disp(['Cleaning file alignment:'])
vOldCurrentDirectory = cd; % save current directory
for i = 1:1:size(vSubs, 1)
% for all subdirectories do
vCurrentPath = vSubs{i}; % current path
if isequal(vCurrentPath(size(vCurrentPath, 2)), cStandardSlash)
% last character of vCurrentPath is backslah
vCurrentPath = vCurrentPath(1:(size(vCurrentPath, 2) - 1)); % remove last backslash (character)
end % of if
cd(vCurrentPath); % change to current subdirectory
% get all files
vFiles = fAllFiles(vCurrentPath); % get all files in the current path
for j = 1:1:size(vFiles, 1)
% for all files in the current subdirectory do
if isequal(fRight(vFiles{j}, 2), ['.m'])
% file is m-file
fprintf(['%s%s\n'], ['...'], vFiles{j}); % display file name
bSuccess = bSuccess & fCleanFileAlignment({vFiles{j}}); % actual clean statement and success management
end % of if
end % of for j
end % of for i
cd(vOldCurrentDirectory); % change back to old current directory
% creating index file if necessary
if bCreateIndexFile
% create index file
if ~fCreateIndexFile({vPath, [''], -1})
% unsuccessful operation
warning(['Couldn''t create index file.'])
end % of if
end % of if