From 38be99ed8d352ad27ce68a0a5886294ff05c445b Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Wed, 23 Oct 2019 13:05:58 +0200
Subject: [PATCH] replace `filesep` with `/`

On Windows, `filesep` evaluates to `\` and, in a `*printf` statement, this can have unintended consequences (e.g. `\t` evaluates to the tab character

Since '/' works on all systems, replace all occurrences of `filesep` with `/` in the codebase
---
 src/@graph/writeGraphFile.m        | 10 +++++-----
 src/@page/write.m                  |  4 ++--
 src/@report/compile.m              |  4 ++--
 src/@report/write.m                |  2 +-
 src/@report_table/writeTableFile.m | 10 +++++-----
 src/initialize_reporting_toolbox.m |  2 +-
 6 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/@graph/writeGraphFile.m b/src/@graph/writeGraphFile.m
index 0c0cf30..c12c6fd 100644
--- a/src/@graph/writeGraphFile.m
+++ b/src/@graph/writeGraphFile.m
@@ -39,16 +39,16 @@ if ne < 1
     return
 end
 
-if exist([rep_dir filesep o.graphDirName], 'dir') ~= 7
-    mkdir([rep_dir filesep o.graphDirName]);
+if exist([rep_dir '/' o.graphDirName], 'dir') ~= 7
+    mkdir([rep_dir '/' o.graphDirName]);
 end
 if isempty(o.graphName)
-    graphName = sprintf([o.graphDirName filesep 'graph_pg%d_sec%d_row%d_col%d.tex'], pg, sec, row, col);
+    graphName = sprintf([o.graphDirName '/graph_pg%d_sec%d_row%d_col%d.tex'], pg, sec, row, col);
 else
-    graphName = [o.graphDirName filesep o.graphName];
+    graphName = [o.graphDirName '/' o.graphName];
 end
 
-[fid, msg] = fopen([rep_dir filesep graphName], 'w');
+[fid, msg] = fopen([rep_dir '/' graphName], 'w');
 if fid == -1
     error(['@graph.writeGraphFile: ' msg]);
 end
diff --git a/src/@page/write.m b/src/@page/write.m
index 51e4a6a..15f27ae 100644
--- a/src/@page/write.m
+++ b/src/@page/write.m
@@ -42,11 +42,11 @@ end
 fprintf(fid, '\n');
 
 if ~isempty(o.latex)
-    dir = [rep_dir filesep o.pageDirName];
+    dir = [rep_dir '/' o.pageDirName];
     if exist(dir, 'dir') ~= 7
         mkdir(dir);
     end
-    pagename = [dir filesep 'page_' num2str(pg) '.tex'];
+    pagename = [dir '/page_' num2str(pg) '.tex'];
     [fidp, msg] = fopen(pagename, 'w');
     if fidp == -1
         error(['@page.write: ' msg]);
diff --git a/src/@report/compile.m b/src/@report/compile.m
index 78dcc6e..a2e62a7 100644
--- a/src/@report/compile.m
+++ b/src/@report/compile.m
@@ -57,7 +57,7 @@ assert(ischar(opts.compiler), '@report.compile: compiler file must be a string')
 assert(islogical(opts.showReport), '@report.compile: showReport must be either true or false');
 assert(islogical(opts.showOutput), '@report.compile: showOutput must be either true or false');
 
-if exist([o.directory filesep o.fileName], 'file') ~= 2
+if exist([o.directory '/' o.fileName], 'file') ~= 2
     o.write();
 end
 
@@ -111,7 +111,7 @@ if status ~= 0
            '  ' opts.compiler ' returned the error code: ' num2str(status)]);
 end
 if o.showOutput || opts.showOutput
-    fprintf('Done.\n\nYour compiled report is located here:\n  %s.pdf\n\n\n', [pwd filesep rfn])
+    fprintf('Done.\n\nYour compiled report is located here:\n  %s.pdf\n\n\n', [pwd '/' rfn])
 end
 if opts.showReport && ~isoctave
     open([rfn '.pdf']);
diff --git a/src/@report/write.m b/src/@report/write.m
index 0707f93..a1872f1 100644
--- a/src/@report/write.m
+++ b/src/@report/write.m
@@ -31,7 +31,7 @@ function o = write(o)
 if exist(o.directory, 'dir') ~= 7
     mkdir(o.directory);
 end
-[fid, msg] = fopen([o.directory filesep o.fileName], 'w');
+[fid, msg] = fopen([o.directory '/' o.fileName], 'w');
 if fid == -1
     error(['@report.write: ' msg]);
 end
diff --git a/src/@report_table/writeTableFile.m b/src/@report_table/writeTableFile.m
index bfc2a9b..144f816 100644
--- a/src/@report_table/writeTableFile.m
+++ b/src/@report_table/writeTableFile.m
@@ -40,16 +40,16 @@ if ne == 0 && ~is_data_table
     return
 end
 
-if exist([rep_dir filesep o.tableDirName], 'dir') ~= 7
-    mkdir([rep_dir filesep o.tableDirName]);
+if exist([rep_dir '/' o.tableDirName], 'dir') ~= 7
+    mkdir([rep_dir '/' o.tableDirName]);
 end
 if isempty(o.tableName)
-    tableName = sprintf([o.tableDirName filesep 'table_pg%d_sec%d_row%d_col%d.tex'], pg, sec, row, col);
+    tableName = sprintf([o.tableDirName '/table_pg%d_sec%d_row%d_col%d.tex'], pg, sec, row, col);
 else
-    tableName = [o.tableDirName filesep o.tableName];
+    tableName = [o.tableDirName '/' o.tableName];
 end
 
-[fid, msg] = fopen([rep_dir filesep tableName], 'w');
+[fid, msg] = fopen([rep_dir '/' tableName], 'w');
 if fid == -1
     error(['@report_table.writeTableFile: ' msg]);
 end
diff --git a/src/initialize_reporting_toolbox.m b/src/initialize_reporting_toolbox.m
index e51c565..f421b17 100644
--- a/src/initialize_reporting_toolbox.m
+++ b/src/initialize_reporting_toolbox.m
@@ -24,5 +24,5 @@ function initialize_reporting_toolbox()
 reporting_src_root = strrep(which('initialize_reporting_toolbox'), 'initialize_reporting_toolbox.m', '');
 
 % Add path to reporting source
-addpath([reporting_src_root filesep '..' filesep 'macros']);
+addpath([reporting_src_root '/../macros']);
 end
-- 
GitLab