Mercurial > hg > octave-nkf
diff src/file-io.cc @ 9701:531280b07625
implement fskipl
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 07 Oct 2009 11:08:54 +0200 |
parents | 66fdc831c580 |
children | 09da0bd91412 |
line wrap: on
line diff
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -396,6 +396,47 @@ return retval; } +DEFUN (fskipl, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} fskipl (@var{fid}, @var{count})\n\ +Skips a given number of lines, i.e. discards characters until an end-of-line\n\ +is met exactly @var{count}-times, or end-of-file occurs.\n\ +Returns the number of lines skipped (end-of-line sequences encountered).\n\ +If @var{count} is omitted, it defaults to 1. @var{count} may also be\n\ +@code{Inf}, in which case lines are skipped to the end of file.\n\ +This form is suitable for counting lines in a file.\n\ +@seealso{fgetl, fgets}\n\ +@end deftypefn") +{ + static std::string who = "fskipl"; + + octave_value retval; + + int nargin = args.length (); + + if (nargin == 1 || nargin == 2) + { + octave_stream os = octave_stream_list::lookup (args(0), who); + + if (! error_state) + { + octave_value count_arg = (nargin == 2) ? args(1) : octave_value (); + + bool err = false; + + long tmp = os.skipl (count_arg, err, who); + + if (! (error_state || err)) + retval = tmp; + } + } + else + print_usage (); + + return retval; +} + + static octave_stream do_stream_open (const std::string& name, const std::string& mode, const std::string& arch, int& fid)