37 #if defined (HAVE_CONFIG_H)
50 #if defined (HAVE_ZLIB_H)
121 tmp_files.push (file);
127 while (! tmp_files.empty ())
148 size_t pos = mode.find (
'W');
150 if (pos != std::string::npos)
153 "fopen: treating mode \"W\" as equivalent to \"w\"");
157 pos = mode.find (
'R');
159 if (pos != std::string::npos)
162 "fopen: treating mode \"R\" as equivalent to \"r\"");
166 pos = mode.find (
'A');
168 if (pos != std::string::npos)
171 "fopen: treating mode \"A\" as equivalent to \"a\"");
175 pos = mode.find (
'z');
177 if (pos != std::string::npos)
179 #if defined (HAVE_ZLIB)
190 size_t bpos = mode.find (
'b');
191 size_t tpos = mode.find (
't');
193 if (bpos == std::string::npos && tpos == std::string::npos)
198 static std::ios::openmode
201 std::ios::openmode
retval = std::ios::in;
204 retval = std::ios::in;
205 else if (mode ==
"wt")
207 else if (mode ==
"at")
208 retval = std::ios::out | std::ios::app;
209 else if (mode ==
"r+t" || mode ==
"rt+")
210 retval = std::ios::in | std::ios::out;
211 else if (mode ==
"w+t" || mode ==
"wt+")
213 else if (mode ==
"a+t" || mode ==
"at+")
214 retval = std::ios::in | std::ios::out | std::ios::app;
215 else if (mode ==
"rb" || mode ==
"r")
216 retval = std::ios::in | std::ios::binary;
217 else if (mode ==
"wb" || mode ==
"w")
219 else if (mode ==
"ab" || mode ==
"a")
220 retval = std::ios::out | std::ios::app | std::ios::binary;
221 else if (mode ==
"r+b" || mode ==
"rb+" || mode ==
"r+")
222 retval = std::ios::in | std::ios::out | std::ios::binary;
223 else if (mode ==
"w+b" || mode ==
"wb+" || mode ==
"w+")
226 else if (mode ==
"a+b" || mode ==
"ab+" || mode ==
"a+")
227 retval = (std::ios::in | std::ios::out | std::ios::app
230 error (
"invalid mode specified");
249 if (
args.length () != 1)
263 if (
args.length () != 1)
290 if (
args.length () != 1)
308 retval = os.
flush ();
337 if (nargin < 1 || nargin > 2)
349 return ovl (tmp, tmp.length ());
375 int nargin =
args.length ();
377 if (nargin < 1 || nargin > 2)
389 return ovl (tmp, tmp.length ());
391 return ovl (-1.0, 0.0);
415 int nargin =
args.length ();
417 if (nargin < 1 || nargin > 2)
426 off_t tmp = os.
skipl (count_arg, err, who);
455 if (! (md & std::ios::out))
460 #if defined (HAVE_ZLIB)
463 FILE *
fptr = std::fopen (fname.c_str (), mode.c_str ());
465 int fd = fileno (fptr);
467 gzFile gzf = ::gzdopen (fd, mode.c_str ());
473 retval.
error (std::strerror (errno));
478 FILE *fptr = std::fopen (fname.c_str (), mode.c_str ());
484 retval.error (std::strerror (errno));
504 retval = do_stream_open (name, mode, arch, fid);
610 int nargin =
args.length ();
612 if (nargin < 1 || nargin > 3)
619 if (
args(0).is_string ())
625 if (
nargout < 2 &&
args(0).string_value () ==
"all")
652 int error_number = 0;
654 retval =
ovl (-1.0, os.
error (
false, error_number));
683 if (
args.length () > 0)
684 warning (
"freport: ignoring extra arguments");
703 if (
args.length () != 1)
737 int nargin =
args.length ();
739 if (nargin < 2 || nargin > 3)
757 if (
args.length () != 1)
786 int nargin =
args.length ();
788 if (! (nargin > 1 || (nargin > 0 &&
args(0).is_string ())))
796 if (
args(0).is_string ())
804 if (!
args(fmt_n).is_string ())
805 error (
"%s: format TEMPLATE must be a string", who.c_str ());
809 if (nargin > 1 + fmt_n)
814 tmp_args(
i-fmt_n-1) =
args(
i);
817 result = os.
printf (
args(fmt_n), tmp_args, who);
845 int nargin =
args.length ();
852 if (!
args(0).is_string ())
853 error (
"%s: format TEMPLATE must be a string", who.c_str ());
865 result = stdout_stream.
printf (
args(0), tmp_args, who);
889 if (
args.length () != 2)
912 if (
args.length () != 1)
936 int nargin =
args.length ();
950 error (
"%s: unable to create output buffer", who.c_str ());
955 error (
"%s: format TEMPLATE must be a string", who.c_str ());
1033 int nargin =
args.length ();
1035 if (nargin < 2 || nargin > 3)
1042 if (!
args(1).is_string ())
1043 error (
"%s: format TEMPLATE must be a string", who.c_str ());
1045 if (nargin == 3 &&
args(2).is_string ())
1054 ?
args(2).vector_value ()
1060 retval =
ovl (tmp, count, os.
error ());
1072 error (
"%s: argument STRING must be a string", who.c_str ());
1096 int nargin =
args.length ();
1098 if (nargin < 2 || nargin > 3)
1108 error (
"%s: unable to create temporary input buffer", who.c_str ());
1110 if (!
args(1).is_string ())
1111 error (
"%s: format TEMPLATE must be a string", who.c_str ());
1113 if (nargin == 3 &&
args(2).is_string ())
1132 retval =
ovl (tmp, count, errmsg,
1133 (os.
eof () ? data.length () : os.
tell ()) + 1);
1149 int nargin =
args.length ();
1168 if (
args(0).is_string ())
1175 error (
"%s: unable to create temporary input buffer", who.c_str ());
1189 else if (
args(1).is_string ())
1191 fmt =
args(1).string_value ();
1193 if (
args(1).is_sq_string ())
1199 error (
"%s: FORMAT must be a string", who.c_str ());
1205 if (
args(2).is_numeric_type ())
1207 ntimes =
args(2).idx_type_value ();
1209 if (ntimes <
args(2).double_value ())
1210 error (
"%s: REPEAT = %g is too large",
1211 who.c_str (),
args(2).double_value ());
1225 return ovl (result, count, errmsg);
1228 DEFUN (textscan, args, ,
1495 return textscan_internal (who, args);
1498 DEFUN (__textscan__, args, ,
1508 return textscan_internal (
args(0).string_value (), args.
splice (0, 1));
2203 ## Test unfinished comment
2205 %!
c = textscan (
"1 2 /* half comment",
"%n %u8",
"CommentStyle", {
"/*",
"*/"});
2206 %! assert (
c, {1, 2});
2208 ## Test reading from a real file
2211 %! fid = fopen (
f,
"w+");
2213 %! fprintf (fid,
" %f %f /* comment */ %f %f ",
d);
2214 %! fseek (fid, 0,
"bof");
2215 %!
A = textscan (fid,
"%f %f",
"CommentStyle", {
"/*",
"*/"});
2219 %! assert (
A{1}, [
d(1);
d(3)], 1
e-6);
2220 %! assert (
A{2}, [
d(2);
d(4)], 1
e-6);
2254 input_type, output_type);
2256 catch (octave::execution_exception&
e)
2258 error (e,
"fread: invalid PRECISION specified");
2267 catch (octave::execution_exception& e)
2269 error (e,
"fread: SKIP must be an integer");
2277 return os.
read (size, block_size, input_type, output_type, skip,
2281 DEFUN (fread, args, ,
2452 int nargin = args.
length ();
2454 if (nargin < 1 || nargin > 5)
2466 if (nargin > idx && !
args(idx).is_string ())
2485 octave_value tmp = do_fread (os, size, prec, skip, arch, count);
2487 return ovl (tmp, count);
2504 catch (octave::execution_exception& e)
2506 error (e,
"fwrite: invalid PRECISION specified");
2515 catch (octave::execution_exception& e)
2517 error (e,
"fwrite: SKIP must be an integer");
2525 return os.
write (data, block_size, output_type, skip, flt_fmt);
2528 DEFUN (fwrite, args, ,
2550 int nargin = args.
length ();
2552 if (nargin < 2 || nargin > 5)
2599 return ovl (os.
eof () ? 1.0 : 0.0);
2623 int nargin = args.
length ();
2625 if (nargin < 1 || nargin > 2)
2636 clear = (opt ==
"clear");
2639 int error_number = 0;
2643 return ovl (error_message, error_number);
2687 std::string name =
args(0).xstring_value (
"popen: COMMAND must be a string");
2688 std::string mode =
args(1).xstring_value (
"popen: MODE must be a string");
2698 else if (mode ==
"w")
2705 error (
"popen: invalid MODE specified");
2725 DEFUN (tempname, args, ,
2745 int nargin = args.
length ();
2753 dir =
args(0).xstring_value (
"tempname: DIR must be a string");
2760 pfx =
args(1).xstring_value (
"tempname: PREFIX must be a string");
2818 DEFUN (tmpfile, args, ,
2849 error (
"tmpfile: failed to create octave_stdiostream object");
2855 retval =
ovl (-1, std::strerror (errno));
2861 DEFUN (mkstemp, args, ,
2885 int nargin = args.
length ();
2887 if (nargin < 1 || nargin > 2)
2890 std::string tmpl8 =
args(0).xstring_value (
"mkstemp: TEMPLATE argument must be a string");
2895 strcpy (tmp, tmpl8.c_str ());
2902 retval(2) = std::strerror (errno);
2906 const char *fopen_mode =
"w+b";
2908 FILE *fid = fdopen (fd, fopen_mode);
2913 retval(2) = std::strerror (errno);
2924 error (
"mkstemp: failed to create octave_stdiostream object");
2940 convert (
int x,
int ibase,
int obase)
2944 int tmp = x % obase;
2946 if (tmp > ibase - 1)
2947 error (
"umask: invalid digit");
2951 while ((x = (x - tmp) / obase))
2955 if (tmp > ibase - 1)
2956 error (
"umask: invalid digit");
2958 retval += mult *
tmp;
2986 int mask =
args(0).xint_value (
"umask: MASK must be an integer");
2989 error (
"umask: MASK must be a positive integer value");
2991 int oct_mask = convert (mask, 8, 10);
2996 return ovl (status);
3053 return const_value (
"SEEK_SET", args, -1);
3064 return const_value (
"SEEK_CUR", args, 0);
3075 return const_value (
"SEEK_END", args, 1);
3098 return const_value (
"stdin", args, stdin_file);
3110 return const_value (
"stdout", args, stdout_file);
3123 return const_value (
"stderr", args, stderr_file);
void warning_with_id(const char *id, const char *fmt,...)
static std::ios::openmode fopen_mode_to_ios_mode(const std::string &mode)
fputs(in,"these\nare\nsome\nstrings\n")
int octave_mkostemp_wrapper(char *tmpl)
bool is_true(const std::string &s)
static octave_stream stdout_stream
For example cd octave end example noindent changes the current working directory to file
static octave_value stdin_file
octave_value reshape(const dim_vector &dv) const
static octave_stream stdin_stream
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, octave::mach_info::float_format flt_fmt)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
nd group nd example oindent or xample printf("%s\n", nthargout(2,"system","cmd"))
int unlink(const std::string &name)
OCTINTERP_API void print_usage(void)
static string_vector get_info(int fid)
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
octave_idx_type length(void) const
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
std::string tempnam(const std::string &dir, const std::string &pfx)
int seek(off_t offset, int origin)
int int_value(bool req_int=false, bool frc_str_conv=false) const
OCTINTERP_API octave_value_list FSEEK_END(const octave_value_list &=octave_value_list(), int=0)
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
double lo_ieee_inf_value(void)
static void normalize_fopen_mode(std::string &mode, bool &use_zlib)
size_type size(const size_type d) const
Size of the specified dimension.
static octave_stream create(const std::string &n, std::ios::openmode arg_md=std::ios::in, octave::mach_info::float_format flt_fmt=octave::mach_info::native_float_format())
off_t skipl(off_t count, bool &err, const std::string &who)
octave::mach_info::float_format flt_fmt
static octave_stream create(std::ostream *arg, const std::string &n="")
OCTINTERP_API octave_value_list Fumask(const octave_value_list &=octave_value_list(), int=0)
std::string xstring_value(const char *fmt,...) const
OCTINTERP_API octave_value_list Fpclose(const octave_value_list &=octave_value_list(), int=0)
static std::string tilde_expand(const std::string &)
static octave_value stdout_file
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
static std::string getenv(const std::string &name)
void cleanup_tmp_files(void)
int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
static int do_fwrite(octave_stream &os, const octave_value &data, const octave_value &prec_arg, const octave_value &skip_arg, const octave_value &arch_arg)
static octave_stream stderr_stream
std::stack< std::string > tmp_files
static int insert(octave_stream &os)
OCTINTERP_API octave_value_list FSEEK_SET(const octave_value_list &=octave_value_list(), int=0)
OCTINTERP_API octave_value_list Fferror(const octave_value_list &=octave_value_list(), int=0)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
OCTINTERP_API octave_value_list Ffeof(const octave_value_list &=octave_value_list(), int=0)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
static float_format string_to_float_format(const std::string &)
octave_idx_type numel(const octave_value_list &idx)
static octave_stream create(std::istream *arg=0, const std::string &n="")
std::string string_value(bool force=false) const
OCTINTERP_API octave_value_list Fstdout(const octave_value_list &=octave_value_list(), int=0)
int octave_unlink_wrapper(const char *nm)
bool is_string(void) const
OCTINTERP_API octave_value_list FP_tmpdir(const octave_value_list &=octave_value_list(), int=0)
static octave_value stderr_file
#define DEFUNX(name, fname, args_name, nargout_name, doc)
int puts(const std::string &s, const std::string &who)
static void clear(bool flush=true)
octave_value_list splice(octave_idx_type offset, octave_idx_type len, const octave_value_list &lst=octave_value_list()) const
static int remove(int fid, const std::string &who="")
static octave_stream create(const char *data, std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format())
FILE * octave_tmpfile_wrapper(void)
std::string error(bool clear, int &err_num)
static octave_stream lookup(int fid, const std::string &who="")
OCTINTERP_API octave_value_list FSEEK_CUR(const octave_value_list &=octave_value_list(), int=0)
octave_value_list oscanf(const std::string &fmt, const std::string &who)
OCTINTERP_API octave_value_list Fpopen(const octave_value_list &=octave_value_list(), int=0)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
octave_value textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
With real return the complex result
static octave_stream create(const std::string &n, gzFile f=0, int fid=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_zfile_ptr_buf::close_fcn cf=c_zfile_ptr_buf::file_close)
void warning(const char *fmt,...)
octave_value read(const Array< double > &size, octave_idx_type block_size, oct_data_conv::data_type input_type, oct_data_conv::data_type output_type, octave_idx_type skip, octave::mach_info::float_format flt_fmt, octave_idx_type &count)
void mark_for_deletion(const std::string &file)
static octave_stream create(const std::string &n, FILE *f=0, std::ios::openmode m=std::ios::in|std::ios::out, octave::mach_info::float_format ff=octave::mach_info::native_float_format(), c_file_ptr_buf::close_fcn cf=c_file_ptr_buf::file_close)
bool is_sq_string(void) const
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
bool is_valid(void) const
OCTINTERP_API octave_value_list Fstderr(const octave_value_list &=octave_value_list(), int=0)
OCTINTERP_API std::string do_string_escapes(const std::string &s)
=val(i)}if ode{val(i)}occurs in table i
static std::string list_open_files(void)
static octave_value open_file_numbers(void)
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
octave::sys::file_stat fs(filename)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
static octave_stream create(const std::string &n, std::ios::openmode arg_md=std::ios::out, octave::mach_info::float_format flt_fmt=octave::mach_info::native_float_format())
static data_type string_to_data_type(const std::string &s)
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
OCTINTERP_API octave_value_list Fstdin(const octave_value_list &=octave_value_list(), int=0)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
void initialize_file_io(void)
std::string get_P_tmpdir(void)
Vector representing the dimensions (size) of an Array.
OCTINTERP_API octave_value_list Ffscanf(const octave_value_list &=octave_value_list(), int=0)
std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
static int get_file_number(const octave_value &fid)
static void clear(octave::dynamic_library &oct_file)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Array< double > xvector_value(const char *fmt,...) const
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
F77_RET_T const F77_INT F77_CMPLX * A