changeset 222:6671cb83a2dd

Make use of is_valid_file_id for fid checks
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Wed, 21 May 2014 17:56:22 +0200
parents 470586565dc7
children 8b159045242f
files inst/ufl.m
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/inst/ufl.m	Mon May 19 23:18:33 2014 +0200
+++ b/inst/ufl.m	Wed May 21 17:56:22 2014 +0200
@@ -31,13 +31,13 @@
   filename = "default.ufl";
 
   if (numel (varargin) < 1)
-    if (fid < 0)
+    if (! is_valid_file_id (fid))
       print_usage ();
     endif
   elseif (! all (cellfun ("ischar", varargin)))
     error ("ufl: all arguments should be strings");
   elseif (strcmpi (varargin{1}, "start"))
-    if (fid >= 0)
+    if (is_valid_file_id (fid))
       error ("ufl: a file is already open");
     else
       if (numel (varargin) > 1)
@@ -48,21 +48,25 @@
       endif
       fid = fopen (filename, "w");
     endif
-    if (fid < 0)
+    if (! is_valid_file_id (fid))
       error (["ufl: could not open file ", filename]);
     endif
   elseif (strcmpi (varargin{1}, "end"))
-    if (fid < 0)
+    if (! is_valid_file_id (fid))
       error ("ufl: no open file");
     else
       fclose (fid);
       fid = -1;
     endif
-  elseif (fid < 0)
+  elseif (! is_valid_file_id (fid))
     error ("ufl: no open file");
   else
-    fprintf (fid, "%s ", varargin{:});
-    fprintf (fid, "\n");
+    if (is_valid_file_id (fid))
+      fprintf (fid, "%s ", varargin{:});
+      fprintf (fid, "\n");
+    else
+      error ("ufl: no open file");
+    endif
   endif
 
 endfunction