From: Steven Lord on

"Mason Freed" <mfreedREMOVETHIS(a)mfreedREMOVETHIS.com> wrote in message
news:hvo7qt$2bh$1(a)fred.mathworks.com...
> "Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message
> <hvo77o$naj$1(a)fred.mathworks.com>...
>
>> No magic suggestions for the simple reason that Matlab m-files should not
>> have a space in their filenames... If you're doing check-in sanity checks
>> as you wrote above then this would be one obvious source of reported
>> error.
>>
>> Yair Altman http://UndocumentedMatlab.com
>
> Thanks. I was under the impression originally that the issue occurred on
> PATHS with spaces in the name (e.g. "C:\Documents and settings") but
> you're exactly right. The only issue is with file NAMES that contain
> spaces. So no issue at all (and a good addition to the check!).

For that check, you will want to use ISVARNAME. That will detect if the
name of your script or function file violates any of these rules:

1) Names must be NAMELENGTHMAX or fewer characters
2) Names must start with a letter
3) Names must contain only letters, numbers, and underscore
4) Names must not be a keyword (see ISKEYWORD)

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: dpb on
Steven Lord wrote:
> "Mason Freed" <mfreedREMOVETHIS(a)mfreedREMOVETHIS.com> wrote in message
> news:hvo7qt$2bh$1(a)fred.mathworks.com...
....

>> Thanks. I was under the impression originally that the issue occurred on
>> PATHS with spaces in the name (e.g. "C:\Documents and settings") but
>> you're exactly right. The only issue is with file NAMES that contain
>> spaces. So no issue at all (and a good addition to the check!).
>
> For that check, you will want to use ISVARNAME. That will detect if the
> name of your script or function file violates any of these rules:
>
> 1) Names must be NAMELENGTHMAX or fewer characters
> 2) Names must start with a letter
> 3) Names must contain only letters, numbers, and underscore
> 4) Names must not be a keyword (see ISKEYWORD)

Leaving only the issue of possible name collisions throughout a large
project, maybe...?

--

From: Yair Altman on
> > > Any updates on this question?? There MUST be some way to distinguish
> > > warnings from syntax errors using the mlint() function. The information is
> > > obviously there - the editor shows them in different colors.
> > >
> > > Anybody?
> >
> > What do you intend to do with this information? Do you want simply to check
> > if the function _can_ run without actually running it? Or do you want to
> > get a list of errors so that you can tell someone specifically what
> > lines/sections to fix?

> My solution was to use the undocumented internal function mlintmex, as follows:
>
> errMsgs = mlintmex('-m2', srcFileName);
> allMsgs = mlintmex('-m0', srcFileName);
>
> numErrors = length(strfind(regexprep(errMsgs,'\*\*\*.*',''),char(10)));
> numAllMsg = length(strfind(regexprep(allMsgs,'\*\*\*.*',''),char(10)));
> numWarns = numAllMsg - numErrors;
>
> (and from the messages themselves I extracted the actual error/warning location)

Apparently, the built-in mlint function has an undocumented feature of accepting any mlintmex input argument. After all, all mlint's args are passed to mlintmex that actually does all the lint processing. This undocumented feature is even documented in an internal comment within the mlint.m file, although the actual extra args are not themselves documented.

So, in summary, you could simply do:
errMsgs = mlint('-m2',srcFileNames); % m2 = errors only
m1Msgs = mlint('-m1',srcFileNames); % m1 = errors and severe warnings only
allMsgs = mlint('-m0',srcFileNames); % m0 = all errors and warnings

Note that mlint returns the data in struct format, while mlintmex returns a string that you must parse.

