From 3a223e9c0866982a701513bb959b54ea51d1448d Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 3 Dec 2019 12:04:49 +0100
Subject: [PATCH] fix uncommon bug in parsing dynare command line options

previously, `nopathchange` and `nopreprocessoroutput` were set even if they were values instead of option names.

`nopathchange` would further remove all options that contained `'nopathchange'`

e.g. `dynare example1.mod savemacro=nopathchange` would erroneously set `nopathchange` to true and would delete the `savemacro` option altogether

In the fix, just check that the match starts in position 1 as, if the argument passed is longer than the matching pattern (e.g. nopathchangee), the preprocessor will stop processing with a usage error
---
 matlab/dynare.m | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/matlab/dynare.m b/matlab/dynare.m
index d5b86f54bb..324261e436 100644
--- a/matlab/dynare.m
+++ b/matlab/dynare.m
@@ -51,15 +51,12 @@ change_path_flag = true;
 % Filter out some options.
 preprocessoroutput = true;
 if nargin>1
-    id = strfind(varargin,'nopathchange');
-    if ~all(cellfun(@isempty, id))
+    id = ismember(varargin, 'nopathchange');
+    if any(id)
         change_path_flag = false;
-        varargin(cellfun(@isempty, id) == 0) = [];
-    end
-    id = strfind(varargin, 'nopreprocessoroutput');
-    if ~all(cellfun(@isempty, id))
-        preprocessoroutput = false;
+        varargin(id) = [];
     end
+    preprocessoroutput = ~ismember('nopreprocessoroutput', varargin);
 end
 
 % Check matlab path
-- 
GitLab