Skip to content
Snippets Groups Projects
Commit 9f7d3524 authored by Johannes Pfeifer's avatar Johannes Pfeifer
Browse files

Add check for valid filename

Uses the same restrictions as variable names.
parent c6cf5ea6
Branches
Tags
No related merge requests found
...@@ -96,6 +96,10 @@ end ...@@ -96,6 +96,10 @@ end
% Testing if file have extension % Testing if file have extension
% If no extension default .mod is added % If no extension default .mod is added
dot_location=(strfind(fname,'.'));
if length(dot_location)>1
error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions')
end
if isempty(strfind(fname,'.')) if isempty(strfind(fname,'.'))
fnamelength = length(fname); fnamelength = length(fname);
fname1 = [fname '.dyn']; fname1 = [fname '.dyn'];
...@@ -106,9 +110,10 @@ if isempty(strfind(fname,'.')) ...@@ -106,9 +110,10 @@ if isempty(strfind(fname,'.'))
fname = fname1; fname = fname1;
% Checking file extension % Checking file extension
else else
if ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... if dot_location~=length(fname)-3 ... %if the file name has fewer than 4 characters and there is a period
|| ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ...
&& ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN') && ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN')
error('DYNARE: argument must be a filename with .mod or .dyn extension') error('DYNARE: argument must be a filename with .mod or .dyn extension and must not include any other periods')
end; end;
fnamelength = length(fname) - 4; fnamelength = length(fname) - 4;
end; end;
...@@ -155,6 +160,10 @@ if ~exist(fname,'file') || isequal(fname,'dir') ...@@ -155,6 +160,10 @@ if ~exist(fname,'file') || isequal(fname,'dir')
error(['dynare:: can''t open ' fname]) error(['dynare:: can''t open ' fname])
end end
if ~isvarname(fname(1:end-4))
error('DYNARE: argument of dynare must conform to Matlab''s convention for naming functions, i.e. start with a letter and not contain special characters. Please rename your MOD-file.')
end
% pre-dynare-preprocessor-hook % pre-dynare-preprocessor-hook
if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/priorprocessing.m'],'file') if exist(fname(1:end-4),'dir') && exist([fname(1:end-4) filesep 'hooks'],'dir') && exist([fname(1:end-4) filesep 'hooks/priorprocessing.m'],'file')
run([fname(1:end-4) filesep 'hooks/priorprocessing']) run([fname(1:end-4) filesep 'hooks/priorprocessing'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment