37 #if defined (HAVE_CONFIG_H) 50 #if defined (HAVE_ZLIB_H) 63 #include "builtin-defun-decls.h" 120 size_t pos =
mode.find (
'W');
122 if (pos != std::string::npos)
125 pos =
mode.find (
'R');
127 if (pos != std::string::npos)
130 pos =
mode.find (
'A');
132 if (pos != std::string::npos)
135 pos =
mode.find (
'z');
137 if (pos != std::string::npos)
139 #if defined (HAVE_ZLIB) 150 size_t bpos =
mode.find (
'b');
151 size_t tpos =
mode.find (
't');
153 if (bpos == std::string::npos && tpos == std::string::npos)
158 static std::ios::openmode
161 std::ios::openmode
retval = std::ios::in;
165 else if (
mode ==
"wt")
167 else if (
mode ==
"at")
168 retval = std::ios::out | std::ios::app;
169 else if (
mode ==
"r+t" ||
mode ==
"rt+")
170 retval = std::ios::in | std::ios::out;
171 else if (
mode ==
"w+t" ||
mode ==
"wt+")
173 else if (
mode ==
"a+t" ||
mode ==
"at+")
174 retval = std::ios::in | std::ios::out | std::ios::app;
175 else if (
mode ==
"rb" ||
mode ==
"r")
176 retval = std::ios::in | std::ios::binary;
177 else if (
mode ==
"wb" ||
mode ==
"w")
179 else if (
mode ==
"ab" ||
mode ==
"a")
180 retval = std::ios::out | std::ios::app | std::ios::binary;
181 else if (
mode ==
"r+b" ||
mode ==
"rb+" ||
mode ==
"r+")
182 retval = std::ios::in | std::ios::out | std::ios::binary;
183 else if (
mode ==
"w+b" ||
mode ==
"wb+" ||
mode ==
"w+")
186 else if (
mode ==
"a+b" ||
mode ==
"ab+" ||
mode ==
"a+")
187 retval = (std::ios::in | std::ios::out | std::ios::app
190 error (
"invalid mode specified");
209 if (args.length () != 1)
225 if (args.length () != 1)
254 if (args.length () != 1)
301 int nargin = args.length ();
343 int nargin = args.length ();
361 return ovl (-1.0, 0.0);
385 int nargin = args.length ();
427 if (! (md & std::ios::out))
432 #if defined (HAVE_ZLIB) 437 int fd = fileno (
fptr);
439 gzFile gzf = ::gzdopen (fd,
mode.c_str ());
445 retval.error (std::strerror (errno));
456 retval.error (std::strerror (errno));
600 if (args(0).is_string ())
606 if (
nargout < 2 && args(0).string_value () ==
"all")
633 int error_number = 0;
678 if (args.length () > 0)
679 warning (
"freport: ignoring extra arguments");
700 if (args.length () != 1)
736 int nargin = args.length ();
747 return ovl (
os.
seek (args(1), origin_arg));
758 if (args.length () != 1)
774 if (! (
nargin > 1 || (
nargin > 0 && args(0).is_string ())))
784 if (args(0).is_string ())
792 if (! args(fmt_n).is_string ())
793 error (
"%s: format TEMPLATE must be a string", who.c_str ());
802 tmp_args(
i-fmt_n-1) = args(
i);
834 return printf_internal (interp, who, args,
nargout);
893 return puts_internal (interp, who, args);
916 DEFUN (sprintf, args, ,
948 error (
"%s: unable to create output buffer", who.c_str ());
953 error (
"%s: format TEMPLATE must be a string", who.c_str ());
963 tmp_args(
i-1) = args(
i);
994 if (! args(1).is_string ())
995 error (
"%s: format TEMPLATE must be a string", who.c_str ());
997 if (
nargin == 3 && args(2).is_string ())
1007 ? args(2).vector_value ()
1070 return scanf_internal (interp, who, args);
1078 if (!
val.is_string ())
1079 error (
"%s: argument STRING must be a string", who.c_str ());
1088 DEFUN (sscanf, args, ,
1110 std::string data = get_scan_string_data (args(0), who);
1115 error (
"%s: unable to create temporary input buffer", who.c_str ());
1117 if (! args(1).is_string ())
1118 error (
"%s: format TEMPLATE must be a string", who.c_str ());
1120 if (
nargin == 3 && args(2).is_string ())
1172 if (args(0).is_string ())
1174 std::string data = get_scan_string_data (args(0), who);
1179 error (
"%s: unable to create temporary input buffer", who.c_str ());
1197 else if (args(1).is_string ())
1199 fmt = args(1).string_value ();
1201 if (args(1).is_sq_string ())
1207 error (
"%s: FORMAT must be a string", who.c_str ());
1213 if (args(2).isnumeric ())
1215 ntimes = args(2).idx_type_value ();
1217 if (ntimes < args(2).double_value ())
1218 error (
"%s: REPEAT = %g is too large",
1219 who.c_str (), args(2).double_value ());
1503 return textscan_internal (interp, who, args);
1506 DEFMETHOD (__textscan__, interp, args, ,
1516 return textscan_internal (interp, args(0).string_value (),
2256 ## Test unfinished comment 2258 %!
c = textscan (
"1 2 /* half comment",
"%n %u8",
"CommentStyle", {
"/*",
"*/"});
2259 %! assert (
c, {1, 2});
2261 ## Test reading from a real file 2264 %!
fid = fopen (
f,
"w+");
2266 %! fprintf (
fid,
" %f %f /* comment */ %f %f ",
d);
2267 %! fseek (
fid, 0,
"bof");
2268 %!
A = textscan (
fid,
"%f %f",
"CommentStyle", {
"/*",
"*/"});
2272 %! assert (
A{1}, [
d(1);
d(3)], 1
e-6);
2273 %! assert (
A{2}, [
d(2);
d(4)], 1
e-6);
2307 input_type, output_type);
2309 catch (octave::execution_exception&
e)
2311 error (
e,
"fread: invalid PRECISION specified");
2320 catch (octave::execution_exception&
e)
2322 error (
e,
"fread: SKIP must be an integer");
2330 return os.
read (size, block_size, input_type, output_type, skip,
2507 if (
nargin > idx && ! args(idx).is_string ())
2545 catch (octave::execution_exception&
e)
2547 error (
e,
"fwrite: invalid PRECISION specified");
2556 catch (octave::execution_exception&
e)
2558 error (
e,
"fwrite: SKIP must be an integer");
2644 return ovl (
os.
eof () ? 1.0 : 0.0);
2647 DEFMETHODX (
"ferror", Fferror, interp, args, ,
2683 clear = (opt ==
"clear");
2686 int error_number = 0;
2690 return ovl (error_message, error_number);
2734 std::string name = args(0).xstring_value (
"popen: COMMAND must be a string");
2735 std::string mode = args(1).xstring_value (
"popen: MODE must be a string");
2747 else if (
mode ==
"w")
2754 error (
"popen: invalid MODE specified");
2759 DEFMETHODX (
"pclose", Fpclose, interp, args, ,
2776 DEFUN (tempname, args, ,
2804 dir = args(0).xstring_value (
"tempname: DIR must be a string");
2811 pfx = args(1).xstring_value (
"tempname: PREFIX must be a string");
2903 error (
"tmpfile: failed to create octave_stdiostream object");
2911 retval =
ovl (-1, std::strerror (errno));
2945 std::string tmpl8 = args(0).xstring_value (
"mkstemp: TEMPLATE argument must be a string");
2950 strcpy (
tmp, tmpl8.c_str ());
2957 retval(2) = std::strerror (errno);
2961 const char *fopen_mode =
"w+b";
2963 FILE *
fid = fdopen (fd, fopen_mode);
2968 retval(2) = std::strerror (errno);
2979 error (
"mkstemp: failed to create octave_stdiostream object");
2997 convert (
int x,
int ibase,
int obase)
3001 int tmp =
x % obase;
3003 if (
tmp > ibase - 1)
3004 error (
"umask: invalid digit");
3008 while ((
x = (
x -
tmp) / obase))
3012 if (
tmp > ibase - 1)
3013 error (
"umask: invalid digit");
3022 DEFUNX (
"umask", Fumask, args, ,
3043 int mask = args(0).xint_value (
"umask: MASK must be an integer");
3046 error (
"umask: MASK must be a positive integer value");
3048 int oct_mask = convert (mask, 8, 10);
3053 return ovl (status);
3067 DEFUNX (
"P_tmpdir", FP_tmpdir, args, ,
3089 DEFUNX (
"SEEK_SET", FSEEK_SET, args, ,
3097 return const_value (
"SEEK_SET", args, -1);
3100 DEFUNX (
"SEEK_CUR", FSEEK_CUR, args, ,
3108 return const_value (
"SEEK_CUR", args, 0);
3111 DEFUNX (
"SEEK_END", FSEEK_END, args, ,
3119 return const_value (
"SEEK_END", args, 1);
3147 DEFMETHODX (
"stdout", Fstdout, interp, args, ,
3161 DEFMETHODX (
"stderr", Fstderr, interp, args, ,
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
std::string error(bool clear, int &err_num)
std::string list_open_files(void) const
static std::ios::openmode fopen_mode_to_ios_mode(const std::string &mode)
int octave_mkostemp_wrapper(char *tmpl)
stream_list & get_stream_list(void)
For example cd octave end example noindent changes the current working directory to file
int int_value(bool req_int=false, bool frc_str_conv=false) const
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
int unlink(const std::string &name)
OCTINTERP_API void print_usage(void)
identity matrix If supplied two scalar respectively For allows like xample val
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
string_vector get_info(int fid) const
std::string tempnam(const std::string &dir, const std::string &pfx)
std::string xstring_value(const char *fmt,...) const
std::string tilde_expand(const std::string &name)
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)
octave::stream_list & streams
printf("%s\, nthargout(2, "system", "cmd"))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
octave_value_list splice(octave_idx_type offset, octave_idx_type len, const octave_value_list &lst=octave_value_list()) const
float_format string_to_float_format(const std::string &s)
double lo_ieee_inf_value(void)
static void normalize_fopen_mode(std::string &mode, bool &use_zlib)
octave_value textscan(const std::string &fmt, octave_idx_type ntimes, const octave_value_list &options, const std::string &who, octave_idx_type &count)
std::string getl(octave_idx_type max_len, bool &err, const std::string &who)
octave::mach_info::float_format flt_fmt
octave_value stdin_file(void) const
#define DEFMETHODX(name, fname, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method with certain internal name.
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
octave_value scanf(const std::string &fmt, const Array< double > &size, octave_idx_type &count, const std::string &who)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &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)
fputs(in, "these\re\ome\trings\)
stream lookup(int fid, const std::string &who="") const
std::stack< std::string > tmp_files
nd deftypefn *std::string name
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
F77_RET_T const F77_INT F77_CMPLX * A
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 octave::stream create(const std::string &n, gzFile f=nullptr, 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)
OCTAVE_EXPORT octave_value_list or both For fclose
bool is_valid(void) const
int octave_unlink_wrapper(const char *nm)
octave_value stdout_file(void) const
off_t skipl(off_t count, bool &err, const std::string &who)
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())
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
std::complex< T > trunc(const std::complex< T > &x)
bool is_true(const std::string &s)
FILE * octave_tmpfile_wrapper(void)
octave_value open_file_numbers(void) const
int puts(const std::string &s, const std::string &who)
With real return the complex result
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, mach_info::float_format flt_fmt, octave_idx_type &count)
int seek(off_t offset, int origin)
void warning(const char *fmt,...)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
int printf(const std::string &fmt, const octave_value_list &args, const std::string &who)
void mark_for_deletion(const std::string &file)
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_sq_string(void) const
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())
OCTINTERP_API std::string do_string_escapes(const std::string &s)
FloatComplex(* fptr)(const FloatComplex &, float, int, octave_idx_type &)
Array< double > xvector_value(const char *fmt,...) const
int remove(int fid, const std::string &who="")
octave_value_list oscanf(const std::string &fmt, const std::string &who)
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
octave_idx_type length(void) const
octave_value stderr_file(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
static octave::stream create(const std::string &n, FILE *f=nullptr, 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)
octave::sys::file_stat fs(filename)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
bool is_string(void) const
static data_type string_to_data_type(const std::string &s)
OCTAVE_EXPORT octave_value_list error nd deftypefn *const octave_scalar_map err
std::string gets(octave_idx_type max_len, bool &err, const std::string &who)
int get_file_number(const octave_value &fid) const
std::string get_P_tmpdir(void)
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())
Vector representing the dimensions (size) of an Array.
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
octave_value_list & prepend(const octave_value &val)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x