Yair Altman
http://UndocumentedMatlab.com
From: us on
"Yair Altman" <altmanyDEL(a)gmailDEL.comDEL> wrote in message <hvo3ak$aeb$1(a)fred.mathworks.com>...
> "Mason Freed" wrote in message ...
> > First, thanks Yair. Your suggestion works perfectly, in a handful of lines. How do you find all of your nifty undocumented stuff?
>
> There are two main sources: reading/searching this newsgroup and reading the internal code of Matlab's m-files. I make a habit of noting down new stuff which is undocumented - then when the need occurs (often years later), I have an immediate answer.
>
> Here's another thread that documents mlintmex usage that you may find useful, which I posted a few years ago: http://www.mathworks.com/matlabcentral/newsreader/view_thread/145245
>
> In this particular case, I think I learned about mlintmex from the indomitable Us (Urs) Schwartz, but I can't find the original reference now. He also posted the related utilities FDEP and FARG on the File Exchange that you may find useful (as are all of his utilities). In any case, Us posted the following humorous comment about the source of *his* knowledge some years ago: http://www.mathworks.com/matlabcentral/newsreader/view_thread/115423#292260
>
> Yair Altman
> http://UndocumentedMatlab.com

just a note
the file below (please, use the ...view original format... to copy/paste!) runs through all currently known MLINT/MLINTMEX options (2010a) and collects each option in an output struct with respective fieldnames...
additional notes:
- some options (eg, -yacc, -ud) will take some time(!!!!!)...
- the copy may have wrapped the syntax falsly...

% example
r=doli('unique');
[r.call.message]

us
<<<<< FILE >>>>>

%DOLI MLINT a file with various options
%
%SYNTAX
%-------------------------------------------------------------------------------
% R = DOLI(FNAM);
% use MLINT
%
% R = DOLI(FNAM,1);
% use MLINTMEX
%
%OUTPUT
%-------------------------------------------------------------------------------
% R : output struct with fieldnames == MLINT option
% and content of output
% retrieve messages, eg,
% [R.calls.message]
%
% other help removed for posting

%-------------------------------------------------------------------------------
function r=doli(varargin)

% created:
% us 12-Feb-2001 us(a)neurol.unizh.ch
% modified:
% us 23-Jun-2010 15:43:22
%
% localid: us(a)USZ|ws-nos-36362|x86|Windows XP|7.10.0.499.R2010a

opt={
% option remarks
% -------------------------------
'-all'
'-allmsg'
'-amb'
'-body'
'-callops'
'-calls'
'-com'
'-cyc'
% '-db' % == -set + -ud + -tab
'-dty'
'-edit'
'-en' % messages in english
'-id'
'-ja' % messages in japanese
'-lex'
'-m0' % + other opt
'-m1' % + other opt
'-m2' % + other opt
'-m3' % + other opt
'-mess'
'-msg'
'-notok'
'-pf'
'-set'
'-spmd'
'-stmt'
'-tab'
'-tmtree'
'-tmw' % not valid anymore
'-toks'
'-tree'
'-ty'
'-ud'
'-yacc' % ONLY: !mlint FILE -yacc -...

% default behavior of DOLI
% '-struct' % output -> struct
};

r.o=opt;
if ~nargin
help(mfilename);
return;
end
if nargin > 1
eng=(a)mlint;
else
eng=(a)mlintmex;
end
fnam=which(varargin{1});
if isempty(fnam)
disp(sprintf('DOLI> file not found %s',varargin{1}));
return;
end

fmt=max(cellfun('length',opt(:,1)));
fmt=sprintf('%%-6s> %%-%d.%ds %%d',fmt,fmt);

disp(sprintf('%s > %s','MLINT',fnam))
for i=1:size(opt,1);
copt=opt{i,1};
sopt=copt(2:end);
if strcmp(sopt,'yacc')
[tmp,tmp]=system(sprintf('mlint %s -yacc -m3',fnam)); %#ok
else
tmp=eng(fnam,copt,'-struct');
end
if iscell(tmp)
tmp=tmp{:};
end
disp(sprintf(fmt,'OPTION',copt,numel(tmp)));
r.(sopt)=tmp;
end
end
%-------------------------------------------------------------------------------
From: us on
"us "
> % example
> r=doli('unique');
> [r.call.message]

must read

[r.calls.message]

sorry for confusion
us